Re: How to use perl dbi to create a database

2010-06-29 Thread Ashish Mukherjee
http://search.cpan.org/~timb/DBI-1.611/DBI.pm#data_sources

This is how you can check for existence of a database.

- Ashish

On Mon, Jun 28, 2010 at 2:21 PM, Sharma, Sumit sumit.sha...@aeroflex.comwrote:

 Hello,



 I am trying to use Perl to identify if a given database exists or not
 and if it doesn't create the database and then connect to it.



 Is there any way using Perl DBI to first identify whether a given
 database exists or not if it doesn't create the database?



 Sumit


 Notice: This e-mail is intended solely for use of the individual or entity
 to which it is
 addressed and may contain information that is proprietary, privileged,
 company confidential
 and/or exempt from disclosure under applicable law. If the reader is not
 the intended
 recipient or agent responsible for delivering the message to the intended
 recipient, you are
 hereby notified that any dissemination, distribution or copying of this
 communication is
 strictly prohibited. If this communication has been transmitted from a U.S.
 location it may
 also contain data subject to the International Traffic in Arms Regulations
 or U.S. Export
 Administration Regulations and cannot be disseminated, distributed or
 copied to foreign
 nationals, residing in the U.S. or abroad, without the prior approval of
 the U.S. Department
 of State or appropriate export licensing authority. If you have received
 this communication
 in error, please notify the sender by reply e-mail or collect telephone
 call and delete or
 destroy all copies of this e-mail message, any physical copies made of this
 e-mail message
 and/or any file attachment(s).




Re: Issue with prepared statement

2010-06-05 Thread Ashish Mukherjee
Hello,

Generally, there is no gain to using bind parameters if you don't know the
columns to be projected in advance in SELECT and your LIKE regex is also
dynamic. It can't prepare a query execution plan and cache it for later use,
since the basic constructs of your query keep changing.  I am not even sure
you can use a placeholder for a column to be SELECT'ed.

- Ashish

On Sat, Jun 5, 2010 at 2:33 AM, Lethal Possum lethal.pos...@gmail.comwrote:

 Hello,

 I am trying to create a prepared statement for the following query in
 MySQL:

 INSERT IGNORE INTO foo (group, value) (SELECT 101, value FROM bar
 WHERE value LIKE '%something%');

 So far my Perl code looks something like this:

 my $group = 101;
 my $pattern = '%something%';
 my $query = 'INSERT IGNORE INTO foo (group, value) (SELECT ?, value
 FROM bar WHERE value LIKE ?);';
 my $sth = $dbh-prepare($query);
 $sth-execute($id, $pattern) or die($sth-errstr);

 It does not insert anything into the table foo even though there are
 values in table bar that match the pattern. So my question is: what am
 I doing wrong. I have other, simpler prepared queries in my program
 that work just fine but this one does not do anything and does not
 trigger any error as far as I can see.

 Are ? parameters allowed in a nested SELECT?
 Are they allowed not in the WHERE clause?
 Are they allowed with the LIKE operator?

 Thanks in advance for your help.

 Tom