in reply to (jeffa) Re: weird DBI error re: parameter binding
in thread weird DBI error re: parameter binding

I agree .. I had a Sh*t fit when I saw the table names and field names.. its not my doing.. I'm just workin with what I have.

my $query = q{SELECT x FROM Referrals WHERE [Today's Date]>?}; $sth = $dbh->prepare($query); $sth->execute($date);
produced the error
DBD::ODBC::st execute failed: called with 1 bind variables when 0 are +needed at C:\Documents and Settings\xxx\Desktop\distribute.pl line 263.
I have no idea why this is causing problems. If it were a type mismatch the DBD would probably say so.. .as I have had similar errors in the past. The query does work if I hard code in a value and call with no bind variables however. So at least things aren't THAT screwed up.

edit:I took jeffa's suggestion and just interpolated it like I did before the grand days of discovering parameter binding.. this worked just fine... still bugs me though.

Replies are listed 'Best First'.
Re^3: weird DBI error re: parameter binding (guess)
by tye (Sage) on Jul 30, 2003 at 17:50 UTC

    Sounds like your DBD doesn't handle [ and ] and so sees the ' as the start of a string literal and so doesn't consider the ? to be a placeholder.

                    - tye
      I tried escaping the ' but that didn't work. I agree it probably is the ' causing the problems. I know that Access can handle and because I use them all the time when people put spaces in field names i'm working with.

        Just to be clear, the DBD mostly doesn't need to "handle" [ and ] for them to just be passed along to the database to deal with and to "work".

        The problem is that the DBD code that looks for placeholder ?s knows to not grab ?s inside of quotes but doesn't (at appears) know that it should ignore quotes inside of square brackets.

        I doubt you can escape the single quote in a way that will both be understood by the DBD ?-finding code and correctly understood by the database. The DBD code needs to be enhanced to support this syntax.

                        - tye