0

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!

Arash Sharif
  • 542
  • 7
  • 16

2 Answers2

1

IT is expecting a sequence of parameters. Use:

[blah_variable]

kylieCatt
  • 10,672
  • 5
  • 43
  • 51
1

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!
GomoX
  • 919
  • 8
  • 21