Commits

Michael Trier committed 0628eae

Raised an error when sqlite version does not support default values. Addresses #909 in a purposeful way.

Comments (0)

Files changed (5)

lib/sqlalchemy/databases/sqlite.py

                      "and will cause errors in some cases.  Version 2.1.3 "
                      "or greater is recommended.") %
                     '.'.join([str(subver) for subver in sqlite_ver]))
+            if self.dbapi.sqlite_version_info < (3, 3, 8):
+                self.supports_default_values = False
         self.supports_cast = (self.dbapi is None or vers(self.dbapi.sqlite_version) >= vers("3.2.3"))
 
     def dbapi(cls):
         preparer = self.preparer
 
         if not colparams:
-            return "INSERT INTO %s DEFAULT VALUES" % (
-                (preparer.format_table(insert_stmt.table),))
+            if not self.dialect.supports_default_values:
+                raise exc.NotSupportedError(
+                    "The version of SQLite you are using, %s, does not support DEFAULT VALUES." % (self.dialect.dbapi.sqlite_version))
+
+            return ("INSERT INTO %s DEFAULT VALUES" % (
+                (preparer.format_table(insert_stmt.table),)))
         else:
             return ("INSERT INTO %s (%s) VALUES (%s)" %
                     (preparer.format_table(insert_stmt.table),

lib/sqlalchemy/engine/base.py

       result sets against textual statements where no explicit
       typemap was present.
 
+    supports_default_values
+      Indicates if the construct ``INSERT INTO tablename DEFAULT VALUES`` is supported
     """
 
     def create_connect_args(self, url):

lib/sqlalchemy/engine/default.py

     supports_pk_autoincrement = True
     dbapi_type_map = {}
     default_paramstyle = 'named'
+    supports_default_values = True
 
     def __init__(self, convert_unicode=False, assert_unicode=False, encoding='utf-8', paramstyle=None, dbapi=None, **kwargs):
         self.convert_unicode = convert_unicode

test/dialect/sqlite.py

     __only_on__ = 'sqlite'
 
     # empty insert (i.e. INSERT INTO table DEFAULT VALUES)
-    # fails as recently as sqlite 3.3.6.  passes on 3.4.1.  this syntax
-    # is nowhere to be found in the sqlite3 documentation or changelog, so can't
-    # determine what versions in between it's legal for.
+    # fails on 3.3.7 and before
     def _test_empty_insert(self, table, expect=1):
         try:
             table.create()
         finally:
             table.drop()
 
-    @testing.exclude('sqlite', '<', (3, 4), 'no database support')
+    @testing.exclude('sqlite', '<', (3, 3, 8), 'no database support')
     def test_empty_insert_pk1(self):
         self._test_empty_insert(
             Table('a', MetaData(testing.db),
                   Column('id', Integer, primary_key=True)))
 
-    @testing.exclude('sqlite', '<', (3, 4), 'no database support')
+    @testing.exclude('sqlite', '<', (3, 3, 8), 'no database support')
     def test_empty_insert_pk2(self):
         self.assertRaises(
             exc.DBAPIError,
                   Column('x', Integer, primary_key=True),
                   Column('y', Integer, primary_key=True)))
 
-    @testing.exclude('sqlite', '<', (3, 4), 'no database support')
+    @testing.exclude('sqlite', '<', (3, 3, 8), 'no database support')
     def test_empty_insert_pk3(self):
         self.assertRaises(
             exc.DBAPIError,
                   Column('y', Integer, DefaultClause('123'),
                          primary_key=True)))
 
-    @testing.exclude('sqlite', '<', (3, 4), 'no database support')
+    @testing.exclude('sqlite', '<', (3, 3, 8), 'no database support')
     def test_empty_insert_pk4(self):
         self._test_empty_insert(
             Table('d', MetaData(testing.db),
                   Column('x', Integer, primary_key=True),
                   Column('y', Integer, DefaultClause('123'))))
 
-    @testing.exclude('sqlite', '<', (3, 4), 'no database support')
+    @testing.exclude('sqlite', '<', (3, 3, 8), 'no database support')
     def test_empty_insert_nopk1(self):
         self._test_empty_insert(
             Table('e', MetaData(testing.db),
                   Column('id', Integer)))
 
-    @testing.exclude('sqlite', '<', (3, 4), 'no database support')
+    @testing.exclude('sqlite', '<', (3, 3, 8), 'no database support')
     def test_empty_insert_nopk2(self):
         self._test_empty_insert(
             Table('f', MetaData(testing.db),

test/orm/inheritance/basic.py

         sess.add(s1)
         sess.flush()
         assert sess.query(Sub).get(10) is s1
-    
+
     def test_plain_descriptor(self):
         """test that descriptors prevent inheritance from propigating properties to subclasses."""