|
15 | 15 | class SessionFactory(): |
16 | 16 | def __init__(self, connection_string, echo, version = 1.1): |
17 | 17 | if 'sqlite' in connection_string: |
18 | | - from pysqlite2 import dbapi2 as sqlite |
19 | | - self.engine = create_engine(connection_string, module = sqlite, encoding='utf-8', echo=echo) |
20 | 18 |
|
21 | | - @event.listens_for(self.engine, "connect") |
22 | | - def connect(dbapi_connection, connection_rec): |
23 | | - dbapi_connection.enable_load_extension(True) |
24 | | - dbapi_connection.execute("SELECT load_extension('{0}');".format("mod_spatialite")) |
| 19 | + #from pysqlite2 import dbapi2 as sqlite |
| 20 | + #import pyspatialite.dpabi as sqlite |
| 21 | + # self.engine = create_engine(connection_string, model = sqlite ,encoding='utf-8', echo=echo) |
25 | 22 |
|
26 | | - self.engine.execute("SELECT InitSpatialMetaData();")#("SELECT load_extension('mod_spatialite');")# |
| 23 | + # @event.listens_for(self.engine, "connect") |
| 24 | + # def connect(dbapi_connection, connection_rec): |
| 25 | + # dbapi_connection.enable_load_extension(True) |
| 26 | + # dbapi_connection.execute("SELECT load_extension('{0}');".format("mod_spatialite")) |
| 27 | + |
| 28 | + # self.engine.execute("SELECT InitSpatialMetaData();")# |
| 29 | + # self.engine.connect().connection.enable_load_extension(True) |
| 30 | + # self.engine.execute("SELECT load_extension('mod_spatialite');")# |
| 31 | + self.engine = create_engine(connection_string, encoding='utf-8', echo=echo) |
27 | 32 | self.test_engine = self.engine |
28 | 33 |
|
| 34 | + # engine = create_engine(...) |
| 35 | + # conn = engine.connect() |
| 36 | + # conn.connection.<do DBAPI things> |
| 37 | + # cursor = conn.connection.cursor(<DBAPI specific arguments..>) |
| 38 | + |
29 | 39 | elif 'mssql' in connection_string: |
30 | 40 | self.engine = create_engine(connection_string, encoding='utf-8', echo=echo, pool_recycle=3600) |
31 | 41 | self.test_engine = create_engine(connection_string, encoding='utf-8', echo=echo, pool_recycle=3600, connect_args={'timeout': 1}) |
@@ -57,14 +67,17 @@ def createConnection(self, engine, address, db=None, user=None, password=None, d |
57 | 67 |
|
58 | 68 | if engine == 'sqlite': |
59 | 69 | connection_string = engine +':///'+address |
| 70 | + return SessionFactory(connection_string, echo = False, version= dbtype) |
| 71 | + |
60 | 72 | else: |
61 | 73 | connection_string = dbconnection.buildConnDict(dbconnection(), engine, address, db, user, password) |
| 74 | + if self.isValidConnection(connection_string, dbtype): |
| 75 | + return SessionFactory(connection_string, echo = False, version= dbtype) |
| 76 | + else : |
| 77 | + return None |
62 | 78 | # if self.testConnection(connection_string): |
63 | 79 |
|
64 | | - if self.isValidConnection(connection_string, dbtype): |
65 | | - return SessionFactory(connection_string, echo = False, version= dbtype) |
66 | | - else : |
67 | | - return None |
| 80 | + |
68 | 81 |
|
69 | 82 | @classmethod |
70 | 83 | def isValidConnection(self, connection_string, dbtype=2.0): |
|
0 commit comments