python - MySQLdb execute -
i have searched high , low on site , many others , have found similar questions, none of answers have worked me (usually accounting tuple). i'm writing python script parse html pages , populate database. have working except populating part...
here code segment deals mysql database (note: using mysqldb module in python)
conn = mysqldb.connect(user="root", passwd="xxxxx",db="nutrients") cur = conn.cursor() test = "canned corn" cur.execute("insert food (name) values (%s)", (test,)) conn.commit() i first testing parsed string wasn't working. gives me 2 errors:
traceback (most recent call last): file "c:\python32\lib\site-packages\mysqldb\cursors.py", line 171, in execute r = self._query(query) file "c:\python32\lib\site-packages\mysqldb\cursors.py", line 330, in _query rowcount = self._do_query(q) file "c:\python32\lib\site-packages\mysqldb\cursors.py", line 294, in _do_query db.query(q) _mysql_exceptions.programmingerror: (1064, "you have error in sql syntax ; check manual corresponds mysql server version right s yntax use near '%s)' @ line 1")
traceback (most recent call last): file "c:\python32\lib\site-packages\mysqldb\cursors.py", line 171, in execute r = self._query(query) file "c:\python32\lib\site-packages\mysqldb\cursors.py", line 330, in _query rowcount = self._do_query(q) file "c:\python32\lib\site-packages\mysqldb\cursors.py", line 294, in _do_query db.query(q) _mysql_exceptions.programmingerror: (1064, "you have error in sql syntax ; check manual corresponds mysql server version right s yntax use near '%s)' @ line 1")
why query not work!?
update: after pulling hair out decided revert 2.7.3 , guess what... works :d should have know error of type... none less everyone!
i think don't need tricky or advanced sql; need store , retrieve stuff. so, think orm might make life lot easier you.
i suggest try using autumn orm:
http://pypi.python.org/pypi/autumn/0.5.1
that small , simple orm, easy understand , work with.
another , popular orm python sqlalchemy:
Comments
Post a Comment