Bobspadger / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

Strange pyodbc.ProgrammingError #102

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello, 

I get a problem during a query on MySQL 5.0.

This is what i'm trying to do:

Connecting to MySQL.. Everything is Ok!

cursor.execute("insert into ? (test) values ('test')", 'connection')
cnxn.commit()

So, it seems that the table name (?) have to be changed with connection.
But unfortunately this is what i get:

C:\>python mysqlC.py asd asd 1
Traceback (most recent call last):
  File "test.py", line 998, in <module>
    cursor.execute("insert into ? (test) values ('test')", 'connection')
pyodbc.ProgrammingError: ('42000', "[42000] [MySQL][ODBC 5.1
Driver][mysqld-5.0.
67-community-nt]You have an error in your SQL syntax; check the manual that
corr
esponds to your MySQL server version for the right syntax to use near
'_latin1'connection' (test) values ('test')' at line 1 (1064)
(SQLExecDirectW)")

Why?

Original issue reported on code.google.com by sectyst...@gmail.com on 6 Jun 2010 at 7:07

GoogleCodeExporter commented 9 years ago
I pass the query directly to the ODBC driver.  Apparently the MySQL driver 
doesn't support passing the table name as a parameter.  (I don't know of any 
drivers that do.)

You'll have to manually build the SQL to change the table.  I would still use 
question marks for actual parameters, though -- it avoids SQL injection attacks.

Original comment by mkleehammer on 20 Aug 2010 at 7:53

GoogleCodeExporter commented 9 years ago

Original comment by mkleehammer on 21 Nov 2010 at 4:43