Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Debian DBD::ODBC select row by timestamp

by mje (Deacon)
on Jul 23, 2012 at 15:51 UTC ( #983196=note: print w/ replies, xml ) Need Help??


in reply to Debian DBD::ODBC select row by timestamp

This happens because your SQL contains colons and ':' is a placeholder introducer. There are 2 ways to fix it. 1) replace '2012-07-22 00:00:00 ' (BTW, notice trailing space) with ? and call execute passing '2012-07-22 00:00:00' as an argument (read about placeholders in DBI). 2) set odbc_ignore_named_placeholders. The first is best.


Comment on Re: Debian DBD::ODBC select row by timestamp
Re^2: Debian DBD::ODBC select row by timestamp
by alexx_sh (Novice) on Jul 23, 2012 at 17:09 UTC
    Can you help me with code? I try read, but i can't write it by my self.
      my $sth = $dbh-> prepare (SELECT val from table where DD_MM_YYYY = ?); $sth->execute('2012-07-22 00:00:00');
      ? is the placeholder. It serves great use and it protects you against SQL injection attacks, by automatically quoting (and thereby neutralising) any "dangerous" characters.

      Of course you should add the usual or die ... checks to make sure no error happened. Also you have to verify the format of the DD_MM_YYY field to make sure your query sends in the timestamp in the right format.

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      My blog: Imperial Deltronics
        when i try your code i get err

        Search pattern not terminated at ./script.pl line 34.

        if i try code like this $dbh-> prepare ('SELECT val from table where DD_MM_YYYY = ?');

        Error at Line : syntax error near ?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-07-30 23:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (241 votes), past polls