Search code examples
pythonsqlparameterizedadodbapi

Resolving SQL type name error when using qmark style parameters?


I am attempting to make the following parameterized SQL query using a ADO connection through the adodbapi package and I am getting

Type name is invalid

database errors that I can not resolve.

cursor.execute("SELECT * FROM ?", ["Compound"])

This results in the following error:

DatabaseError: (-2147352567, 'Exception occurred.', (0, 'Microsoft SQL Server Compact OLE DB Provider', 'Type name is invalid.', None, 0, -2147217872), None)
Command:
SELECT * FROM ?
Parameters:
[Name: p0, Dir.: Input, Type: adBSTR, Size: 8, Value: "Compound", Precision: 0, NumericScale: 0]

I am assuming Type name is invalid. and Type: adBSTR are the key components of the message but I cannot find information on this data type other than it is a null-terminated unicode character string.

I have tried different string encoding such as

[r"Compound"]
[b"Compound"]
[u"Compound"] 

And the query works fine with the normal string:

cursor.execute("SELECT * FROM Compound")

Is this actually due to the parameter type or maybe the qmark paramstyle implementation?


Solution

  • Table name (as well as a column name) can not be parameterized in Sql. Parameters are designed to pass values of data.