def set_sql_mode(self, sql_mode): """Set the connection sql_mode. See MySQL documentation for legal values.""" if self._server_version < (4, 1): raise NotSupportedError("server is too old to set sql_mode") self.query("SET SESSION sql_mode='{!s}'".format(sql_mode)) self.store_result()
def set_sql_mode(self, sql_mode): """Set the connection sql_mode. See MySQL documentation for legal values.""" if self._server_version < (4, 1): raise NotSupportedError("server is too old to set sql_mode") self._orig_query("SET SESSION sql_mode='%s'" % sql_mode) r = self.store_result() res = r.fetch_row(0) print "set_sql_mode result:",res
def __call__(self, connection): """ Parse the connection string. Initiate a trial connection with the database to check transactionality once instead of once per db_cls instance. Create database if option is enabled and database doesn't exist. """ self.connection = connection db_flags = self._db_cls._parse_connection_string(connection, self.use_unicode, charset=self.charset, timeout=self.timeout) self._db_flags = db_flags # connect to server to determin tranasactional capabilities # can't use db_cls instance as it requires this information to work try: connection = MySQLdb.connect(**db_flags['kw_args']) except OperationalError: if self._create_db: kw_args = db_flags.get('kw_args', {}).copy() db = kw_args.pop('db', None) if not db: raise connection = MySQLdb.connect(**kw_args) create_query = 'create database %s' % db if self.use_unicode and not self.charset: create_query += ' default character set %s' % ( self._db_cls.unicode_charset) elif self.charset: create_query += ' default character set %s' % self.charset connection.query(create_query) connection.store_result() else: raise transactional = connection.server_capabilities & CLIENT.TRANSACTIONS connection.close() # Some tweaks to transaction/locking db_flags based on server setup if db_flags['try_transactions'] == '-': transactional = False elif not transactional and db_flags['try_transactions'] == '+': raise NotSupportedError('transactions not supported by the server') db_flags['transactions'] = transactional del db_flags['try_transactions'] if transactional or db_flags['mysql_lock']: db_flags['use_TM'] = True # will not be 100% accurate in regard to per thread connections # but as close as we're going to get it. self.connected_timestamp = DateTime() # return self as the database connection object # (assigned to _v_database_connection) return self
def query(self, query_string, max_rows=1000): self._register() for qs in query_string.split('\0'): qs = qs.strip() if qs: if match_select(qs): raise NotSupportedError( "can not SELECT in deferred connections") self._sql_string_list.append(qs) return (),()
def set_character_set(self, charset): """Set the connection character set to charset. The character set can only be changed in MySQL-4.1 and newer. If you try to change the character set from the current value in an older version, NotSupportedError will be raised.""" if self.character_set_name() != charset: try: super(Connection, self).set_character_set(charset) except AttributeError: if self._server_version < (4, 1): raise NotSupportedError("server is too old to set charset") self.query('SET NAMES %s' % charset) self.store_result() self.bytes_literal.charset = charset