def test_serial(): db.set_server_fields(s.a, 'ka') for uri in _util.get_uris(['mysqldb', 'psycopg2']): with core.ScratchDB(uri, create) as scratch: scratch.conn.debug(sys.stdout) man = orm.Manager(scratch.conn) man.insert(s.a(va='row 1')) man.create(s.a(va='row 2')) man.save(s.a(va='row 3')) inserted = list(scratch.conn.all('select * from a')) assert_equal(inserted, [(1, 'row 1'), (2, 'row 2'), (3, 'row 3')])
def test_insertmany(): # what happens in autocommit mode if a book is already present? # answer: the books before the error are inserted, the others not; # things are tricky, for instance this test fails with # MySQLdb 1.2.4c1 but works with MySQLdb 1.2.3 for uri in _util.get_uris(['sqlite3', 'psycopg2', 'mysqldb']): with core.ScratchDB(uri, _util.createbook, autocommit=True) as scratch: manager = orm.Manager(scratch.conn) manager.insert(s.book('0002', 'book2', 1)) books = [s.book('0001', 'book1', 1), s.book('0002', 'book2', 1), s.book('0003', 'book3', 1)] try: s.book._insert.many(scratch.conn, books) except: pass yield check, manager
def test_savepoints(): for uri in get_uris(['psycopg2', 'mysqldb', 'sqlite3']): with core.ScratchDB(uri, create) as db: yield check1, db.conn yield check2, db.conn