Python/MySQL Frustration

Victor Subervi victorsubervi at gmail.com
Sun Sep 20 21:26:55 CEST 2009


Yeah, that was the problem..."num" was a string ;) Just caught it myself,
too. Thanks,
V

On Sun, Sep 20, 2009 at 2:37 PM, Philip Semanchuk <philip at semanchuk.com>wrote:

>
> On Sep 20, 2009, at 2:25 PM, Victor Subervi wrote:
>
>  Hi;
>> I have the following code:
>>
>>    while i < num:
>>     cat = 'cat' + str(i)
>>     cat = form.getfirst(cat, '')
>>     item = 'item' + str(i)
>>     item = form.getfirst(item, '')
>>     descr = 'descr' + str(i)
>>     descr = form.getfirst(descr, '')
>>     uom = 'uom' + str(i)
>>     uom = form.getfirst(uom, '')
>>     price = 'price' + str(i)
>>     price = form.getfirst(price, '')
>>     sql = 'Category="' + cat + '", Item="' + item + '", Description="' +
>> descr + '", UOM="' + uom + '", Price="' + price + '"'
>>     sql = 'insert into %s values (%s);' % (company, sql)
>>     cursor.execute(sql)
>>     i += 1
>> Now, all of this posts to the mysql database, but it forms an infinite
>> loop!
>> I have num == 1! I have printed num to make sure it's actually only 1 (or
>> 2,
>> depending). What in the heck am I doing wrong?
>>
>
>
>
> Are you sure that num is a integer and not a string?
>
> What happens when you step through the code with a debugger?
>
> Simplify your code, for your sake and ours. Begin commenting out lines,
> starting with cursor.execute(sql) and working your way up to the first line
> below the while statement. (You can replace the cursor.execute() with a
> print statement to monitor the value of i.) Does your infinite loop
> disappear when you get rid of that stuff?
>
>
> HTH
> Philip
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090920/a0dcf92c/attachment.html>


More information about the Python-list mailing list