本文整理汇总了Python中_mysql_connector.MySQL.free_result方法的典型用法代码示例。如果您正苦于以下问题:Python MySQL.free_result方法的具体用法?Python MySQL.free_result怎么用?Python MySQL.free_result使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_mysql_connector.MySQL
的用法示例。
在下文中一共展示了MySQL.free_result方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_query
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import free_result [as 别名]
def test_query(self):
config = self.connect_kwargs.copy()
cmy = MySQL(buffered=True)
self.assertRaises(MySQLInterfaceError, cmy.query)
cmy.connect(**config)
self.assertRaises(MySQLInterfaceError, cmy.query, "SELECT spam")
self.assertTrue(cmy.query("SET @ham = 4"))
self.assertEqual(None, cmy.num_fields())
self.assertEqual(0, cmy.field_count())
self.assertTrue(cmy.query("SELECT @ham"))
self.assertEqual(4, cmy.fetch_row()[0])
self.assertEqual(None, cmy.fetch_row())
cmy.free_result()
self.assertTrue(cmy.query("SELECT 'ham', 'spam', 5", raw=True))
row = cmy.fetch_row()
self.assertTrue(isinstance(row[0], bytearray))
self.assertEqual(bytearray(b'spam'), row[1])
self.assertEqual(None, cmy.fetch_row())
cmy.free_result()
示例2: test_select_db
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import free_result [as 别名]
def test_select_db(self):
cmy = MySQL(buffered=True)
cmy.connect(**self.connect_kwargs)
cmy.select_db('mysql')
cmy.query("SELECT DATABASE()")
self.assertEqual(b'mysql', cmy.fetch_row()[0])
cmy.free_result()
cmy.select_db('myconnpy')
cmy.query("SELECT DATABASE()")
self.assertEqual(b'myconnpy', cmy.fetch_row()[0])
cmy.free_result()
示例3: test_change_user
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import free_result [as 别名]
def test_change_user(self):
connect_kwargs = self.connect_kwargs.copy()
connect_kwargs['unix_socket'] = None
connect_kwargs['ssl_disabled'] = False
cmy1 = MySQL(buffered=True)
cmy1.connect(**connect_kwargs)
cmy2 = MySQL(buffered=True)
cmy2.connect(**connect_kwargs)
new_user = {
'user': 'cextuser',
'host': self.config['host'],
'database': self.connect_kwargs['database'],
'password': 'connc',
}
try:
cmy1.query("DROP USER '{user}'@'{host}'".format(**new_user))
except MySQLInterfaceError:
# Probably not created
pass
stmt = ("CREATE USER '{user}'@'{host}' IDENTIFIED WITH "
"caching_sha2_password").format(**new_user)
cmy1.query(stmt)
if tests.MYSQL_VERSION < (8, 0, 5):
cmy1.query("SET old_passwords = 0")
res = cmy1.query("SET PASSWORD FOR '{user}'@'{host}' = "
"PASSWORD('{password}')".format(**new_user))
else:
res = cmy1.query("ALTER USER '{user}'@'{host}' IDENTIFIED BY "
"'{password}'".format(**new_user))
cmy1.query("GRANT ALL ON {database}.* "
"TO '{user}'@'{host}'".format(**new_user))
cmy2.query("SHOW GRANTS FOR {user}@{host}".format(**new_user))
cmy2.query("SELECT USER()")
orig_user = cmy2.fetch_row()[0]
cmy2.free_result()
cmy2.change_user(user=new_user['user'], password=new_user['password'],
database=new_user['database'])
cmy2.query("SELECT USER()")
current_user = cmy2.fetch_row()[0]
self.assertNotEqual(orig_user, current_user)
self.assertTrue(
u"{user}@".format(**new_user) in current_user.decode('utf8'))
cmy2.free_result()
示例4: test_field_count
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import free_result [as 别名]
def test_field_count(self):
cmy = MySQL(buffered=True)
cmy.connect(**self.connect_kwargs)
table = "field_count"
cmy.select_db('myconnpy')
cmy.query("DROP TABLE IF EXISTS {0}".format(table))
cmy.query("CREATE TABLE {0} (c1 INT, c2 INT, c3 INT)".format(table))
cmy.query("SELECT * FROM {0}".format(table))
self.assertEqual(3, cmy.field_count())
cmy.free_result()
cmy.query("INSERT INTO {0} (c1, c2, c3) VALUES "
"(1, 10, 100)".format(table))
cmy.commit()
cmy.query("SELECT * FROM {0}".format(table))
self.assertEqual(3, cmy.field_count())
cmy.free_result()
cmy.query("DROP TABLE IF EXISTS {0}".format(table))