# the function with the connection in the state we found (either idle
# or intrans)
try:
- with conn.transaction():
+ from psycopg import Cursor
+
+ with conn.transaction(), Cursor(conn, row_factory=dict_row) as cur:
if conn_encoding(conn) == "ascii":
- conn.execute("set local client_encoding to utf8")
- with conn.cursor(row_factory=dict_row) as cur:
- cur.execute(cls._get_info_query(conn), {"name": name})
- recs = cur.fetchall()
+ cur.execute("set local client_encoding to utf8")
+ cur.execute(cls._get_info_query(conn), {"name": name})
+ recs = cur.fetchall()
except e.UndefinedObject:
return None
cls: Type[T], conn: "AsyncConnection[Any]", name: str
) -> Optional[T]:
try:
+ from psycopg import AsyncCursor
+
async with conn.transaction():
- if conn_encoding(conn) == "ascii":
- await conn.execute("set local client_encoding to utf8")
- async with conn.cursor(row_factory=dict_row) as cur:
+ async with AsyncCursor(conn, row_factory=dict_row) as cur:
+ if conn_encoding(conn) == "ascii":
+ await cur.execute("set local client_encoding to utf8")
await cur.execute(cls._get_info_query(conn), {"name": name})
recs = await cur.fetchall()
except e.UndefinedObject: