Created
July 31, 2009 02:12
-
-
Save galvez/159047 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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