Problem with odbc (pywin32) and unicode

Frank Millman frank at
Fri Jan 27 06:18:53 EST 2006

Hi all

I am using odbc from pywin32 to connect to MS SQL Server. I am changing
my program from the old (incorrect) style of embedding values in the
SQL command to the new (correct) style of passing the values as
parameters. I have hit a problem.

The following all work -
    cur.execute("select * from users where userid = '%s'" % 'frank')  #
old style
    cur.execute("select * from users where userid = '%s'" % u'frank')
# old style
    cur.execute("select * from users where userid = ?", ['frank'])  #
new style

This does not work -
    cur.execute("select * from users where userid = ?", [u'frank'])  #
new style

I get the following error -
OdbcError: Found an insert row that didn't have 1 columns [sic]

It is the combination of new style and unicode that does not work.

I realise that odbc is not fully DB-API compliant, but I have got away
with it up to now. Does anyone know of a solution to this problem?


Frank Millman

ps to Fredrik, who just added this to a recent post -

"(just curious, but from where do people get the idea that arbitrary
just have to be inserted into the the SQL statement text all the time?
this some PHP misfeature?) "

I can't answer for anyone else, but this is my excuse.

Sequence of events -

  learn a bit about Python - play in interpreter, write simple scripts,
  learn a bit about SQL - play in an interactive session, run some
commands, etc.
  try to combine the two - wow, it works!
  read in the DB-API about parameter passing - frankly, don't
understand it.
  therefore stick with what works for me.

Parameter passing seems to be one of those things that, if you
understand it, you can't imagine that there is anyone out there that
does not understand it, and therefore you think that the documentation
is perfectly clear. However, if you are one of those unfortunate souls
who have never come across such a thing, the docs simply do do not
spell it out clearly enough, so one's reaction is more 'huh?' than

More information about the Python-list mailing list