Commits

Michael Trier committed c28cc05

Added prefixes option to that accepts a list of string to insert after CREATE in the CREATE TABLE statement. Closes #1075.

  • Participants
  • Parent commits 3ff4a1b

Comments (0)

Files changed (4)

     - 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

File lib/sqlalchemy/schema.py

             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
         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

File lib/sqlalchemy/sql/compiler.py

             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"
 

File test/engine/metadata.py

 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
                           '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()