Problem with odbc (pywin32) and unicode



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?

Thanks

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
data
just have to be inserted into the the SQL statement text all the time?
is
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,
etc.
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
'aha!'

.



Relevant Pages

  • Re: Sybase Source. What "data flow source" to use?
    ... "Allan Mitchell" wrote: ... when I right-click over a SQL 2005 database and select Import ... datasources defined in ODBC Datasources on my computer, ...
    (microsoft.public.sqlserver.dts)
  • Re: SQL using C
    ... I am almost a new C programmer and now I need to use SQL within my C ... The people who are telling you to use a C API are out of their mind. ... is not less complicated than ODBC and ties the user to a single ...
    (comp.lang.c)
  • Re: Quick primer on Unidata-to-SQL Server Connectivity?
    ... but creating a view and then running an SQL query with more than one ... but somewhat extensive experience with UniData SQL. ... until some things improved in UniData ODBC. ...
    (comp.databases.pick)
  • Re: Sybase Source. What "data flow source" to use?
    ... when I right-click over a SQL 2005 ... database and select Import Data, the list of providers does not include ... either A) the list of datasources defined in ODBC Datasources on my computer, ... I've been so excited about SSIS and telling my co-workers how ...
    (microsoft.public.sqlserver.dts)
  • Re: Access SQL DAYOFWEEK() problem
    ... not a SQL function ... "Duane Hookom" wrote: ... >> Could anyone tell me what is the correct syntax for the scalar functions? ... >> ODBC Scalar Functions ...
    (microsoft.public.access.modulesdaovba)