chromebookdev
chromebookdev

Reputation: 494

pyodbc informix getting blank select with >1 variable

Using win10/64bit informix odbc driver.

I’m finding I get an empty result of the cursor.execute command when using two variables.

Making the execute command of:

(“””SELECT FIRST 10 accountcode FROM database WHERE ? LIKE ?”””, var1, var2)

But the results from that are always blank.

var1 = ‘catalog_code’
var2 = ‘cat1’

If I rewrite and replace the first variable, manually typing the field name, or using an inline variable +var1+ Then I get the correct result.

Is this a pyodbc issue? Syntax or type issue with my first variable?

Upvotes: 0

Views: 83

Answers (1)

Jonathan Leffler
Jonathan Leffler

Reputation: 754470

It isn’t 100% clear why you expect any data to be returned. You can’t select column names via placeholders. Treated as string literals, the names you give are not the same. The underscore metacharacter does not appear in the second position. Even if the variables we're reversed, the LIKE would still fail.

Upvotes: 1

Related Questions