Skip to content

Commit 04f9887

Browse files
committed
🚑 Fix #46
1 parent 7933855 commit 04f9887

File tree

5 files changed

+34
-9
lines changed

5 files changed

+34
-9
lines changed

requirements_dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ pytest-timeout
1515
pytimeparse>=1.1.8
1616
simplejson>=3.16.0
1717
six>=1.12.0
18-
sqlalchemy>=1.3.7,<1.4.0
18+
sqlalchemy>=1.3.7,<1.4.0 ; python_version<"3.0"
19+
sqlalchemy>=1.3.7 ; python_version>="3.0"
1920
sqlalchemy-utils==0.36.6 ; python_version<"3.0"
2021
sqlalchemy-utils>=0.36.6 ; python_version>="3.0"
2122
tox

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[flake8]
2-
ignore = D203,D401,W503,E203,F401,F403
2+
ignore = I100,I201,I202,D203,D401,W503,E203,F401,F403,C901,E501
33
exclude = tests
44
max-line-length = 88
55

sqlite3_to_mysql/mysql_utils.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
"DECIMAL",
2020
"DOUBLE",
2121
"ENUM",
22-
"DECIMAL",
2322
"FLOAT",
2423
"INTEGER",
25-
"INTEGER",
2624
"JSON",
2725
"LONGBLOB",
2826
"LONGTEXT",

sqlite3_to_mysql/transporter.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@
1414

1515
import mysql.connector
1616
import six
17-
from mysql.connector import CharacterSet, errorcode
17+
from mysql.connector import (
18+
CharacterSet,
19+
__version__ as mysql_connector_version_string,
20+
errorcode,
21+
)
22+
from packaging import version
1823
from tqdm import tqdm, trange
1924

2025
from sqlite3_to_mysql.sqlite_utils import (
@@ -26,7 +31,6 @@
2631
convert_timedelta,
2732
unicase_compare,
2833
)
29-
3034
from .mysql_utils import (
3135
MYSQL_BLOB_COLUMN_TYPES,
3236
MYSQL_COLUMN_TYPES,
@@ -151,6 +155,9 @@ def __init__(self, **kwargs):
151155

152156
self._sqlite_cur = self._sqlite.cursor()
153157

158+
self._connect()
159+
160+
def _connect(self, retried_mysql_57=False):
154161
try:
155162
self._mysql = mysql.connector.connect(
156163
user=self._mysql_user,
@@ -184,6 +191,23 @@ def __init__(self, **kwargs):
184191
raise ValueError(
185192
"Your MySQL version does not support InnoDB FULLTEXT indexes!"
186193
)
194+
except mysql.connector.ProgrammingError as err:
195+
if not retried_mysql_57:
196+
# Looks like we're dealing with mysql-connector-python >= 8.0.30 and MySQL 5.7 or MariaDB
197+
# https://github.com/techouse/sqlite3-to-mysql/issues/46
198+
# https://dev.mysql.com/doc/relnotes/connector-python/en/news-8-0-30.html
199+
mysql_connector_version = version.parse(mysql_connector_version_string)
200+
if (
201+
mysql_connector_version.major >= 8
202+
and mysql_connector_version.micro >= 30
203+
):
204+
self._logger.warning(
205+
"Looks like you're using mysql-connector-python >= 8.0.30 with an older version of MySQL."
206+
)
207+
CharacterSet.set_mysql_version((5, 7))
208+
return self._connect(retried_mysql_57=True)
209+
self._logger.error(err)
210+
raise
187211
except mysql.connector.Error as err:
188212
self._logger.error(err)
189213
raise
@@ -243,7 +267,7 @@ def _create_database(self):
243267
self._mysql_cur.close()
244268
self._mysql.commit()
245269
self._mysql.database = self._mysql_database
246-
self._mysql_cur = self._mysql.cursor(prepared=True)
270+
self._mysql_cur = self._mysql.cursor(prepared=True) # pylint: disable=W0201
247271
except mysql.connector.Error as err:
248272
self._logger.error(
249273
"MySQL failed creating databse %s: %s",

tox.ini

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ skip_install = true
5858
deps =
5959
pylint
6060
-rrequirements_dev.txt
61-
disable = C0209,C0301,C0411,R,W0107,W0622
6261
commands =
6362
pylint --rcfile=tox.ini sqlite3_to_mysql
6463

@@ -101,4 +100,7 @@ exclude =
101100
max-complexity = 10
102101
max-line-length = 88
103102
import-order-style = pycharm
104-
application-import-names = flake8
103+
application-import-names = flake8
104+
105+
[pylint]
106+
disable = C0209,C0301,C0411,R,W0107,W0622

0 commit comments

Comments
 (0)