Skip to content
Open
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion src/firebird/driver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5496,12 +5496,13 @@ def __action(self, action: ServerAction, label: str, session_id: int) -> str:
# response should contain the error message
raise DatabaseError(response)
return response
def start(self, *, config: str, name: str | None=None) -> int:
def start(self, *, config: str, name: str | None=None, plugins: str | list[str] | None) -> int:
"""Start new trace session. **(ASYNC service)**

Arguments:
config: Trace session configuration.
name: Trace session name.
plugins: Plugins to use for the session (only for FIREBIRD 6+)

Returns:
Trace session ID.
Expand All @@ -5511,6 +5512,11 @@ def start(self, *, config: str, name: str | None=None) -> int:
spb.insert_tag(ServerAction.TRACE_START)
if name is not None:
spb.insert_string(SrvTraceOption.NAME, name)
if plugins is not None:
if isinstance(plugins, list):
plugins = ",".join(plugins)
spb.insert_string(SrvTraceOption.PLUGINS, plugins)

spb.insert_string(SrvTraceOption.CONFIG, config, encoding=self._srv().encoding)
self._srv()._svc.start(spb.get_buffer())
response = self._srv()._fetch_line()
Expand Down Expand Up @@ -5581,6 +5587,8 @@ def store():
'%Y-%m-%d %H:%M:%S')
elif line.lstrip().startswith('flags:'):
current['flags'] = line.split(':')[1].strip().split(',')
elif line.lstrip().startswith('plugins:'):
current['plugins'] = line.split(':')[1].strip().split(',')
else: # pragma: no cover
raise InterfaceError(f"Unexpected line in trace session list: {line}")
store()
Expand Down
3 changes: 3 additions & 0 deletions src/firebird/driver/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ class SrvTraceOption(IntEnum):
ID = 1
NAME = 2
CONFIG = 3
PLUGINS = 4

class SrvPropertiesOption(IntEnum):
"""Parameters for ServerAction.PROPERTIES.
Expand Down Expand Up @@ -1372,12 +1373,14 @@ class TraceSession:
timestamp (datetime.datetime): Session start timestamp
name (str): Session name (if defined)
flags (list): List with session flag names
plugins (list): List with trace plugins for this session
"""
id: int
user: str
timestamp: datetime.datetime
name: str = ''
flags: list = field(default_factory=list)
plugins: list = field(default_factory=list)

@dataclass
class ImpData:
Expand Down
24 changes: 24 additions & 0 deletions src/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import sys
import os

from firebird.driver.fbapi import load_api
sys.path.append(os.getcwd())
script_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(script_dir)
from firebird.driver.core import connect_server

load_api("/home/artmkn/wspace/reps/rdb5trace/gen/Debug/firebird/lib/libfbclient.so")

with connect_server('', user='SYSDBA', password='masterkey') as srv:

trace_session_id = srv.trace.start(config="#MESSAGETRACE\ndatabase\n{\nenabled = true\n}", name="messagetrace")
print(trace_session_id)

a = input()
# K = 1
# V = TraceSession(id=1, user='SYSDBA', timestamp=..., name=<LONG_NAME_OF_TRACE_SESSION>, flags=['active', ' trace'])
# for k,v in srv.trace.sessions.items():
# if v.flags[0] == 'active':
# print(f"Trace {v.name}: Plugins: {v.plugins}")