o ]1@sdZddlZddlZddlmZmZddlmZmZddl m Z m Z m Z m Z mZmZmZmZmZmZddddd d Zed Zd d ZGdddejZdS)a This module implements connections for MySQLdb. Presently there is only one class: Connection. Others are unlikely. However, you might want to make your own subclasses. In most cases, you will probably override Connection.default_cursor with a non-standard Cursor class. N)cursors_mysql)unicodePY2) WarningErrorInterfaceError DataError DatabaseErrorOperationalErrorIntegrityError InternalErrorNotSupportedErrorProgrammingErrorutf8cp1252koi8_rkoi8_u)utf8mb4utf8mb3latin1koi8rkoi8uz^(\d+)cCs t|}|rt|dSdS)zReturns the leading numeric part of a string. >>> numeric_part("20-alpha") 20 >>> numeric_part("foo") >>> numeric_part("16b") 16 N)re_numeric_partmatchintgroup)smr 5/usr/lib/python3/dist-packages/MySQLdb/connections.py numeric_parts r"cseZdZdZejZfddZddZdddZ d d Z d d Z d dZ ddZ ddZeejds6ddZfddZddZddZeZeZeZeZeZeZeZeZeZeZZ S) Connectionz MySQL Database Connection Objectcsddlm}m}ddlm}m}ddlm}|}d|vr%| d|d<d|vr0| d|d<d |vr9|d } n|} i} | D]\} } t | t rXt | t rX| d d | | <qA| | | <qA| |d <| d |j} |d d }|srtsud}nd}| d|}| dd }| dd|_|dd}tddtdd dD}|dkr||jO}|dkr||jO}||d<| dd}tt|j|i|| |_tdd| D|_t|jt<tdd|dd dD|_ d|_!||d fdd }|s|"}|#||r|$||r4|j%|j&|j'|j(|j)|j*|j+fD]}||j,|<q%t-|j,|j.<||jt-<|j/|j0@|_1|j1rN|d urN|2|g|_3d S)!a Create a connection to the database. It is strongly recommended that you only use keyword parameters. Consult the MySQL C API documentation for more information. :param str host: host to connect :param str user: user to connect as :param str password: password to use :param str passwd: alias of password, for backward compatibility :param str database: database to use :param str db: alias of database, for backward compatibility :param int port: TCP/IP port to connect to :param str unix_socket: location of unix_socket to use :param dict conv: conversion dictionary, see MySQLdb.converters :param int connect_timeout: number of seconds to wait before the connection attempt fails. :param bool compress: if set, compression is enabled :param str named_pipe: if set, a named pipe is used to connect (Windows only) :param str init_command: command which is run once the connection is created :param str read_default_file: file from which default client values are read :param str read_default_group: configuration group to use from the default file :param type cursorclass: class object, used to create cursors (keyword only) :param bool use_unicode: If True, text-like columns are returned as unicode objects using the connection's character set. Otherwise, text-like columns are returned as bytes. Unicode objects will always be encoded to the connection's character set regardless of this setting. Default to False on Python 2 and True on Python 3 so that you can always get python `str` object by default. :param str charset: If supplied, the connection character set will be changed to this character set. On Python 2, this option changes default value of `use_unicode` option from False to True. :param str auth_plugin: If supplied, the connection default authentication plugin will be changed to this value. Example values: `mysql_native_password` or `caching_sha2_password` :param str sql_mode: If supplied, the session SQL mode will be changed to this setting. For more details and legal values, see the MySQL documentation. :param int client_flag: flags to use or 0 (see MySQL docs or constants/CLIENTS.py) :param dict ssl: dictionary or mapping contains SSL connection parameters; see the MySQL documentation for more details (mysql_ssl_set()). If this is set, and the client does not support SSL, NotSupportedError will be raised. :param bool local_infile: enables LOAD LOCAL INFILE; zero disables :param bool autocommit: If False (default), autocommit is disabled. If True, autocommit is enabled. If None, autocommit isn't set and server default is used. :param bool binary_prefix: If set, the '_binary' prefix will be used for raw byte query arguments (e.g. Binary). This is disabled by default. There are a number of undocumented, non-standard methods. See the documentation for the MySQL C API for some hints on what they do. r)CLIENT FIELD_TYPE) conversions _bytes_or_str)proxydatabasedbpasswordpasswdconvN cursorclasscharsetTF use_unicodesql_mode binary_prefix client_flagcSg|]}t|qSr r".0nr r r! z'Connection.__init__...r)r autocommitcSs$g|]\}}t|tur||fqSr )typer)r8kvr r r!r:s cSr5r r6r7r r r!r:r;asciics|jSN)string_literalencodeencoding)udummyr*r r!unicode_literalsz,Connection.__init__..unicode_literalrF)4MySQLdb.constantsr$r%MySQLdb.convertersr&r'weakrefr(copypopitems isinstancerlistdefault_cursorgetr_binary_prefixtuplerget_client_infosplitMULTI_STATEMENTS MULTI_RESULTSsuperr#__init__r.dictencodersbytesget_server_info_server_versionrIcharacter_set_nameset_character_set set_sql_modeSTRING VAR_STRINGVARCHAR TINY_BLOB MEDIUM_BLOB LONG_BLOBBLOB converterrJSONserver_capabilities TRANSACTIONS_transactionalrAmessages)selfargskwargsr$r%r&r'r(kwargs2r-conv2rCrDr.r/r1r2r4client_versionrArMt __class__rLr!r_2stQ       $    &        zConnection.__init__cCs*t|}||krtj||dSdSrF)boolget_autocommitr connectionrA)ruonr r r!rAs zConnection.autocommitNcCs|p|j|S)z Create a cursor on which queries may be performed. The optional cursorclass parameter is used to create the Cursor. By default, self.cursorclass=cursors.Cursor is used. )r.)rur.r r r!cursorszConnection.cursorcCs$t|tr t|}tj||dSrF)rT bytearrayrbrrquery)rurr r r!rs zConnection.querycCs.t|ttfs J||}|jrd|S|S)Ns_binary)rTrbrrGrX)rubsxr r r!_bytes_literals  zConnection._bytes_literalcCsddt|j|S)Ns(%s),)joinmapliteral)rur{r r r!_tuple_literalszConnection._tuple_literalcCst|tr|||j}n=t|tr||}n2t|tr-tr'||}n%||}nt|t t fr:| |}n| ||j }t|trL||j}t|tsSJ|S)aIf o is a single object, returns an SQL literal as a string. If o is a non-string sequence, the items of the sequence are converted and returned as a sequence. Non-standard. For internal use; do not use this in your applications. )rTrrGrHrIrrrbrrYrUrescapera)ruorr r r!rs         zConnection.literalcCs|ddS)ziExplicitly begin a connection. This method is not used when autocommit=False (default). sBEGINN)r)rur r r!beginszConnection.begin warning_countcCs |}|rt|dSdS)zpReturn the number of warnings generated from the last query. This is derived from the info() method.r)inforr[)rurr r r!rszConnection.warning_countcsrt||}||kr4z tt||Wnty3|jdkr&td| d|| Ynw||_ dS)zSet the connection character set to charset. The character set can only be changed in MySQL-4.1 and newer. If you try to change the character set from the current value in an older version, NotSupportedError will be raised.r>z server is too old to set charsetz SET NAMES %sN) _charset_to_encodingrWrer^r#rfAttributeErrorrdrr store_resultrI)rur/ py_charsetr|r r!rf's      zConnection.set_character_setcCs,|jdkr td|d||dS)zNSet the connection sql_mode. See MySQL documentation for legal values.r>z!server is too old to set sql_modezSET SESSION sql_mode='%s'N)rdrrr)rur2r r r!rg7s  zConnection.set_sql_modecCs.|jdkrdS|d|}|d}|S)zReturn detailed information about warnings as a sequence of tuples of (Level, Code, Message). This is only supported in MySQL-4.1 and up. If your server is an earlier version, an empty sequence is returned.r>r z SHOW WARNINGSr)rdrr fetch_row)rurwarningsr r r! show_warnings?s   zConnection.show_warningsrF)!__name__ __module__ __qualname____doc__rCursorrVr_rArrrrrrhasattrrrrrfrgrrrrr r r r r rr __classcell__r r r|r!r#-s6 ,      r#)rresysMySQLdbrrMySQLdb.compatrrMySQLdb._exceptionsrrrr r r r r rrrcompilerr"rr#r r r r!s0