Example #1
0
    def __init__(self, cursorclass, *args,
                 encoders=None,
                 decoders=None,
                 row_formatter=None,
                 defer_warnings=None,
                 use_result=None,
                 client_flag=None, **kwargs):
        """
        :param cursorclass: the cursor class
        :param args: connection args, for details see connect
        :param encoders: the list of functions to convert from python to sql
        :param decoders: the list of functions to convert from sql to python
        :param row_formatter: the function to format row
        :param client_flag: the flags of client, for details see connect
        :param defer_warnings: if True, the warnings will be ignored
        :param kwargs: connection keyword arguments, for details see connect
        """

        self.cursorclass = cursorclass
        self.encoders = default_encoders if encoders is None else encoders
        self.decoders = default_decoders if decoders is None else decoders
        self.row_formatter = default_row_formatter if row_formatter is None else row_formatter
        self.format = _wsql.format
        self.defer_warnings = defer_warnings
        self.use_result = use_result

        client_flag = client_flag or 0
        client_version = tuple((int(n) for n in _wsql.get_client_info().split('.')[:2]))
        if client_version >= (4, 1):
            client_flag |= _wsql.constants.CLIENT_MULTI_STATEMENTS
        if client_version >= (5, 0):
            client_flag |= _wsql.constants.CLIENT_MULTI_RESULTS

        self._db = _wsql.connect(*args, client_flag=client_flag, **kwargs)
        self.messages = []
        self._server_version = None
        weakref.finalize(self, lambda db: db.closed or db.close(), db=self._db)
Example #2
0
 def test_client_info(self):
     self.assertIsInstance(_wsql.get_client_info(), str)
Example #3
0
 def test_client_info(self):
     self.assertIsInstance(_wsql.get_client_info(), str)