From ab2cf9d58b1c668f0861bf076f6582c9a3141c3a Mon Sep 17 00:00:00 2001 From: Vin Date: Tue, 17 Dec 2013 00:48:49 +0000 Subject: [PATCH 1/2] Changed insert_hashes to fit the new data format --- dejavu/database.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) mode change 100644 => 100755 dejavu/database.py diff --git a/dejavu/database.py b/dejavu/database.py old mode 100644 new mode 100755 index 018ddd4..78b1237 --- a/dejavu/database.py +++ b/dejavu/database.py @@ -260,14 +260,13 @@ class SQLDatabase(Database): """ return self.query(None) - def insert_hashes(self, hashes): + def insert_hashes(self, sid, hashes): """ Insert series of hash => song_id, offset values into the database. """ - # TODO: Fix this when hashes will be a new format. values = [] - for hash, (sid, offset) in hashes: + for hash, offset in hashes: values.append((hash, sid, offset)) with self.cursor() as cur: From bed11f3de7b0020f91fcf08458bff3987fdc9f81 Mon Sep 17 00:00:00 2001 From: Wessie Date: Tue, 17 Dec 2013 02:00:05 +0100 Subject: [PATCH 2/2] Switched back to MySQLdb for better support of executemany. --- dejavu/cursor.py | 10 +++++----- dejavu/database.py | 11 ++++++----- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/dejavu/cursor.py b/dejavu/cursor.py index 1b46b52..07649c6 100644 --- a/dejavu/cursor.py +++ b/dejavu/cursor.py @@ -2,8 +2,8 @@ from __future__ import unicode_literals from __future__ import absolute_import import Queue -import pymysql -import pymysql.cursors +import MySQLdb as mysql +import MySQLdb.cursors def cursor_factory(**factory_options): @@ -26,18 +26,18 @@ class Cursor(object): """ _cache = Queue.Queue(maxsize=5) - def __init__(self, cursor_type=pymysql.cursors.DictCursor, **options): + def __init__(self, cursor_type=mysql.cursors.DictCursor, **options): super(Cursor, self).__init__() try: conn = self._cache.get_nowait() except Queue.Empty: - conn = pymysql.connect(**options) + conn = mysql.connect(**options) self.conn = conn self.cursor_type = cursor_type - def __enter__(self): + def __enter__(slf): self.cursor = self.conn.cursor(self.cursor_type) return self.cursor diff --git a/dejavu/database.py b/dejavu/database.py index 78b1237..a08bfcd 100755 --- a/dejavu/database.py +++ b/dejavu/database.py @@ -1,6 +1,8 @@ from __future__ import absolute_import from binascii import unhexlify +from MySQLdb.cursors import Cursor + class Database(object): def __init__(self): super(Database, self).__init__() @@ -274,14 +276,13 @@ class SQLDatabase(Database): def return_matches(self, hashes): """ - Return the (song_id, offset_diff) tuples associated with - a list of + Return the (song_id, offset_diff) tuples associated with + a list of - sha1 => (None, sample_offset) + sha1 => (None, sample_offset) - values. + values. """ - from pymysql.cursors import Cursor # Create a dictionary of hash => offset pairs for later lookups mapper = {} for hash, (_, offset) in hashes: