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
U
·ý°dL=ã@s|ddlZddlmZe dejejB¡ZGdd„dƒZGdd„dƒZGd    d
„d
eeƒZ    Gd d „d eƒZ
Gd d„dee
ƒZ dS)éNé)Úerrz|\s*((?:INSERT|REPLACE)\b.+\bVALUES?\s*)(\(\s*(?:%s|%\(.+\)s)\s*(?:,\s*(?:%s|%\(.+\)s)\s*)*\))(\s*(?:ON DUPLICATE.*)?);?\s*\Zc@s.eZdZdZdZdd„Zdd„Zdd„Zd    d
„Zd d „Z    d d„Z
dd„Z dd„Z dd„Z d;dd„Zdd„Zd<dd„Zdd„Zd=dd „Zd>d!d"„Zd#d$„Zd%d&„Zd?d(d)„Zd*d+„Zd@d,d-„Zd.d/„ZdAd1d2„Zd3d4„Zd5d6„Zd7d8„Zd9d:„Zej Z ej!Z!ej"Z"ej#Z#ej$Z$ej%Z%ej&Z&ej'Z'ej(Z(ej)Z)dS)BÚCursora
    This is the object used to interact with the database.
 
    Do not create an instance of a Cursor yourself. Call
    connections.Connection.cursor().
 
    See `Cursor <https://www.python.org/dev/peps/pep-0249/#cursor-objects>`_ in
    the specification.
    i cCs4||_d|_d|_d|_d|_d|_d|_d|_dS)Nréÿÿÿÿr)Ú
connectionÚ descriptionÚ    rownumberÚrowcountÚ    arraysizeÚ    _executedÚ_resultÚ_rows)Úselfr©rúFd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\pymysql/cursors.pyÚ__init__!szCursor.__init__cCs.|j}|dkrdSz| ¡rqW5d|_XdS)zD
        Closing a cursor just exhausts all remaining data.
        N)rÚnextset©rÚconnrrrÚclose+sz Cursor.closecCs|S©Nr©rrrrÚ    __enter__8szCursor.__enter__cGs~| ¡dSr)r)rÚexc_inforrrÚ__exit__;szCursor.__exit__cCs|jst d¡‚|jS)Nz Cursor closed)rrÚProgrammingErrorrrrrÚ_get_db?s
zCursor._get_dbcCs|jst d¡‚dS)Nzexecute() first)r rrrrrrÚ_check_executedDszCursor._check_executedcCs|Srr©rÚrowrrrÚ    _conv_rowHszCursor._conv_rowcGsdS©z!Does nothing, required by DB API.Nr©rÚargsrrrÚ setinputsizesKszCursor.setinputsizescGsdSr!rr"rrrÚsetoutputsizesNszCursor.setoutputsizesFcCsT| ¡}|j}|dks ||jk    r$dS|js.dSd|_| ¡|j|d| ¡dS)zGet the next query set.N©Ú
unbufferedT)rr Zhas_nextÚ _clear_resultZ next_resultÚ_do_get_result)rr'rZcurrent_resultrrrÚ_nextsetQs zCursor._nextsetcCs
| d¡S)NF©r*rrrrr_szCursor.nextsetNcsDt|tƒr| ˆ¡}n*t|ttfƒr@t|ƒ‡‡fdd„|Dƒƒ}|S)Nc3s|]}ˆj|ˆdVqdS))ÚencodingN)Ú _ensure_bytes)Ú.0Úv©r,rrrÚ    <genexpr>fsz'Cursor._ensure_bytes.<locals>.<genexpr>)Ú
isinstanceÚstrÚencodeÚtupleÚlistÚtype)rÚxr,rr0rr-bs
 
 zCursor._ensure_bytescsRt|ttfƒr$t‡fdd„|DƒƒSt|tƒrD‡fdd„| ¡DƒSˆ |¡SdS)Nc3s|]}ˆ |¡VqdSr©Úliteral©r.Úarg©rrrr1ksz&Cursor._escape_args.<locals>.<genexpr>csi|]\}}|ˆ |¡“qSrr9)r.ÚkeyÚvalr=rrÚ
<dictcomp>msz'Cursor._escape_args.<locals>.<dictcomp>)r2r5r6ÚdictÚitemsÚescape)rr#rrr=rÚ _escape_argsis
 
zCursor._escape_argscCs$| ¡}|dk    r || ||¡}|S)a¾
        Returns the exact string that would be sent to the database by calling the
        execute() method.
 
        :param query: Query to mogrify.
        :type query: str
 
        :param args: Parameters used with query. (optional)
        :type args: tuple, list or dict
 
        :return: The query with argument binding applied.
        :rtype: str
 
        This method follows the extension to the DB API 2.0 followed by Psycopg.
        N)rrD)rÚqueryr#rrrrÚmogrifysszCursor.mogrifycCs*| ¡r
q| ||¡}| |¡}||_|S)a¡Execute a query.
 
        :param query: Query to execute.
        :type query: str
 
        :param args: Parameters used with query. (optional)
        :type args: tuple, list or dict
 
        :return: Number of affected rows.
        :rtype: int
 
        If args is a list or tuple, %s can be used as a placeholder in the query.
        If args is a dict, %(name)s can be used as a placeholder in the query.
        )rrFÚ_queryr )rrEr#ÚresultrrrÚexecuteŠs  
zCursor.executec    s˜|sdSt ˆ¡}|rx| d¡d}| d¡ ¡}| d¡p>d}|ddkrX|d    d
ks\t‚ˆ ||||ˆjˆ ¡j¡St    ‡‡fd d „|Dƒƒˆ_
ˆj
S) aÏRun several data against one query.
 
        :param query: Query to execute.
        :type query: str
 
        :param args: Sequence of sequences or mappings. It is used as parameter.
        :type args: tuple or list
 
        :return: Number of rows affected, if any.
        :rtype: int or None
 
        This method improves performance on multiple-row INSERT and
        REPLACE. Otherwise it is equivalent to looping over args with
        execute().
        NrrééÚrú(rú)c3s|]}ˆ ˆ|¡VqdSr)rIr;©rErrrr1Äsz%Cursor.executemany.<locals>.<genexpr>) ÚRE_INSERT_VALUESÚmatchÚgroupÚrstripÚAssertionErrorÚ_do_execute_manyÚmax_stmt_lengthrr,Úsumr    )rrEr#ÚmZq_prefixZq_valuesZ    q_postfixrrOrÚ executemany¢s$
ú    zCursor.executemanyc Cs| ¡}|j}t|tƒr"| |¡}t|tƒr6| |¡}t|ƒ}    t|ƒ}||t|ƒ|ƒ}
t|
tƒrn|
 |d¡}
|    |
7}    d} |D]t} ||| |ƒ}
t|
tƒr¦|
 |d¡}
t|    ƒt|
ƒt|ƒd|krâ| |     |    |¡7} t|ƒ}    n|    d7}    |    |
7}    q~| |     |    |¡7} | |_
| S)NÚsurrogateescaperró,) rrDr2r3r4Ú    bytearrayÚiterÚnextÚlenrIr    ) rÚprefixÚvaluesZpostfixr#rVr,rrCZsqlr/Úrowsr<rrrrUÇs2
 
 
 
 
 
  
 
zCursor._do_execute_manyrcs„| ¡‰|rHdˆ›d‰| dd ‡‡fdd„t|ƒDƒ¡¡| ¡dˆd ‡fdd    „tt|ƒƒDƒ¡f}| |¡||_|S)
abExecute stored procedure procname with args.
 
        :param procname: Name of procedure to execute on server.
        :type procname: str
 
        :param args: Sequence of parameters to use with procedure.
        :type args: tuple or list
 
        Returns the original args.
 
        Compatibility warning: PEP-249 specifies that any modified
        parameters must be returned. This is currently impossible
        as they are only available by storing them in a server
        variable and then retrieved by a query. Since stored
        procedures return zero or more result sets, there is no
        reliable way to get at OUT or INOUT parameters via callproc.
        The server variables are named @_procname_n, where procname
        is the parameter above and n is the position of the parameter
        (from zero). Once all result sets generated by the procedure
        have been fetched, you can issue a SELECT @_procname_0, ...
        query using .execute() to get any OUT or INOUT values.
 
        Compatibility warning: The act of calling a stored procedure
        itself creates an empty result set. This appears after any
        result sets generated by the procedure. This is non-standard
        behavior with respect to the DB-API. Be sure to use nextset()
        to advance through all result sets; otherwise you may get
        disconnected.
        z@_z_%d=%szSET %sú,c3s$|]\}}ˆ|ˆ |¡fVqdSr)rC)r.Úindexr<)rÚfmtrrr1sz"Cursor.callproc.<locals>.<genexpr>z CALL %s(%s)csg|]}dˆ|f‘qS)z@_%s_%dr)r.Úi)ÚprocnamerrÚ
<listcomp>sz#Cursor.callproc.<locals>.<listcomp>)rrGÚjoinÚ    enumeraterÚranger_r )rrgr#Úqr)rrergrÚcallprocås$ ÿÿÿþ
zCursor.callproccCsD| ¡|jdks"|jt|jƒkr&dS|j|j}|jd7_|S)zFetch the next row.Nr©rr rr_©rrHrrrÚfetchones  zCursor.fetchonecCsL| ¡|jdkrdS|j|p"|j}|j|j|…}t|t|jƒƒ|_|S)zFetch several rows.Nr)rr rr
Úminr_)rÚsizeÚendrHrrrÚ    fetchmanys
zCursor.fetchmanycCsD| ¡|jdkrdS|jr.|j|jd…}n|j}t|jƒ|_|S)zFetch all the rows.NrrnrorrrÚfetchall)s
 zCursor.fetchallÚrelativecCsf| ¡|dkr|j|}n|dkr*|}nt d|¡‚d|krRt|jƒks\ntdƒ‚||_dS)NrvÚabsoluteúunknown scroll mode %srz out of range)rrrrr_r Ú
IndexError)rÚvalueÚmodeÚrrrrÚscroll5s z Cursor.scrollcCs(| ¡}| ¡| |¡| ¡|jSr©rr(rEr)r    ©rrlrrrrrGBs
 
z Cursor._querycCs(d|_d|_d|_d|_d|_d|_dS)Nr)rr r    rÚ    lastrowidr rrrrr(Is zCursor._clear_resultcCs8| ¡}|j|_}|j|_|j|_|j|_|j|_dSr)    rr Z affected_rowsr    rZ    insert_idr€rbr )rrrHrrrr)Rs  zCursor._do_get_resultcCs t|jdƒSr©r]rprrrrÚ__iter__\szCursor.__iter__)F)N)N)N)r)N)rv)*Ú__name__Ú
__module__Ú __qualname__Ú__doc__rVrrrrrrr r$r%r*rr-rDrFrIrYrUrmrprtrur}rGr(r)r‚rÚWarningÚErrorZInterfaceErrorZ DatabaseErrorZ    DataErrorZOperationalErrorZIntegrityErrorZ InternalErrorrÚNotSupportedErrorrrrrrsL
 
 
 
 
 
%
1    
 
 
    
rcs(eZdZeZ‡fdd„Zdd„Z‡ZS)ÚDictCursorMixincsvttˆƒ ¡g}ˆjrRˆjjD]*}|j}||kr@|jd|}| |¡q |ˆ_    |rrˆj
rr‡fdd„ˆj
Dƒˆ_
dS)NÚ.csg|]}ˆ |¡‘qSr)r )r.r|rrrrh{sz2DictCursorMixin._do_get_result.<locals>.<listcomp>) ÚsuperrŠr)rr ÚfieldsÚnameZ
table_nameÚappendÚ_fieldsr )rrÚfrŽ©Ú    __class__rrr)os  
zDictCursorMixin._do_get_resultcCs|dkr dS| t|j|ƒ¡Sr)Ú    dict_typeÚziprrrrrr }szDictCursorMixin._conv_row)rƒr„r…rAr”r)r Ú __classcell__rrr’rrŠks rŠc@seZdZdZdS)Ú
DictCursorz.A cursor which returns results as a dictionaryN©rƒr„r…r†rrrrr—ƒsr—c@speZdZdZdd„Zdd„ZeZdd„Zdd    „Zd
d „Z    d d „Z
dd„Z dd„Z dd„Z ddd„Zddd„ZdS)ÚSSCursoraÃ
    Unbuffered Cursor, mainly useful for queries that return a lot of data,
    or for connections to remote servers over a slow network.
 
    Instead of copying every row of data into a buffer, this will fetch
    rows as needed. The upside of this is the client uses much less memory,
    and rows are returned much faster when traveling over a slow network
    or if the result set is very big.
 
    There are limitations, though. The MySQL protocol doesn't support
    returning the total number of rows, so the only way to tell how many rows
    there are is to iterate over every row returned. Also, it currently isn't
    possible to scroll backwards, as only the current row is held in memory.
    cCs|Srrrrrrr —szSSCursor._conv_rowcCsN|j}|dkrdS|jdk    r2|j|jkr2|j ¡z| ¡r>q4W5d|_XdSr)rr Z_finish_unbuffered_queryrrrrrršs
zSSCursor.closecCs,| ¡}| ¡|j|dd| ¡|jS©NTr&r~rrrrrGªs
zSSCursor._querycCs |jddSršr+rrrrr±szSSCursor.nextsetcCs| |j ¡¡S)zRead next row.)r r Z_read_rowdata_packet_unbufferedrrrrÚ    read_next´szSSCursor.read_nextcCs.| ¡| ¡}|dkrdS|jd7_|S)zFetch next row.Nr)rr›rrrrrrp¸s zSSCursor.fetchonecCs t| ¡ƒS)zÈ
        Fetch all, as per MySQLdb. Pretty useless for large queries, as
        it is buffered. See fetchall_unbuffered(), if you want an unbuffered
        generator version of this method.
        )r6Úfetchall_unbufferedrrrrruÁszSSCursor.fetchallcCs t|jdƒS)zÛ
        Fetch all, implemented as a generator, which isn't to standard,
        however, it doesn't make sense to return everything in a list, as that
        would use ridiculous memory for large result sets.
        NrrrrrrœÉszSSCursor.fetchall_unbufferedcCs| ¡Sr)rœrrrrr‚ÑszSSCursor.__iter__NcCsX| ¡|dkr|j}g}t|ƒD]0}| ¡}|dkr:qT| |¡|jd7_q"|S)z Fetch many.Nr)rr
rkr›rr)rrrrbrfrrrrrtÔs 
zSSCursor.fetchmanyrvcCsž| ¡|dkrH|dkr"t d¡‚t|ƒD] }| ¡q*|j|7_nR|dkrŒ||jkrdt d¡‚||j}t|ƒD] }| ¡qv||_nt d|¡‚dS)Nrvrz0Backwards scrolling not supported by this cursorrwrx)rrr‰rkr›rr)rrzr{Ú_rsrrrr}ãs&ÿ 
 
ÿ
 
zSSCursor.scroll)N)rv)rƒr„r…r†r rÚ__del__rGrr›rprurœr‚rtr}rrrrr™‡s    
r™c@seZdZdZdS)Ú SSDictCursorz;An unbuffered cursor, which returns results as a dictionaryNr˜rrrrrŸýsrŸ) ÚrerLrÚcompileÚ
IGNORECASEÚDOTALLrPrrŠr—r™rŸrrrrÚ<module>s 
ü]v