Arash Sharif
Arash Sharif

Reputation: 592

Python oursql treating a string variable as a char array

Forgive my ignorance as I am new to oursql. I'm simply trying to pass a parameter to a statement:

cursor.execute("select blah from blah_table where blah_field = ?", blah_variable)

this treated whatever is inside the blah_variable as a char array so if I pass "hello" it will throw a ProgrammingError telling me that 1 parameter was expected but 5 was given.

I've tried looking through the docs but their examples are not using variables. Thanks!

Upvotes: 0

Views: 234

Answers (2)

GomoX
GomoX

Reputation: 917

The cursor.execute() call expects a params argument that is iterable. The documentation only hints at it, but the code actually unpacks the argument and passes it to another function:

# from oursqlx/cursor.pyx:121
# in Cursor.execute()
        else:
            stmt.execute(*params)

You would need to phrase your call like:

cursor.execute("select blah from blah_table where blah_field = ?", [blah_variable]) # brackets!

Upvotes: 1

kylieCatt
kylieCatt

Reputation: 11039

IT is expecting a sequence of parameters. Use:

[blah_variable]

Upvotes: 1

Related Questions