Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# mssql/zxjdbc.py 

2# Copyright (C) 2005-2020 the SQLAlchemy authors and contributors 

3# <see AUTHORS file> 

4# 

5# This module is part of SQLAlchemy and is released under 

6# the MIT License: http://www.opensource.org/licenses/mit-license.php 

7 

8""" 

9.. dialect:: mssql+zxjdbc 

10 :name: zxJDBC for Jython 

11 :dbapi: zxjdbc 

12 :connectstring: mssql+zxjdbc://user:pass@host:port/dbname[?key=value&key=value...] 

13 :driverurl: http://jtds.sourceforge.net/ 

14 

15 .. note:: Jython is not supported by current versions of SQLAlchemy. The 

16 zxjdbc dialect should be considered as experimental. 

17 

18""" # noqa 

19from .base import MSDialect 

20from .base import MSExecutionContext 

21from ... import engine 

22from ...connectors.zxJDBC import ZxJDBCConnector 

23 

24 

25class MSExecutionContext_zxjdbc(MSExecutionContext): 

26 

27 _embedded_scope_identity = False 

28 

29 def pre_exec(self): 

30 super(MSExecutionContext_zxjdbc, self).pre_exec() 

31 # scope_identity after the fact returns null in jTDS so we must 

32 # embed it 

33 if self._select_lastrowid and self.dialect.use_scope_identity: 

34 self._embedded_scope_identity = True 

35 self.statement += "; SELECT scope_identity()" 

36 

37 def post_exec(self): 

38 if self._embedded_scope_identity: 

39 while True: 

40 try: 

41 row = self.cursor.fetchall()[0] 

42 break 

43 except self.dialect.dbapi.Error: 

44 self.cursor.nextset() 

45 self._lastrowid = int(row[0]) 

46 

47 if ( 

48 self.isinsert or self.isupdate or self.isdelete 

49 ) and self.compiled.returning: 

50 self._result_proxy = engine.FullyBufferedResultProxy(self) 

51 

52 if self._enable_identity_insert: 

53 table = self.dialect.identifier_preparer.format_table( 

54 self.compiled.statement.table 

55 ) 

56 self.cursor.execute("SET IDENTITY_INSERT %s OFF" % table) 

57 

58 

59class MSDialect_zxjdbc(ZxJDBCConnector, MSDialect): 

60 jdbc_db_name = "jtds:sqlserver" 

61 jdbc_driver_name = "net.sourceforge.jtds.jdbc.Driver" 

62 

63 execution_ctx_cls = MSExecutionContext_zxjdbc 

64 

65 def _get_server_version_info(self, connection): 

66 return tuple( 

67 int(x) for x in connection.connection.dbversion.split(".") 

68 ) 

69 

70 

71dialect = MSDialect_zxjdbc