dibbler/sqlalchemy/dialects/mssql/zxjdbc.py

70 lines
2.2 KiB
Python
Raw Normal View History

2017-04-15 18:33:29 +02:00
# mssql/zxjdbc.py
# Copyright (C) 2005-2017 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
2010-05-07 19:33:49 +02:00
2017-04-15 18:33:29 +02:00
"""
.. dialect:: mssql+zxjdbc
:name: zxJDBC for Jython
:dbapi: zxjdbc
:connectstring: mssql+zxjdbc://user:pass@host:port/dbname\
[?key=value&key=value...]
:driverurl: http://jtds.sourceforge.net/
2010-05-07 19:33:49 +02:00
2017-04-15 18:33:29 +02:00
.. note:: Jython is not supported by current versions of SQLAlchemy. The
zxjdbc dialect should be considered as experimental.
2010-05-07 19:33:49 +02:00
"""
2017-04-15 18:33:29 +02:00
from ...connectors.zxJDBC import ZxJDBCConnector
from .base import MSDialect, MSExecutionContext
from ... import engine
2010-05-07 19:33:49 +02:00
class MSExecutionContext_zxjdbc(MSExecutionContext):
_embedded_scope_identity = False
def pre_exec(self):
super(MSExecutionContext_zxjdbc, 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
2017-04-15 18:33:29 +02:00
except self.dialect.dbapi.Error:
2010-05-07 19:33:49 +02:00
self.cursor.nextset()
self._lastrowid = int(row[0])
2017-04-15 18:33:29 +02:00
if (self.isinsert or self.isupdate or self.isdelete) and \
self.compiled.returning:
self._result_proxy = engine.FullyBufferedResultProxy(self)
2010-05-07 19:33:49 +02:00
if self._enable_identity_insert:
2017-04-15 18:33:29 +02:00
table = self.dialect.identifier_preparer.format_table(
self.compiled.statement.table)
2010-05-07 19:33:49 +02:00
self.cursor.execute("SET IDENTITY_INSERT %s OFF" % table)
class MSDialect_zxjdbc(ZxJDBCConnector, MSDialect):
jdbc_db_name = 'jtds:sqlserver'
jdbc_driver_name = 'net.sourceforge.jtds.jdbc.Driver'
execution_ctx_cls = MSExecutionContext_zxjdbc
def _get_server_version_info(self, connection):
2017-04-15 18:33:29 +02:00
return tuple(
int(x)
for x in connection.connection.dbversion.split('.')
)
2010-05-07 19:33:49 +02:00
dialect = MSDialect_zxjdbc