コード例 #1
0
    def test_failure(self):
        self.fail1()
        with SqliteCursor(db1) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='F1';")
            self.assertEqual(cur.fetchone()['COUNT(*)'], 0)

        with SqliteCursor(db2) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='F2';")
            self.assertEqual(cur.fetchone()['COUNT(*)'], 0)
コード例 #2
0
    def test_cascade_halt(self):
        with SqliteCursor() as cur:
            cur.execute("INSERT INTO test_table(field) VALUES('X');")
            self.layer1()

        with SqliteCursor() as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='X';")
            row = cur.fetchone()
            self.assertEqual(row['COUNT(*)'], 0)
コード例 #3
0
    def test_success(self):
        self.success1()
        with SqliteCursor(db1) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='S1';")
            self.assertEqual(cur.fetchone()['COUNT(*)'], 1)

        with SqliteCursor(db2) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='S2';")
            self.assertEqual(cur.fetchone()['COUNT(*)'], 1)
コード例 #4
0
    def test_nest(self):
        with SqliteCursor(DBPATH) as cur:
            self.add_one()
            cur.execute(
                "INSERT INTO test_table(field) VALUES('one point five')")
            self.add_two()

        with SqliteCursor(DBPATH) as cur:
            cur.execute("SELECT COUNT(*) FROM test_table WHERE field='two'")
            row = cur.fetchone()
            self.assertEqual(row["COUNT(*)"], 1)
コード例 #5
0
ファイル: seed.py プロジェクト: redcartel/SqliteCursor.py
def seed(dbpath=DBPATH):
    with SqliteCursor(dbpath) as cur:
        SQL = """ DELETE FROM test_table; """
        cur.execute(SQL)

        SQL = """ INSERT INTO test_table (field) VALUES (?); """
        vals = [('A', ), ('B', ), ('C', )]
        for val in vals:
            cur.execute(SQL, val)
コード例 #6
0
def schema(dbpath=DBPATH):
    with SqliteCursor(dbpath) as cur:
        SQL = "DROP TABLE IF EXISTS test_table;"
        cur.execute(SQL)
        SQL = """ CREATE TABLE test_table(
            pk INTEGER PRIMARY KEY AUTOINCREMENT,
            field TEXT
            ); """
        cur.execute(SQL)
コード例 #7
0
 def fail2(self):
     with SqliteCursor(db2) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('F2');")
         raise HaltCommits
コード例 #8
0
 def fail1(self):
     with SqliteCursor(db1) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('F1');")
         self.fail2()
コード例 #9
0
 def success2(self):
     with SqliteCursor(db2) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('S2');")
コード例 #10
0
 def layer2(self):
     with SqliteCursor() as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('X');")
         raise HaltCommits
コード例 #11
0
 def layer1(self):
     with SqliteCursor() as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('X');")
         self.layer2()
コード例 #12
0
 def add_two(self):
     with SqliteCursor(DBPATH) as cur:
         cur.execute("INSERT INTO test_table(field) VALUES('two')")