Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix inserting default values into MySQL. (fixes #49)

  • Loading branch information...
commit b1417f57941500ebc67b2c376a9993421903cbb7 1 parent 42a49ea
@anandology anandology authored
Showing with 11 additions and 2 deletions.
  1. +4 −0 test/db.py
  2. +7 −2 web/db.py
View
4 test/db.py
@@ -112,6 +112,10 @@ def t(active):
self.assertEquals(a, active)
t(False)
t(True)
+
+ def test_insert_default_values(self):
+ db = webtest.setup_database(self.dbname)
+ db.insert("person")
class PostgresTest(DBTest):
dbname = "postgres"
View
9 web/db.py
@@ -487,7 +487,6 @@ def __init__(self, db_module, keywords):
self.db_module = db_module
self.keywords = keywords
-
self._ctx = threadeddict()
# flag to enable/disable printing queries
self.printing = config.get('debug_sql', config.get('debug', False))
@@ -744,7 +743,7 @@ def q(x): return "(" + x + ")"
_values = SQLQuery.join([sqlparam(v) for v in values.values()], ', ')
sql_query = "INSERT INTO %s " % tablename + q(_keys) + ' VALUES ' + q(_values)
else:
- sql_query = SQLQuery("INSERT INTO %s DEFAULT VALUES" % tablename)
+ sql_query = SQLQuery(self._get_insert_default_values_query(tablename))
if _test: return sql_query
@@ -769,6 +768,9 @@ def q(x): return "(" + x + ")"
if not self.ctx.transactions:
self.ctx.commit()
return out
+
+ def _get_insert_default_values_query(self, table):
+ return "INSERT INTO %s DEFAULT VALUES" % table
def multiple_insert(self, tablename, values, seqname=None, _test=False):
"""
@@ -971,6 +973,9 @@ def __init__(self, **keywords):
def _process_insert_query(self, query, tablename, seqname):
return query, SQLQuery('SELECT last_insert_id();')
+
+ def _get_insert_default_values_query(self, table):
+ return "INSERT INTO %s () VALUES()" % table
def import_driver(drivers, preferred=None):
"""Import the first available driver or preferred driver.
Please sign in to comment.
Something went wrong with that request. Please try again.