Browse Source

connection à une base de donnée

ArnAud 9 years ago
parent
commit
3e80b68303
3 changed files with 8 additions and 7 deletions
  1. 2
    2
      Database/sqlsettings.py
  2. 5
    5
      Database/sqlwrapper.py
  3. 1
    0
      requirements.txt

+ 2
- 2
Database/sqlsettings.py View File

@@ -11,8 +11,8 @@ class SQLSettings(object):
11 11
         },
12 12
         'mysql': {
13 13
             # TODO à définir
14
-            'driver': '',
15
-            'encoding': '',
14
+            'driver': 'pymysql',
15
+            'encoding': 'utf8',
16 16
         }
17 17
     }
18 18
 

+ 5
- 5
Database/sqlwrapper.py View File

@@ -1,7 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 
3 3
 from sqlalchemy import * # TODO ajuster les classes à importer
4
-from sql_settings import SqlSettings as sqlsettings
4
+from Database.sqlsettings import SQLSettings as sqlsettings
5 5
 from django.conf import settings
6 6
 import re
7 7
 
@@ -33,13 +33,13 @@ class SqlWrapper(object):
33 33
         driver = sqlsettings.dbms_list[dialect]['driver']
34 34
         username = connection_params['USER']
35 35
         password = connection_params['PASSWORD']
36
-        hostname = connection_params['HOST'] if connection_params['HOST']!='' else sqlsettings.DEFAULT_HOSTNAME
37
-        port = connection_params['PORT']
36
+        hostname = connection_params['HOST'] if 'HOST' in connection_params else sqlsettings.DEFAULT_HOSTNAME
37
+        port = connection_params['PORT'] if 'PORT' in connection_params else ''
38 38
         host = hostname if port=='' else '%s:%s' % (hostname, port)
39 39
         database = connection_params['NAME']
40 40
 
41 41
         connection_string = '%s+%s://%s:%s@%s/%s' % (dialect, driver, username, password, host, database)
42
-        engine = create_engine(connection_string, encoding=sqlsettings.dbms_list[dialect]['encoding'], echo=True, poolclass=NullPool)
42
+        engine = create_engine(connection_string, encoding=sqlsettings.dbms_list[dialect]['encoding'], echo=True)
43 43
         return engine
44 44
 
45 45
     def get_read_engine(self):
@@ -130,7 +130,7 @@ class SqlWrapper(object):
130 130
         elif column_type=='BOOLEAN':
131 131
             column = Column(column_name, BOOLEAN)
132 132
 
133
-        if column and column_extra:
133
+        if column is not None and column_extra:
134 134
             if 'nullable' in column_extra:
135 135
                 column.nullable = column_extra['nullable']
136 136
             if 'primarykey' in column_extra:

+ 1
- 0
requirements.txt View File

@@ -1,3 +1,4 @@
1 1
 Django==1.7.8
2 2
 psycopg2==2.6
3 3
 SQLAlchemy==1.0.4
4
+PyMySQL==0.6.6

Loading…
Cancel
Save