本文整理汇总了Python中_mysql_connector.MySQL.field_count方法的典型用法代码示例。如果您正苦于以下问题:Python MySQL.field_count方法的具体用法?Python MySQL.field_count怎么用?Python MySQL.field_count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类_mysql_connector.MySQL
的用法示例。
在下文中一共展示了MySQL.field_count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_query
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import field_count [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_field_count
# 需要导入模块: from _mysql_connector import MySQL [as 别名]
# 或者: from _mysql_connector.MySQL import field_count [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))