Archive of June 2010
python-mysqldb: execute() first
While working on implementing a schema-free, MySQL-backed data store (thanks, Bret Taylor!), I ran into a problem with using MySQLdb to access the database. I’ll eventually post the code I wrote up on this site so others can see my example, but for now the following will suffice. When performing a SELECT, I would get the following error upon attempting to fetch my results.
Incorrect Python:
q = "SELECT body FROM entities WHERE id='%s'" % (entity_id)
self.conn.cursor().execute(q)
entity = self.conn.cursor().fetchone()
Error:
File "datastore.py", line 93, in get
entity = self.conn.cursor().fetchone()
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 340, in fetchone
self._check_executed()
File "/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 70, in _check_executed
self.errorhandler(self, ProgrammingError, "execute() first")
File "/usr/lib/pymodules/python2.6/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.ProgrammingError: execute() first
The issue was using two separate cursor objects. Here’s the corrected code:
c = self.conn.cursor()
q = "SELECT body FROM entities WHERE id='%s'" % (entity_id)
c.execute(q)
entity = c.fetchone()
ERROR: please fix package in OpenWRT
I’m putting together an OpenWRT package for a project I’m working on and ran into a perplexing error message as I was testing my new package’s Makefile:
[shaddi@sloth backfire]$ make menuconfig
ERROR: please fix package/click/Makefile
To get a more descriptive error message, enter the following from the root directory of your OpenWRT source distribution:
TOPDIR=$PWD make -C package/<package_name> DUMP=1
Doing this let me discover that I was using a deprecated description tag inside my Makefile.