views:

73

answers:

2

Ok, I'm going crazy on this one. MySQL is throwing a fit about this bit of SQL:

INSERT INTO `test_table` 
  ( `column1`, `column2` ) 
VALUES 
  ( ?COURSEID, ?COURSENAME )

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'COURSENAME )' at line 1

My debug code is showing both of the parameter values filled.

A: 

Not sure if that will work. I would change to either

VALUES (?, ?)

OR

VALUES (:COURSEID, :COURSENAME)

:courseid is Oracle syntax, dunno for any others
OMG Ponies
+1  A: 

MySQL does not support named parameter placeholders. You can use only positional parameter placeholders. That is, a placeholder is just a ? symbol.

This conforms to the ANSI SQL behavior, by the way. RDBMS like Oracle support named parameters as an extension to the standard.

Bill Karwin
Bill, I believe you've identified the problem. In the past I had used named parameters with MySQL, but I had only done so with the MySQL driver for .NET. In this case, I'm using the ODBC driver and I have a feeling it's not handling the named parameters quite the same. Thanks for the heads up thought, I didn't know named parameters weren't officially part of SQL.
T. Stone
Right, if the .NET driver supports named parameters, it must be rewriting the query string before it sends it to the MySQL server. PHP's PDO library does something similar, so you can use named parameters with any back-end, even if it doesn't support named parameters. But it's hard to get that kind of query-rewriting right, for instance a string literal could contain characters that look like a parameter placeholder, so the query parsing in the driver has to be clever enough to tell the difference.
Bill Karwin