Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Debian DBD::ODBC select row by timestamp

by mje (Curate)
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

Replies are listed 'Best First'.
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.


      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 ./ 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://983196]
[choroba]: Snow here. Good morning nonetheless.
[Corion]: A good morning to you too, Discipulus!
[Discipulus]: ah! buran stroke again?
[choroba]: Not sure what meteorological event it's been, but it's -6 now and lots of snow around.

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2018-03-19 08:06 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (236 votes). Check out past polls.