Exemple #1
0
 def test_fetchall(self):
     """
     You can fetch all
     """
     db = sqlite3.connect(':memory:')
     cursor = BlockingCursor(db.cursor())
     d = cursor.execute('create table foo (name text)')
     d.addCallback(lambda _: cursor.execute('insert into foo (name) values(?)', ('name1',)))
     d.addCallback(lambda _: cursor.execute('select name from foo'))
     d.addCallback(lambda _: cursor.fetchall())
     def check(result):
         self.assertEqual(result, [('name1',)])
     d.addCallback(check)
     return d
Exemple #2
0
 def test_execute(self):
     """
     You can execute queries in pretended asynchronousness
     """
     db = sqlite3.connect(':memory:')
     cursor = BlockingCursor(db.cursor())
     d = cursor.execute('create table foo (name text)')
     d.addCallback(lambda _: cursor.execute('insert into foo (name) values(?)', ('name1',)))
     d.addCallback(lambda _: cursor.execute('select name from foo'))
     d.addCallback(lambda _: cursor.fetchone())
     def check(result):
         self.assertEqual(result, ('name1',))
     d.addCallback(check)
     return d