本文整理汇总了Python中Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB.delete方法的典型用法代码示例。如果您正苦于以下问题:Python SQLiteCacheDB.delete方法的具体用法?Python SQLiteCacheDB.delete怎么用?Python SQLiteCacheDB.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB
的用法示例。
在下文中一共展示了SQLiteCacheDB.delete方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestSqliteCacheDB
# 需要导入模块: from Tribler.Core.CacheDB.sqlitecachedb import SQLiteCacheDB [as 别名]
# 或者: from Tribler.Core.CacheDB.sqlitecachedb.SQLiteCacheDB import delete [as 别名]
#.........这里部分代码省略.........
do_integrity_check.called = False
SQLiteCacheDB.do_quick_integrity_check = do_integrity_check
sqlite_test_2 = SQLiteCacheDB(db_path2)
self.assertTrue(do_integrity_check.called)
def test_clean_db(self):
sqlite_test_2 = SQLiteCacheDB(os.path.join(self.session_base_dir, "test_db.db"), DB_SCRIPT_ABSOLUTE_PATH)
sqlite_test_2.clean_db(vacuum=True, exiting=False)
sqlite_test_2.close()
@skipIf(sys.platform == "win32", "chmod does not work on Windows")
@raises(CantOpenError)
def test_open_db_connection_no_permission(self):
os.chmod(os.path.join(self.session_base_dir), 0)
sqlite_test_2 = SQLiteCacheDB(os.path.join(self.session_base_dir, "test_db.db"))
def test_insert(self):
self.test_create_db()
self.sqlite_test.insert('person', lastname='a', firstname='b')
self.assertEqual(self.sqlite_test.size('person'), 1)
def test_fetchone(self):
self.test_insert()
one = self.sqlite_test.fetchone(u"SELECT * FROM person")
self.assertEqual(one, ('a', 'b'))
one = self.sqlite_test.fetchone(u"SELECT lastname FROM person WHERE firstname == 'b'")
self.assertEqual(one, 'a')
one = self.sqlite_test.fetchone(u"SELECT lastname FROM person WHERE firstname == 'c'")
self.assertIsNone(one)
def test_insertmany(self):
self.test_create_db()
values = []
for i in range(100):
value = (str(i), str(i ** 2))
values.append(value)
self.sqlite_test.insertMany('person', values)
self.assertEqual(self.sqlite_test.size('person'), 100)
def test_fetchall(self):
self.test_insertmany()
all = self.sqlite_test.fetchall('select * from person')
self.assertEqual(len(all), 100)
all = self.sqlite_test.fetchall("select * from person where lastname=='101'")
self.assertEqual(all, [])
def test_insertorder(self):
self.test_insertmany()
self.sqlite_test.insert('person', lastname='1', firstname='abc')
one = self.sqlite_test.fetchone("select firstname from person where lastname == '1'")
self.assertTrue(one == '1' or one == 'abc')
all = self.sqlite_test.fetchall("select firstname from person where lastname == '1'")
self.assertEqual(len(all), 2)
def test_update(self):
self.test_insertmany()
self.sqlite_test.update('person', "lastname == '2'", firstname='56')
one = self.sqlite_test.fetchone("select firstname from person where lastname == '2'")
self.assertEqual(one, '56')
self.sqlite_test.update('person', "lastname == '3'", firstname=65)
one = self.sqlite_test.fetchone("select firstname from person where lastname == '3'")
self.assertEqual(one, 65)
self.sqlite_test.update('person', "lastname == '4'", firstname=654, lastname=44)
one = self.sqlite_test.fetchone("select firstname from person where lastname == 44")
self.assertEqual(one, 654)
def test_delete_single_element(self):
"""
This test tests whether deleting using a single element as value works.
"""
self.test_insert()
self.sqlite_test.insert('person', lastname='x', firstname='z')
one = self.sqlite_test.fetchone(u"SELECT * FROM person")
self.assertEqual(one, ('a', 'b'))
self.sqlite_test.delete("person", lastname="a")
one = self.sqlite_test.fetchone(u"SELECT * FROM person")
self.assertEqual(one, ('x', 'z'))
def test_delete_tuple(self):
"""
This test tests whether deleting using a tuple as value works.
"""
self.test_insert()
self.sqlite_test.insert('person', lastname='x', firstname='z')
one = self.sqlite_test.fetchone(u"SELECT * FROM person")
self.assertEqual(one, ('a', 'b'))
self.sqlite_test.delete("person", lastname=("LIKE", "a"))
one = self.sqlite_test.fetchone(u"SELECT * FROM person")
self.assertEqual(one, ('x', 'z'))