Example #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())
Example #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
Example #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
Example #4
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