Xׯd5ddlmZddlmZdZdZdZdZddZd ZGd d e Z Gd d e eZ Gdde Z GddZ GddZGddZdS))modules) DBLoginErrorcV|ddddS)N\z\\'z\'replacess ..\workbench\db_utils.pyescape_sql_stringr s& 99T6 " " * *3 6 66c.|ddS)N```rr s r escape_sql_identifierrs 99S$  rc~|ddddddS)Nrr_z\_%z\%rr s r escape_schema_wildcardsr s6 99S$   ' 'U 3 3 ; ;C G GGrcddl} |dd|}||krn|}! |dd|}||krn|}!|S)NrTz(.*PASSWORD.*\(')(.*)('\).*)z \1XXXXXX\3z0(.*IDENTIFIED (BY|WITH).*(\'|\"))(.*)((\'|\").*)z \1xxxxxxx\5)resub)r rsss r strip_passwordr$su III VV3]A F F 77     VVGXY Z Z 77    HrFcd}||vrdnd}d}d}d}||dD]4} |r| dkr |sd}|| z }| |vr|s |sd}n || z }d}n|rn |sd}|| z }5|r|sdS|S)a Extracts from a string starting at the given index and ending once the first character in limit is found. If force_limit is True, will return None if the limit is not found and the end of the string is reached. z'"`TFNr) sourceindexlimit force_limitquotinghandle_embedded_quotingtoken limit_found escape_foundchars r substring_to_delimiterr)4sG&+w&6&6ddE EKLuvv " t||L|#   5== ("("&KKTME"'K   L TME;t rc`g}d}t|}d}||krd}||}|dvr-t||dz|d}|r|t|zdz}n4|dvr |r|dz }d}n&d }n#t||d}|t|z}|r||d}n|n||k|S) a  Extracts from a string an array with all the valid IDs found Expected format is a dot separated list of IDs where they could optionally be quoted by single, double or back quotes. If an invalid ID is found the process will stop. rFrz"'`Tz. N)lenr)append)ridsr lengthprevious_tokenr%r(s r parse_mysql_idsr2fs C E [[FN &..e} 6>>*6519dDIIE /E *Q.t||!!QJE%*NN EE/vudCCE *   JJu   !NN ] 9 &..< JrceZdZdZdS) MySQLErrorcdt||d|zz||_||_dS)Nz (code %i)) Exception__init__codelocationselfmsgr8r9s r r7zMySQLError.__init__s44|D'8!8999   rN__name__ __module__ __qualname__r7rrr r4r4s#!!!!!rr4ceZdZdZdS)MySQLLoginErrorcjt||||tj||dSN)r4r7rr:s r r7zMySQLLoginError.__init__s5D#tX666dC(((((rNr=rrr rBrBs#)))))rrBc,eZdZdZddZdZdZdZdS) QueryError)iiiiNc0||_||_||_dSrD)r<error errortext)r;r<rIrJs r r7zQueryError.__init__sDHDJDNNNrc@|jdzt|jzS)Nz . SQL Error: )r<strrIr;s r __str__zQueryError.__str__s 8& &TZ 88rcdd} t|j}n#t$rYnwxYw||jvSNr)intrI ValueErrornot_connected_errors)r;r8s r is_connection_errorzQueryError.is_connection_errorsI D __dd     d 4, ,,s  &&c|jdkS)NrG)rIrMs r is_error_recoverablezQueryError.is_error_recoverables : rrD)r>r?r@rSr7rNrTrVrrr rFrFs[7 999---rrFceZdZdZdZdS)ConnectionTunnelctj||_|jdkr+tj|j|_dSd|_dSrP)r DbMySQLQuery openTunneltunnel getTunnelPortport)r;infos r r7zConnectionTunnel.__init__sN*55d;; ;??,::4;GGDIIIDIIIrch|jdkr&tj|jdSdSrP)r\rrZ closeTunnelrMs r __del__zConnectionTunnel.__del__s3 ;??  , ,T[ 9 9 9 9 9 ?rN)r>r?r@r7rbrrr rXrXs2:::::rrXcneZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdS) MySQLResultc||_dSrD)result)r;rfs r r7zMySQLResult.__init__s  rc`|jr&tj|jdSdSrD)rfrrZ closeResultrMs r rbzMySQLResult.__del__s5 ; :  , ,T[ 9 9 9 9 9 : :rcJtj|jSrD)rrZresultFirstRowrfrMs r firstRowzMySQLResult.firstRows#224;???rcJtj|jSrD)rrZ resultNextRowrfrMs r nextRowzMySQLResult.nextRow#11$+>>>rcLtj|j|SrD)rrZresultFieldStringValueByNamerfr;names r stringByNamezMySQLResult.stringByName#@@dSSSrctj|j|}t |t s|dS|SNutf-8)rrZrqrf isinstancerLdecode)r;rsr s r unicodeByNamezMySQLResult.unicodeByNamesE  = =dk4 P P!S!! %88G$$ $rcLtj|j|SrD)rrZresultFieldIntValueByNamerfrrs r intByNamezMySQLResult.intByNames#==dk4PPPrcLtj|j|SrD)rrZresultFieldDoubleValueByNamerfrrs r floatByNamezMySQLResult.floatByNamerurcLtj|j|SrD)rrZresultFieldStringValuerfr;is r stringByIndexzMySQLResult.stringByIndex#::4;JJJrctj|j|}t |t s|dS|Srw)rrZrrfryrLrz)r;rr s r unicodeByIndexzMySQLResult.unicodeByIndexsE  7 7 Q G G!S!! %88G$$ $rcLtj|j|SrD)rrZresultFieldDoubleValuerfrs r floatByIndexzMySQLResult.floatByIndexrrcLtj|j|SrD)rrZresultFieldIntValuerfrs r intByIndexzMySQLResult.intByIndexs#77 QGGGrcJtj|jSrD)rrZresultNumFieldsrfrMs r numFieldszMySQLResult.numFieldss#33DK@@@rcJtj|jSrD)rrZ resultNumRowsrfrMs r numRowszMySQLResult.numRowsrorcLtj|j|SrD)rrZresultFieldNamerfrs r fieldNamezMySQLResult.fieldName#33DKCCCrcLtj|j|SrD)rrZresultFieldTyperfrs r fieldTypezMySQLResult.fieldTyperrN)r>r?r@r7rbrkrnrtr{r~rrrrrrrrrrrr rdrds$:::@@@???TTT QQQTTTKKK KKKHHHAAA???DDDDDDDDrrdcreZdZdZddZdZddZdZdZdZ d Z e d Z d Z d Zd ZdZeZdS)MySQLConnectionas Connection to a MySQL server, use as: info = grt.root.wb.rdbmsMgmt.storedConns[0] conn = MySQLConnection(info) conn.connect() result = conn.executeQuery("SHOW DATABASES") flag = result.firstRow() while flag: print result.stringByName("Database") flag = result.nextRow() Nc|t|tusJ||_d|_d|_||_||_dSrP)typerL connect_info connection server_down status_cbpassword)r;r_rrs r r7zMySQLConnection.__init__ sBIc)))) "  rc.|dSrD) disconnectrMs r rbzMySQLConnection.__del__s rcP|jr||||jdSdSrD)rr)r;r8rIs r send_statuszMySQLConnection.send_statuss5 > ; NN4(9 : : : : : ; ;rcd|_|js|jj}d}d|vr|d}d|d<|j0t j|j|j|_n)t j |j|_|dkr||d<n|d=|jdkrd|_t j }|dkrntt j t j |jjdd|jjd |d vrd |_tt j t j |jjdd|jjd |dd dSdS) NFOPT_READ_TIMEOUTi,riuserName@hostName)iiTzConnection created)rrrparameterValueskeysrrrZopenConnectionPopenConnection lastErrorCoderB lastErrorr4r)r;paramsold_timeout_valuer8s r connectzMySQLConnection.connectsR  6&6F " !V[[]]22$*+=$>!)-F% &}(")"6"F"FtGXZ^Zg"h"h")"6"E"EdFW"X"X A%%->)**-."""#+99;;4<<)'*>*H*H*J*JGL`LnLnLpLp~B~O~_`j~k~k~kmqm~mNOYmZmZs[\\\;&&'+D$ !5!?!?!A!A7CWCeCeCgCgtxuFuVWaubububdhdudEFPdQdQjRSSS   Q 4 5 5 5 5 57 6 6rc0|ddS)NzSELECT 1T) executeQueryrMs r pingzMySQLConnection.ping:s *%%%trc|sdS |jdn#t$r }Yd}~dSd}~wwxYwdS)NFzselect 1T) is_connectedsql exec_queryrF)r;es r try_pingzMySQLConnection.try_ping>sj  "" 5  H   + + + +   55555 ts3 AAc|jr]ttjdr$tj|jd|_|dddSdS)NcloseConnectionrrzConnection closed by client)rhasattrrrZrrrMs r rzMySQLConnection.disconnectGsm ? @w+->?? F$44T_EEEDO   R!> ? ? ? ? ?  @ @rc|jdkSrP)rrMs r rzMySQLConnection.is_connectedNs""rc|jrtj|j|}|dkrtj|j}t tj|j}|||tdt |d||||d|dkS|ddtdd)NrError executing '' r7Connection to MySQL server is currently not established) rrrZexecutelastConnectionErrorCoderlastConnectionErrorrrFr;queryrfr8rIs r rzMySQLConnection.executeSs ? \)11$/5IIFzz)AA$/RRd$W%9%M%Mdo%^%^__etU+++J^E=R=R=R=RTYTYZ\`bghhh   Q   Q;    R!Z [ [ [VXZ[[ [rc8|jrtj|jt |t s|dn|}|dkrutj|j}tj|j}| ||td|d|||| dt|S| ddtddNrxrrrrr) rrrZrryrLencoderrrrFrdrs r rzMySQLConnection.executeQueryds ? \)66teopuwze{e{IG U\H]H]H]BGHHFzz+CCDOTT,@@QQ  u--- jUUUEE!JDRWXXX   Q   v&& &   R!Z [ [ [VXZ[[ [rc|jr8tj|jt |t s|dn|}t|dkrutj|j}tj |j}| ||td|d|||| dg}tdt|D]*}| t||+|S| ddtddr)rrrZexecuteQueryMultiResultryrLrr-rrrrFranger.rd)r;rrfr8rI result_listr s r rz'MySQLConnection.executeQueryMultiResulttsn ? \)AA$/pz|ACFqGqGTRSXS_S_`gShShShMRSSF6{{a+CCDOTT,@@QQ  u--- jUUUEE!JDRWXXX   Q   Kq#f++.. ? ?"";ve}#=#=>>>>    R!Z [ [ [VXZ[[ [rcJtj|jSrD)rrZlastUpdateCountrrMs r updateCountzMySQLConnection.updateCounts#33DODDDr)NNrD)r>r?r@__doc__r7rbrrrrrpropertyrrrrr affectedRowsrrr rrs  !!!!;;;;666>@@@##X#\\\"\\\ \\\(EEELLLrrN)F)grtrrr rrrr)r2r6r4rBrFrXrdrrrr rs,777   HHH    0000d,,,\!!!!!!!!)))))j,))) , : : : : : : : :8D8D8D8D8D8D8D8DvKKKKKKKKKKr