mapepire-python 1.0.0__tar.gz → 2.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/PKG-INFO +22 -2
  2. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/README.md +19 -0
  3. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/async_base_job.py +22 -0
  4. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/client/query.py +19 -4
  5. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/client/sql_job.py +24 -0
  6. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/core/cursor.py +79 -34
  7. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/data_types.py +28 -0
  8. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/pool/pool_query.py +14 -2
  9. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/version.py +1 -1
  10. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python.egg-info/PKG-INFO +22 -2
  11. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python.egg-info/requires.txt +2 -1
  12. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/pyproject.toml +2 -1
  13. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/LICENSE +0 -0
  14. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/__init__.py +0 -0
  15. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/asyncio/__init__.py +0 -0
  16. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/asyncio/connection.py +0 -0
  17. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/asyncio/cursor.py +0 -0
  18. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/authentication/kerberosTokenProvider.py +0 -0
  19. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/base_job.py +0 -0
  20. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/client/__init__.py +0 -0
  21. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/client/async_sql_job.py +0 -0
  22. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/client/websocket_client.py +0 -0
  23. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/core/__init__.py +0 -0
  24. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/core/connection.py +0 -0
  25. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/core/exceptions.py +0 -0
  26. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/core/utils.py +0 -0
  27. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/pool/__init__.py +0 -0
  28. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/pool/async_websocket_client.py +0 -0
  29. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/pool/pool_client.py +0 -0
  30. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/pool/pool_job.py +0 -0
  31. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/py.typed +0 -0
  32. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/query_manager.py +0 -0
  33. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/ssl.py +0 -0
  34. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python/websocket.py +0 -0
  35. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python.egg-info/SOURCES.txt +0 -0
  36. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python.egg-info/dependency_links.txt +0 -0
  37. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/mapepire_python.egg-info/top_level.txt +0 -0
  38. {mapepire_python-1.0.0 → mapepire_python-2.0.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapepire-python
3
- Version: 1.0.0
3
+ Version: 2.0.0
4
4
  Author-email: Adam Shedivy <adam.shedivy@ibm.com>, Irfan Sharif <IrfanSharif@ibm.com>
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -225,7 +225,7 @@ Requires-Dist: pywin32; sys_platform == "win32" and extra == "kerberos"
225
225
  Provides-Extra: dev
226
226
  Requires-Dist: ruff<0.16,>=0.15; extra == "dev"
227
227
  Requires-Dist: mypy<2.4,>=1.0; extra == "dev"
228
- Requires-Dist: black<27.0,>=24.3.0; extra == "dev"
228
+ Requires-Dist: black<27.0,>=26.10.0; extra == "dev"
229
229
  Requires-Dist: isort<8.1,>=5.12; extra == "dev"
230
230
  Requires-Dist: pytest>=9.0.3; extra == "dev"
231
231
  Requires-Dist: pep249abc; extra == "dev"
@@ -237,6 +237,7 @@ Requires-Dist: setuptools; extra == "dev"
237
237
  Requires-Dist: wheel; extra == "dev"
238
238
  Requires-Dist: packaging; extra == "dev"
239
239
  Requires-Dist: pre-commit; extra == "dev"
240
+ Requires-Dist: virtualenv>=21.15.0; extra == "dev"
240
241
  Requires-Dist: python-dotenv; extra == "dev"
241
242
  Requires-Dist: pytest-env; extra == "dev"
242
243
  Dynamic: license-file
@@ -763,6 +764,25 @@ with SQLJob("./mapepire.ini") as sql_job:
763
764
  print(result)
764
765
  ```
765
766
 
767
+ ### Run CL commands
768
+
769
+ - `clcommand()` runs a CL command in the SQL job (`cl` request)
770
+ - `rcclcommand()` runs it in the remote command job (`rccl` request)
771
+
772
+ Both need Mapepire Server v2.5.0 or later, which added `rccl` and the message format these methods return.
773
+
774
+ ```python
775
+ from mapepire_python import SQLJob
776
+
777
+ with SQLJob("./mapepire.ini") as sql_job:
778
+ result = sql_job.rcclcommand("CHKOBJ OBJ(QSYS) OBJTYPE(*LIB)")
779
+ print(result.success, result.data)
780
+ ```
781
+
782
+ Both return a `CLCommandResult` whose `data` is the list of messages the command produced. A failed command returns `success=False` and `error` instead of raising. `PoolJob` has async versions of both methods.
783
+
784
+ CL commands can also go through `query()` with `QueryOptions(isClCommand=True)` or `QueryOptions(isRemoteClCommand=True)`, or through the sync PEP 249 `Cursor` with `cursor.execute(cmd, isRemoteClCommand=True)`.
785
+
766
786
  ## 2. Using the `PoolJob` object to run queries asynchronously
767
787
 
768
788
  The `PoolJob` object can be used to create and run queries asynchronously:
@@ -520,6 +520,25 @@ with SQLJob("./mapepire.ini") as sql_job:
520
520
  print(result)
521
521
  ```
522
522
 
523
+ ### Run CL commands
524
+
525
+ - `clcommand()` runs a CL command in the SQL job (`cl` request)
526
+ - `rcclcommand()` runs it in the remote command job (`rccl` request)
527
+
528
+ Both need Mapepire Server v2.5.0 or later, which added `rccl` and the message format these methods return.
529
+
530
+ ```python
531
+ from mapepire_python import SQLJob
532
+
533
+ with SQLJob("./mapepire.ini") as sql_job:
534
+ result = sql_job.rcclcommand("CHKOBJ OBJ(QSYS) OBJTYPE(*LIB)")
535
+ print(result.success, result.data)
536
+ ```
537
+
538
+ Both return a `CLCommandResult` whose `data` is the list of messages the command produced. A failed command returns `success=False` and `error` instead of raising. `PoolJob` has async versions of both methods.
539
+
540
+ CL commands can also go through `query()` with `QueryOptions(isClCommand=True)` or `QueryOptions(isRemoteClCommand=True)`, or through the sync PEP 249 `Cursor` with `cursor.execute(cmd, isRemoteClCommand=True)`.
541
+
523
542
  ## 2. Using the `PoolJob` object to run queries asynchronously
524
543
 
525
544
  The `PoolJob` object can be used to create and run queries asynchronously:
@@ -10,11 +10,15 @@ from websockets.asyncio.client import ClientConnection
10
10
 
11
11
  from .base_job import BaseJob
12
12
  from .data_types import (
13
+ BaseRequest,
14
+ CLCommandResult,
15
+ ClRequest,
13
16
  ConnectionResult,
14
17
  ConnectRequest,
15
18
  DaemonServer,
16
19
  JobStatus,
17
20
  QueryOptions,
21
+ RcclRequest,
18
22
  )
19
23
 
20
24
  __all__ = ["AsyncBaseJob"]
@@ -209,6 +213,24 @@ class AsyncBaseJob(BaseJob):
209
213
  except Exception as e:
210
214
  raise RuntimeError(f"Failed to run query: {e}") from e
211
215
 
216
+ async def clcommand(self, cmd: str) -> CLCommandResult:
217
+ """Run a CL command in the SQL job (``cl``)."""
218
+ return await self._run_cl_command(cmd, remote=False)
219
+
220
+ async def rcclcommand(self, cmd: str) -> CLCommandResult:
221
+ """Run a CL command in the remote command job (``rccl``, Mapepire Server v2.5.0+)."""
222
+ return await self._run_cl_command(cmd, remote=True)
223
+
224
+ async def _run_cl_command(self, cmd: str, remote: bool) -> CLCommandResult:
225
+ request: BaseRequest = (
226
+ RcclRequest(id=self._get_unique_id("rcclcommand"), cmd=cmd)
227
+ if remote
228
+ else ClRequest(id=self._get_unique_id("clcommand"), cmd=cmd)
229
+ )
230
+ return CLCommandResult.from_dict( # type: ignore[attr-defined]
231
+ await self.send(json.dumps(dataclasses.asdict(request)))
232
+ )
233
+
212
234
  async def close(self) -> None: # type: ignore[override]
213
235
  logger.info("Closing job %s", self.id)
214
236
  await self.dispose()
@@ -12,6 +12,7 @@ from ..data_types import (
12
12
  PrepareSqlExecuteRequest,
13
13
  QueryOptions,
14
14
  QueryResult,
15
+ RcclRequest,
15
16
  SqlCloseRequest,
16
17
  SqlCloseResponse,
17
18
  SqlMoreRequest,
@@ -40,7 +41,8 @@ class Query(Generic[T]):
40
41
  self.sql: str = query
41
42
  self.is_prepared: bool = True if opts.parameters is not None else False
42
43
  self.parameters: Union[Sequence[Any], Mapping[Union[str, int], Any]] = opts.parameters if opts.parameters is not None else []
43
- self.is_cl_command: Optional[bool] = opts.isClCommand
44
+ self.is_remote_cl_command: Optional[bool] = opts.isRemoteClCommand
45
+ self.is_cl_command: Optional[bool] = opts.isClCommand or opts.isRemoteClCommand
44
46
  self.should_auto_close: Optional[bool] = opts.autoClose
45
47
  self.is_terse_results: Optional[bool] = opts.isTerseResults
46
48
 
@@ -71,6 +73,9 @@ class Query(Generic[T]):
71
73
  if self.state == QueryState.RUN_DONE:
72
74
  raise Exception("Statement has already been fully run")
73
75
 
76
+ if self.is_cl_command:
77
+ return self.run()
78
+
74
79
  logger.debug("Preparing and executing query")
75
80
  query_result = QueryResult.from_dict( # type: ignore
76
81
  self._execute_query(
@@ -83,7 +88,7 @@ class Query(Generic[T]):
83
88
  )
84
89
  self.state = QueryState.RUN_DONE if query_result.is_done else QueryState.RUN_MORE_DATA_AVAIL
85
90
 
86
- if not query_result.success and not self.is_cl_command:
91
+ if not query_result.success:
87
92
  self.state = QueryState.ERROR
88
93
  error_list = {k: v for k, v in {"error": query_result.error, "sql_state": query_result.sql_state, "sql_rc": query_result.sql_rc}.items() if v}
89
94
  if not error_list:
@@ -111,7 +116,13 @@ class Query(Generic[T]):
111
116
 
112
117
  logger.debug("Executing query: rows_to_fetch=%s", rows_to_fetch)
113
118
 
114
- if self.is_cl_command:
119
+ request: BaseRequest
120
+ if self.is_remote_cl_command:
121
+ request = RcclRequest(
122
+ id=self.job._get_unique_id("rcclcommand"),
123
+ cmd=self.sql,
124
+ )
125
+ elif self.is_cl_command:
115
126
  request = ClRequest(
116
127
  id=self.job._get_unique_id("clcommand"),
117
128
  cmd=self.sql,
@@ -136,6 +147,10 @@ class Query(Generic[T]):
136
147
 
137
148
  query_result = QueryResult.from_dict(self._execute_query(request)) # type: ignore
138
149
 
150
+ # CL commands return all messages in one response; mapepire-server 2.5.0+ omits is_done for them
151
+ if self.is_cl_command:
152
+ query_result.is_done = True
153
+
139
154
  self.state = QueryState.RUN_DONE if query_result.is_done else QueryState.RUN_MORE_DATA_AVAIL
140
155
 
141
156
  if not query_result.success and not self.is_cl_command:
@@ -152,7 +167,7 @@ class Query(Generic[T]):
152
167
  return query_result
153
168
 
154
169
  @handle_ws_errors
155
- def fetch_more(self, rows_to_fetch: Optional[int] = None) -> Dict[str, Any]:
170
+ def fetch_more(self, rows_to_fetch: Optional[int] = None) -> SqlMoreResponse:
156
171
  if rows_to_fetch is None:
157
172
  rows_to_fetch = self._rows_to_fetch
158
173
  else:
@@ -11,11 +11,15 @@ from mapepire_python.websocket import handle_ws_errors
11
11
 
12
12
  from ..base_job import BaseJob
13
13
  from ..data_types import (
14
+ BaseRequest,
15
+ CLCommandResult,
16
+ ClRequest,
14
17
  ConnectionResult,
15
18
  ConnectRequest,
16
19
  DaemonServer,
17
20
  JobStatus,
18
21
  QueryOptions,
22
+ RcclRequest,
19
23
  )
20
24
 
21
25
  __all__ = ["SQLJob"]
@@ -202,6 +206,26 @@ class SQLJob(BaseJob):
202
206
  except Exception as e:
203
207
  raise RuntimeError(f"Failed to run query: {e}")
204
208
 
209
+ def clcommand(self, cmd: str) -> CLCommandResult:
210
+ """Run a CL command in the SQL job (``cl``)."""
211
+ return self._run_cl_command(cmd, remote=False)
212
+
213
+ def rcclcommand(self, cmd: str) -> CLCommandResult:
214
+ """Run a CL command in the remote command job (``rccl``, Mapepire Server v2.5.0+)."""
215
+ return self._run_cl_command(cmd, remote=True)
216
+
217
+ @handle_ws_errors
218
+ def _run_cl_command(self, cmd: str, remote: bool) -> CLCommandResult:
219
+ request: BaseRequest = (
220
+ RcclRequest(id=self._get_unique_id("rcclcommand"), cmd=cmd)
221
+ if remote
222
+ else ClRequest(id=self._get_unique_id("clcommand"), cmd=cmd)
223
+ )
224
+ self.send(json.dumps(dataclasses.asdict(request)))
225
+ if self._socket is None:
226
+ raise RuntimeError("SQL Job not connected")
227
+ return CLCommandResult.from_dict(json.loads(self._socket.recv())) # type: ignore
228
+
205
229
  def close(self) -> None:
206
230
  logger.info("Closing job %s", self.id)
207
231
  self._status = JobStatus.Ended
@@ -1,7 +1,18 @@
1
1
  import logging
2
2
  import weakref
3
3
  from collections import deque
4
- from typing import TYPE_CHECKING, Any, Optional, Sequence, Type, Union, cast
4
+ from dataclasses import dataclass, field
5
+ from typing import (
6
+ TYPE_CHECKING,
7
+ Any,
8
+ Deque,
9
+ List,
10
+ Optional,
11
+ Sequence,
12
+ Type,
13
+ Union,
14
+ cast,
15
+ )
5
16
 
6
17
  import pep249
7
18
  from pep249 import (
@@ -14,23 +25,33 @@ from pep249 import (
14
25
  SQLQuery,
15
26
  )
16
27
 
17
- if TYPE_CHECKING:
18
- # pylint: disable=cyclic-import
19
- from ..core.connection import Connection
20
-
21
28
  from ..client.query import Query, QueryState
22
29
  from ..client.sql_job import SQLJob
23
30
  from ..core.exceptions import convert_runtime_errors
24
31
  from ..core.utils import DB_TYPE_MAP, QueryResultSet, raise_if_closed, row_to_tuple
25
32
  from ..data_types import QueryOptions
26
33
 
34
+ if TYPE_CHECKING:
35
+ # pylint: disable=cyclic-import
36
+ from ..core.connection import Connection
37
+
27
38
  __all__ = ["Cursor"]
28
39
 
29
40
  logger = logging.getLogger(__name__)
30
41
 
31
42
 
43
+ @dataclass
44
+ class _ResultState:
45
+ """Fetch state for one query: its column metadata and rows received but not yet returned."""
46
+
47
+ metadata: Any
48
+ rows: Deque[Any] = field(default_factory=deque)
49
+
50
+
32
51
  class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.TransactionalCursor):
33
52
  max_rows = 2147483647
53
+ # Rows requested per round trip when fetchone() (and so iteration) needs more data.
54
+ fetch_size = 100
34
55
 
35
56
  def __init__(self, connection: "Connection", job: SQLJob) -> None:
36
57
  super().__init__()
@@ -38,7 +59,10 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
38
59
  self.job = job
39
60
  self.query: Optional[Query] = None
40
61
  self.query_q: deque[Query] = deque(maxlen=20)
41
- self._result_set: Optional[QueryResultSet] = None
62
+ # Keyed weakly so a query evicted from query_q takes its buffered rows with it.
63
+ self._results: "weakref.WeakKeyDictionary[Query, _ResultState]" = (
64
+ weakref.WeakKeyDictionary()
65
+ )
42
66
  self._metadata = None
43
67
  self.__closed = False
44
68
  self.__has_results = False
@@ -97,6 +121,7 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
97
121
  else:
98
122
  create_opts = QueryOptions(
99
123
  isClCommand=kwargs.get("isClCommand", None),
124
+ isRemoteClCommand=kwargs.get("isRemoteClCommand", None),
100
125
  isTerseResults=kwargs.get("isTerseResults", None),
101
126
  parameters=parameters if parameters else None,
102
127
  autoClose=kwargs.get("autoclose", None),
@@ -104,6 +129,19 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
104
129
 
105
130
  query = Query(self.job, operation, create_opts)
106
131
 
132
+ if query.is_cl_command:
133
+ # CL commands return messages, not rows, and Query.run() does not raise when they fail.
134
+ cl_result = query.run()
135
+ self.query = None
136
+ self._metadata = None
137
+ self.__set_has_results(False)
138
+ self.rowcount = -1
139
+ if not cl_result["success"]:
140
+ raise RuntimeError(
141
+ {"error": cl_result["error"] or "CL command failed for unknown reason"}
142
+ )
143
+ return self
144
+
107
145
  prepare_result = query.prepare_sql_execute()
108
146
 
109
147
  qs = QueryResultSet(prepare_result)
@@ -113,6 +151,8 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
113
151
  self.query = query
114
152
  self.__set_has_results(True)
115
153
  self.query_q.append(query)
154
+ # Rows that arrive with the execute response are served by the first fetch.
155
+ self._results[query] = _ResultState(self._metadata, deque(qs.data or []))
116
156
  else:
117
157
  self.__set_has_results(False)
118
158
 
@@ -156,42 +196,46 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
156
196
  for col in self._metadata.columns
157
197
  ]
158
198
 
199
+ def _fetch_rows(self, size: int, batch_size: int = 0) -> ResultSet:
200
+ """Return up to ``size`` rows of the current query as tuples.
201
+
202
+ Buffered rows are served first; the server is only asked for more once
203
+ the buffer is empty, and then for at least ``batch_size`` rows. Once the
204
+ result set is exhausted this returns what it has (possibly ``[]``)
205
+ instead of raising.
206
+ """
207
+ if self.query is None:
208
+ return []
209
+ state = self._results[self.query]
210
+ rows: List[ResultRow] = []
211
+ while len(rows) < size:
212
+ if not state.rows:
213
+ if self.query.state == QueryState.RUN_DONE:
214
+ break
215
+ res = self.query.fetch_more(rows_to_fetch=max(size - len(rows), batch_size))
216
+ if not res.data:
217
+ break
218
+ state.rows.extend(res.data)
219
+ rows.append(row_to_tuple(state.rows.popleft(), state.metadata))
220
+ return rows
221
+
159
222
  @raise_if_closed
160
223
  @convert_runtime_errors
161
224
  def fetchone(self) -> Optional[ResultRow]:
162
- if not self.query or self.query.state == QueryState.RUN_DONE:
163
- return None
164
- res = self.query.fetch_more(rows_to_fetch=1)
165
- if res:
166
- self._result_set = QueryResultSet(res)
167
- if self._result_set.data:
168
- return row_to_tuple(self._result_set.data[0], self._metadata)
169
- return None
225
+ rows = self._fetch_rows(1, batch_size=self.fetch_size)
226
+ return rows[0] if rows else None
170
227
 
171
228
  @raise_if_closed
172
229
  @convert_runtime_errors
173
230
  def fetchall(self) -> ResultSet:
174
- if not self.query:
175
- return []
176
-
177
- res = self.query.fetch_more(rows_to_fetch=self.max_rows)
178
- if res:
179
- self._result_set = QueryResultSet(res)
180
- return [row_to_tuple(row, self._metadata) for row in self._result_set.data]
181
- return []
231
+ return self._fetch_rows(self.max_rows)
182
232
 
183
233
  @raise_if_closed
184
234
  @convert_runtime_errors
185
235
  def fetchmany(self, size: Optional[int] = None) -> ResultSet:
186
236
  if size is None:
187
237
  size = self.arraysize
188
- if not self.query:
189
- return []
190
- res = self.query.fetch_more(rows_to_fetch=size)
191
- if res:
192
- self._result_set = QueryResultSet(res)
193
- return [row_to_tuple(row, self._metadata) for row in self._result_set.data]
194
- return []
238
+ return self._fetch_rows(size)
195
239
 
196
240
  def executescript(self, script: SQLQuery) -> "Cursor":
197
241
  """A lazy implementation of SQLite's `executescript`."""
@@ -202,6 +246,7 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
202
246
  if len(self.query_q) > 1:
203
247
  self.query_q.popleft()
204
248
  self.query = self.query_q[0]
249
+ self._metadata = self._results[self.query].metadata
205
250
  self.__set_has_results(True)
206
251
  return True
207
252
  return None
@@ -214,11 +259,11 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
214
259
  if self._closed:
215
260
  return
216
261
  logger.debug("Closing cursor")
217
- if self.query:
218
- for q in self.query_q:
219
- q.close()
220
- self.query_q.clear()
221
- self._closed = True
262
+ for q in self.query_q:
263
+ q.close()
264
+ self.query_q.clear()
265
+ self._results.clear()
266
+ self._closed = True
222
267
 
223
268
  def commit(self) -> None:
224
269
  self.job.query_and_run("COMMIT")
@@ -73,6 +73,7 @@ class MessageType(Enum):
73
73
  SQL_MORE = "sqlmore"
74
74
  SQL_CLOSE = "sqlclose"
75
75
  CL = "cl"
76
+ RCCL = "rccl"
76
77
  PING = "ping"
77
78
  GET_DB_JOB = "getdbjob"
78
79
  GET_VERSION = "getversion"
@@ -316,9 +317,28 @@ class JobLogEntry:
316
317
  MESSAGE_SECOND_LEVEL_TEXT: str
317
318
 
318
319
 
320
+ @dataclass
321
+ class CLMessage:
322
+ id: Optional[str] = None
323
+ type: Optional[str] = None
324
+ severity: Optional[int] = None
325
+ text: Optional[str] = None
326
+ help: Optional[str] = None
327
+ time: Optional[int] = None
328
+ messageLibrary: Optional[str] = None
329
+ messageFile: Optional[str] = None
330
+ sendingProgram: Optional[str] = None
331
+ sendingInstruction: Optional[str] = None
332
+ receivingProgram: Optional[str] = None
333
+ receivingInstruction: Optional[str] = None
334
+
335
+
319
336
  @dataclass_json
320
337
  @dataclass
321
338
  class CLCommandResult(ServerResponse):
339
+ # sql_rc and sql_state are only set by `cl` requests; `rccl` does not run SQL.
340
+ data: List[CLMessage] = field(default_factory=list)
341
+ # Deprecated: no longer sent by Mapepire Server, kept for backwards compatibility
322
342
  joblog: List[JobLogEntry] = field(default_factory=list)
323
343
 
324
344
 
@@ -328,6 +348,8 @@ class QueryOptions:
328
348
  isClCommand: Optional[bool] = None
329
349
  parameters: Optional[Union[Sequence[Any], Mapping[Union[str, int], Any]]] = None
330
350
  autoClose: Optional[bool] = None
351
+ # `rccl` instead of `cl` (Mapepire Server v2.5.0+); implies isClCommand
352
+ isRemoteClCommand: Optional[bool] = None
331
353
 
332
354
 
333
355
  @dataclass_json
@@ -406,6 +428,12 @@ class ClRequest(BaseRequest):
406
428
  type: str = field(default=MessageType.CL.value, init=False)
407
429
 
408
430
 
431
+ @dataclass
432
+ class RcclRequest(BaseRequest):
433
+ cmd: str = ""
434
+ type: str = field(default=MessageType.RCCL.value, init=False)
435
+
436
+
409
437
  @dataclass
410
438
  class PingRequest(BaseRequest):
411
439
  type: str = field(default=MessageType.PING.value, init=False)
@@ -10,6 +10,7 @@ from mapepire_python.data_types import (
10
10
  PrepareSqlExecuteRequest,
11
11
  QueryOptions,
12
12
  QueryResult,
13
+ RcclRequest,
13
14
  SqlCloseRequest,
14
15
  SqlCloseResponse,
15
16
  SqlMoreRequest,
@@ -42,7 +43,8 @@ class PoolQuery:
42
43
  self.sql: str = query
43
44
  self.is_prepared: bool = True if opts.parameters is not None else False
44
45
  self.parameters: Optional[Union[Sequence[Any], Mapping[Union[str, int], Any]]] = opts.parameters
45
- self.is_cl_command: Optional[bool] = opts.isClCommand
46
+ self.is_remote_cl_command: Optional[bool] = opts.isRemoteClCommand
47
+ self.is_cl_command: Optional[bool] = opts.isClCommand or opts.isRemoteClCommand
46
48
  self.should_auto_close: Optional[bool] = opts.autoClose
47
49
  self.is_terse_results: Optional[bool] = opts.isTerseResults
48
50
 
@@ -76,7 +78,13 @@ class PoolQuery:
76
78
 
77
79
  logger.debug("Executing async query: rows_to_fetch=%s", rows_to_fetch)
78
80
 
79
- if self.is_cl_command:
81
+ request: BaseRequest
82
+ if self.is_remote_cl_command:
83
+ request = RcclRequest(
84
+ id=self.job._get_unique_id("rcclcommand"),
85
+ cmd=self.sql,
86
+ )
87
+ elif self.is_cl_command:
80
88
  request = ClRequest(
81
89
  id=self.job._get_unique_id("clcommand"),
82
90
  cmd=self.sql,
@@ -101,6 +109,10 @@ class PoolQuery:
101
109
 
102
110
  query_result = QueryResult.from_dict(await self._execute_query(request)) # type: ignore
103
111
 
112
+ # CL commands return all messages in one response; mapepire-server 2.5.0+ omits is_done for them
113
+ if self.is_cl_command:
114
+ query_result.is_done = True
115
+
104
116
  self.state = QueryState.RUN_DONE if query_result.is_done else QueryState.RUN_MORE_DATA_AVAIL
105
117
 
106
118
  if not query_result.success and not self.is_cl_command:
@@ -1,4 +1,4 @@
1
- _MAJOR = "1"
1
+ _MAJOR = "2"
2
2
  _MINOR = "0"
3
3
  # On main and in a nightly release the patch should be one ahead of the last
4
4
  # released build.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapepire-python
3
- Version: 1.0.0
3
+ Version: 2.0.0
4
4
  Author-email: Adam Shedivy <adam.shedivy@ibm.com>, Irfan Sharif <IrfanSharif@ibm.com>
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -225,7 +225,7 @@ Requires-Dist: pywin32; sys_platform == "win32" and extra == "kerberos"
225
225
  Provides-Extra: dev
226
226
  Requires-Dist: ruff<0.16,>=0.15; extra == "dev"
227
227
  Requires-Dist: mypy<2.4,>=1.0; extra == "dev"
228
- Requires-Dist: black<27.0,>=24.3.0; extra == "dev"
228
+ Requires-Dist: black<27.0,>=26.10.0; extra == "dev"
229
229
  Requires-Dist: isort<8.1,>=5.12; extra == "dev"
230
230
  Requires-Dist: pytest>=9.0.3; extra == "dev"
231
231
  Requires-Dist: pep249abc; extra == "dev"
@@ -237,6 +237,7 @@ Requires-Dist: setuptools; extra == "dev"
237
237
  Requires-Dist: wheel; extra == "dev"
238
238
  Requires-Dist: packaging; extra == "dev"
239
239
  Requires-Dist: pre-commit; extra == "dev"
240
+ Requires-Dist: virtualenv>=21.15.0; extra == "dev"
240
241
  Requires-Dist: python-dotenv; extra == "dev"
241
242
  Requires-Dist: pytest-env; extra == "dev"
242
243
  Dynamic: license-file
@@ -763,6 +764,25 @@ with SQLJob("./mapepire.ini") as sql_job:
763
764
  print(result)
764
765
  ```
765
766
 
767
+ ### Run CL commands
768
+
769
+ - `clcommand()` runs a CL command in the SQL job (`cl` request)
770
+ - `rcclcommand()` runs it in the remote command job (`rccl` request)
771
+
772
+ Both need Mapepire Server v2.5.0 or later, which added `rccl` and the message format these methods return.
773
+
774
+ ```python
775
+ from mapepire_python import SQLJob
776
+
777
+ with SQLJob("./mapepire.ini") as sql_job:
778
+ result = sql_job.rcclcommand("CHKOBJ OBJ(QSYS) OBJTYPE(*LIB)")
779
+ print(result.success, result.data)
780
+ ```
781
+
782
+ Both return a `CLCommandResult` whose `data` is the list of messages the command produced. A failed command returns `success=False` and `error` instead of raising. `PoolJob` has async versions of both methods.
783
+
784
+ CL commands can also go through `query()` with `QueryOptions(isClCommand=True)` or `QueryOptions(isRemoteClCommand=True)`, or through the sync PEP 249 `Cursor` with `cursor.execute(cmd, isRemoteClCommand=True)`.
785
+
766
786
  ## 2. Using the `PoolJob` object to run queries asynchronously
767
787
 
768
788
  The `PoolJob` object can be used to create and run queries asynchronously:
@@ -5,7 +5,7 @@ pep249abc
5
5
  [dev]
6
6
  ruff<0.16,>=0.15
7
7
  mypy<2.4,>=1.0
8
- black<27.0,>=24.3.0
8
+ black<27.0,>=26.10.0
9
9
  isort<8.1,>=5.12
10
10
  pytest>=9.0.3
11
11
  pep249abc
@@ -17,6 +17,7 @@ setuptools
17
17
  wheel
18
18
  packaging
19
19
  pre-commit
20
+ virtualenv>=21.15.0
20
21
  python-dotenv
21
22
  pytest-env
22
23
 
@@ -40,7 +40,7 @@ kerberos = [
40
40
  dev = [
41
41
  "ruff>=0.15,<0.16",
42
42
  "mypy>=1.0,<2.4",
43
- "black>=24.3.0,<27.0",
43
+ "black>=26.10.0,<27.0",
44
44
  "isort>=5.12,<8.1",
45
45
  "pytest>=9.0.3",
46
46
  "pep249abc",
@@ -52,6 +52,7 @@ dev = [
52
52
  "wheel",
53
53
  "packaging",
54
54
  "pre-commit",
55
+ "virtualenv>=21.15.0",
55
56
  "python-dotenv",
56
57
  "pytest-env",
57
58
  ]
File without changes