Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Resolving SQL type name error when using qmark style parameters?

Writer Andrew Henderson

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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.