summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPhilip Jenvey <pjenvey@underboss.org>2009-09-11 08:10:32 +0000
committerPhilip Jenvey <pjenvey@underboss.org>2009-09-11 08:10:32 +0000
commitf385260987da45ce140edba986b1ac0c2a6a9e35 (patch)
tree087e9236e9d1bfa46563be149a06c8fffeeaf408 /lib
parent0c26713326f8e9367e58f9c693455b055a1aef8c (diff)
downloadsqlalchemy-f385260987da45ce140edba986b1ac0c2a6a9e35.tar.gz
mssql+zxjdbc support
original patch from Victor Ng fixes #1505
Diffstat (limited to 'lib')
-rw-r--r--lib/sqlalchemy/dialects/mssql/__init__.py4
-rw-r--r--lib/sqlalchemy/dialects/mssql/zxjdbc.py64
-rw-r--r--lib/sqlalchemy/test/requires.py4
3 files changed, 69 insertions, 3 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/__init__.py b/lib/sqlalchemy/dialects/mssql/__init__.py
index e3a829047..292320568 100644
--- a/lib/sqlalchemy/dialects/mssql/__init__.py
+++ b/lib/sqlalchemy/dialects/mssql/__init__.py
@@ -1,3 +1,3 @@
-from sqlalchemy.dialects.mssql import base, pyodbc, adodbapi, pymssql
+from sqlalchemy.dialects.mssql import base, pyodbc, adodbapi, pymssql, zxjdbc
-base.dialect = pyodbc.dialect \ No newline at end of file
+base.dialect = pyodbc.dialect
diff --git a/lib/sqlalchemy/dialects/mssql/zxjdbc.py b/lib/sqlalchemy/dialects/mssql/zxjdbc.py
new file mode 100644
index 000000000..28b9547d8
--- /dev/null
+++ b/lib/sqlalchemy/dialects/mssql/zxjdbc.py
@@ -0,0 +1,64 @@
+"""Support for the Microsoft SQL Server database via the zxjdbc JDBC
+connector.
+
+JDBC Driver
+-----------
+
+Requires the jTDS driver, available from: http://jtds.sourceforge.net/
+
+Connecting
+----------
+
+URLs are of the standard form of
+``mssql+zxjdbc://user:pass@host:port/dbname[?key=value&key=value...]``.
+
+Additional arguments which may be specified either as query string
+arguments on the URL, or as keyword arguments to
+:func:`~sqlalchemy.create_engine()` will be passed as Connection
+properties to the underlying JDBC driver.
+
+"""
+from sqlalchemy.connectors.zxJDBC import ZxJDBCConnector
+from sqlalchemy.dialects.mssql.base import MSDialect, MSExecutionContext
+from sqlalchemy.engine import base
+
+class MS_zxjdbcExecutionContext(MSExecutionContext):
+
+ _embedded_scope_identity = False
+
+ def pre_exec(self):
+ super(MS_zxjdbcExecutionContext, self).pre_exec()
+ # scope_identity after the fact returns null in jTDS so we must
+ # embed it
+ if self._select_lastrowid and self.dialect.use_scope_identity:
+ self._embedded_scope_identity = True
+ self.statement += "; SELECT scope_identity()"
+
+ def post_exec(self):
+ if self._embedded_scope_identity:
+ while True:
+ try:
+ row = self.cursor.fetchall()[0]
+ break
+ except self.dialect.dbapi.Error, e:
+ self.cursor.nextset()
+ self._lastrowid = int(row[0])
+
+ if (self.isinsert or self.isupdate or self.isdelete) and self.compiled.returning:
+ self._result_proxy = base.FullyBufferedResultProxy(self)
+
+ if self._enable_identity_insert:
+ table = self.dialect.identifier_preparer.format_table(self.compiled.statement.table)
+ self.cursor.execute("SET IDENTITY_INSERT %s OFF" % table)
+
+
+class MS_zxjdbc(ZxJDBCConnector, MSDialect):
+ jdbc_db_name = 'jtds:sqlserver'
+ jdbc_driver_name = 'net.sourceforge.jtds.jdbc.Driver'
+
+ execution_ctx_cls = MS_zxjdbcExecutionContext
+
+ def _get_server_version_info(self, connection):
+ return tuple(int(x) for x in connection.connection.dbversion.split('.'))
+
+dialect = MS_zxjdbc
diff --git a/lib/sqlalchemy/test/requires.py b/lib/sqlalchemy/test/requires.py
index f3f4ec191..be6ae9594 100644
--- a/lib/sqlalchemy/test/requires.py
+++ b/lib/sqlalchemy/test/requires.py
@@ -70,7 +70,9 @@ def independent_connections(fn):
# ODBC as well.
return _chain_decorators_on(
fn,
- no_support('sqlite', 'no driver support')
+ no_support('sqlite', 'no driver support'),
+ exclude('mssql', '<', (9, 0, 0),
+ 'SQL Server 2005+ is required for independent connections'),
)
def row_triggers(fn):