zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
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
U
¸ý°dJã@sšdZddlZddlmZddlmZddlmZddlmZdd    lm    Z    dd
l
m Z dd l m Z Gd d „d eƒZGdd„deƒZGdd„de eƒZeZdS)aH
 
 
.. dialect:: mysql+pyodbc
    :name: PyODBC
    :dbapi: pyodbc
    :connectstring: mysql+pyodbc://<username>:<password>@<dsnname>
    :url: https://pypi.org/project/pyodbc/
 
.. note::
 
    The PyODBC for MySQL dialect is **not tested as part of
    SQLAlchemy's continuous integration**.
    The recommended MySQL dialects are mysqlclient and PyMySQL.
    However, if you want to use the mysql+pyodbc dialect and require
    full support for ``utf8mb4`` characters (including supplementary
    characters like emoji) be sure to use a current release of
    MySQL Connector/ODBC and specify the "ANSI" (**not** "Unicode")
    version of the driver in your DSN or connection string.
 
Pass through exact pyodbc connection string::
 
    import urllib
    connection_string = (
        'DRIVER=MySQL ODBC 8.0 ANSI Driver;'
        'SERVER=localhost;'
        'PORT=3307;'
        'DATABASE=mydb;'
        'UID=root;'
        'PWD=(whatever);'
        'charset=utf8mb4;'
    )
    params = urllib.parse.quote_plus(connection_string)
    connection_uri = "mysql+pyodbc:///?odbc_connect=%s" % params
 
éNé)Ú MySQLDialect)ÚMySQLExecutionContext)ÚTIMEé)Úexc)Úutil)ÚPyODBCConnector)ÚTimec@seZdZdd„ZdS)Ú _pyodbcTIMEcCs dd„}|S)NcSs|S©N©)Úvaluer r úWd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/dialects/mysql/pyodbc.pyÚprocess<sz-_pyodbcTIME.result_processor.<locals>.processr )ÚselfÚdialectZcoltyperr r rÚresult_processor;sz_pyodbcTIME.result_processorN)Ú__name__Ú
__module__Ú __qualname__rr r r rr :sr c@seZdZdd„ZdS)ÚMySQLExecutionContext_pyodbccCs*| ¡}| d¡| ¡d}| ¡|S)NzSELECT LAST_INSERT_ID()r)Z create_cursorÚexecuteZfetchoneÚclose)rÚcursorZ    lastrowidr r rÚ get_lastrowidDs
 
 z*MySQLExecutionContext_pyodbc.get_lastrowidN)rrrrr r r rrCsrcsVeZdZdZe ejee    i¡ZdZ
e Z dZ dd„Zdd„Zdd„Z‡fd    d
„Z‡ZS) ÚMySQLDialect_pyodbcTZMySQLcCsFd|_z| |d¡}|r|WSWntjk
r6YnXt d¡dS)z:Sniff out the character set in use for connection results.NZcharacter_set_clientz@Could not detect the connection character set.  Assuming latin1.Úlatin1)Z_connection_charsetZ_fetch_settingrZ
DBAPIErrorrÚwarn)rÚ
connectionrr r rÚ_detect_charsetTs  
ÿz#MySQLDialect_pyodbc._detect_charsetcCs t ||¡Sr )rÚ_get_server_version_info)rrr r rr!msz,MySQLDialect_pyodbc._get_server_version_infocCs4t d¡ t|jƒ¡}| d¡}|r,t|ƒSdSdS)Nz    \((\d+)\)r)ÚreÚcompileÚsearchÚstrÚargsÚgroupÚint)rÚ    exceptionÚmÚcr r rÚ_extract_error_codeps
 
z'MySQLDialect_pyodbc._extract_error_codecstƒ ¡‰‡fdd„}|S)NcsDˆdk    rˆ|ƒd}d}|j|dd|j|dd|jdddS)Nriøÿÿÿzutf-8)Úencoding)Z setdecodingZ setencoding)ÚconnZpyodbc_SQL_CHARZpyodbc_SQL_WCHAR©Zsuper_r rÚ
on_connect{sz2MySQLDialect_pyodbc.on_connect.<locals>.on_connect)Úsuperr0)rr0©Ú    __class__r/rr0xs
 zMySQLDialect_pyodbc.on_connect)rrrZsupports_statement_cacherZ update_copyrZcolspecsr
r Zsupports_unicode_statementsrZexecution_ctx_clsZpyodbc_driver_namer r!r,r0Ú __classcell__r r r2rrLsr)Ú__doc__r"ÚbaserrÚtypesrÚrrZconnectors.pyodbcr    Z sql.sqltypesr
r rrrr r r rÚ<module>
s%               >