Permalink
Browse files

Pass params as tuple to MSSQL. (closes #71)

MYSQL 1.02 doesn't accept params as list. Added hooks to pass params as
tuple only for MSSQL.
  • Loading branch information...
1 parent f9fe1a8 commit 67f1c1831624fdab5e441cb655a7823fc054a5a9 @anandology anandology committed Jun 21, 2011
Showing with 20 additions and 2 deletions.
  1. +20 −2 web/db.py
View
@@ -583,8 +583,8 @@ def _db_execute(self, cur, sql_query):
try:
a = time.time()
- paramstyle = getattr(self, 'paramstyle', 'pyformat')
- out = cur.execute(sql_query.query(paramstyle), sql_query.values())
+ query, params = self._process_query(sql_query)
+ out = cur.execute(query, params)
b = time.time()
except:
if self.printing:
@@ -598,6 +598,14 @@ def _db_execute(self, cur, sql_query):
if self.printing:
print >> debug, '%s (%s): %s' % (round(b-a, 2), self.ctx.dbq_count, str(sql_query))
return out
+
+ def _process_query(self, sql_query):
+ """Takes the SQLQuery object and returns query string and parameters.
+ """
+ paramstyle = getattr(self, 'paramstyle', 'pyformat')
+ query = sql_query.query(paramstyle)
+ params = sql_query.values())
+ return query, params
def _where(self, where, vars):
if isinstance(where, (int, long)):
@@ -1065,6 +1073,16 @@ def __init__(self, **keywords):
self.dbname = "mssql"
DB.__init__(self, db, keywords)
+ def _process_query(self, sql_query):
+ """Takes the SQLQuery object and returns query string and parameters.
+ """
+ # MSSQLDB expects params to be a tuple.
+ # Overwriting the default implementation to convert params to tuple.
+ paramstyle = getattr(self, 'paramstyle', 'pyformat')
+ query = sql_query.query(paramstyle)
+ params = sql_query.values())
+ return query, tuple(params)
+
def sql_clauses(self, what, tables, where, group, order, limit, offset):
return (
('SELECT', what),

0 comments on commit 67f1c18

Please sign in to comment.