Best unofficial Apache Server developers community |
|
I'm trying to use mysqlDB, but I've run into a problem that doesn't make sense to me at all. My problem is centered around the table name in the following execute statements. This works:
Neither of these work:
The thing is, both of the non-working ones result in the same error message:
Notice that in the error message, AIN0 is surrounded by single quotes, even in the case where I inserted it using the string interpolation operator. Just to be sure, I made an intentional syntax error in the working case in order to see what MySQL was looking at.
Sure enough, in the one that MySQL works correctly with, AIN0 is not surrounded by single quotes leading me to believe that that is what is causing the error. Why are single quotes being inserted around my strings when I use string interpolation and how do I get them to stop?
posted via StackOverflow
|
|
 
|
If by "string interpolation" you mean like Python's string formatting, that's NOT what you are using. When you use parameterised SQL, the place holders can appear only where an expression can appear in SQL. A table name is not an expression. When your argument is a string, it is wrapped in single quotes so that in the resultant SQL it looks like an SQL string literal. This involves doubling single quotes e.g. what in Python would appear as a string literal like So, you can't stop it from wrapping single quotes arround it. You need to do two steps: (1) build an SQL string that inserts |