Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ydb_dbapi/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def __init__(self) -> None:
self._description: list[tuple] | None = None
self._state: CursorStatus = CursorStatus.ready

self._table_path_prefix: str = ""

@property
def description(self) -> list[tuple] | None:
return self._description
Expand Down Expand Up @@ -134,6 +136,12 @@ def _fetchall_from_buffer(self) -> list:
self._raise_if_closed()
return list(self._rows or iter([]))

def _append_table_path_prefix(self, query: str) -> str:
if self._table_path_prefix:
prgm = f'PRAGMA TablePathPrefix = "{self._table_path_prefix}";\n'
return prgm + query
return query


class Cursor(BufferedCursor):
def __init__(
Expand Down Expand Up @@ -225,6 +233,9 @@ def execute(
) -> None:
self._raise_if_closed()
self._raise_if_running()

query = self._append_table_path_prefix(query)

if self._tx_context is not None:
self._stream = self._execute_transactional_query(
tx_context=self._tx_context, query=query, parameters=parameters
Expand Down Expand Up @@ -376,6 +387,9 @@ async def execute(
) -> None:
self._raise_if_closed()
self._raise_if_running()

query = self._append_table_path_prefix(query)

if self._tx_context is not None:
self._stream = await self._execute_transactional_query(
tx_context=self._tx_context, query=query, parameters=parameters
Expand Down
Loading