[Tutor] Didn't take long to hit my next wall!
Alan Gauld
alan.gauld at freenet.co.uk
Sun Apr 16 01:08:28 CEST 2006
Hi John,
I've no idea why its not working but this illustrates why I prefer to create
the sql string outside the execute - its a lot easier to debug when you can
print the string exactly as passed to execute. I know many others like to
leave execute to do the escaping stuff but I prefer to see what I'm doing
and put in a little extra effort.
So I would write it as:
query = '''UPDATE cost_grid
SET cost_1 = %s
WHERE cost_grid_id = %s
AND finish_dro = %s'''' % ( a,c,b)
c.execute(query)
Dunno if that helps but its my experience FWIW,
Alan G.
----- Original Message -----
From: "John CORRY" <john.corry at ntlworld.com>
To: <tutor at python.org>
Sent: Saturday, April 15, 2006 10:26 PM
Subject: [Tutor] Didn't take long to hit my next wall!
> Hi,
>
> I am having problems amending records in my database.
>
> If I use the following code my database is updated fine.
>
> c = '"PF1"'
> b = 91.4
> a = 85.00
> import mx.ODBC
> import mx.ODBC.Windows
> db = mx.ODBC.Windows.DriverConnect('DSN=vfp')
> c = db.cursor()
> c.execute('UPDATE cost_grid SET cost_1 = ? where cost_grid_id = "PF1"
> and finish_dro = ?', ( a, b,))
>
> db.commit()
> c.close()
>
> However if I use the following code:-
> Where the only difference is I use the c variable instead of the actual
> "PF1". The database does not get updated. I have also tried
> C = "PF1" but this does not work either.
>
> c = '"PF1"'
> b = 91.4
> a = 85.00
> import mx.ODBC
> import mx.ODBC.Windows
> db = mx.ODBC.Windows.DriverConnect('DSN=vfp')
> c = db.cursor()
> c.execute('UPDATE cost_grid SET cost_1 = ? where cost_grid_id = ? and
> finish_dro = ?', ( a, c,b,))
>
> db.commit()
> c.close()
>
> Any suggestions would be greatly appreciated.
>
> Thanks,
>
> John.
>
More information about the Tutor
mailing list