On Thu, May 27, 2010 at 8:34 AM, Victor Subervi <victorsube...@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
-- http://mail.python.org/mailman/listinfo/python-list