本文整理汇总了Python中database.DatabaseManager.close方法的典型用法代码示例。如果您正苦于以下问题:Python DatabaseManager.close方法的具体用法?Python DatabaseManager.close怎么用?Python DatabaseManager.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.DatabaseManager
的用法示例。
在下文中一共展示了DatabaseManager.close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DatabaseManagerTest
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import close [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: get_dbm
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import close [as 别名]
class get_dbm(object):
def __enter__(self):
self.dbm = DatabaseManager(config.DB_HOST, config.DB_USER, config.DB_PASSWORD, config.DB_NAME)
return self.dbm
def __exit__(self, type, value, traceback):
self.dbm.close()
示例3: test_cursor_type
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import close [as 别名]
def test_cursor_type(self):
dbm = DatabaseManager(config.DB_HOST, config.DB_USER, config.DB_PASSWORD, config.DB_NAME)
get_cursor_type = dbm._DatabaseManager__get_cursor_type
self.assertEqual(get_cursor_type(use_dict=True), MySQLdb.cursors.DictCursor)
self.assertEqual(get_cursor_type(use_dict=False), MySQLdb.cursors.Cursor)
dbm.close()
示例4: query_product
# 需要导入模块: from database import DatabaseManager [as 别名]
# 或者: from database.DatabaseManager import close [as 别名]
self.dbm.insert("INSERT INTO query_product (query_id, product_name, bought, sequence) VALUES (%s, %s, %s, %s)", (qrow['id'], vrow['pageinfo'], bought, sequence))
sequence += 1
self.dbm.commit()
count = self.dbm.get_value('select COUNT(*) FROM query_product')
max_count = self.query_count * self.product_count
print '\nQuery-Product table statistics (inserted/maximum): %d/%d (%.2f%%)' % (count, max_count, 100.0*count/max_count)
def get_session_end(self, start_time):
"""Get session end time.
@param start_time string of timestamp in milliseconds
@return string of the same format
"""
start_ts = int(start_time)
end_ts = start_ts + self.session_duration * 1000
return str(end_ts)
if __name__ == '__main__':
import config
from database import DatabaseManager
dbm = DatabaseManager(config.DB_HOST, config.DB_USER, config.DB_PASSWORD, config.DB_NAME)
try:
swf = None
if hasattr(config, 'stopwords'):
swf = config.stopwords
preprocessor = RawDataPreprocessor(dbm, config.session_duration, stopwords_file=swf)
preprocessor.run()
finally:
dbm.close()