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
         },
11
         },
12
         'mysql': {
12
         'mysql': {
13
             # TODO à définir
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
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 
2
 
3
 from sqlalchemy import * # TODO ajuster les classes à importer
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
 from django.conf import settings
5
 from django.conf import settings
6
 import re
6
 import re
7
 
7
 
33
         driver = sqlsettings.dbms_list[dialect]['driver']
33
         driver = sqlsettings.dbms_list[dialect]['driver']
34
         username = connection_params['USER']
34
         username = connection_params['USER']
35
         password = connection_params['PASSWORD']
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
         host = hostname if port=='' else '%s:%s' % (hostname, port)
38
         host = hostname if port=='' else '%s:%s' % (hostname, port)
39
         database = connection_params['NAME']
39
         database = connection_params['NAME']
40
 
40
 
41
         connection_string = '%s+%s://%s:%s@%s/%s' % (dialect, driver, username, password, host, database)
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
         return engine
43
         return engine
44
 
44
 
45
     def get_read_engine(self):
45
     def get_read_engine(self):
130
         elif column_type=='BOOLEAN':
130
         elif column_type=='BOOLEAN':
131
             column = Column(column_name, BOOLEAN)
131
             column = Column(column_name, BOOLEAN)
132
 
132
 
133
-        if column and column_extra:
133
+        if column is not None and column_extra:
134
             if 'nullable' in column_extra:
134
             if 'nullable' in column_extra:
135
                 column.nullable = column_extra['nullable']
135
                 column.nullable = column_extra['nullable']
136
             if 'primarykey' in column_extra:
136
             if 'primarykey' in column_extra:

+ 1
- 0
requirements.txt View File

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

Loading…
Cancel
Save