Yet Another MySQL Problem
Victor Subervi
victorsubervi at gmail.com
Thu May 27 09:34:04 EDT 2010
On Thu, May 27, 2010 at 8:34 AM, Victor Subervi <victorsubervi at gmail.com>wrote:
> Hi;
> I have this code:
>
> sql = "insert into %s (%s) values ('%%s');" % (personalDataTable,
> string.join(cols[1:], ', '))
> # cursor.execute(sql, string.join(vals[1:], "', '"))
> cursor.execute('insert into %s (%s) values ("%s");' %
> (personalDataTable, string.join(cols[1:], ', '), string.join(vals[1:], '",
> "')))
>
> Now, if I uncomment the 2nd line and comment the third, the command fails
> because, apparently, that "');" at the tail end of sql (1st line) gets
> chopped off. Why??
>
> (Note to self: enterPeople3.py)
>
...and here's another one:
print 'insert into categories (Store, Category, Parent) values("%s",
"%s", Null)'% (store, cat)
# cursor.execute('insert into categories (Store, Category, Parent)
values("%s", "%s", Null)', (store, cat))
If I print out and manually insert, all goes well. If I uncomment the 2nd
line, it inserts store and cat with single quote marks and screws everything
up!
mysql> select * from categories;
+----+------------+------------+--------+
| ID | Store | Category | Parent |
+----+------------+------------+--------+
| 1 | 'products' | 'prodCat1' | NULL |
| 2 | 'products' | 'prodCat2' | NULL |
+----+------------+------------+--------+
as opposed to
mysql> select * from categories;
+----+------------+------------+--------+
| ID | Store | Category | Parent |
+----+------------+------------+--------+
| 1 | products | prodCat1 | NULL |
| 2 | products | prodCat2 | NULL |
+----+------------+------------+--------+
TIA,
beno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100527/17a84b48/attachment-0001.html>
More information about the Python-list
mailing list