Resolving Sql Type Name Error When Using Qmark Style Parameters?

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?

1 Answer

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.