本文整理汇总了Python中database.DatabaseManager.query方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.query方法的具体用法?Python DatabaseManager.query怎么用?Python DatabaseManager.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DatabaseManagerTest
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import query [as 别名]
class DatabaseManagerTest(unittest.TestCase):
def setUp(self):
self.dbm = DatabaseManager(config.DB_HOST, config.DB_USER, config.DB_PASSWORD, config.DB_NAME)
def tearDown(self):
self.dbm.close()
def table_exists(self, table_name):
__query = self.dbm._DatabaseManager__query
cursor = __query('SHOW TABLES LIKE %s', (table_name))
return cursor.rowcount == 1
def test_query(self):
random_table_name = 'gmucrjcx'
self.assertFalse(self.table_exists(random_table_name))
self.dbm.query('CREATE TABLE %s (id integer)' % (random_table_name))
self.assertTrue(self.table_exists(random_table_name))
self.dbm.query('DROP TABLE %s' % (random_table_name))
self.assertFalse(self.table_exists(random_table_name))
def test_insert_and_get_value(self):
random_table_name = 'ghgsnimb'
count_query = 'SELECT COUNT(*) FROM %s' % (random_table_name)
self.dbm.query('CREATE TABLE %s (id integer PRIMARY KEY AUTO_INCREMENT)' % (random_table_name))
self.assertEqual(self.dbm.get_value(count_query), 0)
self.assertTrue(self.dbm.insert('INSERT INTO %s VALUES (NULL)' % (random_table_name)) > 0)
self.assertEqual(self.dbm.get_value(count_query), 1)
self.assertTrue(self.dbm.insert('INSERT INTO %s VALUES (NULL)' % (random_table_name)) > 0)
self.assertEqual(self.dbm.get_value(count_query), 2)
self.dbm.query('DROP TABLE %s' % (random_table_name))
示例2: index
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import query [as 别名]
def index():
d = DatabaseManager()
values = d.query("SELECT * FROM users", None)
if values:
return 'it works'