コード例 #1
0
async def test_commit(loop=None):
    """
    When not using `autocommit` parameter do not forget to explicitly call
    this method for your changes to persist within database.
    """
    async with aioodbc.connect(dsn=dsn, loop=loop) as conn:
        async with conn.cursor() as cur:
            sql = 'INSERT INTO t1 VALUES(1, "test");'
            await cur.execute(sql)
            # Make sure your changes will be actually saved into database
            await cur.commit()

    async with aioodbc.connect(dsn=dsn, loop=loop) as conn:
        async with conn.cursor() as cur:
            sql_select = 'SELECT * FROM t1;'
            await cur.execute(sql_select)
            # At this point without autocommiting you will not see
            # the data inserted above
            print(await cur.fetchone())
コード例 #2
0
async def test_connect_context_manager(loop, dsn):
    async with aioodbc.connect(dsn=dsn, loop=loop, echo=True) as conn:
        assert not conn.closed
        assert conn.echo

        cur = await conn.execute('SELECT 10;')
        assert cur.echo
        (resp, ) = await cur.fetchone()
        assert resp == 10
        await cur.close()

    assert conn.closed
コード例 #3
0
async def test_connect_context_manager(loop, dsn):
    async with aioodbc.connect(dsn=dsn, loop=loop) as conn:
        assert not conn.closed
    assert conn.closed
コード例 #4
0
ファイル: test_connection.py プロジェクト: aio-libs/aioodbc
async def test_connect_context_manager(loop, dsn):
    async with aioodbc.connect(dsn=dsn, loop=loop) as conn:
        assert not conn.closed
    assert conn.closed