Skip to content

Instantly share code, notes, and snippets.

@galvez
Created July 31, 2009 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galvez/159047 to your computer and use it in GitHub Desktop.
Save galvez/159047 to your computer and use it in GitHub Desktop.
class DBCursor(MySQLdb.cursors.DictCursor):
def lock_on_string(self, str, timeout=1000):
self.execute('select get_lock(%s, %s);', (str, timeout))
return self.fetchone()
def unlock_on_string(str, timeout=1000):
self.execute('select release_lock(%s);', (str,))
return self.fetchone()
@staticmethod
def instantiate(*args, **kargs):
# fixme: use ConfigFile to load connection info
conn = MySQLdb.connect(host='localhost', user='root', passwd='', db='amp')
cursor = conn.cursor(DBCursor)
setattr(cursor, 'conn', conn)
conn.set_character_set('utf8')
cursor.execute('set names utf8;')
cursor.execute('set character set utf8;')
cursor.execute('set character_set_connection = utf8;')
return cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment