def testQuerySingleColumn(self): with temp.AutoTempFilePath(suffix=".sqlite") as db_filepath: with contextlib.closing(sqlite3.connect(db_filepath)) as conn: with contextlib.closing(conn.cursor()) as cursor: cursor.execute("CREATE TABLE foo (bar TEXT)") cursor.execute("INSERT INTO foo VALUES ('quux'), ('norf'), ('thud')") conn.commit() context = sqlite.ConnectionContext(conn) results = list(context.Query("SELECT * FROM foo")) self.assertEqual(results, [("quux",), ("norf",), ("thud",)])
def testQueryMultipleColumns(self): with temp.AutoTempFilePath(suffix=".sqlite") as db_filepath: with contextlib.closing(sqlite3.connect(db_filepath)) as conn: with contextlib.closing(conn.cursor()) as cursor: cursor.execute("CREATE TABLE foo (bar INTEGER, baz TEXT)") cursor.execute("INSERT INTO foo(bar, baz) VALUES (42, 'quux')") cursor.execute("INSERT INTO foo(bar, baz) VALUES (108, 'norf')") conn.commit() context = sqlite.ConnectionContext(conn) results = list(context.Query("SELECT bar, baz FROM foo")) self.assertEqual(results, [(42, "quux"), (108, "norf")])