-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathengine_app_api.py
586 lines (532 loc) · 30.2 KB
/
engine_app_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
import json
class EngineAppApi:
def __init__(self, socket):
self.engine_socket = socket
def get_script(self, doc_handle):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetScript", "params": []})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
def set_script(self, doc_handle, script):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "SetScript", "params": [script]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
def do_reload(self, doc_handle, param_list=[]):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DoReload", "params": param_list})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
def do_reload_ex(self, doc_handle, param_list=[]):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DoReloadEx", "params": param_list})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
def get_app_layout(self, doc_handle):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetAppLayout", "params": []})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
def get_object(self, doc_handle, param_list=[]):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetObject", "params": param_list})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
def get_field(self, doc_handle, field_name, state_name=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetField", "params":
{"qFieldName": field_name, "qStateName": state_name}})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
def create_object(self, doc_handle, q_id="LB01", q_type = "ListObject", struct_name="qListObjectDef",
ob_struct={}):
msg=json.dumps({"jsonrpc": "2.0", "id": 0, "method": "CreateObject", "handle": doc_handle,
"params": [{"qInfo": {"qId": q_id, "qType": q_type},struct_name: ob_struct}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# AddAlternateState method: Create an alternate state in app
# You can create multiple states within a Qlik Sense app and apply these states to specific objects within the app.
# Objects in a given state are not affected by user selections in the other states.
# Call GetAppLayout() afterwards to get the latest states
def add_alternate_state(self, doc_handle, state_name):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "AddAlternateState", "params": [state_name]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# AddFieldFromExpression method: Adds a field on the fly. !! The expression of a field on the fly is persisted but
# not its values. !!
def add_field_from_expression(self, doc_handle, field_name, expr_value):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "AddFieldFromExpression",
"params": [field_name, expr_value]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# CheckExpression method: Checks whether an expression is valid or not
# qErrorMsg is empty if it's valid
def check_expression(self, doc_handle, expr_value):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "CheckExpression", "params": [expr_value]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# CheckScriptSyntax method: Checks whether a load script is valid or not
# Used AFTER doing SetScript method
# errors are displayed in an array discussing positions of characters in script where failing
def check_script(self, doc_handle, expr_value):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "CheckScriptSyntax",
"params": [expr_value]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
def clear_all(self, doc_handle, locked_also=False, alt_state=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "ClearAll",
"params": [locked_also, alt_state]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# CreateConnection method: Creates a connection. A connection indicates from which data source, the data should
# be taken. The connection can be: an ODBC connection, OLEDB connection, a custom connection, a folder connection
# (lib connection), an internet connection, Single Sign-On
def create_connection(self, doc_handle, connect_name, connect_string, connect_type, user_name, password,
mod_date="", meta="", sso_passthrough="LOG_ON_SERVICE_USER"):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "CreateConnection", "params": [{
"qName": connect_name,
"qMeta": meta,
"qConnectionString": connect_string,
"qType": connect_type
}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# CreateDimension method: Creates a master dimension.
# A Master Dimension is stored in the library of an app and can be used in many objects. Several generic objects
# can contain the same dimension.
# Parameters:
# qProp (MANDATORY: send dim_id, dim_title, dim_grouping, dim_field, dim_label, meta_def (optional)
def create_master_dim(self, doc_handle, dim_id, dim_title, dim_grouping="N", dim_field='', dim_label='',
meta_def=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "CreateDimension", "params": [{
"qInfo": {
"qId": dim_id,
"qType": "Dimension"
},
"qDim": {
"title": dim_title,
"qGrouping": dim_grouping,
"qFieldDefs": [
dim_field
],
"qFieldLabels": [
dim_label
]
},
"qMetaDef": {
"title": meta_def
}
}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# DestroyDimension method: Removes a dimension
def destroy_dim(self, doc_handle, dim_id):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DestroyDimension", "params": [{dim_id}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# DestroyMeasure method: Removes a measure
def destroy_measure(self, doc_handle, measure_id):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DestroyDimension",
"params": [{measure_id}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# DestroyObject method: Removes an app object. The children of the object (if any) are removed as well.
def destroy_object(self, doc_handle, object_id):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DestroyObject", "params": [{object_id}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# DestroySessionObject method: Removes a session object. The children of the object (if any) are removed as well.
def destroy_session_object(self, doc_handle, object_id):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DestroySessionObject",
"params": [{object_id}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# DestroySessionVariable method: Removes an transient variable.
def destroy_session_variable(self, doc_handle, var_id):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DestroySessionVariable",
"params": [{var_id}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# DestroyVariableById method: Removes a varable..
# Script-defined variables cannot be removed using the DestroyVariableById method or the
# DestroyVariableByName method.
def destroy_variable_by_id(self, doc_handle, var_name):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DestroyVariableById",
"params": [{var_name}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# CreateMeasure method: Creates a master dimension.
# A Master Dimension is stored in the library of an app and can be used in many objects. Several generic objects
# can contain the same dimension.
# Parameters:
# qProp (MANDATORY: send dim_id, dim_title, dim_grouping, dim_field, dim_label, meta_def (optional)
def create_master_measure(self, doc_handle, measure_id, measure_title, measure_expr, meta_def=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "CreateMeasure", "params": [{
"qInfo": {
"qId": measure_id,
"qType": "Measure"
},
"qMeasure": {
"qLabel": measure_title,
"qDef": measure_expr
},
"qMetaDef": {
"title": measure_title
}
}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# CreateObject method: Creates a generic object at app level. It is possible to create a generic object that is
# linked to another object. A linked object is an object that points to a linking object. The linking object is
# defined in the properties of the linked object (in qExtendsId). The linked object has the same properties as the
# linking object.
# TODO: Come back to this - Very important that it is well understood how we want to create objects / datasets from
# python in app
# Convert hypercube to dict or some other data set
# CreateSession Object method: Creates a generic object at app level. It is possible to create a generic object that is linked to another object. A linked object is an object that points to a linking object. The linking object is defined in the properties of the linked object (in qExtendsId). The linked object has the same properties as the linking object.
# TODO: Come back to this - Very important that it is well understood how we want to create objects / datasets from
# python in app
# Convert hypercube to dict or some other data set
# CreateSessionVariable method:
# A variable in Qlik Sense is a named entity, containing a data value. This value can be static or be the result of a calculation. A variable acquires its value at the same time that the variable is created or after when updating the properties of the variable. Variables can be used in bookmarks and can contain numeric or alphanumeric data. Any change made to the variable is applied everywhere the variable is used.
# When a variable is used in an expression, it is substituted by its value or the variable's definition.
#### Example: The variable x contains the text string Sum(Sales). In a chart, you define the expression $(x)/12. The effect is exactly the same as having the chart expression Sum(Sales)/12. However, if you change the value of the variable x to Sum(Budget), the data in the chart are immediately recalculated with the expression interpreted as Sum(Budget)/12.
def create_session_variable(self, doc_handle, var_id="", var_name="", var_comment="", var_def=""):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "CreateSessionVariable", "params": [{
"qInfo": {
"qId": var_id,
"qType": "Variable"
},
"qName": var_name,
"qComment": var_comment,
"qDefinition": var_def
}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# CreateVariable method:
# A variable in Qlik Sense is a named entity, containing a data value. This value can be static or be the result of a calculation. A variable acquires its value at the same time that the variable is created or after when updating the properties of the variable. Variables can be used in bookmarks and can contain numeric or alphanumeric data. Any change made to the variable is applied everywhere the variable is used.
# When a variable is used in an expression, it is substituted by its value or the variable's definition.
#### Example: The variable x contains the text string Sum(Sales). In a chart, you define the expression $(x)/12. The effect is exactly the same as having the chart expression Sum(Sales)/12. However, if you change the value of the variable x to Sum(Budget), the data in the chart are immediately recalculated with the expression interpreted as Sum(Budget)/12.
def create_variable(self, doc_handle, var_id="", var_name="", var_comment="", var_def=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "CreateVariable", "params": [{
"qInfo": {
"qId": var_id,
"qType": "Variable"
},
"qName": var_name,
"qComment": var_comment,
"qDefinition": var_def
}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# DoReload method: Reloads the script that is set in an app.
# Parameters:
# qMode (optional): Error handling mode (Integer).. 0: for default mode, 1: for ABEND; the reload of the script ends if an error occurs., 2: for ignore; the reload of the script continues even if an error is detected in the script.
# qPartial (optional): Set to true for partial reload, The default value is false.
# qDebug (optional): Set to true if debug breakpoints are to be honored. The execution of the script will be in debug mode. The default value is false.
def do_reload(self, doc_handle, reload_mode=0, partial_mode=False, debug_mode=False):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DoReload",
"params": [reload_mode, partial_mode, debug_mode]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# DoSave method: Saves an app - All objects and data in the data model are saved.
# Desktop only - server auto saves
def do_save(self, doc_handle):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "DoSave", "params": []})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# Evaluate method: Evaluates an expression as a string. (Actually uses EvaluateEx, which is better for giving the data type back to python)
# Parameters: qExpression
def expr_eval(self, doc_handle, expr):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "EvaluateEx",
"params": {"qExpression": expr}})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetAllInfos method: Get the identifier and the type of any generic object in an app by using the GetAllInfos method.
def get_all_infos(self, doc_handle):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetAllInfos", "params": []})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetAppProperties method: Gets the properties of an app.
def get_app_properties(self, doc_handle):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetAppProperties", "params": []})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetConnection method: Retrieves a connection and returns: The creation time of the connection, The identifier of
# the connection, The type of the connection, The name of the connection, The connection string
def get_connection(self, doc_handle, connection_id):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetConnection", "params": [connection_id]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetConnections method: Lists the connections in an app
def get_connections(self, doc_handle):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetConnections", "params": []})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetDatabaseInfo: Get information about an ODBC, OLEDB or CUSTOM connection
def get_db_info(self, doc_handle, connection_id):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetDatabaseInfo",
"params": [connection_id]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetDatabaseOwners: List the owners of a database for a ODBC, OLEDB or CUSTOM connection
def get_db_owners(self, doc_handle, connection_id):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetDatabaseOwners",
"params": [connection_id]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetDatabases: List the databases of a ODBC, OLEDB or CUSTOM connection
def get_databases(self, doc_handle, connection_id):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetDatabases", "params": [connection_id]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetDatabaseTableFields: List the fields in a table for a ODBC, OLEDB or CUSTOM connection
# Parameters taken are: connection_id (mandatory), db_name, db_owner, table_name (mandatory)
def get_db_table_fields(self, doc_handle, connection_id, db_name="", db_owner="", table_name=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetDatabaseTableFields",
"params": [connection_id, db_name, db_owner, table_name]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetDatabaseTablePreview: Preview the data in the fields in a table for a ODBC, OLEDB or CUSTOM connection
# Parameters taken are: connection_id (mandatory), db_name, db_owner, table_name (mandatory)
def get_db_table_preview(self, doc_handle, connection_id, db_name="", db_owner="", table_name=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetDatabaseTablePreview",
"params": [connection_id, db_name, db_owner, table_name]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetDatabaseTables: List the tables in a database for a specific owner and for a ODBC, OLEDB or CUSTOM connection
# Parameters taken are: connection_id (mandatory), db_name, db_owner
def get_db_tables(self, doc_handle, connection_id, db_name="", db_owner=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetDatabaseTables",
"params": [connection_id, db_name, db_owner]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetDimension: Get the handle of a dimension by using the GetDimension method.
# Parameter: dimension id
def get_dim_handle(self, doc_handle, dim_id):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetDimension", "params": [dim_id]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetEmptyScript: Creates a script that contains one section. This section contains Set statements that give
# localized information from the regional settings of the computer.
# Parameter: none
def get_empty_script(self, doc_handle):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetEmptyScript", "params": []})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetFieldDescription: Get the description of a field
# Parameter: field name
def get_field_descr(self, doc_handle, field_name):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetFieldDescription",
"params": {"qFieldName": field_name}})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetField method: Retrieves the handle of a field.
# Parameter: field name
def get_field_handle(self, doc_handle, field_name):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetField", "params":
[field_name]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetFileTableFields method: Lists the fields of a table for a folder connection.
# Parameters:
# qConnectionId (MANDATORY): Identifier of the connection.
# qRelativePath: Path of the connection file
# qDataFormat: Type of the file
# qTable (MOSTLY MANDATORY): Name of the table ***This parameter must be set for XLS, XLSX, HTML and XML files.***
def get_file_table_fields(self, doc_handle, connection_id, rel_path="", data_fmt="", table_name=""):
msg = json.dumps(
{"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetFileTableFields", "params": [
connection_id, rel_path, {"qType": data_fmt}, table_name]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetFileTablePreview method: Preview the data in the fields of a table for a folder connection.
# Parameters:
# qConnectionId (MANDATORY): Identifier of the connection.
# qRelativePath: Path of the connection file
# qDataFormat: Type of the file
# qTable (MOSTLY MANDATORY): Name of the table ***This parameter must be set for XLS, XLSX, HTML and XML files.***
def get_file_table_preview(self, doc_handle, connection_id, rel_path="", data_fmt="", table_name=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetFileTablePreview", "params": [
connection_id, rel_path, {"qType": data_fmt}, table_name]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetFileTablesEx method: List the tables and fields of a XML file or from a JSON file, for a folder connection
# Parameters:
# qConnectionId (MANDATORY): Identifier of the connection.
# qRelativePath: Path of the connection file
# qDataFormat: Type of the file (XML, JSON)
# qTable (MOSTLY MANDATORY): Name of the table ***This parameter must be set for XLS, XLSX, HTML and XML files.***
def get_file_table_ex(self, doc_handle, connection_id, rel_path="", data_fmt=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetFileTablesEx", "params": [
connection_id, rel_path, {"qType": data_fmt}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetFileTables method: Lists the tables for a folder connection.
# Parameters:
# qConnectionId (MANDATORY): Identifier of the connection.
# qRelativePath: Path of the connection file
# qDataFormat: Type of the file (XML, JSON)
def get_file_tables(self, doc_handle, connection_id, rel_path="", data_fmt=""):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetFileTables", "params": [
connection_id, rel_path, {"qType": data_fmt}]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
# GetFolderItemsForConnection method: List the items for a folder connection
# Parameter: connection_id
def get_folder_items_for_connection(self, doc_handle, connection_id):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "GetFolderItemsForConnection",
"params": [connection_id]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']
def create_session_object(self, doc_handle, param):
msg = json.dumps({"jsonrpc": "2.0", "id": 0, "handle": doc_handle, "method": "CreateSessionObject",
"params": [param]})
response = json.loads(self.engine_socket.send_call(self.engine_socket, msg))
try:
return response['result']
except KeyError:
return response['error']