Skip to content

Commit aadcc5b

Browse files
author
Stephanie Reeder
committed
add support for in memory sqlite db
1 parent 7e424ca commit aadcc5b

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/Examples/Sample.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
#connect to database
2323
#createconnection (dbtype, servername, dbname, username, password)
24-
session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')
24+
#session_factory = dbconnection.createConnection('mysql', 'localhost', 'odm2', 'ODM', 'odm')
25+
session_factory = dbconnection.createConnection('sqlite', '/Users/stephanie/DEV/DBs/ODM2.sqlite', 2.0)
2526
# session_factory= dbconnection.createConnection('mssql')
2627

2728

src/api/ODMconnection.py

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,27 @@
1515
class SessionFactory():
1616
def __init__(self, connection_string, echo, version = 1.1):
1717
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)
2018

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)
2522

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)
2732
self.test_engine = self.engine
2833

34+
# engine = create_engine(...)
35+
# conn = engine.connect()
36+
# conn.connection.<do DBAPI things>
37+
# cursor = conn.connection.cursor(<DBAPI specific arguments..>)
38+
2939
elif 'mssql' in connection_string:
3040
self.engine = create_engine(connection_string, encoding='utf-8', echo=echo, pool_recycle=3600)
3141
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
5767

5868
if engine == 'sqlite':
5969
connection_string = engine +':///'+address
70+
return SessionFactory(connection_string, echo = False, version= dbtype)
71+
6072
else:
6173
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
6278
# if self.testConnection(connection_string):
6379

64-
if self.isValidConnection(connection_string, dbtype):
65-
return SessionFactory(connection_string, echo = False, version= dbtype)
66-
else :
67-
return None
80+
6881

6982
@classmethod
7083
def isValidConnection(self, connection_string, dbtype=2.0):

0 commit comments

Comments
 (0)