views:

202

answers:

1

Hi!

What’s wrong here? This is how I found on examples of Subsonic 2 CodingHorror and doesn't works :(

new CodingHorror().Execute("SELECT * FROM product WHERE IdProduct = @IdProduct", 1);

The error I get is “Parameter '@IdProduct' must be defined

I’m using Subsonic 2.x and MySQL!

Thank you for your help! :)

A: 

Try using ? instead of @Product.

new CodingHorror().Execute("SELECT * FROM product WHERE IdProduct = ?", 1);

MySQL uses a different (vs. SQL Server) syntax to refer to parameters, and since you're using a CodingHorror (aka direct SQL piped to the DB without SubSonic getting in between) you will probably need to use the native parameter syntax of the RDBMS, in this case MySQL.

Take a look at this blog post for a more thorough example of the diffs in parameter syntax between SQL Server and MySQL.

Note that I'm assuming that SubSonic doesn't do anything sneaky (e.g. scan the SQL strings for parameter names and replace them according to DB-specific rules)-- I'm assuming that SubSonic simply passes the SQL string as-is over to the DB.

Justin Grant
Hi,Thank you a lot for your help!It was a good shot, but unfortunately it’s not the solution because Subsonic sneaks the SQL String and with MySQL Parameter syntax Subsonic doesn’t recognize any parameter.SubSonic.SqlQueryException: The parameter count doesn't match up with the values entered - this could be our fault with our parser; please check the list to make sure the count adds up, and if it does, please add some spacing around the parameters in the list.
David
Hmm. Is the parser smart enough to know that "-- @foo" is a comment? If not, that'd be an easy way to fool the parser.
Justin Grant