]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
merged Rick Morrison / Runar Petursson's MS-SQL module, with adjustments to alias...
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Apr 2006 01:35:48 +0000 (01:35 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Apr 2006 01:35:48 +0000 (01:35 +0000)
lib/sqlalchemy/databases/__init__.py
lib/sqlalchemy/databases/information_schema.py
lib/sqlalchemy/engine.py
lib/sqlalchemy/schema.py
test/indexes.py
test/select.py
test/testbase.py
test/testtypes.py

index 10cf9f6b225d1fe71b84067f3af25de60cb14acb..f009034c751b6f5337243da1c042529f640b5800 100644 (file)
@@ -5,4 +5,4 @@
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 
-__all__ = ['oracle', 'postgres', 'sqlite', 'mysql']
\ No newline at end of file
+__all__ = ['oracle', 'postgres', 'sqlite', 'mysql', 'mssql']
index feb3cf0c52cf0c3c588ff9c504b0a7e049c9468a..468e9a54863fcbba83d75e3b1e538a4b1bc51d29 100644 (file)
@@ -56,6 +56,18 @@ gen_key_constraints = schema.Table("key_column_usage", generic_engine,
     Column("constraint_name", String),
     schema="information_schema")
 
+gen_ref_constraints = schema.Table("referential_constraints", generic_engine,
+    Column("constraint_catalog", String),
+    Column("constraint_schema", String),
+    Column("constraint_name", String),
+    Column("unique_constraint_catlog", String),
+    Column("unique_constraint_schema", String),
+    Column("unique_constraint_name", String),
+    Column("match_option", String),
+    Column("update_rule", String),
+    Column("delete_rule", String),
+    schema="information_schema")
+                                   
 class ISchema(object):
     def __init__(self, engine):
         self.engine = engine
index 55bad6abd926bb301b9cac3b187d12c964bdffa2..727ee30ad2201e34011b4adceba6d64324c03623 100644 (file)
@@ -193,7 +193,7 @@ class SQLSession(object):
     connection = property(_connection, doc="the connection represented by this SQLSession.  The connection is late-connecting, meaning the call to the connection pool only occurs when it is first called (and the pool will typically only connect the first time it is called as well)")
     
     def begin(self):
-        """begins" a transaction on this SQLSession's connection.  repeated calls to begin() will increment a counter that must be decreased by corresponding commit() statements before an actual commit occurs.  this is to provide "nested" behavior of transactions so that different functions in a particular call stack can call begin()/commit() independently of each other without knowledge of an existing transaction."""
+        """begins a transaction on this SQLSession's connection.  repeated calls to begin() will increment a counter that must be decreased by corresponding commit() statements before an actual commit occurs.  this is to provide "nested" behavior of transactions so that different functions in a particular call stack can call begin()/commit() independently of each other without knowledge of an existing transaction. """
         if self.__tcount == 0:
             self.__transaction = self.connection
             self.engine.do_begin(self.connection)
@@ -506,7 +506,7 @@ class SQLEngine(schema.SchemaEngine):
         self.commit()
         
     def begin(self):
-        """"begins a transaction on the current thread's SQLSession."""
+        """ begins a transaction on the current thread SQLSession. """
         self.session.begin()
             
     def rollback(self):
@@ -647,7 +647,7 @@ class SQLEngine(schema.SchemaEngine):
         return ResultProxy(cursor, self, typemap=compiled.typemap)
 
     def execute(self, statement, parameters=None, connection=None, cursor=None, echo=None, typemap=None, commit=False, return_raw=False, **kwargs):
-        """executes the given string-based SQL statement with the given parameters.  
+        """ executes the given string-based SQL statement with the given parameters.  
 
         The parameters can be a dictionary or a list, or a list of dictionaries or lists, depending
         on the paramstyle of the DBAPI.
@@ -659,7 +659,7 @@ class SQLEngine(schema.SchemaEngine):
         up.
 
         In all error cases, a rollback() is immediately performed on the connection before
-        propigating the exception outwards.
+        propagating the exception outwards.
 
         Other options include:
 
index 756c03b6efcbb3651828b83490c3e0c35997d59f..eabfee9bb7aa25ade57af6bf0a315a559219f0c5 100644 (file)
@@ -256,7 +256,7 @@ class Column(sql.ColumnClause, SchemaItem):
         default=None : a scalar, python callable, or ClauseElement representing the "default value" for this column,
         which will be invoked upon insert if this column is not present in the insert list or is given a value
         of None.
-        
+
         hidden=False : indicates this column should not be listed in the
         table's list of columns.  Used for the "oid" column, which generally
         isnt in column lists.
@@ -271,7 +271,9 @@ class Column(sql.ColumnClause, SchemaItem):
         indexed in a unique index . Pass true to autogenerate the index
         name. Pass a string to specify the index name. Multiple columns that
         specify the same index name will all be included in the index, in the
-        order of their creation.  """
+        order of their creation.
+
+        """
         
         name = str(name) # in case of incoming unicode
         super(Column, self).__init__(name, None, type)
@@ -507,6 +509,7 @@ class Sequence(DefaultGenerator):
         """calls the visit_seauence method on the given visitor."""
         return visitor.visit_sequence(self)
 
+
 class Index(SchemaItem):
     """Represents an index of columns from a database table
     """
index 17c2e7dc679e4632c92ca53ffcbf258241fe82c5..7ad008f5dca9a28197cd7e1baf3c7bbcfbf93c4f 100644 (file)
@@ -42,9 +42,10 @@ class IndexTest(testbase.AssertMixin):
         """test that mixed-case index identifiers are legal"""
         employees = Table('companyEmployees', testbase.db,
                           Column('id', Integer, primary_key=True),
-                          Column('firstName', String),
-                          Column('lastName', String),
-                          Column('emailAddress', String))        
+                          Column('firstName', String(30)),
+                          Column('lastName', String(30)),
+                          Column('emailAddress', String(30)))
+
         employees.create()
         self.created.append(employees)
         
index 9c260c324387d7155d7a846deea5c8012d40d561..0fc406e4a64b13b5d03dfbb392ee9a641b22bed4 100644 (file)
@@ -6,6 +6,7 @@ import sqlalchemy.databases.oracle as oracle
 import sqlalchemy.databases.sqlite as sqlite
 
 db = ansisql.engine()
+#db = create_engine('mssql')
 
 from testbase import PersistTest
 import unittest, re
@@ -595,6 +596,7 @@ class CRUDTest(SQLTest):
         
 class SchemaTest(SQLTest):
     def testselect(self):
+        # these tests will fail with the MS-SQL compiler since it will alias schema-qualified tables
         self.runtest(table4.select(), "SELECT remotetable.rem_id, remotetable.datatype_id, remotetable.value FROM remote_owner.remotetable")
         self.runtest(table4.select(and_(table4.c.datatype_id==7, table4.c.value=='hi')), "SELECT remotetable.rem_id, remotetable.datatype_id, remotetable.value FROM remote_owner.remotetable WHERE remotetable.datatype_id = :remotetable_datatype_id AND remotetable.value = :remotetable_value")
 
index 1578be5a0c7505fa35340d5f20e0d27e75671794..923ed7de993693d90f38851d0531f1c0721b4ac6 100644 (file)
@@ -46,9 +46,11 @@ def parse_argv():
         elif DBTYPE == 'oracle8':
             db_uri = 'oracle://user=scott&password=tiger'
             opts = {'use_ansi':False}
+        elif DBTYPE == 'mssql':
+            db_uri = 'mssql://database=test&user=scott&password=tiger'
 
     if not db_uri:
-        raise "Could not create engine.  specify --db <sqlite|sqlite_file|postgres|mysql|oracle> to test runner."
+        raise "Could not create engine.  specify --db <sqlite|sqlite_file|postgres|mysql|oracle|oracle8|mssql> to test runner."
 
     if PROXY:
         db = proxy.ProxyEngine(echo=echo, default_ordering=True, **opts)
index 708b38a281e9354d9408d46941bb0c3d2a129f5d..c2e3043c999b00b3162b716ba752abe101265545 100644 (file)
@@ -147,8 +147,8 @@ class BinaryTest(AssertMixin):
     def testbinary(self):
         stream1 =self.get_module_stream('sqlalchemy.sql')
         stream2 =self.get_module_stream('sqlalchemy.engine')
-        binary_table.insert().execute(misc='sql.pyc', data=stream1, data_slice=stream1[0:100])
-        binary_table.insert().execute(misc='engine.pyc', data=stream2, data_slice=stream2[0:99])
+        binary_table.insert().execute(primary_id=1, misc='sql.pyc',    data=stream1, data_slice=stream1[0:100])
+        binary_table.insert().execute(primary_id=2, misc='engine.pyc', data=stream2, data_slice=stream2[0:99])
         l = binary_table.select().execute().fetchall()
         print len(stream1), len(l[0]['data']), len(l[0]['data_slice'])
         self.assert_(list(stream1) == list(l[0]['data']))
@@ -179,7 +179,7 @@ class DateTest(AssertMixin):
         collist = [Column('user_id', INT, primary_key = True), Column('user_name', VARCHAR(20)), Column('user_datetime', DateTime),
                    Column('user_date', Date), Column('user_time', Time)]
         
-        if db.engine.__module__.endswith('mysql'):
+        if db.engine.__module__.endswith('mysql') or db.engine.__module__.endswith('mssql'):
             # strip microseconds -- not supported by this engine (should be an easier way to detect this)
             for d in insert_data:
                 if d[2] is not None:
@@ -198,6 +198,7 @@ class DateTest(AssertMixin):
         users_with_date = Table('query_users_with_date', db, redefine = True, *collist)
         users_with_date.create()
         insert_dicts = [dict(zip(fnames, d)) for d in insert_data]
+
         for idict in insert_dicts:
             users_with_date.insert().execute(**idict) # insert the data