http://www.perlmonks.org?node_id=983196


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.

      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 ?