Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

refactor

  • Loading branch information...
commit 874fb7418a1a2cb7f1175607db8c18884fd35084 1 parent 76706aa
Qiangning Hong authored
7 oursql/connections.py
View
@@ -47,13 +47,6 @@ def _connect(self):
self.password, self.db, False, self.charset)
def query(self, sql, args):
- result = self._query(sql, args)
- if isinstance(result, tuple):
- return result[0] # affected rows
- else:
- return result
-
- def _query(self, sql, args):
try:
return self._umysql_conn.query(sql, args)
except umysql.Error, exc:
9 oursql/cursors.py
View
@@ -3,7 +3,12 @@
from .utils import setdocstring
class Cursor(pymysql.cursors.Cursor):
- setdocstring(pymysql.cursors.Cursor)
- def execute(self, query, args=()):
+ @setdocstring(pymysql.cursors.Cursor)
+ def execute(self, query, args=None):
conn = self._get_db()
+
+ if args is None:
+ args = ()
+ elif not isinstance(args, (tuple, list, dict)):
+ args = (args,)
return conn.query(query, args)
10 tests/test_oursql_dbapi20.py
View
@@ -5,15 +5,15 @@
import oursql
def setup_module():
+ @apply
def print_sqls():
print "patch"
import oursql.connections
- orig_query = oursql.connections.Connection._query
- def _query(self, *a, **kw):
- print a, kw
+ orig_query = oursql.connections.Connection.query
+ def query(self, *a, **kw):
+ print "QUERY:", a, kw
return orig_query(self, *a, **kw)
- oursql.connections.Connection._query = _query
- print_sqls()
+ oursql.connections.Connection.query = query
class test_oursql(dbapi20.DatabaseAPI20Test):
driver = oursql
Please sign in to comment.
Something went wrong with that request. Please try again.