def test_sqlite_simple_ddl(self): self.delete_db_file() db = DB() db.connect_sqlite(self.DB_FILE) db.exec("CREATE TABLE test1 (name VARCHAR, value VARCHAR)") db.exec("INSERT INTO test1 (name, value) VALUES (?, ?)", ["tyrbot", "1"]) db.get_connection().close() db.connect_sqlite(self.DB_FILE) self.assertEqual([{ 'name': 'tyrbot', 'value': '1' }], db.query("SELECT * FROM test1")) db.get_connection().close() self.delete_db_file()
def test_sqlite_transaction_rollback(self): self.delete_db_file() db = DB() db.connect_sqlite(self.DB_FILE) db.exec("CREATE TABLE test1 (name VARCHAR, value VARCHAR)") db.begin_transaction() db.exec("INSERT INTO test1 (name, value) VALUES (?, ?)", ["tyrbot", "1"]) db.rollback_transaction() db.get_connection().close() db.connect_sqlite(self.DB_FILE) self.assertEqual([], db.query("SELECT * FROM test1")) db.get_connection().close() self.delete_db_file()
def test_sqlite_transaction_rollback_using_with(self): self.delete_db_file() db = DB() db.connect_sqlite(self.DB_FILE) db.exec("CREATE TABLE test1 (name VARCHAR, value VARCHAR)") try: with db.transaction(): db.exec("INSERT INTO test1 (name, value) VALUES (?, ?)", ["tyrbot", "1"]) raise Exception("Testing") except Exception: pass db.get_connection().close() db.connect_sqlite(self.DB_FILE) self.assertEqual([], db.query("SELECT * FROM test1")) db.get_connection().close() self.delete_db_file()