[codeface] [PATCH] Fix: python-mysql library requires iterable types

  • From: Mitchell Joblin <joblin.m@xxxxxxxxx>
  • To: codeface@xxxxxxxxxxxxx
  • Date: Wed, 5 Feb 2014 21:52:13 +0100

From: Mitchell Joblin <mitchell.joblin.ext@xxxxxxxxxxx>

- python-mysql requires the queries to be formated like so
  "SELECT id FROM project WHERE name=%s "
    "AND analysisMethod=%s", (name, analysisMethod)

- when the query only has one variable a tuple must still be
  otherwise execution failes
  e.g., ("SELECT id FROM project WHERE name=%s;", (name,))
    not ("SELECT id FROM project WHERE name=%s;", name)

Signed-off-by: Mitchell Joblin <mitchell.joblin.ext@xxxxxxxxxxx>
---
 codeface/cluster/cluster.py | 2 +-
 codeface/dbmanager.py       | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/codeface/cluster/cluster.py b/codeface/cluster/cluster.py
index aa4542b..ecc58e2 100755
--- a/codeface/cluster/cluster.py
+++ b/codeface/cluster/cluster.py
@@ -950,7 +950,7 @@ def writeIDwithCmtStats2File(id_mgr, outdir, 
releaseRangeID, dbm, conf):
 
     # Clear the information before writing new commints
     dbm.doExec("DELETE FROM author_commit_stats WHERE releaseRangeId=%s",
-               (int(releaseRangeID)))
+               (int(releaseRangeID),))
 
     for id in sorted(id_mgr.getPersons().keys()):
         pi = id_mgr.getPI(id)
diff --git a/codeface/dbmanager.py b/codeface/dbmanager.py
index 7954af0..ae21283 100644
--- a/codeface/dbmanager.py
+++ b/codeface/dbmanager.py
@@ -98,7 +98,7 @@ class DBManager:
                     format(name, analysisMethod))
             self.doExecCommit("INSERT INTO project (name, analysisMethod) " +
                         "VALUES (%s, %s);", (name, analysisMethod))
-            self.doExec("SELECT id FROM project WHERE name=%s;", name)
+            self.doExec("SELECT id FROM project WHERE name=%s;", (name,))
         elif self.cur.rowcount > 1:
             raise Exception("Duplicate projects {}/{} in database!".
                     format(name, analysisMethod))
-- 
1.8.1.2


Other related posts:

  • » [codeface] [PATCH] Fix: python-mysql library requires iterable types - Mitchell Joblin