mapepire-python 1.0.1__py3-none-any.whl → 2.0.0__py3-none-any.whl

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.
@@ -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:
@@ -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
@@ -121,6 +121,7 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
121
121
  else:
122
122
  create_opts = QueryOptions(
123
123
  isClCommand=kwargs.get("isClCommand", None),
124
+ isRemoteClCommand=kwargs.get("isRemoteClCommand", None),
124
125
  isTerseResults=kwargs.get("isTerseResults", None),
125
126
  parameters=parameters if parameters else None,
126
127
  autoClose=kwargs.get("autoclose", None),
@@ -128,6 +129,19 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
128
129
 
129
130
  query = Query(self.job, operation, create_opts)
130
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
+
131
145
  prepare_result = query.prepare_sql_execute()
132
146
 
133
147
  qs = QueryResultSet(prepare_result)
@@ -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,8 +1,8 @@
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.
5
- _PATCH = "1"
5
+ _PATCH = "0"
6
6
  # This is mainly for nightly builds which have the suffix ".dev$DATE". See
7
7
  # https://semver.org/#is-v123-a-semantic-version for the semantics.
8
8
  _SUFFIX = ""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapepire-python
3
- Version: 1.0.1
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:
@@ -1,11 +1,11 @@
1
1
  mapepire_python/__init__.py,sha256=Zefd0EuqhUkFbeCcP5tdZRL7NhCSFTP0-3dEyFFnaW4,1937
2
- mapepire_python/async_base_job.py,sha256=maTbQ4QRFo4lp5U-0J8rOR4LOczNVazz9LuTFJ-096s,8120
2
+ mapepire_python/async_base_job.py,sha256=1aPWg6yqs46VTYK4avdypTV5HmZz2Ub2ivSDfgtiSyo,9027
3
3
  mapepire_python/base_job.py,sha256=SGoiE2J8L9GjU0m0UvwEsfme7MEv0WpdAyQnakEib3Y,3048
4
- mapepire_python/data_types.py,sha256=JzvfwEb034ztAkWc5hbD3_Dc4ja5bWVbZkuam1JI1s4,14565
4
+ mapepire_python/data_types.py,sha256=D5vgvqQjgJ0vb902DHH1c7idoudKkYxf3iGHmUjiJIk,15531
5
5
  mapepire_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  mapepire_python/query_manager.py,sha256=XgdQr10XZYgL2lYBGjLoO3WgS6lVsVDQIX9MUNYVnmg,2259
7
7
  mapepire_python/ssl.py,sha256=ERCbmz3tvKM2WULsCNgDQJe1CMEmCMVqiQU5ZSOFntc,849
8
- mapepire_python/version.py,sha256=5d9nDLkpssmcgQAKf1xvJ2rom9ZiDGRkoyL70m1yVE8,407
8
+ mapepire_python/version.py,sha256=b7XH6xjFZFr43NcGRp379GavqSoFw0sXX9_qHIkk8ro,407
9
9
  mapepire_python/websocket.py,sha256=mGZVaaFVe_7ZvL0M4pArh4nzUhF1okrF4nI42DsFjc4,2765
10
10
  mapepire_python/asyncio/__init__.py,sha256=GuuLvYhXJOathaIe5aCI-fBh0eN4-IhRzgKzj0bNtfI,1375
11
11
  mapepire_python/asyncio/connection.py,sha256=oeSdnJG3MwKUyAekhFxP0-NPq8rgP0C8D7-1JffMaJs,3582
@@ -13,21 +13,21 @@ mapepire_python/asyncio/cursor.py,sha256=nAPxnSqtBBRFzUSjbGxj5CcazYHVh2Tt9A4t94z
13
13
  mapepire_python/authentication/kerberosTokenProvider.py,sha256=FSVvAIP0wKYc-_CciRtmmxFXjQQCrqj71UQdA4crb54,4459
14
14
  mapepire_python/client/__init__.py,sha256=UyTf722DdQIlkm_kDvd8NXCkuX794aGOD7AIL3arzio,58
15
15
  mapepire_python/client/async_sql_job.py,sha256=h_Zgok3gVffQt_EnUBLp9DgqrEeoUNJpr_JaEdK8UX0,392
16
- mapepire_python/client/query.py,sha256=AqlrGqcFKik7dw_HBN4TZVq1lQ4qS0EzI1O9zbi4LP8,7686
17
- mapepire_python/client/sql_job.py,sha256=oV4IKK_XFoZ97p0shs_hxrJY2cEQO-yzkOiahjmPRSw,6475
16
+ mapepire_python/client/query.py,sha256=IMnNjncgAGWkz-OnbmBhP0t8F0kpJneDRNpy8gpbfoY,8223
17
+ mapepire_python/client/sql_job.py,sha256=DR7_hyzghJnYMyfb_kSRVzxa6odCnSLNz-PeaYb9tnM,7461
18
18
  mapepire_python/client/websocket_client.py,sha256=6BveG0KBJuImnvFvP_gj887oaGvdOscpw8ciBPPiej4,568
19
19
  mapepire_python/core/__init__.py,sha256=l4qVM67YjxmaQgbS9dxZKx-hLDHXL4uilcrRZyzYOSk,497
20
20
  mapepire_python/core/connection.py,sha256=byYj_l4bt_fRjOxCSr98KRWIiXsxateRr1Kicj_bNPM,2721
21
- mapepire_python/core/cursor.py,sha256=9kY0ibmUWbXZlelvxd8b5Ikc7CDTLIvs5sCN5tVYazg,7946
21
+ mapepire_python/core/cursor.py,sha256=9tO-btsCklfw5tXd6bM8wglrnBFP3Ru3oHxOteXpYgk,8536
22
22
  mapepire_python/core/exceptions.py,sha256=TKeotZyDmisV_0nz-LIRuTDRlxRDuF51zhCsqlqNVIs,2328
23
23
  mapepire_python/core/utils.py,sha256=poSgmkQ6EzCR06h6Uq6c-OtJWNoPZPzawfqCxdc5t5Q,3574
24
24
  mapepire_python/pool/__init__.py,sha256=ltwC9PuKGhvnIt5AZOJqS1VRgE5BPyNWZU5PJOrmTlg,91
25
25
  mapepire_python/pool/async_websocket_client.py,sha256=xfYsunSPj4Kk91lZz-Rlpf1oWY5H-8CyGi0rkRZ1Cvg,556
26
26
  mapepire_python/pool/pool_client.py,sha256=XQ4DcgDDFJ4DD8w7n1q64UAEvj0KW9a82FUn-ea9n70,6394
27
27
  mapepire_python/pool/pool_job.py,sha256=JJNOqsOBENJgdRE16bxfJHxYFTDYoFSWprVYq1mKqX4,1028
28
- mapepire_python/pool/pool_query.py,sha256=V2lJPFdxfmMXm8jSAaL0-jAE-v_Nt1YrkfvCIHol67g,6309
29
- mapepire_python-1.0.1.dist-info/licenses/LICENSE,sha256=YvuKOpYh3COIF0yqq-nCMXtpS7mh1GyYvPVlW2j1G-M,11359
30
- mapepire_python-1.0.1.dist-info/METADATA,sha256=4dlQwRdO58hJW0bsiKlZLBs63zmZQgJb7J9QKBoKWVc,40402
31
- mapepire_python-1.0.1.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
32
- mapepire_python-1.0.1.dist-info/top_level.txt,sha256=J41xe6UH-ueP4KTS1BB3U-6FVTSca56t_Uxwa13Uwkw,16
33
- mapepire_python-1.0.1.dist-info/RECORD,,
28
+ mapepire_python/pool/pool_query.py,sha256=J_PsMOz9qX-WCMzg-OXPElMGNKmBk1renQfR9QgwnmY,6811
29
+ mapepire_python-2.0.0.dist-info/licenses/LICENSE,sha256=YvuKOpYh3COIF0yqq-nCMXtpS7mh1GyYvPVlW2j1G-M,11359
30
+ mapepire_python-2.0.0.dist-info/METADATA,sha256=UzCVY1y2B85deayDGs6vTMiRlbn1a8m0j-FJa8NxSrA,41340
31
+ mapepire_python-2.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
32
+ mapepire_python-2.0.0.dist-info/top_level.txt,sha256=J41xe6UH-ueP4KTS1BB3U-6FVTSca56t_Uxwa13Uwkw,16
33
+ mapepire_python-2.0.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (84.0.0)
2
+ Generator: setuptools (84.2.1)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5