]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Added prefixes option to that accepts a list of string to insert after CREATE in...
authorMichael Trier <mtrier@gmail.com>
Sat, 5 Jul 2008 03:31:30 +0000 (03:31 +0000)
committerMichael Trier <mtrier@gmail.com>
Sat, 5 Jul 2008 03:31:30 +0000 (03:31 +0000)
CHANGES
lib/sqlalchemy/schema.py
lib/sqlalchemy/sql/compiler.py
test/engine/metadata.py

diff --git a/CHANGES b/CHANGES
index 50a988c07039373a0585710b27acedc194eb26b2..191a648e214912a6bbc67cb13c61ff2edc150384 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -33,6 +33,11 @@ CHANGES
     - Session.bind gets used as a default even when table/mapper
       specific binds are defined.
 
+- schema
+    - Added prefixes option to `Table` that accepts a list of 
+      strings to insert after CREATE in the CREATE TABLE statement.
+      [ticket:1075]
+
 - sqlite
     - Modified SQLite's representation of "microseconds" to 
       match the output of str(somedatetime), i.e. in that the
index e1e5e079ce8981424a0d609df5c5d6d2c99d2c2e..fff93df721a1ee1605eabccc80ea2336d41effc7 100644 (file)
@@ -176,6 +176,10 @@ class Table(SchemaItem, expression.TableClause):
             been defined elsewhere in the application, else an exception is
             raised.
 
+          prefixes
+            A list of strings to insert after CREATE in the CREATE TABLE
+            statement.  They will be separated by spaces.
+
           useexisting
             Defaults to False: indicates that if this Table was already
             defined elsewhere in the application, disregard the rest of the
@@ -224,6 +228,8 @@ class Table(SchemaItem, expression.TableClause):
         if kwargs.get('info'):
             self._info = kwargs.pop('info')
 
+        self._prefixes = kwargs.pop('prefixes', [])
+
         self.__extra_kwargs(**kwargs)
 
         # load column definitions from the database if 'autoload' is defined
index c8324d753924ba8655639a29e93d767dbe3734e5..51ad1dfb0981c686e75899927bd042822a2b3e32 100644 (file)
@@ -788,7 +788,7 @@ class SchemaGenerator(DDLBase):
             if column.default is not None:
                 self.traverse_single(column.default)
 
-        self.append("\nCREATE TABLE " + self.preparer.format_table(table) + " (")
+        self.append("\nCREATE " + " ".join(table._prefixes) + " TABLE " + self.preparer.format_table(table) + " (")
 
         separator = "\n"
 
index ec088d7b2f0cda414915768498c54163758edcb6..db08fdb5269b0cc60ffb655b1f88c62cfb8f4a05 100644 (file)
@@ -1,6 +1,6 @@
 import testenv; testenv.configure_for_tests()
 import pickle
-from sqlalchemy import MetaData
+from sqlalchemy import MetaData, create_engine
 from testlib.sa import Table, Column, Integer, String, UniqueConstraint, \
      CheckConstraint, ForeignKey
 import testlib.sa as tsa
@@ -116,5 +116,34 @@ class MetaDataTest(TestBase, ComparesTables):
                           'fake_table',
                           MetaData(testing.db), autoload=True)
 
+
+class TableOptionsTest(TestBase):
+    def mock_engine(self):
+        buffer = []
+        def executor(sql, *a, **kw):
+            buffer.append(sql)
+        engine = create_engine(testing.db.name + '://',
+                               strategy='mock', executor=executor)
+        assert not hasattr(engine, 'mock')
+        engine.mock = buffer
+        return engine
+
+    def setUp(self):
+        self.engine = self.mock_engine()
+        self.metadata = MetaData(self.engine)
+
+    def test_prefixes(self):
+        table1 = Table("temporary_table_1", self.metadata,
+                      Column("col1", Integer),
+                      prefixes = ["TEMPORARY"])
+        table1.create()
+        assert [str(x) for x in self.engine.mock if 'CREATE TEMPORARY TABLE' in str(x)]
+        del self.engine.mock[:]
+        table2 = Table("temporary_table_2", self.metadata,
+                      Column("col1", Integer),
+                      prefixes = ["VIRTUAL"])
+        table2.create()
+        assert [str(x) for x in self.engine.mock if 'CREATE VIRTUAL TABLE' in str(x)]
+
 if __name__ == '__main__':
     testenv.main()