1# connectors/zxJDBC.py
2# Copyright (C) 2005-2016 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
8import sys
9from . import Connector
10
11
12class ZxJDBCConnector(Connector):
13    driver = 'zxjdbc'
14
15    supports_sane_rowcount = False
16    supports_sane_multi_rowcount = False
17
18    supports_unicode_binds = True
19    supports_unicode_statements = sys.version > '2.5.0+'
20    description_encoding = None
21    default_paramstyle = 'qmark'
22
23    jdbc_db_name = None
24    jdbc_driver_name = None
25
26    @classmethod
27    def dbapi(cls):
28        from com.ziclix.python.sql import zxJDBC
29        return zxJDBC
30
31    def _driver_kwargs(self):
32        """Return kw arg dict to be sent to connect()."""
33        return {}
34
35    def _create_jdbc_url(self, url):
36        """Create a JDBC url from a :class:`~sqlalchemy.engine.url.URL`"""
37        return 'jdbc:%s://%s%s/%s' % (self.jdbc_db_name, url.host,
38                                      url.port is not None
39                                      and ':%s' % url.port or '',
40                                      url.database)
41
42    def create_connect_args(self, url):
43        opts = self._driver_kwargs()
44        opts.update(url.query)
45        return [
46            [self._create_jdbc_url(url),
47             url.username, url.password,
48             self.jdbc_driver_name],
49            opts]
50
51    def is_disconnect(self, e, connection, cursor):
52        if not isinstance(e, self.dbapi.ProgrammingError):
53            return False
54        e = str(e)
55        return 'connection is closed' in e or 'cursor is closed' in e
56
57    def _get_server_version_info(self, connection):
58        # use connection.connection.dbversion, and parse appropriately
59        # to get a tuple
60        raise NotImplementedError()
61