Exemplo n.º 1
0
async def test_example():
    dsn = 'Driver=SQLite;Database=sqlite.db'

    async with aioodbc.create_pool(dsn=dsn, loop=loop) as pool:
        async with pool.acquire() as conn:
            async with conn.cursor() as cur:
                await cur.execute('SELECT 42;')
                val = await cur.fetchone()
                print(val)
Exemplo n.º 2
0
def _connect_pool(loop, finalizer, **kw):
    pool = loop.run_until_complete(aioodbc.create_pool(loop=loop, **kw))

    def fin():
        pool.close()
        loop.run_until_complete(pool.wait_closed())

    finalizer(fin)
    return pool
Exemplo n.º 3
0
async def test_example():
    dsn = 'Driver=SQLite;Database=sqlite.db'

    async with aioodbc.create_pool(dsn=dsn, loop=loop) as pool:
        async with pool.acquire() as conn:
            async with conn.cursor() as cur:
                await cur.execute('SELECT 42;')
                val = await cur.fetchone()
                print(val)
Exemplo n.º 4
0
    async def go():
        async with aioodbc.create_pool(dsn=dsn, loop=loop) as pool:
            async with pool.acquire() as conn:
                async with conn.cursor() as cur:
                    assert not pool.closed
                    assert not conn.closed
                    assert not cur.closed

                    await cur.execute('SELECT 1')
                    val = await cur.fetchone()
                    assert (1,) == tuple(val)

        assert pool.closed
        assert conn.closed
        assert cur.closed
Exemplo n.º 5
0
async def test_all_context_managers(dsn, loop, executor):
    kw = dict(dsn=dsn, loop=loop, executor=executor)
    async with aioodbc.create_pool(**kw) as pool:
        async with pool.acquire() as conn:
            async with conn.cursor() as cur:
                assert not pool.closed
                assert not conn.closed
                assert not cur.closed

                await cur.execute('SELECT 1')
                val = await cur.fetchone()
                assert (1, ) == tuple(val)

    assert pool.closed
    assert conn.closed
    assert cur.closed
Exemplo n.º 6
0
 async def _connection(self):
     try:
         async with aioodbc.create_pool(
                 host=self._host,
                 port=self._port,
                 user=self._user,
                 password=self._password,
                 dsn=self._dsn,
                 connect_timeout=self._connect_timeout,
                 loop=self.Loop) as pool:
             self._conn_pool = pool
             self.ConnectionEvent.set()
             await self._loader()
     except BaseException:
         L.exception("Unexpected ODBC connection error")
         raise
Exemplo n.º 7
0
async def sql_select(query, count):
    try:
        dsn = config['DB_URI']
    except Exception:
        return None
    async with aioodbc.create_pool(dsn=dsn, loop=app.loop) as pool:
        async with pool.acquire() as con:
            async with con.cursor() as cur:
                await cur.execute(query)
                if count == 'all':
                    val = await cur.fetch()
                    return val
                if count == 1:
                    val = await cur.fetchone()
                    return val
                if count > 1:
                    val = await cur.fetchmany(count)
                    return val