MySQL Forums
Forum List  »  Perl

Re: executing an SQL statement
Posted by: Randy Clamons
Date: April 11, 2007 03:21PM

Ok, the error message is all Perl. Your sql command string isn't properly formed--and it probably won't work the way you expect. I would format your sql command in Perl, then send the whole thing to mysql. A combination of localtime and sprintf should work.

Try something like this:

@date = localtime(time) ;

# this formats the date for you, but leaves leading spaces
$date = sprintf("%4d%2d%2d",1900+$date[5],$date[4],$date[3]);

# this replaces the spaces with 0's
$date =~ s/\s/0/g ;

# now we can make a filename
$filename = $date.'SS.txt';

# create the sql select statement
$sql = "SELECT Caseid, Updtname, Updtaddr, Updtcsz, Payto, Chkname, Chkaddr, Chkcsz
INTO OUTFILE '$filename' 
FIELDS TERMINATED BY ''
LINES TERMINATED BY '\r\n'
FROM miha2005.miha05
WHERE (Outcome=1 OR Outcome=2) AND Saqlang=3 AND Paid<>1 AND Payto<3 ";

# No we're all set to go

$sth = $dbh->prepare($sql);
$sth->execute ();
$sth->finish ();
$dbh->disconnect ();

There are lots of ways of getting this done. This is just one idea for you.

Options: ReplyQuote


Subject
Written By
Posted
April 10, 2007 04:15PM
April 11, 2007 10:02AM
Re: executing an SQL statement
April 11, 2007 03:21PM
April 11, 2007 03:56PM
April 11, 2007 10:08AM
April 13, 2007 12:26PM
April 17, 2007 04:26PM
April 18, 2007 12:30PM
April 18, 2007 04:02PM
April 23, 2007 04:08PM
April 24, 2007 09:20AM
April 24, 2007 11:39AM
April 24, 2007 02:26PM
April 24, 2007 02:20PM
April 24, 2007 02:31PM
April 24, 2007 03:57PM
April 25, 2007 11:46PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.