diff --git a/.github/workflows/django.yaml b/.github/workflows/django.yaml new file mode 100644 index 00000000..4e18374a --- /dev/null +++ b/.github/workflows/django.yaml @@ -0,0 +1,53 @@ +name: Django compat test + +on: + push: + +jobs: + build: + runs-on: ubuntu-20.04 + steps: + - name: Start MySQL + run: | + sudo systemctl start mysql.service + mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -uroot -proot mysql + mysql -uroot -proot -e "CREATE USER 'scott'@'%' IDENTIFIED BY 'tiger'; GRANT ALL ON *.* TO scott;" + + - uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-django-pip-1 + restore-keys: | + ${{ runner.os }}-pip- + + - name: Set up Python + uses: actions/setup-python@v2 + with: + # https://www.mail-archive.com/django-updates@googlegroups.com/msg209056.html + python-version: "3.8" + + - uses: actions/checkout@v2 + with: + fetch-depth: 2 + + - name: Install mysqlclient + env: + PIP_NO_PYTHON_VERSION_WARNING: 1 + PIP_DISABLE_PIP_VERSION_CHECK: 1 + run: | + pip install -U pytest pytest-cov tblib + pip install . + # pip install mysqlclient # Use stable version + + - name: Run Django test + env: + DJANGO_VERSION: "2.2.24" + run: | + sudo apt-get install libmemcached-dev + wget https://github.com/django/django/archive/${DJANGO_VERSION}.tar.gz + tar xf ${DJANGO_VERSION}.tar.gz + cp ci/test_mysql.py django-${DJANGO_VERSION}/tests/ + cd django-${DJANGO_VERSION}/tests/ + pip install .. + pip install -r requirements/py3.txt + PYTHONPATH=.. python3 ./runtests.py --settings=test_mysql diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 748d2c2b..e3c0fec1 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -9,23 +9,41 @@ jobs: runs-on: ubuntu-20.04 strategy: matrix: - python-version: [3.5, 3.6, 3.7, 3.8, 3.9] + python-version: ["3.6", "3.7", "3.8", "3.9", "3.10"] steps: - name: Start MySQL run: | sudo systemctl start mysql.service mysql -uroot -proot -e "CREATE DATABASE mysqldb_test" + + - uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-1 + restore-keys: | + ${{ runner.os }}-pip- + - uses: actions/checkout@v2 + with: + fetch-depth: 2 + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + + - name: Install dependencies + env: + PIP_NO_PYTHON_VERSION_WARNING: 1 + PIP_DISABLE_PIP_VERSION_CHECK: 1 + run: | + pip install -U coverage pytest pytest-cov + python setup.py develop + - name: Run tests env: TESTDB: actions.cnf run: | - pip install -U pip - pip install -U mock coverage pytest pytest-cov - pip install . - pytest --cov ./MySQLdb + pytest --cov=MySQLdb tests + - uses: codecov/codecov-action@v1 diff --git a/.github/workflows/windows.yaml b/.github/workflows/windows.yaml index c65ce188..ac9b28da 100644 --- a/.github/workflows/windows.yaml +++ b/.github/workflows/windows.yaml @@ -10,7 +10,7 @@ jobs: build: runs-on: windows-latest env: - CONNECTOR_VERSION: "3.1.11" + CONNECTOR_VERSION: "3.2.4" steps: - name: Cache Connector @@ -61,14 +61,14 @@ jobs: shell: cmd working-directory: mysqlclient run: | + py -3.10 -m pip install -U setuptools wheel pip + py -3.10 setup.py bdist_wheel py -3.9 -m pip install -U setuptools wheel pip py -3.9 setup.py bdist_wheel py -3.8 -m pip install -U setuptools wheel pip py -3.8 setup.py bdist_wheel py -3.7 -m pip install -U setuptools wheel pip py -3.7 setup.py bdist_wheel - py -3.6 -m pip install -U setuptools wheel pip - py -3.6 setup.py bdist_wheel - name: Upload Wheel uses: actions/upload-artifact@v2 @@ -81,12 +81,12 @@ jobs: working-directory: mysqlclient/dist run: | ls -la + py -3.10 -m pip install --no-index --find-links . mysqlclient + py -3.10 -c "import MySQLdb; print(MySQLdb.version_info)" py -3.9 -m pip install --no-index --find-links . mysqlclient py -3.9 -c "import MySQLdb; print(MySQLdb.version_info)" py -3.8 -m pip install --no-index --find-links . mysqlclient py -3.8 -c "import MySQLdb; print(MySQLdb.version_info)" py -3.7 -m pip install --no-index --find-links . mysqlclient py -3.7 -c "import MySQLdb; print(MySQLdb.version_info)" - py -3.6 -m pip install --no-index --find-links . mysqlclient - py -3.6 -c "import MySQLdb; print(MySQLdb.version_info)" diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 75c6d425..00000000 --- a/.travis.yml +++ /dev/null @@ -1,63 +0,0 @@ -dist: bionic -language: python - -# See aws s3 ls s3://travis-python-archives/binaries/ubuntu/18.04/x86_64/ -python: - - "nightly" - - "pypy3" - -cache: pip - -services: - - mysql - -install: - - pip install -U pip - - pip install -U mock coverage pytest pytest-cov codecov - -env: - global: - - TESTDB=travis.cnf - -before_script: - - "mysql --help" - - "mysql --print-defaults" - - "mysql -e 'create database mysqldb_test charset utf8mb4;'" - -script: - - pip install -e . - - pytest --cov ./MySQLdb - -after_success: - - codecov - -jobs: - fast_finish: true - include: - - &django_2_2 - name: "Django 2.2 test" - env: - - DJANGO_VERSION=2.2.7 - python: "3.8" - install: - - pip install -U pip - - wget https://github.com/django/django/archive/${DJANGO_VERSION}.tar.gz - - tar xf ${DJANGO_VERSION}.tar.gz - - pip install -e django-${DJANGO_VERSION}/ - - cp ci/test_mysql.py django-${DJANGO_VERSION}/tests/ - - pip install . - - before_script: - - mysql -e 'create user django identified by "secret"' - - mysql -e 'grant all on *.* to django' - - mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql mysql - - script: - - cd django-${DJANGO_VERSION}/tests/ - - ./runtests.py --parallel=2 --settings=test_mysql - #- &django_3_0 - # <<: *django_2_2 - # name: "Django 3.0 test (Python 3.8)" - # python: "3.8" - -# vim: sw=2 ts=2 sts=2 diff --git a/HISTORY.rst b/HISTORY.rst index 16fcbd59..19d57bee 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,3 +1,22 @@ +====================== + What's new in 2.1.0 +====================== + +Release: 2021-11-17 + +* Add ``multistatement=True`` option. You can disable multi statement. (#500). +* Remove unnecessary bytes encoder which is remained for Django 1.11 + compatibility (#490). +* Deprecate ``passwd`` and ``db`` keyword. Use ``password`` and ``database`` + instead. (#488). +* Windows: Binary wheels are built with MariaDB Connector/C 3.2.4. (#508) +* ``set_character_set()`` sends ``SET NAMES`` query always. This means + all new connections send it too. This solves compatibility issues + when server and client library are different version. (#509) +* Remove ``escape()`` and ``escape_string()`` from ``MySQLdb`` package. + (#511) +* Add Python 3.10 support and drop Python 3.5 support. + ====================== What's new in 2.0.3 ====================== @@ -75,7 +94,7 @@ Release: 2019-08-09 * ``--static`` build supports ``libmariadbclient.a`` * Try ``mariadb_config`` when ``mysql_config`` is not found -* Fixed warning happend in Python 3.8 (#359) +* Fixed warning happened in Python 3.8 (#359) * Fixed ``from MySQLdb import *``, while I don't recommend it. (#369) * Fixed SEGV ``MySQLdb.escape_string("1")`` when libmariadb is used and no connection is created. (#367) @@ -275,7 +294,7 @@ More tests for date and time columns. (#41) Fix calling .execute() method for closed cursor cause TypeError. (#37) -Improve peformance to parse date. (#43) +Improve performance to parse date. (#43) Support geometry types (#49) diff --git a/INSTALL.rst b/INSTALL.rst deleted file mode 100644 index 0b49f3e6..00000000 --- a/INSTALL.rst +++ /dev/null @@ -1,146 +0,0 @@ -==================== -MySQLdb Installation -==================== - -.. contents:: -.. - -Prerequisites -------------- - -+ Python 3.5 or higher - -+ setuptools - - * https://pypi.org/project/setuptools/ - -+ MySQL 5.5 or higher - - * https://www.mysql.com/downloads/ - - * MySQL 5.1 may work, but not supported. - -+ C compiler - - * Most free software-based systems already have this, usually gcc. - - * Most commercial UNIX platforms also come with a C compiler, or - you can also use gcc. - - * If you have some Windows flavor, you should use Windows SDK or - Visual C++. - - -Building and installing ------------------------ - -The setup.py script uses mysql_config to find all compiler and linker -options, and should work as is on any POSIX-like platform, so long as -mysql_config is in your path. - -Depending on which version of MySQL you have, you may have the option -of using three different client libraries. To select the client library, -edit the [options] section of site.cfg: - - static - if True, try to link against a static library; otherwise link - against dynamic libraries (default). - This option doesn't work for MySQL>5.6 since libmysqlclient - requires libstdc++. If you want to use, add `-lstdc++` to - mysql_config manually. - -If `/lib` is not added to `/etc/ld.so.conf`, `import _mysql` -doesn't work. To fix this, (1) set `LD_LIBRARY_PATH`, or (2) add -`-Wl,-rpath,/lib` to ldflags in your mysql_config. - -Finally, putting it together:: - - $ tar xz mysqlclient-1.3.6.tar.gz - $ cd mysqlclient-1.3.6 - $ # edit site.cfg if necessary - $ python setup.py build - $ sudo python setup.py install # or su first - - -Windows -....... - -I don't do Windows. However if someone provides me with a package for -Windows, I'll make it available. Don't ask me for help with Windows -because I can't help you. - -Generally, though, running setup.py is similar to above:: - - C:\...> python setup.py install - C:\...> python setup.py bdist_wininst - -The latter example should build a Windows installer package, if you -have the correct tools. In any event, you *must* have a C compiler. -Additionally, you have to set an environment variable (mysqlroot) -which is the path to your MySQL installation. In theory, it would be -possible to get this information out of the registry, but like I said, -I don't do Windows, but I'll accept a patch that does this. - -On Windows, you will definitely have to edit site.cfg since there is -no mysql_config in the MySQL package. - - -Binary Packages ---------------- - -I don't plan to make binary packages any more. However, if someone -contributes one, I will make it available. Several OS vendors have -their own packages available. - - -Red Hat Linux -............. - -MySQL-python is pre-packaged in Red Hat Linux 7.x and newer. This -includes Fedora Core and Red Hat Enterprise Linux. - - -Debian GNU/Linux -................ - -Packaged as `python-mysqldb`_:: - - # apt-get install python-mysqldb - -Or use Synaptic. - -.. _`python-mysqldb`: http://packages.debian.org/python-mysqldb - - -Ubuntu -...... - -Same as with Debian. - - -Gentoo Linux -............ - -Packaged as `mysql-python`_. :: - - # emerge sync - # emerge mysql-python - # emerge zmysqlda # if you use Zope - -.. _`mysql-python`: https://packages.gentoo.org/packages/search?q=mysql-python - - -BSD -... - -MySQL-python is a ported package in FreeBSD, NetBSD, and OpenBSD, -although the name may vary to match OS conventions. - - -License -------- - -GPL or the original license based on Python 1.5.2's license. - - -:Author: Andy Dustman diff --git a/MANIFEST.in b/MANIFEST.in index 415a995a..07563caf 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -3,7 +3,6 @@ recursive-include tests *.py include doc/conf.py include MANIFEST.in include HISTORY.rst -include INSTALL.rst include README.md include LICENSE include metadata.cfg diff --git a/Makefile b/Makefile index 8c8cddc8..783d1919 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ doc: .PHONY: clean clean: + python3 setup.py clean find . -name '*.pyc' -delete find . -name '__pycache__' -delete - rm *.so - python3 setup.py clean + rm -rf build diff --git a/MySQLdb/__init__.py b/MySQLdb/__init__.py index 824acace..b567363b 100644 --- a/MySQLdb/__init__.py +++ b/MySQLdb/__init__.py @@ -38,8 +38,6 @@ string_literal, MySQLError, DataError, - escape, - escape_string, DatabaseError, InternalError, Warning, @@ -54,11 +52,6 @@ TimestampFromTicks, ) -try: - frozenset -except NameError: - from sets import ImmutableSet as frozenset - threadsafety = 1 apilevel = "2.0" paramstyle = "format" @@ -169,8 +162,6 @@ def Connect(*args, **kwargs): "converters", "cursors", "debug", - "escape", - "escape_string", "get_client_info", "paramstyle", "string_literal", diff --git a/MySQLdb/_mysql.c b/MySQLdb/_mysql.c index 27880ca2..f10cd015 100644 --- a/MySQLdb/_mysql.c +++ b/MySQLdb/_mysql.c @@ -310,7 +310,7 @@ _mysql_ResultObject_Initialize( PyObject *fun2=NULL; int j, n2=PySequence_Size(fun); // BINARY_FLAG means ***_bin collation is used. - // To distinguish text and binary, we shoud use charsetnr==63 (binary). + // To distinguish text and binary, we should use charsetnr==63 (binary). // But we abuse BINARY_FLAG for historical reason. if (fields[i].charsetnr == 63) { flags |= BINARY_FLAG; @@ -414,7 +414,7 @@ _mysql_ConnectionObject_Initialize( *db = NULL, *unix_socket = NULL; unsigned int port = 0; unsigned int client_flag = 0; - static char *kwlist[] = { "host", "user", "passwd", "db", "port", + static char *kwlist[] = { "host", "user", "password", "database", "port", "unix_socket", "conv", "connect_timeout", "compress", "named_pipe", "init_command", diff --git a/MySQLdb/connections.py b/MySQLdb/connections.py index 8e226ffe..38324665 100644 --- a/MySQLdb/connections.py +++ b/MySQLdb/connections.py @@ -62,9 +62,9 @@ def __init__(self, *args, **kwargs): :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 passwd: alias of password (deprecated) :param str database: database to use - :param str db: alias of database, for backward compatibility + :param str db: alias of database (deprecated) :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 @@ -110,6 +110,10 @@ class object, used to create cursors (keyword only) :param int client_flag: flags to use or 0 (see MySQL docs or constants/CLIENTS.py) + :param bool multi_statements: + If True, enable multi statements for clients >= 4.1. + Defaults to True. + :param str ssl_mode: specify the security settings for connection to the server; see the MySQL documentation for more details @@ -144,10 +148,10 @@ class object, used to create cursors (keyword only) kwargs2 = kwargs.copy() - if "database" in kwargs2: - kwargs2["db"] = kwargs2.pop("database") - if "password" in kwargs2: - kwargs2["passwd"] = kwargs2.pop("password") + if "db" in kwargs2: + kwargs2["database"] = kwargs2.pop("db") + if "passwd" in kwargs2: + kwargs2["password"] = kwargs2.pop("passwd") if "conv" in kwargs: conv = kwargs["conv"] @@ -169,14 +173,10 @@ class object, used to create cursors (keyword only) self._binary_prefix = kwargs2.pop("binary_prefix", False) client_flag = kwargs.get("client_flag", 0) - client_version = tuple( - [numeric_part(n) for n in _mysql.get_client_info().split(".")[:2]] - ) - if client_version >= (4, 1): + client_flag |= CLIENT.MULTI_RESULTS + multi_statements = kwargs2.pop("multi_statements", True) + if multi_statements: client_flag |= CLIENT.MULTI_STATEMENTS - if client_version >= (5, 0): - client_flag |= CLIENT.MULTI_RESULTS - kwargs2["client_flag"] = client_flag # PEP-249 requires autocommit to be initially off @@ -186,22 +186,11 @@ class object, used to create cursors (keyword only) self.cursorclass = cursorclass self.encoders = {k: v for k, v in conv.items() if type(k) is not int} - # XXX THIS IS GARBAGE: While this is just a garbage and undocumented, - # Django 1.11 depends on it. And they don't fix it because - # they are in security-only fix mode. - # So keep this garbage for now. This will be removed in 1.5. - # See PyMySQL/mysqlclient-python#306 - self.encoders[bytes] = bytes - self._server_version = tuple( [numeric_part(n) for n in self.get_server_info().split(".")[:2]] ) self.encoding = "ascii" # overridden in set_character_set() - db = proxy(self) - - def unicode_literal(u, dummy=None): - return db.string_literal(u.encode(db.encoding)) if not charset: charset = self.character_set_name() @@ -225,7 +214,13 @@ def unicode_literal(u, dummy=None): # MySQL may return JSON with charset==binary. self.converter[FIELD_TYPE.JSON] = str + db = proxy(self) + + def unicode_literal(u, dummy=None): + return db.string_literal(u.encode(db.encoding)) + self.encoders[str] = unicode_literal + self._transactional = self.server_capabilities & CLIENT.TRANSACTIONS if self._transactional: if autocommit is not None: @@ -298,32 +293,10 @@ def begin(self): """ self.query(b"BEGIN") - if not hasattr(_mysql.connection, "warning_count"): - - def warning_count(self): - """Return the number of warnings generated from the - last query. This is derived from the info() method.""" - info = self.info() - if info: - return int(info.split()[-1]) - else: - return 0 - def set_character_set(self, charset): - """Set 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.""" - py_charset = _charset_to_encoding.get(charset, charset) - if self.character_set_name() != charset: - try: - super().set_character_set(charset) - except AttributeError: - if self._server_version < (4, 1): - raise NotSupportedError("server is too old to set charset") - self.query("SET NAMES %s" % charset) - self.store_result() - self.encoding = py_charset + """Set the connection character set to charset.""" + super().set_character_set(charset) + self.encoding = _charset_to_encoding.get(charset, charset) def set_sql_mode(self, sql_mode): """Set the connection sql_mode. See MySQL documentation for diff --git a/MySQLdb/cursors.py b/MySQLdb/cursors.py index 451dab5f..f8a48640 100644 --- a/MySQLdb/cursors.py +++ b/MySQLdb/cursors.py @@ -375,7 +375,7 @@ def fetchmany(self, size=None): return result def fetchall(self): - """Fetchs all available rows from the cursor.""" + """Fetches all available rows from the cursor.""" self._check_executed() if self.rownumber: result = self._rows[self.rownumber :] @@ -437,7 +437,7 @@ def fetchmany(self, size=None): return r def fetchall(self): - """Fetchs all available rows from the cursor.""" + """Fetches all available rows from the cursor.""" self._check_executed() r = self._fetch_row(0) self.rownumber = self.rownumber + len(r) diff --git a/README.md b/README.md index f65329cf..4dbc54d7 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,10 @@ # mysqlclient -[![Build Status](https://secure.travis-ci.org/PyMySQL/mysqlclient-python.png)](http://travis-ci.org/PyMySQL/mysqlclient-python) +This project is a fork of [MySQLdb1](https://github.com/farcepest/MySQLdb1). +This project adds Python 3 support and fixed many bugs. -This is a fork of [MySQLdb1](https://github.com/farcepest/MySQLdb1). - -This project adds Python 3 support and bug fixes. -I hope this fork is merged back to MySQLdb1 like distribute was merged back to setuptools. +* PyPI: https://pypi.org/project/mysqlclient/ +* GitHub: https://github.com/PyMySQL/mysqlclient ## Support @@ -29,6 +28,22 @@ Or when you have question about MySQL: Building mysqlclient on Windows is very hard. But there are some binary wheels you can install easily. +If binary wheels do not exist for your version of Python, it may be possible to +build from source, but if this does not work, **do not come asking for support.** +To build from source, download the +[MariaDB C Connector](https://mariadb.com/downloads/#connectors) and install +it. It must be installed in the default location +(usually "C:\Program Files\MariaDB\MariaDB Connector C" or +"C:\Program Files (x86)\MariaDB\MariaDB Connector C" for 32-bit). If you +build the connector yourself or install it in a different location, set the +environment variable `MYSQLCLIENT_CONNECTOR` before installing. Once you have +the connector installed and an appropriate version of Visual Studio for your +version of Python: + +``` +$ pip install mysqlclient +``` + ### macOS (Homebrew) Install MySQL and mysqlclient: @@ -83,4 +98,3 @@ $ pip install mysqlclient ### Documentation Documentation is hosted on [Read The Docs](https://mysqlclient.readthedocs.io/) - diff --git a/ci/test_mysql.py b/ci/test_mysql.py index 88a747a6..e285f4cf 100644 --- a/ci/test_mysql.py +++ b/ci/test_mysql.py @@ -16,17 +16,17 @@ "default": { "ENGINE": "django.db.backends.mysql", "NAME": "django_default", - "USER": "django", "HOST": "127.0.0.1", - "PASSWORD": "secret", + "USER": "scott", + "PASSWORD": "tiger", "TEST": {"CHARSET": "utf8mb4", "COLLATION": "utf8mb4_general_ci"}, }, "other": { "ENGINE": "django.db.backends.mysql", "NAME": "django_other", - "USER": "django", "HOST": "127.0.0.1", - "PASSWORD": "secret", + "USER": "scott", + "PASSWORD": "tiger", "TEST": {"CHARSET": "utf8mb4", "COLLATION": "utf8mb4_general_ci"}, }, } diff --git a/MySQLdb/codecov.yml b/codecov.yml similarity index 100% rename from MySQLdb/codecov.yml rename to codecov.yml diff --git a/doc/user_guide.rst b/doc/user_guide.rst index 83b800e8..555adf15 100644 --- a/doc/user_guide.rst +++ b/doc/user_guide.rst @@ -125,19 +125,19 @@ We haven't even begun to touch upon all the parameters ``connect()`` can take. For this reason, I prefer to use keyword parameters:: db=_mysql.connect(host="localhost",user="joebob", - passwd="moonpie",db="thangs") + password="moonpie",database="thangs") This does exactly what the last example did, but is arguably easier to read. But since the default host is "localhost", and if your login name really was "joebob", you could shorten it to this:: - db=_mysql.connect(passwd="moonpie",db="thangs") + db=_mysql.connect(password="moonpie",database="thangs") UNIX sockets and named pipes don't work over a network, so if you specify a host other than localhost, TCP will be used, and you can specify an odd port if you need to (the default port is 3306):: - db=_mysql.connect(host="outhouse",port=3307,passwd="moonpie",db="thangs") + db=_mysql.connect(host="outhouse",port=3307,password="moonpie",database="thangs") If you really had to, you could connect to the local host with TCP by specifying the full host name, or 127.0.0.1. @@ -145,7 +145,7 @@ specifying the full host name, or 127.0.0.1. Generally speaking, putting passwords in your code is not such a good idea:: - db=_mysql.connect(host="outhouse",db="thangs",read_default_file="~/.my.cnf") + db=_mysql.connect(host="outhouse",database="thangs",read_default_file="~/.my.cnf") This does what the previous example does, but gets the username and password and other parameters from ~/.my.cnf (UNIX-like systems). Read @@ -277,10 +277,10 @@ connect(parameters...) user user to authenticate as. Default: current effective user. - passwd + password password to authenticate with. Default: no password. - db + database database to use. Default: no default database. port @@ -511,7 +511,7 @@ callproc(procname, args) can only be returned with a SELECT statement. Since a stored procedure may return zero or more result sets, it is impossible for MySQLdb to determine if there are result sets to fetch - before the modified parmeters are accessible. + before the modified parameters are accessible. The parameters are stored in the server as @_*procname*_*n*, where *n* is the position of the parameter. I.e., if you @@ -561,7 +561,7 @@ Some examples The ``connect()`` method works nearly the same as with `MySQLDB._mysql`_:: import MySQLdb - db=MySQLdb.connect(passwd="moonpie",db="thangs") + db=MySQLdb.connect(password="moonpie",database="thangs") To perform a query, you first need a cursor, and then you can execute queries on it:: diff --git a/metadata.cfg b/metadata.cfg index 2a2e64fa..95433ffb 100644 --- a/metadata.cfg +++ b/metadata.cfg @@ -1,6 +1,6 @@ [metadata] -version: 2.0.3 -version_info: (2,0,3,'final',0) +version: 2.1.0 +version_info: (2,1,0,'final',0) description: Python interface to MySQL author: Inada Naoki author_email: songofacandy@gmail.com @@ -24,6 +24,7 @@ classifiers: Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 + Programming Language :: Python :: 3.10 Topic :: Database Topic :: Database :: Database Engines/Servers py_modules: diff --git a/setup_common.py b/setup_common.py index 28c51829..5b6927ac 100644 --- a/setup_common.py +++ b/setup_common.py @@ -26,7 +26,7 @@ def enabled(options, option): def create_release_file(metadata): - with open("MySQLdb/release.py", "w") as rel: + with open("MySQLdb/release.py", "w", encoding="utf-8") as rel: rel.write( """ __author__ = "%(author)s <%(author_email)s>" diff --git a/setup_posix.py b/setup_posix.py index e556f5c5..99763cbc 100644 --- a/setup_posix.py +++ b/setup_posix.py @@ -128,7 +128,7 @@ def get_config(): if use_mysqlconfig_cflags: # mysql_config may have "-lmysqlclient -lz -lssl -lcrypto", but zlib and # ssl is not used by _mysql. They are needed only for static build. - for L in ("crypto", "ssl", "z"): + for L in ("crypto", "ssl", "z", "zstd"): if L in libraries: libraries.remove(L) diff --git a/setup_windows.py b/setup_windows.py index c25cc52b..b2feb7d2 100644 --- a/setup_windows.py +++ b/setup_windows.py @@ -1,6 +1,5 @@ import os import sys -from distutils.msvccompiler import get_build_version def get_config(): @@ -8,35 +7,34 @@ def get_config(): metadata, options = get_metadata_and_options() - connector = options["connector"] + client = "mariadbclient" + connector = os.environ.get("MYSQLCLIENT_CONNECTOR", options.get("connector")) + if not connector: + connector = os.path.join( + os.environ["ProgramFiles"], "MariaDB", "MariaDB Connector C" + ) extra_objects = [] - # client = "mysqlclient" - client = "mariadbclient" - - vcversion = int(get_build_version()) - if client == "mariadbclient": - library_dirs = [os.path.join(connector, "lib", "mariadb")] - libraries = [ - "kernel32", - "advapi32", - "wsock32", - "shlwapi", - "Ws2_32", - "crypt32", - "secur32", - "bcrypt", - client, - ] - include_dirs = [os.path.join(connector, "include", "mariadb")] - else: - library_dirs = [ - os.path.join(connector, r"lib\vs%d" % vcversion), - os.path.join(connector, "lib"), - ] - libraries = ["kernel32", "advapi32", "wsock32", client] - include_dirs = [os.path.join(connector, r"include")] + library_dirs = [ + os.path.join(connector, "lib", "mariadb"), + os.path.join(connector, "lib"), + ] + libraries = [ + "kernel32", + "advapi32", + "wsock32", + "shlwapi", + "Ws2_32", + "crypt32", + "secur32", + "bcrypt", + client, + ] + include_dirs = [ + os.path.join(connector, "include", "mariadb"), + os.path.join(connector, "include"), + ] extra_link_args = ["/MANIFEST"] diff --git a/site.cfg b/site.cfg index 6b4596a4..08a14b0e 100644 --- a/site.cfg +++ b/site.cfg @@ -9,4 +9,4 @@ static = False # http://stackoverflow.com/questions/1972259/mysql-python-install-problem-using-virtualenv-windows-pip # Windows connector libs for MySQL. You need a 32-bit connector for your 32-bit Python build. -connector = C:\Program Files (x86)\MySQL\MySQL Connector C 6.1 +connector = diff --git a/tests/dbapi20.py b/tests/dbapi20.py index 4824d9cc..4965c9bf 100644 --- a/tests/dbapi20.py +++ b/tests/dbapi20.py @@ -793,7 +793,7 @@ def test_setoutputsize_basic(self): con.close() def test_setoutputsize(self): - # Real test for setoutputsize is driver dependant + # Real test for setoutputsize is driver dependent raise NotImplementedError("Driver need to override this test") def test_None(self): diff --git a/tests/test_MySQLdb_capabilities.py b/tests/test_MySQLdb_capabilities.py index 0b4dd21a..fc213b84 100644 --- a/tests/test_MySQLdb_capabilities.py +++ b/tests/test_MySQLdb_capabilities.py @@ -182,7 +182,7 @@ def test_binary_prefix(self): for binary_prefix in (True, False, None): kwargs = self.connect_kwargs.copy() # needs to be set to can guarantee CHARSET response for normal strings - kwargs["charset"] = "utf8" + kwargs["charset"] = "utf8mb4" if binary_prefix is not None: kwargs["binary_prefix"] = binary_prefix @@ -190,11 +190,11 @@ def test_binary_prefix(self): with closing(conn.cursor()) as c: c.execute("SELECT CHARSET(%s)", (MySQLdb.Binary(b"raw bytes"),)) self.assertEqual( - c.fetchall()[0][0], "binary" if binary_prefix else "utf8" + c.fetchall()[0][0], "binary" if binary_prefix else "utf8mb4" ) # normal strings should not get prefix c.execute("SELECT CHARSET(%s)", ("str",)) - self.assertEqual(c.fetchall()[0][0], "utf8") + self.assertEqual(c.fetchall()[0][0], "utf8mb4") if __name__ == "__main__": diff --git a/tests/test_MySQLdb_times.py b/tests/test_MySQLdb_times.py index 0947f3e5..2081b1ac 100644 --- a/tests/test_MySQLdb_times.py +++ b/tests/test_MySQLdb_times.py @@ -1,11 +1,11 @@ -import mock -import unittest -from time import gmtime from datetime import time, date, datetime, timedelta +from time import gmtime +import unittest +from unittest import mock +import warnings from MySQLdb import times -import warnings warnings.simplefilter("ignore") diff --git a/tests/test_connection.py b/tests/test_connection.py new file mode 100644 index 00000000..960de572 --- /dev/null +++ b/tests/test_connection.py @@ -0,0 +1,26 @@ +import pytest + +from MySQLdb._exceptions import ProgrammingError + +from configdb import connection_factory + + +def test_multi_statements_default_true(): + conn = connection_factory() + cursor = conn.cursor() + + cursor.execute("select 17; select 2") + rows = cursor.fetchall() + assert rows == ((17,),) + + +def test_multi_statements_false(): + conn = connection_factory(multi_statements=False) + cursor = conn.cursor() + + with pytest.raises(ProgrammingError): + cursor.execute("select 17; select 2") + + cursor.execute("select 17") + rows = cursor.fetchall() + assert rows == ((17,),)