You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

83 lines
2.7 KiB

# mysql/mysqldb.py
12 years ago
# Copyright (C) 2005-2013 the SQLAlchemy authors and contributors <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""Support for the MySQL database via the MySQL-python adapter.
MySQL-Python is available at:
http://sourceforge.net/projects/mysql-python
At least version 1.2.1 or 1.2.2 should be used.
Connecting
-----------
Connect string format::
mysql+mysqldb://<user>:<password>@<host>[:<port>]/<dbname>
13 years ago
Unicode
-------
13 years ago
MySQLdb will accommodate Python ``unicode`` objects if the
``use_unicode=1`` parameter, or the ``charset`` parameter,
is passed as a connection argument.
12 years ago
Without this setting, many MySQL server installations default to
13 years ago
a ``latin1`` encoding for client connections, which has the effect
12 years ago
of all data being converted into ``latin1``, even if you have ``utf8``
13 years ago
or another character set configured on your tables
and columns. With versions 4.1 and higher, you can change the connection
character set either through server configuration or by including the
13 years ago
``charset`` parameter. The ``charset``
12 years ago
parameter as received by MySQL-Python also has the side-effect of
13 years ago
enabling ``use_unicode=1``::
# set client encoding to utf8; all strings come back as unicode
create_engine('mysql+mysqldb:///mydb?charset=utf8')
12 years ago
Manually configuring ``use_unicode=0`` will cause MySQL-python to
13 years ago
return encoded strings::
13 years ago
# set client encoding to utf8; all strings come back as utf8 str
create_engine('mysql+mysqldb:///mydb?charset=utf8&use_unicode=0')
Known Issues
-------------
13 years ago
MySQL-python version 1.2.2 has a serious memory leak related
to unicode conversion, a feature which is disabled via ``use_unicode=0``.
13 years ago
It is strongly advised to use the latest version of MySQL-Python.
"""
from sqlalchemy.dialects.mysql.base import (MySQLDialect, MySQLExecutionContext,
MySQLCompiler, MySQLIdentifierPreparer)
13 years ago
from sqlalchemy.connectors.mysqldb import (
12 years ago
MySQLDBExecutionContext,
MySQLDBCompiler,
MySQLDBIdentifierPreparer,
13 years ago
MySQLDBConnector
)
13 years ago
class MySQLExecutionContext_mysqldb(MySQLDBExecutionContext, MySQLExecutionContext):
pass
13 years ago
class MySQLCompiler_mysqldb(MySQLDBCompiler, MySQLCompiler):
pass
13 years ago
class MySQLIdentifierPreparer_mysqldb(MySQLDBIdentifierPreparer, MySQLIdentifierPreparer):
pass
13 years ago
class MySQLDialect_mysqldb(MySQLDBConnector, MySQLDialect):
execution_ctx_cls = MySQLExecutionContext_mysqldb
statement_compiler = MySQLCompiler_mysqldb
preparer = MySQLIdentifierPreparer_mysqldb
dialect = MySQLDialect_mysqldb