Author: phd
Date: 2005-11-30 18:39:28 +0000 (Wed, 30 Nov 2005)
New Revision: 1330
Added:
SQLObject/branches/0.7-bugfix/sqlobject/mssql/
SQLObject/branches/0.7-bugfix/sqlobject/mssql/__init__.py
SQLObject/branches/0.7-bugfix/sqlobject/mssql/mssqlconnection.py
Modified:
SQLObject/branches/0.7-bugfix/setup.py
SQLObject/branches/0.7-bugfix/sqlobject/__init__.py
SQLObject/branches/0.7-bugfix/sqlobject/col.py
SQLObject/branches/0.7-bugfix/sqlobject/conftest.py
SQLObject/branches/0.7-bugfix/sqlobject/converters.py
SQLObject/branches/0.7-bugfix/sqlobject/index.py
SQLObject/branches/0.7-bugfix/sqlobject/sqlite/sqliteconnection.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/dbtest.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto_old.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_blob.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_decimal.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_empty.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_indexes.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_slice.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid.py
SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid_old.py
Log:
Merged MSSQL support.
For BLOBCol use encode()/decode() from PySQLite1 if available; else use base64.
Modified: SQLObject/branches/0.7-bugfix/setup.py
===================================================================
--- SQLObject/branches/0.7-bugfix/setup.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/setup.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -8,7 +8,8 @@
from distutils.core import setup
subpackages = ['firebird', 'inheritance', 'mysql', 'postgres',
- 'sqlite', 'sybase', 'maxdb', 'util', 'manager']
+ 'sqlite', 'sybase', 'maxdb', 'util', 'manager',
+ 'mssql']
import sys
# patch distutils if it can't cope with the "classifiers" keyword
Modified: SQLObject/branches/0.7-bugfix/sqlobject/__init__.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/__init__.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/__init__.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -42,3 +42,8 @@
def MaxdbConnection(*args, **kw):
_warn('MaxdbConnection is deprecated; use connectionForURI("maxdb://...") or "from sqlobject.maxdb import builder; MaxdbConnection = builder()"')
return _maxdb.builder()(*args, **kw)
+
+import mssql as _mssql
+def MSSQLConnection(*args, **kw):
+ _warn('MssqlConnection is deprecated; use connectionForURI("mssql://...") or "from sqlobject.mssql import builder; MSSQLConnection = builder()"')
+ return _mssql.builder()(*args, **kw)
Modified: SQLObject/branches/0.7-bugfix/sqlobject/col.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/col.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/col.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -311,6 +311,9 @@
def _sybaseType(self):
return self._sqlType()
+ def _mssqlType(self):
+ return self._sqlType()
+
def _firebirdType(self):
return self._sqlType()
@@ -329,6 +332,9 @@
def sybaseCreateSQL(self):
return ' '.join([self.dbName, self._sybaseType()] + self._extraSQL())
+ def mssqlCreateSQL(self):
+ return ' '.join([self.dbName, self._mssqlType()] + self._extraSQL())
+
def firebirdCreateSQL(self):
# Ian Sparks pointed out that fb is picky about the order
# of the NOT NULL clause in a create statement. So, we handle
@@ -466,6 +472,17 @@
type += ' NULL'
return type
+ def _mssqlType(self):
+ if not self.length:
+ type = 'varchar(4000)'
+ elif self.varchar:
+ type = 'VARCHAR(%i)' % self.length
+ else:
+ type = 'CHAR(%i)' % self.length
+ if not self.notNone and not self.alternateID:
+ type += ' NULL'
+ return type
+
def _firebirdType(self):
self._check_case_sensitive("FireBird")
if not self.length:
@@ -612,6 +629,9 @@
def _sybaseType(self):
return "BIT"
+ def _mssqlType(self):
+ return "BIT"
+
def _firebirdType(self):
return 'INT'
@@ -682,6 +702,9 @@
def _sybaseType(self):
return 'NUMERIC(18,0) NULL'
+
+ def _mssqlType(self):
+ return 'INT NULL'
def _firebirdType(self):
return 'INT'
@@ -742,6 +765,17 @@
sql = ' '.join([sql, reference])
return sql
+ def mssqlCreateSQL(self):
+ sql = SOKeyCol.mssqlCreateSQL(self)
+ other = findClass(self.foreignKey)
+ tName = other.sqlmeta.table
+ idName = other.sqlmeta.idName
+ reference = ('REFERENCES %(tName)s(%(idName)s) ' %
+ {'tName':tName,
+ 'idName':idName})
+ sql = ' '.join([sql, reference])
+ return sql
+
def maxdbCreateSQL(self):
other = findClass(self.foreignKey)
fidName = self.dbName
@@ -790,6 +824,9 @@
def _sybaseType(self):
return self._postgresType()
+ def _mssqlType(self):
+ return self._postgresType()
+
def _firebirdType(self):
length = max(map(self._getlength, self.enumValues))
enumValues = ', '.join([sqlbuilder.sqlrepr(v, 'firebird') for v in self.enumValues])
@@ -923,6 +960,9 @@
def _sybaseType(self):
return 'DATETIME'
+ def _mssqlType(self):
+ return 'DATETIME'
+
def _sqliteType(self):
return 'TIMESTAMP'
@@ -985,6 +1025,12 @@
def _sybaseType(self):
return self._postgresType()
+
+ def _mssqlType(self):
+ """
+ SQL Server doesn't have a DATE data type, to emulate we use a vc(10)
+ """
+ return 'VARCHAR(10)'
def _firebirdType(self):
return 'DATE'
@@ -1093,7 +1139,7 @@
return None
if isinstance(value, str):
module = state.soObject._connection.module
- if module.__name__ == "sqlite":
+ if module.__name__ in ("sqlite", "pysqlite2.dbapi2"):
value = module.decode(value)
return value
if isinstance(value, (buffer_type, state.soObject._connection._binaryType)):
@@ -1132,6 +1178,9 @@
def _postgresType(self):
return 'BYTEA'
+ def _mssqlType(self):
+ return "IMAGE"
+
class BLOBCol(StringCol):
baseClass = SOBLOBCol
Modified: SQLObject/branches/0.7-bugfix/sqlobject/conftest.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/conftest.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/conftest.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -20,6 +20,7 @@
'sqlite': 'sqlite:///%s/data/sqlite.data' % os.getcwd(),
'sybase': 'sybase://test:test123@sybase/test?autoCommit=0',
'firebird': 'firebird://sysdba:masterkey@localhost/var/lib/firebird/data/test.gdb',
+ 'mssql': 'mssql://sa:@127.0.0.1/test'
}
Option = py.test.Config.Option
Modified: SQLObject/branches/0.7-bugfix/sqlobject/converters.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/converters.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/converters.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -112,7 +112,7 @@
if db in ('mysql', 'postgres'):
for orig, repl in sqlStringReplace:
value = value.replace(orig, repl)
- elif db in ('sqlite', 'firebird', 'sybase', 'maxdb'):
+ elif db in ('sqlite', 'firebird', 'sybase', 'maxdb', 'mssql'):
value = value.replace("'", "''")
else:
assert 0, "Database %s unknown" % db
Modified: SQLObject/branches/0.7-bugfix/sqlobject/index.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/index.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/index.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -77,8 +77,7 @@
', '.join(spec))
return ret
- postgresCreateIndexSQL = maxdbCreateIndexSQL = sybaseCreateIndexSQL = firebirdCreateIndexSQL = sqliteCreateIndexSQL
-
+ postgresCreateIndexSQL = maxdbCreateIndexSQL = mssqlCreateIndexSQL = sybaseCreateIndexSQL = firebirdCreateIndexSQL = sqliteCreateIndexSQL
def mysqlCreateIndexSQL(self, soClass):
if self.unique:
uniqueOrIndex = 'UNIQUE'
Added: SQLObject/branches/0.7-bugfix/sqlobject/mssql/__init__.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/mssql/__init__.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/mssql/__init__.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -0,0 +1,17 @@
+from sqlobject.dbconnection import registerConnection
+
+def builder():
+ import mssqlconnection
+ return mssqlconnection.MSSQLConnection
+
+def isSupported(cls):
+ try:
+ import pymssql
+ except ImportError:
+ try:
+ import adodbapi
+ except ImportError:
+ return False
+ return True
+
+registerConnection(['mssql'], builder, isSupported)
Added: SQLObject/branches/0.7-bugfix/sqlobject/mssql/mssqlconnection.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/mssql/mssqlconnection.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/mssql/mssqlconnection.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -0,0 +1,258 @@
+from sqlobject.dbconnection import DBAPI
+from sqlobject import col
+import re
+
+sqlmodule = None
+
+class MSSQLConnection(DBAPI):
+
+ supportTransactions = True
+ dbName = 'mssql'
+ schemes = [dbName]
+
+ def __init__(self, db, user, password='', host='localhost',
+ autoCommit=0, **kw):
+ global sqlmodule
+ if not sqlmodule:
+ try:
+ import adodbapi as sqlmodule
+ self.dbconnection = sqlmodule.connect
+ # ADO uses unicode only (AFAIK)
+ self.usingUnicodeStrings = True
+ # MSDE does not allow SQL server login
+ if "sspi" in kw and kw["sspi"]:
+ self.make_conn_str = lambda keys: \
+ ["Provider=SQLOLEDB;Data Source=%s;Initial Catalog=%s;Integrated Security=SSPI;Persist Security Info=False" % (
+ keys.host, keys.db)]
+ del kw["sspi"]
+ else:
+ self.make_conn_str = lambda keys: \
+ ["Provider=SQLOLEDB;Data Source=%s;User Id=%s;Password=%s;Initial Catalog=%s" % (
+ keys.host, keys.user, keys.password, keys.db)]
+ except ImportError: # raise the exceptions other than ImportError for adodbapi absence
+ import pymssql as sqlmodule
+ self.dbconnection = sqlmodule.connect
+ sqlmodule.Binary = lambda st: str(st)
+ # don't know whether pymssql uses unicode
+ self.usingUnicodeStrings = False
+ self.make_conn_str = lambda keys: \
+ ["", keys.user, keys.password, keys.host, keys.db]
+ self.autoCommit=autoCommit
+ self.host = host
+ self.db = db
+ self.user = user
+ self.password = password
+ self.limit_re = re.compile('^\s*(select )(.*)', re.IGNORECASE)
+ self.password = password
+ self.module = sqlmodule
+ DBAPI.__init__(self, **kw)
+
+ def connectionFromURI(cls, uri):
+ user, password, host, port, path, args = cls._parseURI(uri)
+ path = path.strip('/')
+ return cls(user=user, password=password, host=host or 'localhost',
+ db=path, **args)
+ connectionFromURI = classmethod(connectionFromURI)
+
+ def insert_id(self, conn):
+ """
+ insert_id method.
+ """
+ c = conn.cursor()
+ # converting the identity to an int is ugly, but it gets returned
+ # as a decimal otherwise :S
+ c.execute('SELECT CONVERT(INT, @@IDENTITY)')
+ return c.fetchone()[0]
+
+ def makeConnection(self):
+ con = self.dbconnection( *self.make_conn_str(self) )
+ cur = con.cursor()
+ cur.execute('SET ANSI_NULLS ON')
+ cur.close()
+ return con
+
+ HAS_IDENTITY = """
+ SELECT col.name, col.status, obj.name
+ FROM syscolumns col
+ JOIN sysobjects obj
+ ON obj.id = col.id
+ WHERE obj.name = '%s'
+ and col.autoval is not null
+
+ """
+ def _hasIdentity(self, conn, table):
+ query = self.HAS_IDENTITY % table
+ c = conn.cursor()
+ c.execute(query)
+ r = c.fetchone()
+ return r is not None
+
+ def _queryInsertID(self, conn, soInstance, id, names, values):
+ """
+ Insert the Initial with names and values, using id.
+ """
+ table = soInstance.sqlmeta.table
+ idName = soInstance.sqlmeta.idName
+ c = conn.cursor()
+ has_identity = self._hasIdentity(conn, table)
+ if id is not None:
+ names = [idName] + names
+ values = [id] + values
+ elif has_identity and idName in names:
+ try:
+ i = names.index( idName )
+ if i:
+ del names[i]
+ del values[i]
+ except ValueError:
+ pass
+
+ if has_identity:
+ if id is not None:
+ c.execute('SET IDENTITY_INSERT %s ON' % table)
+ else:
+ c.execute('SET IDENTITY_INSERT %s OFF' % table)
+
+ q = self._insertSQL(table, names, values)
+ if self.debug:
+ print 'QueryIns: %s' % q
+ c.execute(q)
+ if has_identity:
+ c.execute('SET IDENTITY_INSERT %s OFF' % table)
+
+ if id is None:
+ id = self.insert_id(conn)
+ if self.debugOutput:
+ self.printDebug(conn, id, 'QueryIns', 'result')
+ return id
+
+ def _queryAddLimitOffset(self, query, start, end):
+ if end and not start:
+ limit_str = "SELECT TOP %i" % end
+
+ match = self.limit_re.match(query)
+ if match and len(match.groups()) == 2:
+ return ' '.join([limit_str, match.group(2)])
+ else:
+ return query
+
+ def createColumn(self, soClass, col):
+ return col.mssqlCreateSQL()
+
+ def createIDColumn(self, soClass):
+ key_type = {int: "INT", str: "TEXT"}[soClass.sqlmeta.idType]
+ return '%s %s IDENTITY UNIQUE' % (soClass.sqlmeta.idName, key_type)
+
+ def createIndexSQL(self, soClass, index):
+ return index.mssqlCreateIndexSQL(soClass)
+
+ def joinSQLType(self, join):
+ return 'INT NOT NULL'
+
+ SHOW_TABLES="SELECT name FROM sysobjects WHERE type='U'"
+ def tableExists(self, tableName):
+ for (table,) in self.queryAll(self.SHOW_TABLES):
+ if table.lower() == tableName.lower():
+ return True
+ return False
+
+ def addColumn(self, tableName, column):
+ self.query('ALTER TABLE %s ADD %s' %
+ (tableName,
+ column.mssqlCreateSQL()))
+
+ def delColumn(self, tableName, column):
+ self.query('ALTER TABLE %s DROP COLUMN %s' %
+ (tableName,
+ column.dbName))
+
+ # precision and scale is gotten from column table so that we can create
+ # decimal columns if needed
+ SHOW_COLUMNS = """
+ select
+ name,
+ length,
+ ( select name
+ from systypes
+ where cast(xusertype as int)= cast(sc.xtype as int)
+ ) datatype,
+ prec,
+ scale,
+ isnullable,
+ cdefault,
+ m.text default_text,
+ isnull(len(autoval),0) is_identity
+ from syscolumns sc
+ LEFT OUTER JOIN syscomments m on sc.cdefault = m.id
+ AND m.colid = 1
+ where
+ sc.id in (select id
+ from sysobjects
+ where name = '%s')
+ order by
+ colorder"""
+
+ def columnsFromSchema(self, tableName, soClass):
+ colData = self.queryAll(self.SHOW_COLUMNS
+ % tableName)
+ results = []
+ for field, size, t, precision, scale, nullAllowed, default, defaultText, is_identity in colData:
+ # Seems strange to skip the pk column? What if it's not 'id'?
+ if field == 'id':
+ continue
+ # precision is needed for decimal columns
+ colClass, kw = self.guessClass(t, size, precision, scale)
+ kw['name'] = soClass.sqlmeta.style.dbColumnToPythonAttr(field)
+ kw['notNone'] = not nullAllowed
+ if (defaultText):
+ # Strip ( and )
+ defaultText = defaultText[1:-1]
+ if defaultText[0] == "'":
+ defaultText = defaultText[1:-1]
+ else:
+ if t == "int" : defaultText = int(defaultText)
+ if t == "float" : defaultText = float(defaultText)
+ if t == "numeric": defaultText = float(defaultText)
+ # TODO need to access the "column" to_python method here--but the object doesn't exists yet
+
+ # @@ skip key...
+ kw['default'] = defaultText
+
+ results.append(colClass(**kw))
+ return results
+
+ def _setAutoCommit(self, conn, auto):
+ #raise Exception(repr(auto))
+ return
+ #conn.auto_commit = auto
+ option = "ON"
+ if auto == 0:
+ option = "OFF"
+ c = conn.cursor()
+ c.execute("SET AUTOCOMMIT " + option)
+ conn.setconnectoption(SQL.AUTOCOMMIT, option)
+
+ # precision and scale is needed for decimal columns
+ def guessClass(self, t, size, precision, scale):
+ """
+ Here we take raw values coming out of syscolumns and map to SQLObject class types.
+ """
+ if t.startswith('int'):
+ return col.IntCol, {}
+ elif t.startswith('varchar'):
+ if self.usingUnicodeStrings:
+ return col.UnicodeCol, {'length': size}
+ return col.StringCol, {'length': size}
+ elif t.startswith('char'):
+ if self.usingUnicodeStrings:
+ return col.UnicodeCol, {'length': size,
+ 'varchar': False}
+ return col.StringCol, {'length': size,
+ 'varchar': False}
+ elif t.startswith('datetime'):
+ return col.DateTimeCol, {}
+ elif t.startswith('decimal'):
+ return col.DecimalCol, {'size': precision, # be careful for awkward naming
+ 'precision': scale}
+ else:
+ return col.Col, {}
Modified: SQLObject/branches/0.7-bugfix/sqlobject/sqlite/sqliteconnection.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/sqlite/sqliteconnection.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/sqlite/sqliteconnection.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -3,6 +3,7 @@
sqlite = None
using_sqlite2 = False
+sqlite2_Binary = None
class SQLiteConnection(DBAPI):
@@ -34,6 +35,19 @@
for col_type in "text", "char", "varchar":
sqlite.register_converter(col_type, stop_pysqlite2_converting_strings_to_unicode)
sqlite.register_converter(col_type.upper(), stop_pysqlite2_converting_strings_to_unicode)
+ try:
+ from sqlite import encode, decode
+ except ImportError:
+ import base64
+ sqlite.encode = base64.encodestring
+ sqlite.decode = base64.decodestring
+ else:
+ sqlite.encode = encode
+ sqlite.decode = decode
+ global sqlite2_Binary
+ if sqlite2_Binary is None:
+ sqlite2_Binary = sqlite.Binary
+ sqlite.Binary = lambda s: sqlite2_Binary(sqlite.encode(s))
else:
opts['autocommit'] = autoCommit
if 'encoding' in kw:
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/dbtest.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/dbtest.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/dbtest.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -34,10 +34,14 @@
supportsMatrix = {
'+restrictedEnum': 'postgres',
'-transactions': 'mysql',
- '-dropTableCascade': 'sybase',
+ '-dropTableCascade': 'sybase mssql',
'-dynamicColumn': 'sqlite sybase',
'-fromDatabase': 'sqlite sybase firebird',
- '-expressionIndex': 'mysql sqlite firebird',
+ '-expressionIndex': 'mysql sqlite firebird mssql',
+ '-blobData': 'mssql',
+ '-decimalColumn': 'mssql',
+ '-emptyTable': 'mssql',
+ '-limitSelect' : 'mssql'
}
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -106,10 +106,24 @@
age INT DEFAULT 0,
created VARCHAR(40) NOT NULL,
happy char(1) DEFAULT 'Y' NOT NULL,
- long_field TEXT
+ long_field TEXT,
+ wannahavefun BIT default(0) NOT NULL
)
"""
+ mssqlCreate = """
+ CREATE TABLE auto_test (
+ auto_id int identity(1,1),
+ first_name VARCHAR(100),
+ last_name VARCHAR(200) NOT NULL,
+ age INT DEFAULT 0,
+ created VARCHAR(40) NOT NULL,
+ happy char(1) DEFAULT 'Y' NOT NULL,
+ long_field TEXT,
+ wannahavefun BIT default(0) NOT NULL
+ )
+ """
+
mysqlDrop = """
DROP TABLE IF EXISTS auto_test
"""
@@ -122,6 +136,8 @@
DROP TABLE auto_test
"""
+ mssqlDrop = sybaseDrop
+
def setup_method(self, meth):
conn = getConnection()
dbName = conn.dbName
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto_old.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto_old.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_auto_old.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -112,6 +112,19 @@
)
"""
+ mssqlCreate = """
+ CREATE TABLE old_auto_test (
+ auto_id int IDENTITY(1,1) primary key,
+ first_name VARCHAR(100),
+ last_name VARCHAR(200) NOT NULL,
+ age INT DEFAULT 0,
+ created VARCHAR(40) NOT NULL,
+ happy char(1) DEFAULT 'Y' NOT NULL,
+ long_field TEXT,
+ wannahavefun BIT default(0) NOT NULL
+ )
+ """
+
mysqlDrop = """
DROP TABLE IF EXISTS old_auto_test
"""
@@ -124,6 +137,9 @@
DROP TABLE old_auto_test
"""
+ mssqlDrop = """
+ DROP TABLE old_auto_test
+ """
def setup_method(self, meth):
conn = getConnection()
dbName = conn.dbName
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_blob.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_blob.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_blob.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -9,6 +9,8 @@
image = BLOBCol(default='emptydata', length=65535)
def test_BLOBCol():
+ if not supports('blobData'):
+ return
setupClass(ImageData)
data = ''.join([chr(x) for x in range(256)])
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_decimal.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_decimal.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_decimal.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -7,18 +7,20 @@
Decimal = None
########################################
-## Deciaml columns
+## Decimal columns
########################################
class DecimalTable(SQLObject):
col1 = DecimalCol(size=6, precision=4)
def test_1decimal():
+ if not supports('decimalColumn'):
+ return
setupClass(DecimalTable)
d = DecimalTable(col1=21.12)
assert d.col1 == 21.12
-if Decimal:
+if Decimal and supports('decimalColumn'):
def test_2Decimal():
setupClass(DecimalTable)
d = DecimalTable(col1=Decimal("21.12"))
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_empty.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_empty.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_empty.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -6,6 +6,8 @@
pass
def test_empty():
+ if not supports('emptyTable'):
+ return
setupClass(EmptyClass)
e1 = EmptyClass()
e2 = EmptyClass()
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_indexes.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_indexes.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_indexes.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -29,7 +29,7 @@
mod = SOIndex1._connection.module
try:
SOIndex1(name='blah', number=0)
- except (mod.ProgrammingError, mod.IntegrityError, mod.OperationalError):
+ except (mod.ProgrammingError, mod.IntegrityError, mod.OperationalError, mod.DatabaseError):
# expected
pass
else:
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_select.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -56,6 +56,8 @@
assert count == len(names)
def test_04_indexed_ended_by_exception():
+ if not supports('limitSelect'):
+ return
all = IterTest.select()
count = 0
try:
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_slice.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_slice.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_slice.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -17,6 +17,8 @@
Counter(number=i)
def counterEqual(self, counters, value):
+ if not supports('limitSelect'):
+ return
assert [c.number for c in counters] == value
def test_1(self):
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -9,7 +9,7 @@
class sqlmeta(sqlmeta):
table = 'so_string_id'
- _idType = str
+ idType = str
val = StringCol(alternateID=True)
mysqlCreate = """
@@ -40,6 +40,13 @@
)
"""
+ mssqlCreate = """
+ CREATE TABLE so_string_id (
+ id VARCHAR(50) PRIMARY KEY,
+ val varchar(4000)
+ )
+ """
+
sqliteCreate = postgresCreate
mysqlDrop = """
@@ -52,8 +59,8 @@
sqliteDrop = postgresDrop
firebirdDrop = postgresDrop
+ mssqlDrop = postgresDrop
-
def test_stringID():
setupClass(SOStringID)
t = SOStringID(id='hey', val='whatever')
Modified: SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid_old.py
===================================================================
--- SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid_old.py 2005-11-30 18:35:57 UTC (rev 1329)
+++ SQLObject/branches/0.7-bugfix/sqlobject/tests/test_stringid_old.py 2005-11-30 18:39:28 UTC (rev 1330)
@@ -34,6 +34,13 @@
)
"""
+ mssqlCreate = """
+ CREATE TABLE so_string_id (
+ id VARCHAR(50) primary key,
+ val VARCHAR(50) NULL
+ )
+ """
+
firebirdCreate = """
CREATE TABLE so_string_id (
id VARCHAR(50) NOT NULL PRIMARY KEY,
@@ -53,6 +60,7 @@
sqliteDrop = postgresDrop
firebirdDrop = postgresDrop
+ mssqlDrop = postgresDrop
def test_stringID():
|