本文整理汇总了Python中_mysql_connector.MySQL.select_db方法的典型用法代码示例。如果您正苦于以下问题:Python MySQL.select_db方法的具体用法?Python MySQL.select_db怎么用?Python MySQL.select_db使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_mysql_connector.MySQL
的用法示例。
在下文中一共展示了MySQL.select_db方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_select_db
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import select_db [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()
示例2: test_affected_rows
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import select_db [as 别名]
def test_affected_rows(self):
cmy = MySQL(buffered=True)
cmy.connect(**self.connect_kwargs)
table = "affected_rows"
cmy.select_db('myconnpy')
cmy.query("DROP TABLE IF EXISTS {0}".format(table))
cmy.query("CREATE TABLE {0} (c1 INT, c2 INT)".format(table))
cmy.query("INSERT INTO {0} (c1, c2) VALUES "
"(1, 10), (2, 20), (3, 30)".format(table))
self.assertEqual(3, cmy.affected_rows())
cmy.query("UPDATE {0} SET c2 = c2 + 1 WHERE c1 < 3".format(table))
self.assertEqual(2, cmy.affected_rows())
cmy.query("DELETE FROM {0} WHERE c1 IN (1, 2, 3)".format(table))
self.assertEqual(3, cmy.affected_rows())
cmy.query("DROP TABLE IF EXISTS {0}".format(table))
示例3: test_field_count
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import select_db [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))