database questions ala newbie pythonist

Uwe Grauer news at grauer-online.de
Thu Dec 2 12:25:01 CET 2004


Weinhandl Herbert wrote:
> chris wrote:
> 
> ...
> 
> 
>> This works fine using the literals 0 (For Delstatus) and 1190 (for
>> ProductID)
>> But when I try to use a variable such as:
>>
>> ###################################################################
>> ...
>> varA = '0'
>> varB = '1190'
>> mycursor.execute('Update Categories Set DelStatus = ' varA 'Where 
>> ProductID
>> = ' varB)
> 
> 
> use string formatting expressions
> (which are easier to handle than string concatenation) :
> 
> 'UPDATE Categories SET DelStatus=%d WHERE ProductID=%s;' % (varA,'1190')
> 
> or maybe
> 
> "UPDATE Categories SET DelStatus='%d' WHERE ProductID='%d';" % (0,varB)
> 
> if your DB wants your int's as string
> 
> 

You could also use:
curs.execute('UPDATE Categories SET DelStatus=? WHERE ProductID=?;', 
(varA, 1190))

Uwe




More information about the Python-list mailing list