zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
U
¤ý°dcÃã@s4dZddlmZddlZddlZddlZddlmZmZm    Z    m
Z
m Z m Z m Z ddlmZddlmZddlmZmZdd    lmZdd
lmZdd lmZdd lmZmZmZmZdd l m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&dZ'Gdd„dƒZ(dddœdd„Z)dDddddœdd„Z*dEddddœdd„Z+dFddddœd d!„Z,dGdddd"d#œd$d%„Z-Gd&d'„d'ƒZ.Gd(d)„d)e.ƒZ/Gd*d+„d+e.ƒZ0Gd,d-„d-e.ƒZ1Gd.d/„d/e1ƒZ2Gd0d1„d1ƒZ3Gd2d3„d3e/ƒZ4Gd4d5„d5e/ƒZ5Gd6d7„d7e5ƒZ6Gd8d9„d9e5ƒZ7Gd:d;„d;e1ƒZ8Gd<d=„d=e/ƒZ9Gd>d?„d?e/ƒZ:Gd@dA„dAe/ƒZ;GdBdC„dCe.ƒZ<dS)HzImplementation of Statements.é)Ú annotationsN)ÚAnyÚDictÚIterableÚListÚOptionalÚTupleÚUnioné)ÚLockContention)ÚDbDoc)ÚNotSupportedErrorÚProgrammingError)Ú
ExprParser)Ú
deprecated)Ú mysqlxpb_enum)Ú    DocResultÚResultÚ    RowResultÚ    SqlResult)ÚConnectionTypeÚDatabaseTargetTypeÚ MessageTypeÚProtobufMessageCextTypeÚProtobufMessageTypeÚ
SchemaTypez&The given index name "{}" is not validc@s eZdZdZdddœdd„ZdS)ÚExprzExpression wrapper.rÚNone)ÚexprÚreturncCs
||_dS©N)r)Úselfr©r"úGd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\mysqlx/statement.pyÚ__init__?sz Expr.__init__N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r$r"r"r"r#r<srrzUnion[List, Tuple]©ÚvaluesrcGs*t|ƒdkr&t|dttfƒr&|dS|S)zParse flexible parameters.r
r)ÚlenÚ
isinstanceÚlistÚtuple)r*r"r"r#Úflexible_paramsCsr/ÚÚstrÚbool)Ú
identifierÚsql_modercCsPd|kr8|ddkr |ddkp6|ddko6|ddkS|ddkoN|ddkS)zòCheck if the given identifier is quoted.
 
    Args:
        identifier (string): Identifier to check.
        sql_mode (Optional[string]): SQL mode.
 
    Returns:
        `True` if the identifier has backtick quotes, and False otherwise.
    Ú ANSI_QUOTESrú`éÿÿÿÿú"r")r3r4r"r"r#Úis_quoted_identifierJs
 
ÿr9cCsHt|ƒdkrdSd|kr0| dd¡}d|›dS| dd¡}d|›dS)a@Quote the given identifier with backticks, converting backticks (`) in
    the identifier name with the correct escape sequence (``).
 
    Args:
        identifier (string): Identifier to quote.
        sql_mode (Optional[string]): SQL mode.
 
    Returns:
        A string with the identifier quoted with backticks.
    rz``r5r8z""r6)r+Úreplace)r3r4Úquotedr"r"r#Úquote_identifier[s    r<z Iterable[str])Ú identifiersr4rcsd ‡fdd„|Dƒ¡S)aQuote the given multi-part identifier with backticks.
 
    Args:
        identifiers (iterable): List of identifiers to quote.
        sql_mode (Optional[string]): SQL mode.
 
    Returns:
        A string with the multi-part identifier quoted with backticks.
    Ú.csg|]}t|ˆƒ‘qSr")r<)Ú.0r3©r4r"r#Ú
<listcomp>zsz.quote_multipart_identifier.<locals>.<listcomp>)Újoin)r=r4r"r@r#Úquote_multipart_identifieros
ÿrCzTuple[str, str])Údefault_schemaÚ
table_namer4rcCs^d|kr dnd}||kr"d|›nd}| |d¡}t|ƒdkrB|n |d |¡|d |¡fS)zÞParse table name.
 
    Args:
        default_schema (str): The default schema.
        table_name (str): The table name.
        sql_mode(Optional[str]): The SQL mode.
 
    Returns:
        str: The parsed table name.
    r5r8r6r>r
rr7)Úsplitr+Ústrip)rDrEr4ÚquoteÚ    delimiterÚtempr"r"r#Úparse_table_name~s   þrKc@sDeZdZdZd+ddddœdd„Zedd    œd
d „ƒZed d    œd d„ƒZedd    œdd„ƒZej    dddœdd„ƒZedd    œdd„ƒZ
edd    œdd„ƒZ e j    dddœdd„ƒZ edd    œdd„ƒZ e j    dddœdd„ƒZ edd    œdd„ƒZ edd    œdd„ƒZej    dddœd d„ƒZdd    œd!d"„Zdd    œd#d$„Zdd    œd%d&„Zd'd    œd(d)„Zd*S),Ú    Statementa    Provides base functionality for statement objects.
 
    Args:
        target (object): The target database object, it can be
                         :class:`mysqlx.Collection` or :class:`mysqlx.Table`.
        doc_based (bool): `True` if it is document based.
    Trr2r©ÚtargetÚ    doc_basedrcCs@||_||_|r| ¡nd|_d|_d|_d|_d|_d|_dS)NrTF)    Ú_targetÚ
_doc_basedÚget_connectionÚ _connectionÚ_stmt_idÚ _exec_counterÚ_changedÚ    _preparedÚ_deallocate_prepare_execute©r!rNrOr"r"r#r$sÿzStatement.__init__©rcCs|jS)z#object: The database object target.)rP©r!r"r"r#rN©szStatement.targetrcCs|jjS)z*:class:`mysqlx.Schema`: The Schema object.)rPÚschemar[r"r"r#r\®szStatement.schemaÚintcCs|jS)zXReturns this statement ID.
 
        Returns:
            int: The statement ID.
        ©rTr[r"r"r#Ústmt_id³szStatement.stmt_id©ÚvaluercCs
||_dSr r^©r!rar"r"r#r_¼scCs|jS)z5int: The number of times this statement was executed.©rUr[r"r"r#Ú exec_counterÀszStatement.exec_countercCs|jS)z+bool: `True` if this statement has changes.©rVr[r"r"r#ÚchangedÅszStatement.changedcCs
||_dSr rerbr"r"r#rfÊscCs|jS)z1bool: `True` if this statement has been prepared.©rWr[r"r"r#ÚpreparedÎszStatement.preparedcCs
||_dSr rgrbr"r"r#rhÓscCs
|jdkS)z;bool: `True` if this statement was executed more than once.r
rcr[r"r"r#Úrepeated×szStatement.repeatedcCs|jS)z9bool: `True` to deallocate + prepare + execute statement.©rXr[r"r"r#Údeallocate_prepare_executeÜsz$Statement.deallocate_prepare_executecCs
||_dSr rjrbr"r"r#rkáscCs|jS)zkCheck if it is document based.
 
        Returns:
            bool: `True` if it is document based.
        )rQr[r"r"r#Ú is_doc_basedåszStatement.is_doc_basedcCs|jd7_dS)z@Increments the number of times this statement has been executed.r
Nrcr[r"r"r#Úincrement_exec_counterísz Statement.increment_exec_countercCs
d|_dS)z<Resets the number of times this statement has been executed.rNrcr[r"r"r#Úreset_exec_counterñszStatement.reset_exec_counterrcCst‚dS©zqExecute the statement.
 
        Raises:
           NotImplementedError: This method must be implemented.
        N©ÚNotImplementedErrorr[r"r"r#ÚexecuteõszStatement.executeN)T)r%r&r'r(r$ÚpropertyrNr\r_Úsetterrdrfrhrirkrlrmrnrrr"r"r"r#rL”s< rLcs~eZdZdZdGdddddœ‡fd    d
„ Zd dd œd d„Zdddœdd„Zdddœdd„Zdddœdd„Zdddœdd„Z    dddœdd„Z
ddœdd „Z d!dœd"d#„Z d$dœd%d&„Z d'dœd(d)„Zd*dœd+d,„Zd*dœd-d.„Zd'dœd/d0„Zd$dœd1d2„Zd$dœd3d4„Zed5ƒdddœd6d7„ƒZed5ƒdddœd8d9„ƒZdHd*d:dd;œd<d=„Zd*dd>œd?d@„ZdAddBœdCdD„ZdAdœdEdF„Z‡ZS)IÚFilterableStatementaÉA statement to be used with filterable statements.
 
    Args:
        target (object): The target database object, it can be
                         :class:`mysqlx.Collection` or :class:`mysqlx.Table`.
        doc_based (Optional[bool]): `True` if it is document based
                                    (default: `True`).
        condition (Optional[str]): Sets the search condition to filter
                                   documents or records.
    TNrr2ú Optional[str]r©rNrOÚ    conditionrcsštƒj||di|_i|_d|_d|_d|_d|_d|_d|_    d|_
d|_ d|_ d|_ d|_d|_d|_d|_d|_d|_d|_d|_|r–| |¡dS)N©rNrOr0rF)Úsuperr$Ú _binding_mapÚ    _bindingsÚ_havingÚ _grouping_strÚ    _groupingÚ _limit_offsetÚ_limit_row_countÚ_projection_strÚ_projection_exprÚ    _sort_strÚ
_sort_exprÚ
_where_strÚ _where_exprÚ has_bindingsÚ    has_limitÚ has_group_byÚ
has_havingÚhas_projectionÚhas_sortÚ    has_whereÚ
_set_where©r!rNrOrx©Ú    __class__r"r#r$
s4þþþzFilterableStatement.__init__z!Union[DbDoc, Dict[str, Any], str])Úobjrc
Cs¸t|tƒr| t|ƒ ¡¡n–t|tƒr8| | ¡¡n|t|tƒr¬zt |¡}t|tƒs\t‚Wn,tk
rŠ}zt    dƒ|‚W5d}~XYnX| 
¡D]}| |||¡q”nt    dƒ‚dS)aBind single object.
 
        Args:
            obj (:class:`mysqlx.DbDoc` or str): DbDoc or JSON string object.
 
        Raises:
            :class:`mysqlx.ProgrammingError`: If invalid JSON string to bind.
            ValueError: If JSON loaded is not a dictionary.
        zInvalid JSON string to bindNz%Invalid JSON string or object to bind) r,ÚdictÚbindr Zas_strr1ÚjsonÚloadsÚ
ValueErrorrÚkeys)r!r“ÚresÚerrÚkeyr"r"r#Ú _bind_single.s
 
 
 
 
 
 z FilterableStatement._bind_singler1©ÚclausesrcGs6d|_d t|Ž¡|_t|j|j ƒ ¡|_d|_|S)zÑSets the sorting criteria.
 
        Args:
            *clauses: The expression strings defining the sort criteria.
 
        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
        Tú,)    rrBr/r„rrQZparse_order_specr…rV©r!rŸr"r"r#Ú_sortHs    ÿ
zFilterableStatement._sort©rxrc
Cshd|_||_zt||j ƒ}| ¡|_Wn,tk
rT}ztdƒ|‚W5d}~XYnX|j|_    d|_
|S)aSets the search condition to filter.
 
        Args:
            condition (str): Sets the search condition to filter documents or
                             records.
 
        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
        TzInvalid conditionN) rŽr†rrQrr‡r˜rZplaceholder_name_to_positionr{rV)r!rxrr›r"r"r#rYs
zFilterableStatement._set_where©ÚfieldsrcGs:t|Ž}d|_d |¡|_t|j|j ƒ ¡|_d|_dS)zJSet group by.
 
        Args:
            *fields: List of fields.
        Tr N)    r/rŠrBr~rrQZparse_expr_listrrV©r!r¥r"r"r#Ú _set_group_byns ÿ
z!FilterableStatement._set_group_bycCs$d|_t||j ƒ ¡|_d|_dS)zOSet having.
 
        Args:
            condition (str): The condition.
        TN)r‹rrQrr}rV©r!rxr"r"r#Ú _set_having|szFilterableStatement._set_havingcGs:t|Ž}d|_d |¡|_t|j|j ƒ ¡|_d|_|S)z¡Set the projection.
 
        Args:
            *fields: List of fields.
 
        Returns:
            :class:`mysqlx.FilterableStatement`: Returns self.
        Tr )    r/rŒrBr‚rrQZparse_table_select_projectionrƒrVr¦r"r"r#Ú_set_projection†s     ÿ
z#FilterableStatement._set_projectionúDict[str, Any]rZcCs|jS©zlReturns the binding map dictionary.
 
        Returns:
            dict: The binding map dictionary.
        ©r{r[r"r"r#Úget_binding_map˜sz#FilterableStatement.get_binding_mapzUnion[Dict[str, Any], List]cCs|jS©z\Returns the bindings list.
 
        Returns:
            `list`: The bindings list.
        ©r|r[r"r"r#Ú get_bindings sz FilterableStatement.get_bindingsz9List[Union[ProtobufMessageType, ProtobufMessageCextType]]cCs|jS)zrReturns the grouping expression list.
 
        Returns:
            `list`: The grouping expression list.
        )rr[r"r"r#Ú get_grouping¨sz FilterableStatement.get_groupingrcCs|jS)zdReturns the having expression.
 
        Returns:
            object: The having expression.
        )r}r[r"r"r#Ú
get_having°szFilterableStatement.get_havingr]cCs|jS)z]Returns the limit row count.
 
        Returns:
            int: The limit row count.
        )rr[r"r"r#Úget_limit_row_count¸sz'FilterableStatement.get_limit_row_countcCs|jS)zWReturns the limit offset.
 
        Returns:
            int: The limit offset.
        )r€r[r"r"r#Úget_limit_offsetÀsz$FilterableStatement.get_limit_offsetcCs|jS)zbReturns the where expression.
 
        Returns:
            object: The where expression.
        )r‡r[r"r"r#Úget_where_exprÈsz"FilterableStatement.get_where_exprcCs|jS)zlReturns the projection expression.
 
        Returns:
            object: The projection expression.
        )rƒr[r"r"r#Úget_projection_exprÐsz'FilterableStatement.get_projection_exprcCs|jS)z`Returns the sort expression.
 
        Returns:
            object: The sort expression.
        )r…r[r"r"r#Ú get_sort_exprÚsz!FilterableStatement.get_sort_exprú8.0.12cCs
| |¡S)a&Sets the search condition to filter.
 
        Args:
            condition (str): Sets the search condition to filter documents or
                             records.
 
        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
 
        .. deprecated:: 8.0.12
        ©rr¨r"r"r#Úwhereäs zFilterableStatement.wherecGs
|j|ŽS)zñSets the sorting criteria.
 
        Args:
            *clauses: The expression strings defining the sort criteria.
 
        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
 
        .. deprecated:: 8.0.12
        ©r¢r¡r"r"r#Úsortós zFilterableStatement.sortz Optional[int])Ú    row_countÚoffsetrcCsnt|tƒr|dkrtdƒ‚|jsBt|jdkƒ|_t|jdk ƒ|_||_d|_|rj|     |¡t
j dt d|S)a„Sets the maximum number of items to be returned.
 
        Args:
            row_count (int): The maximum number of items.
 
        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
 
        Raises:
            ValueError: If ``row_count`` is not a positive integer.
 
        .. versionchanged:: 8.0.12
           The usage of ``offset`` was deprecated.
        rz0The 'row_count' value must be a positive integerTzh'limit(row_count, offset)' is deprecated, please use 'offset(offset)' to set the number of items to skip)Úcategory) r,r]r˜r‰r2rUrVrXrr¿ÚwarningsÚwarnÚDeprecationWarning)r!r¾r¿r"r"r#Úlimits
üzFilterableStatement.limit)r¿rcCs$t|tƒr|dkrtdƒ‚||_|S)a:Sets the number of items to skip.
 
        Args:
            offset (int): The number of items to skip.
 
        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
 
        Raises:
            ValueError: If ``offset`` is not a positive integer.
 
        .. versionadded:: 8.0.12
        rz-The 'offset' value must be a positive integer)r,r]r˜r€)r!r¿r"r"r#r¿$szFilterableStatement.offsetr©ÚargsrcGsNd|_t|ƒ}|dkr&| |d¡n$|dkrB|d|j|d<ntdƒ‚|S)a¨Binds value(s) to a specific placeholder(s).
 
        Args:
            *args: The name of the placeholder and the value to bind.
                   A :class:`mysqlx.DbDoc` object or a JSON string
                   representation can be used.
 
        Returns:
            mysqlx.FilterableStatement: FilterableStatement object.
 
        Raises:
            ProgrammingError: If the number of arguments is invalid.
        Tr
réú#Invalid number of arguments to bind)rˆr+rr|r)r!rÆÚcountr"r"r#r•7szFilterableStatement.bindcCst‚dSrorpr[r"r"r#rrOszFilterableStatement.execute)TN)N)r%r&r'r(r$rr¢rr§r©rªr®r±r²r³r´rµr¶r·r¸rr»r½rÄr¿r•rrÚ __classcell__r"r"r‘r#ruþs8ü$
 
 
ÿ#rucsveZdZdZddddœ‡fdd„ Zeddœd    d
„ƒZd dœd d „Zddœdd„Zdddœdd„Z    ddœdd„Z
‡Z S)Ú SqlStatementz¬A statement for SQL execution.
 
    Args:
        connection (mysqlx.connection.Connection): Connection object.
        sql (string): The sql statement to be executed.
    rr1r)Ú
connectionÚsqlrcs8tƒjddd||_||_d|_g|_d|_d|_dS©NFry)rzr$rSÚ_sqlr{r|rˆr‰)r!rÌrÍr‘r"r#r$`szSqlStatement.__init__rZcCs|jS)zstring: The SQL text statement.)rÏr[r"r"r#rÍiszSqlStatement.sqlr«cCs|jSr¬r­r[r"r"r#r®nszSqlStatement.get_binding_mapzUnion[Tuple, List]cCs|jSr¯r°r[r"r"r#r±vszSqlStatement.get_bindingsrrÅcGsHt|ƒdkrtdƒ‚d|_t|Ž}t|ttfƒr8||_n |j |¡|S)zµBinds value(s) to a specific placeholder(s).
 
        Args:
            *args: The value(s) to bind.
 
        Returns:
            mysqlx.SqlStatement: SqlStatement object.
        rrÈT)    r+rrˆr/r,r-r.r|Úappend)r!rÆZbindingsr"r"r#r•~s      zSqlStatement.bindrcCs |j |¡S)zaExecute the statement.
 
        Returns:
            mysqlx.SqlResult: SqlResult object.
        )rSZsend_sqlr[r"r"r#rr‘szSqlStatement.execute) r%r&r'r(r$rsrÍr®r±r•rrrÊr"r"r‘r#rËXs    rËcsFeZdZdZddddœ‡fdd„ Zdd    œd
d „Zd d    œd d„Z‡ZS)ÚWriteStatementz*Provide common write operation attributes.rr2rrMcstƒ ||¡g|_dSr )rzr$Ú_valuesrYr‘r"r#r$s    øzWriteStatement.__init__zpList[Union[int, str, DbDoc, Dict[str, Any], List[Optional[Union[str, int, float, ExprParser, Dict[str, Any]]]]]]rZcCs|jS)z^Returns the list of values.
 
        Returns:
            `list`: The list of values.
        )rÒr[r"r"r#Ú
get_values©szWriteStatement.get_valuesrcCst‚dSrorpr[r"r"r#rr»szWriteStatement.execute)r%r&r'r(r$rÓrrrÊr"r"r‘r#rњs rÑcsfeZdZdZdddœ‡fdd„ Zddœd    d
„Zdddd œd d„Zdddœdd„Zddœdd„Z‡Z    S)Ú AddStatementzA statement for document addition on a collection.
 
    Args:
        collection (mysqlx.Collection): The Collection object.
    rr)Ú
collectionrcstƒ |d¡d|_g|_dS)NTF)rzr$Ú_upsertÚids)r!rÕr‘r"r#r$ËszAddStatement.__init__r2rZcCs|jS)zhReturns `True` if it's an upsert.
 
        Returns:
            bool: `True` if it's an upsert.
        ©rÖr[r"r"r#Ú    is_upsertÐszAddStatement.is_upsertTr`cCs
||_|S)zÿSets the upset flag to the boolean of the value provided.
        Setting of this flag allows updating of the matched rows/documents
        with the provided value.
 
        Args:
            value (optional[bool]): Set or unset the upsert flag.
        rØrbr"r"r#ÚupsertØszAddStatement.upsertr r)cGs:t|ŽD],}t|tƒr$|j |¡q|j t|ƒ¡q|S)zÏAdds a list of documents into a collection.
 
        Args:
            *values: The documents to be added into the collection.
 
        Returns:
            mysqlx.AddStatement: AddStatement object.
        )r/r,r rÒrÐ)r!r*Úvalr"r"r#Úaddãs
     
zAddStatement.addrcCs t|jƒdkrtƒS|j |¡S)ú[Execute the statement.
 
        Returns:
            mysqlx.Result: Result object.
        r)r+rÒrrSÚ send_insertr[r"r"r#rrószAddStatement.execute)T)
r%r&r'r(r$rÙrÚrÜrrrÊr"r"r‘r#rÔÄs  rÔc@s8eZdZdZd dddddœdd    „Zdddd
œd d „ZdS)Ú
UpdateSpeczñUpdate specification class implementation.
 
    Args:
        update_type (int): The update type.
        source (str): The source.
        value (Optional[str]): The value.
 
    Raises:
        ProgrammingError: If `source` is invalid.
    Nr]r1rr)Ú update_typeÚsourcerarc
Csp|tdƒkr| ||¡nR||_zt|dƒ ¡j|_Wn.tk
rd}zt|›ƒ|‚W5d}~XYnX||_    dS)Nú*Mysqlx.Crud.UpdateOperation.UpdateType.SETF)
rÚ
_table_setràrZdocument_fieldr3rár˜rra)r!ràrárar›r"r"r#r$ s zUpdateSpec.__init__)rárarcCs$tdƒ|_t|dƒ ¡|_||_dS)zlTable set.
 
        Args:
            source (str): The source.
            value (str): The value.
        râTN)rràrZparse_table_update_fieldrára)r!rárar"r"r#rãs
zUpdateSpec._table_set)N)r%r&r'r(r$rãr"r"r"r#rßÿs  rßcsÆeZdZdZddddœ‡fdd„ Zdddœd    d
„Zd d œd d„Zddddœdd„Zedƒddddœdd„ƒZ    dddœdd„Z
ddddœdd„Z ddddœdd„Z dddœd d!„Z d"d œd#d$„Z‡ZS)%ÚModifyStatementaUA statement for document update operations on a Collection.
 
    Args:
        collection (mysqlx.Collection): The Collection object.
        condition (str): Sets the search condition to identify the documents
                         to be modified.
 
    .. versionchanged:: 8.0.12
       The ``condition`` parameter is now mandatory.
    rr1r©rÕrxrcstƒj||di|_dS©N)rNrx©rzr$Ú _update_ops©r!rÕrxr‘r"r#r$.szModifyStatement.__init__ržcGs
|j|ŽS)zÉSets the sorting criteria.
 
        Args:
            *clauses: The expression strings defining the sort criteria.
 
        Returns:
            mysqlx.ModifyStatement: ModifyStatement object.
        r¼r¡r"r"r#r½2s    zModifyStatement.sortr«rZcCs|jS©ztReturns the list of update operations.
 
        Returns:
            `list`: The list of update operations.
        ©rèr[r"r"r#Úget_update_ops=szModifyStatement.get_update_opsr)Údoc_pathrarcCs ttdƒ||ƒ|j|<d|_|S)a2Sets or updates attributes on documents in a collection.
 
        Args:
            doc_path (string): The document path of the item to be set.
            value (string): The value to be set on the specified attribute.
 
        Returns:
            mysqlx.ModifyStatement: ModifyStatement object.
        z/Mysqlx.Crud.UpdateOperation.UpdateType.ITEM_SETT©rßrrèrV©r!rírar"r"r#ÚsetEs
ý
zModifyStatement.setr¹cCs ttdƒ||ƒ|j|<d|_|S)aŠAdd an update to the statement setting the field, if it exists at
        the document path, to the given value.
 
        Args:
            doc_path (string): The document path of the item to be set.
            value (object): The value to be set on the specified attribute.
 
        Returns:
            mysqlx.ModifyStatement: ModifyStatement object.
 
        .. deprecated:: 8.0.12
        z3Mysqlx.Crud.UpdateOperation.UpdateType.ITEM_REPLACETrîrïr"r"r#ÚchangeWsý
zModifyStatement.change)Ú    doc_pathsrcGs,t|ŽD]}ttdƒ|ƒ|j|<qd|_|S)aRemoves attributes from documents in a collection.
 
        Args:
            doc_paths (list): The list of document paths of the attributes to be
                              removed.
 
        Returns:
            mysqlx.ModifyStatement: ModifyStatement object.
        z2Mysqlx.Crud.UpdateOperation.UpdateType.ITEM_REMOVET)r/rßrrèrV)r!ròÚitemr"r"r#Úunsetms
þ zModifyStatement.unset©ÚfieldrarcCs ttdƒ||ƒ|j|<d|_|S)a„Insert a value into the specified array in documents of a
        collection.
 
        Args:
            field (string): A document path that identifies the array attribute
                            and position where the value will be inserted.
            value (object): The value to be inserted.
 
        Returns:
            mysqlx.ModifyStatement: ModifyStatement object.
        z3Mysqlx.Crud.UpdateOperation.UpdateType.ARRAY_INSERTTrî©r!rörar"r"r#Ú array_inserts ý
zModifyStatement.array_insertcCs ttdƒ||ƒ|j|<d|_|S)aÀInserts a value into a specific position in an array attribute in
        documents of a collection.
 
        Args:
            doc_path (string): A document path that identifies the array
                               attribute and position where the value will be
                               inserted.
            value (object): The value to be inserted.
 
        Returns:
            mysqlx.ModifyStatement: ModifyStatement object.
        z3Mysqlx.Crud.UpdateOperation.UpdateType.ARRAY_APPENDTrîrïr"r"r#Ú array_append“s ý
zModifyStatement.array_appendz#Union[Dict, DbDoc, ExprParser, str])ÚdocrcCsX|dkr d}t|ttttfƒs&tdƒ‚ttdƒdt|tƒrB| ¡n|ƒ|j    d<d|_
|S)a¢Takes a :class:`mysqlx.DbDoc`, string JSON format or a dict with the
        changes and applies it on all matching documents.
 
        Args:
            doc (object): A generic document (DbDoc), string in JSON format or
                          dict, with the changes to apply to the matching
                          documents.
 
        Returns:
            mysqlx.ModifyStatement: ModifyStatement object.
        Nr0z>Invalid data for update operation on document collection tablez2Mysqlx.Crud.UpdateOperation.UpdateType.MERGE_PATCHú$ÚpatchT) r,rr”r r1rrßrrrèrV)r!rúr"r"r#rü¨s ÿý
zModifyStatement.patchrcCs|jstdƒ‚|j |¡S)ú¤Execute the statement.
 
        Returns:
            mysqlx.Result: Result object.
 
        Raises:
            ProgrammingError: If condition was not set.
        z!No condition was found for modify©rŽrrSZ send_updater[r"r"r#rrÂs    zModifyStatement.execute)r%r&r'r(r$r½rìrðrrñrôrørùrürrrÊr"r"r‘r#rä"s  räcsÆeZdZdZd$dddddœ‡fd    d
„ Zed d œd d„ƒZd ddœdd„Zdd œdd„Zdd œdd„Z    e
j fd ddœdd„Z e
j fd ddœdd„Z dddœdd„Zdddœdd „Zd!d œd"d#„Z‡ZS)%Ú ReadStatementaÅProvide base functionality for Read operations
 
    Args:
        target (object): The target database object, it can be
                         :class:`mysqlx.Collection` or :class:`mysqlx.Table`.
        doc_based (Optional[bool]): `True` if it is document based
                                    (default: `True`).
        condition (Optional[str]): Sets the search condition to filter
                                   documents or records.
    TNrr2rvrrwcs(tƒ |||¡d|_d|_tj|_dS©NF)rzr$Ú_lock_exclusiveÚ _lock_sharedr ÚDEFAULTÚ_lock_contentionrr‘r"r#r$ÜszReadStatement.__init__r rZcCs|jS)z::class:`mysqlx.LockContention`: The lock contention value.)rr[r"r"r#Úlock_contentionçszReadStatement.lock_contention)rrc
CsFzt|jƒ}Wn,tk
r:}ztdƒ|‚W5d}~XYnX||_dS)zÖSet the lock contention.
 
        Args:
            lock_contention (:class:`mysqlx.LockContention`): Lock contention.
 
        Raises:
            ProgrammingError: If is an invalid lock contention value.
        z;Invalid lock contention mode. Use 'NOWAIT' or 'SKIP_LOCKED'N)r rar˜rr)r!rÚ_r›r"r"r#Ú_set_lock_contentionìs    ÿþz"ReadStatement._set_lock_contentioncCs|jS)zrReturns `True` if is `EXCLUSIVE LOCK`.
 
        Returns:
            bool: `True` if is `EXCLUSIVE LOCK`.
        )rr[r"r"r#Úis_lock_exclusiveþszReadStatement.is_lock_exclusivecCs|jS)zlReturns `True` if is `SHARED LOCK`.
 
        Returns:
            bool: `True` if is `SHARED LOCK`.
        )rr[r"r"r#Úis_lock_sharedszReadStatement.is_lock_sharedcCsd|_d|_| |¡|S)zÅExecute a read operation with `SHARED LOCK`. Only one lock can be
           active at a time.
 
        Args:
            lock_contention (:class:`mysqlx.LockContention`): Lock contention.
        FT©rrr©r!rr"r"r#Ú lock_shareds    
zReadStatement.lock_sharedcCsd|_d|_| |¡|S)zÈExecute a read operation with `EXCLUSIVE LOCK`. Only one lock can be
           active at a time.
 
        Args:
            lock_contention (:class:`mysqlx.LockContention`): Lock contention.
        TFr
r r"r"r#Úlock_exclusives    
zReadStatement.lock_exclusiver1r¤cGs|j|Ž|S)zÜSets a grouping criteria for the resultset.
 
        Args:
            *fields: The string expressions identifying the grouping criteria.
 
        Returns:
            mysqlx.ReadStatement: ReadStatement object.
        )r§r¦r"r"r#Úgroup_by*s    
zReadStatement.group_byr£cCs| |¡|S)a=Sets a condition for records to be considered in agregate function
        operations.
 
        Args:
            condition (string): A condition on the agregate functions used on
                                the grouping criteria.
 
        Returns:
            mysqlx.ReadStatement: ReadStatement object.
        )r©r¨r"r"r#Úhaving6s
zReadStatement.havingzUnion[DocResult, RowResult]cCs |j |¡S©rÝ)rSZ    send_findr[r"r"r#rrDszReadStatement.execute)TN)r%r&r'r(r$rsrrrr    r rr r rrrrrÊr"r"r‘r#rÿÐs ü     ÿÿ rÿcsLeZdZdZdddddœ‡fdd„ Zd    dd
œd d „Zd    dd œdd„Z‡ZS)Ú FindStatementa¥A statement document selection on a Collection.
 
    Args:
        collection (mysqlx.Collection): The Collection object.
        condition (Optional[str]): An optional expression to identify the
                                   documents to be retrieved. If not specified
                                   all the documents will be included on the
                                   result unless a limit is set.
    Nrrvrråcstƒ |d|¡dS)NT©rzr$rér‘r"r#r$XszFindStatement.__init__r1r¤cGs
|j|ŽS)zèSets a document field filter.
 
        Args:
            *fields: The string expressions identifying the fields to be
                     extracted.
 
        Returns:
            mysqlx.FindStatement: FindStatement object.
        )rªr¦r"r"r#r¥]s
zFindStatement.fieldsržcGs
|j|ŽS©zÅSets the sorting criteria.
 
        Args:
            *clauses: The expression strings defining the sort criteria.
 
        Returns:
            mysqlx.FindStatement: FindStatement object.
        r¼r¡r"r"r#r½is    zFindStatement.sort)N)r%r&r'r(r$r¥r½rÊr"r"r‘r#rMs
 ÿ rcsXeZdZdZddddœ‡fdd„ Zdddœd    d
„Zddd œd d „Zddœdd„Z‡ZS)ÚSelectStatementz¤A statement for record retrieval operations on a Table.
 
    Args:
        table (mysqlx.Table): The Table object.
        *fields: The fields to be retrieved.
    rr1r©Útabler¥rcstƒ |d¡|j|ŽdSr)rzr$rª©r!rr¥r‘r"r#r$}szSelectStatement.__init__r£cCs
| |¡S)zÔSets the search condition to filter.
 
        Args:
            condition (str): Sets the search condition to filter records.
 
        Returns:
            mysqlx.SelectStatement: SelectStatement object.
        rºr¨r"r"r#r»s    zSelectStatement.whereržcGs
|j|ŽS)zÎSets the order by criteria.
 
        Args:
            *clauses: The expression strings defining the order by criteria.
 
        Returns:
            mysqlx.SelectStatement: SelectStatement object.
        r¼r¡r"r"r#Úorder_byŒs    zSelectStatement.order_byrZc Cs²|jrd|j›nd}|jr(d|j›nd}|jr>d|j›nd}|jrTd|j›nd}|jrrd|j    ›d|j
›nd}d|j p€d    ›d
|j j ›d |jj ›|›|›|›|›|› }|S) zYReturns the generated SQL.
 
        Returns:
            str: The generated SQL.
        z WHERE r0z
 GROUP BY z HAVING z
 ORDER BY z LIMIT z OFFSET zSELECT Ú*z FROM r>)rŽr†rŠr~r‹r}rr„r‰rr€r‚r\ÚnamerN)r!r»rrrrÄZstmtr"r"r#Úget_sql—sÿý6ÿzSelectStatement.get_sql)    r%r&r'r(r$r»rrrÊr"r"r‘r#rus
  rcsHeZdZdZddddœ‡fdd„ Zdddœd    d
„Zd d œd d„Z‡ZS)ÚInsertStatementz—A statement for insert operations on Table.
 
    Args:
        table (mysqlx.Table): The Table object.
        *fields: The fields to be inserted.
    rrrrcstƒ |d¡t|Ž|_dSr)rzr$r/Ú_fieldsrr‘r"r#r$¶szInsertStatement.__init__r)cGs|j tt|Žƒ¡|S)zÃSet the values to be inserted.
 
        Args:
            *values: The values of the columns to be inserted.
 
        Returns:
            mysqlx.InsertStatement: InsertStatement object.
        )rÒrÐr-r/)r!r*r"r"r#r*ºs    zInsertStatement.valuesrrZcCs |j |¡Sr)rSrÞr[r"r"r#rrÆszInsertStatement.execute)r%r&r'r(r$r*rrrÊr"r"r‘r#r®s rcsveZdZdZdddœ‡fdd„ Zdddœd    d
„Zddd œd d „Zddœdd„Zddddœdd„Zddœdd„Z    ‡Z
S)ÚUpdateStatementzÃA statement for record update operations on a Table.
 
    Args:
        table (mysqlx.Table): The Table object.
 
    .. versionchanged:: 8.0.12
       The ``fields`` parameters were removed.
    rr©rrcstƒj|ddi|_dSrÎrç©r!rr‘r"r#r$ÙszUpdateStatement.__init__r1r£cCs
| |¡S)zÔSets the search condition to filter.
 
        Args:
            condition (str): Sets the search condition to filter records.
 
        Returns:
            mysqlx.UpdateStatement: UpdateStatement object.
        rºr¨r"r"r#r»Ýs    zUpdateStatement.whereržcGs
|j|ŽS)zÎSets the order by criteria.
 
        Args:
            *clauses: The expression strings defining the order by criteria.
 
        Returns:
            mysqlx.UpdateStatement: UpdateStatement object.
        r¼r¡r"r"r#rès    zUpdateStatement.order_byr«rZcCs|jSrêrër[r"r"r#rìószUpdateStatement.get_update_opsrrõcCs ttdƒ||ƒ|j|<d|_|S)aUpdates the column value on records in a table.
 
        Args:
            field (string): The column name to be updated.
            value (object): The value to be set on the specified column.
 
        Returns:
            mysqlx.UpdateStatement: UpdateStatement object.
        râTrîr÷r"r"r#rðûs
ý
zUpdateStatement.setrcCs|jstdƒ‚|j |¡S)z£Execute the statement.
 
        Returns:
            mysqlx.Result: Result object
 
        Raises:
            ProgrammingError: If condition was not set.
        z!No condition was found for updaterþr[r"r"r#rr s    zUpdateStatement.execute) r%r&r'r(r$r»rrìrðrrrÊr"r"r‘r#rÏs      rcsHeZdZdZddddœ‡fdd„ Zdddœd    d
„Zd d œd d„Z‡ZS)ÚRemoveStatementaEA statement for document removal from a collection.
 
    Args:
        collection (mysqlx.Collection): The Collection object.
        condition (str): Sets the search condition to identify the documents
                         to be removed.
 
    .. versionchanged:: 8.0.12
       The ``condition`` parameter was added.
    rr1rråcstƒj||ddSrærrér‘r"r#r$'szRemoveStatement.__init__ržcGs
|j|ŽSrr¼r¡r"r"r#r½*s    zRemoveStatement.sortrrZcCs|jstdƒ‚|j |¡S)rýz!No condition was found for remove©rŽrrSZ send_deleter[r"r"r#rr5s    zRemoveStatement.execute)r%r&r'r(r$r½rrrÊr"r"r‘r#r!s  r!csVeZdZdZdddœ‡fdd„ Zdddœd    d
„Zddd œd d „Zddœdd„Z‡ZS)ÚDeleteStatementz¯A statement that drops a table.
 
    Args:
        table (mysqlx.Table): The Table object.
 
    .. versionchanged:: 8.0.12
       The ``condition`` parameter was removed.
    rrrcstƒj|dddSrÎrr r‘r"r#r$MszDeleteStatement.__init__r1r£cCs
| |¡S)zÔSets the search condition to filter.
 
        Args:
            condition (str): Sets the search condition to filter records.
 
        Returns:
            mysqlx.DeleteStatement: DeleteStatement object.
        rºr¨r"r"r#r»Ps    zDeleteStatement.whereržcGs
|j|ŽS)zÎSets the order by criteria.
 
        Args:
            *clauses: The expression strings defining the order by criteria.
 
        Returns:
            mysqlx.DeleteStatement: DeleteStatement object.
        r¼r¡r"r"r#r[s    zDeleteStatement.order_byrrZcCs|jstdƒ‚|j |¡S)rýz!No condition was found for deleter"r[r"r"r#rrfs    zDeleteStatement.execute)    r%r&r'r(r$r»rrrrÊr"r"r‘r#r#Cs
      r#cs:eZdZdZdddddœ‡fdd„ Zd    d
œd d „Z‡ZS) ÚCreateCollectionIndexStatementa)A statement that creates an index on a collection.
 
    Args:
        collection (mysqlx.Collection): Collection.
        index_name (string): Index name.
        index_desc (dict): A dictionary containing the fields members that
                           constraints the index to be created. It must have
                           the form as shown in the following::
 
                               {"fields": [{"field": member_path,
                                            "type": member_type,
                                            "required": member_required,
                                            "collation": collation,
                                            "options": options,
                                            "srid": srid},
                                            # {... more members,
                                            #      repeated as many times
                                            #      as needed}
                                            ],
                                "type": type}
    rr1r«r)rÕÚ
index_nameÚ
index_descrcs4tƒj|dt |¡|_||_|j dg¡|_dS)N)rNr¥)rzr$ÚcopyÚdeepcopyÚ _index_descÚ _index_nameÚpopÚ _fields_desc)r!rÕr%r&r‘r"r#r$‹s z'CreateCollectionIndexStatement.__init__rrZc
Csh|jdkrtt |j¡ƒ‚z`t|jƒ ¡ ¡}t|tƒrZ|dt    dƒkrxtt |j¡ƒ‚n|j
t    dƒkrxtt |j¡ƒ‚Wn8t t fk
r²}ztt |j¡ƒ|‚W5d}~XYnX|j sÊtd|j›ƒ‚t|j tƒsÞtdƒ‚i}|j|d<|jj|d<|jjj|d<d|jkr$|j d¡|d<nd    |d<|j d
d ¡|d
<|d
rPtd ƒ‚g|d <|jrptd|j›ƒ‚z†|j D]x}i}| d¡|d<| d¡|d<| dd ¡|d<| dd ¡|d<t|dtƒsØtdƒ‚t|dtƒsðtdƒ‚|d ¡dkr|dstdƒ‚|d ¡d    kr<|ddkr<tdƒ‚d|kr€|d ¡ d¡srtd|d ¡›dƒ‚| d¡|d<d|kr²|d ¡dkr¤tdƒ‚| d¡|d<d|krä|d ¡dkrÖtd ƒ‚| d¡|d<|d  |¡qzWn:tk
r2}ztd!|›d"|›ƒ|‚W5d}~XYnX|j D]}|r:td#|›ƒ‚q:|j d$d%d&|¡S)'rÝNÚtypezMysqlx.Expr.Expr.Type.IDENTzCRequired member 'fields' not found in the given index description: z,Required member 'fields' must contain a listrrÕr\ZINDEXÚuniqueFz!Unique indexes are not supported.Ú
constraintzUnidentified fields: röÚmemberÚrequiredÚarrayz'Field member 'required' must be Booleanz$Field member 'array' must be BooleanZSPATIALzQField member 'required' must be set to 'True' when index type is set to 'SPATIAL'ZGEOJSONzIIndex 'type' must be set to 'SPATIAL' when field type is set to 'GEOJSON'Z    collationZTEXTzCThe 'collation' member can only be used when field type is set to 'ú'ÚoptionszIThe 'options' member can only be used when index type is set to 'GEOJSON'ZsridzFThe 'srid' member can only be used when index type is set to 'GEOJSON'zRequired inner member z not found in constraint: zUnidentified inner fields: ZmysqlxZcreate_collection_indexT)r*rÚERR_INVALID_INDEX_NAMEÚformatrrZ get_messager,r”rr-r˜ÚAttributeErrorr,r)r-rPrr\r+r r2Ú    TypeErrorÚupperÚ
startswithrÐÚKeyErrorrSZexecute_nonquery)r!Z parsed_identr›rÆZ
field_descr/r"r"r#rr–s¶
 
 
ÿ
ÿ
ÿþ
ÿ 
 
 ÿ ÿ
ÿ
ÿ
ÿÿþ
ÿz&CreateCollectionIndexStatement.execute)r%r&r'r(r$rrrÊr"r"r‘r#r$ts r$)r0)r0)r0)r0)=r(Ú
__future__rr'r–rÁÚtypingrrrrrrr    Ú    constantsr Zdbdocr Úerrorsr rrrZhelpersrZprotobufrÚresultrrrrÚtypesrrrrrrr5rr/r9r<rCrKrLrurËrÑrÔrßrärÿrrrrr!r#r$r"r"r"r#Ú<module>sN $          ÿj\B*;#/}(9!L(1