Exemple #1
0
    def create_connect_args(self, url):
        """
        Connection strings are EXASolution specific. See EXASolution manual on Connection-String-Parameters.

        `ODBC Driver Settings <https://docs.exasol.com/db/latest/connect_exasol/drivers/odbc/using_odbc.htm>`_
        """
        opts = url.translate_connect_args(username="******")
        opts.update(url.query)
        # always enable efficient conversion to Python types: see https://www.exasol.com/support/browse/EXASOL-898
        opts["INTTYPESINRESULTSIFPOSSIBLE"] = "y"
        # Make sure the exasol odbc driver reports the expected error codes.
        # see also:
        #   * https://docs.exasol.com/db/latest/connect_exasol/drivers/odbc/using_odbc.htm
        #   * https://github.com/exasol/sqlalchemy-exasol/issues/118
        opts["SQLSTATEMAPPINGACTIVE"] = "y"
        opts["SQLSTATEMAPPINGS"] = "42X91:23000,27002:23000"

        keys = opts
        query = url.query

        connect_args = {}
        for param in ("ansi", "unicode_results", "autocommit"):
            if param in keys:
                connect_args[param.upper()] = asbool(keys.pop(param))

        dsn_connection = "dsn" in keys or ("host" in keys and "port" not in keys)
        if dsn_connection:
            connectors = ["DSN=%s" % (keys.pop("dsn", "") or keys.pop("host", ""))]
        else:
            connectors = ["DRIVER={%s}" % keys.pop("driver", None)]

        port = ""
        if "port" in keys and not "port" in query:
            port = ":%d" % int(keys.pop("port"))

        connectors.extend(
            [
                "EXAHOST={}{}".format(keys.pop("host", ""), port),
                "EXASCHEMA=%s" % keys.pop("database", ""),
            ]
        )

        user = keys.pop("user", None)
        if user:
            connectors.append("UID=%s" % user)
            connectors.append("PWD=%s" % keys.pop("password", ""))
        else:
            connectors.append("Trusted_Connection=Yes")

        # if set to 'Yes', the ODBC layer will try to automagically
        # convert textual data from your database encoding to your
        # client encoding.  This should obviously be set to 'No' if
        # you query a cp1253 encoded database from a latin1 client...
        if "odbc_autotranslate" in keys:
            connectors.append("AutoTranslate=%s" % keys.pop("odbc_autotranslate"))

        connectors.extend([f"{k}={v}" for k, v in sorted(keys.items())])
        return [[";".join(connectors)], connect_args]
Exemple #2
0
    def create_connect_args(self, url):
        """
        Connection strings are EXASolution specific. See EXASolution manual
        on Connection-String-Parameters
        """
        opts = url.translate_connect_args(username='******')
        opts.update(url.query)
        # always enable efficient conversion to Python types: see https://www.exasol.com/support/browse/EXASOL-898
        opts['INTTYPESINRESULTSIFPOSSIBLE'] = 'y'

        keys = opts
        query = url.query

        connect_args = {}
        for param in ('ansi', 'unicode_results', 'autocommit'):
            if param in keys:
                connect_args[param.upper()] = asbool(keys.pop(param))

        dsn_connection = 'dsn' in keys or \
                        ('host' in keys and 'port' not in keys)
        if dsn_connection:
            connectors = ['DSN=%s' % (keys.pop('dsn', '') or \
                        keys.pop('host', ''))]
        else:
            connectors = [
                "DRIVER={%s}" % keys.pop('driver', self.pyodbc_driver_name)
            ]

        port = ''
        if 'port' in keys and not 'port' in query:
            port = ':%d' % int(keys.pop('port'))

        connectors.extend([
            'EXAHOST=%s%s' % (keys.pop('host', ''), port),
            'EXASCHEMA=%s' % keys.pop('database', '')
        ])

        user = keys.pop("user", None)
        if user:
            connectors.append("UID=%s" % user)
            connectors.append("PWD=%s" % keys.pop('password', ''))
        else:
            connectors.append("Trusted_Connection=Yes")

        # if set to 'Yes', the ODBC layer will try to automagically
        # convert textual data from your database encoding to your
        # client encoding.  This should obviously be set to 'No' if
        # you query a cp1253 encoded database from a latin1 client...
        if 'odbc_autotranslate' in keys:
            connectors.append("AutoTranslate=%s" %
                              keys.pop("odbc_autotranslate"))

        connectors.extend(
            ['%s=%s' % (k, v) for k, v in sorted(six.iteritems(keys))])
        return [[";".join(connectors)], connect_args]
    def create_connect_args(self, url):
        """
        Connection strings are EXASolution specific. See EXASolution manual
        on Connection-String-Parameters
        """
        opts = url.translate_connect_args(username='******')
        opts.update(url.query)
        # always enable efficient conversion to Python types: see https://www.exasol.com/support/browse/EXASOL-898
        opts['INTTYPESINRESULTSIFPOSSIBLE'] = 'y'

        keys = opts
        query = url.query

        connect_args = {}
        for param in ('ansi', 'unicode_results', 'autocommit'):
            if param in keys:
                connect_args[param.upper()] = asbool(keys.pop(param))

        dsn_connection = 'dsn' in keys or \
                        ('host' in keys and 'port' not in keys)
        if dsn_connection:
            connectors = ['DSN=%s' % (keys.pop('dsn', '') or \
                        keys.pop('host', ''))]
        else:
            connectors = ["DRIVER={%s}" %
                            keys.pop('driver', self.pyodbc_driver_name)]

        port = ''
        if 'port' in keys and not 'port' in query:
            port = ':%d' % int(keys.pop('port'))

        connectors.extend(['EXAHOST=%s%s' % (keys.pop('host', ''), port),
                          'EXASCHEMA=%s' % keys.pop('database', '')])

        user = keys.pop("user", None)
        if user:
            connectors.append("UID=%s" % user)
            connectors.append("PWD=%s" % keys.pop('password', ''))
        else:
            connectors.append("Trusted_Connection=Yes")

        # if set to 'Yes', the ODBC layer will try to automagically
        # convert textual data from your database encoding to your
        # client encoding.  This should obviously be set to 'No' if
        # you query a cp1253 encoded database from a latin1 client...
        if 'odbc_autotranslate' in keys:
            connectors.append("AutoTranslate=%s" %
                                keys.pop("odbc_autotranslate"))

        connectors.extend(['%s=%s' % (k, v) for k, v in sorted(six.iteritems(keys))])
        return [[";".join(connectors)], connect_args]