Browse Source

Change the MySQL connector and updates the requirements.txt

Yann Weber 9 years ago
parent
commit
7e53eff0b1
2 changed files with 11 additions and 8 deletions
  1. 7
    6
      EditorialModel/migrationhandler/mysql.py
  2. 4
    2
      requirements.txt

+ 7
- 6
EditorialModel/migrationhandler/mysql.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 
2
 
3
 import copy
3
 import copy
4
-import _mysql as mysqlclient
5
-import _mysql_exceptions
4
+import pymysql
6
 
5
 
7
 import EditorialModel
6
 import EditorialModel
8
 
7
 
43
     # @param db str : The db name
42
     # @param db str : The db name
44
     def __init__(self, host, user, password, db, db_engine = 'InnoDB', foreign_keys = True, debug = False, dryrun = False, drop_if_exists = False):
43
     def __init__(self, host, user, password, db, db_engine = 'InnoDB', foreign_keys = True, debug = False, dryrun = False, drop_if_exists = False):
45
         #Connect to MySQL
44
         #Connect to MySQL
46
-        self.db = mysqlclient.connect(host=host, user=user, passwd=password, db=db)
45
+        self.db = pymysql.connect(host=host, user=user, passwd=password, db=db)
47
         self.debug = debug
46
         self.debug = debug
48
         self.dryrun = dryrun
47
         self.dryrun = dryrun
49
         self.db_engine = db_engine
48
         self.db_engine = db_engine
93
         if self.debug:
92
         if self.debug:
94
             print(query+"\n")
93
             print(query+"\n")
95
         if not self.dryrun:
94
         if not self.dryrun:
96
-            self.db.query(query)
95
+            with self.db.cursor() as cur:
96
+                cur.execute(query)
97
+        self.db.commit() #autocommit
97
     
98
     
98
     ## @brief Add a relationnal field
99
     ## @brief Add a relationnal field
99
     #
100
     #
326
         )
327
         )
327
         try:
328
         try:
328
             self._query(add_col)
329
             self._query(add_col)
329
-        except _mysql_exceptions.OperationalError as e:
330
+        except pymysql.err.InternalError as e:
330
             if drop_if_exists:
331
             if drop_if_exists:
331
                 self._del_column(table_name, col_name)
332
                 self._del_column(table_name, col_name)
332
                 self._add_column(table_name, col_name, col_fieldtype, drop_if_exists)
333
                 self._add_column(table_name, col_name, col_fieldtype, drop_if_exists)
370
                 src_table = self._idname_escape(src_table_name),
371
                 src_table = self._idname_escape(src_table_name),
371
                 fk_name = self._idname_escape(self._fk_name(src_table_name, dst_table_name))
372
                 fk_name = self._idname_escape(self._fk_name(src_table_name, dst_table_name))
372
             ))
373
             ))
373
-        except _mysql_exceptions.OperationalError: pass
374
+        except pymysql.err.InternalError: pass
374
     
375
     
375
     def _fk_name(self, src_table_name, dst_table_name):
376
     def _fk_name(self, src_table_name, dst_table_name):
376
         return "fk_%s_%s"%(src_table_name, dst_table_name)
377
         return "fk_%s_%s"%(src_table_name, dst_table_name)

+ 4
- 2
requirements.txt View File

1
-mysqlclient
2
-mosql==0.11
1
+PyMySQL==0.6.7
2
+mosql==0.11
3
+pep8==1.6.2
4
+pylint==1.4.4

Loading…
Cancel
Save