Commit 3d7c113a authored by Jim Fulton's avatar Jim Fulton

Improved connection status management and added database close method.

parent d67041a7
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
__doc__='''Generic Database adapter __doc__='''Generic Database adapter
$Id: DA.py,v 1.4 1997/08/06 18:19:29 jim Exp $''' $Id: DA.py,v 1.5 1997/08/08 22:55:32 jim Exp $'''
__version__='$Revision: 1.4 $'[11:-2] __version__='$Revision: 1.5 $'[11:-2]
import string, OFS.Folder, Aqueduct.Aqueduct, Aqueduct.RDB import string, OFS.Folder, Aqueduct.Aqueduct, Aqueduct.RDB
import DocumentTemplate, marshal, md5, zlib, base64, DateTime, Acquisition import DocumentTemplate, marshal, md5, zlib, base64, DateTime, Acquisition
...@@ -38,19 +38,33 @@ class Folder(OFS.Folder.Folder): ...@@ -38,19 +38,33 @@ class Folder(OFS.Folder.Folder):
manage_connectionForm=ManageHTMLFile('AqueductDA/connection') manage_connectionForm=ManageHTMLFile('AqueductDA/connection')
manage_addDAForm=ManageHTMLFile('AqueductDA/daAdd') manage_addDAForm=ManageHTMLFile('AqueductDA/daAdd')
start_time=DateTime.now() start_time=DateTime.now()
bad_connection_string=(
"""<p><strong>Warning</strong>: The database is not connected.<p>
""")
def manage_connection(self,value=None,check=None,REQUEST=None): def manage_connection(self,value=None,check=None,REQUEST=None):
'change database connection data' 'change database connection data'
if value is None: return self.database_connection_string() if value is None: return self.database_connection_string()
if check: self.database_connect(value) if check: self.database_connect(value)
else: self.manage_close_connection(REQUEST)
self.database_connection_string(value) self.database_connection_string(value)
return self.manage_main(self,REQUEST) return self.manage_main(self,REQUEST)
def manage_close_connection(self, REQUEST):
" "
try: self._v_database_connection.close()
except: pass
self.bad_connection_string=(
"""<p><strong>Warning</strong>: The database is not connected.<p>
""")
return self.manage_main(self,REQUEST)
def database_connect(self,s=''): def database_connect(self,s=''):
try: self._v_database_connection.close() try: self._v_database_connection.close()
except: pass except: pass
self.bad_connection_string=( self.bad_connection_string=(
"""<strong>Warning</strong>: The database is not connected. """<p><strong>Warning</strong>: The database is not connected.<p>
""") """)
if not s: s=self.folder_database_connection_string() if not s: s=self.folder_database_connection_string()
if not s: return if not s: return
...@@ -155,10 +169,12 @@ class Query(Aqueduct.Aqueduct.BaseQuery,Persistent,Acquisition.Implicit): ...@@ -155,10 +169,12 @@ class Query(Aqueduct.Aqueduct.BaseQuery,Persistent,Acquisition.Implicit):
) )
def query(self,DB__,REQUEST,RESPONSE): def query(self,REQUEST,RESPONSE):
' ' ' '
if DB__ is None: raise 'Database Error', ( try: DB__=self.database_connection()
'No database connection defined') except: raise 'Database Error', (
'%s is not connected to a database' % self.id)
try: try:
argdata=REQUEST.form.value argdata=REQUEST.form.value
argdata=decodestring(argdata) argdata=decodestring(argdata)
...@@ -197,6 +213,9 @@ class Query(Aqueduct.Aqueduct.BaseQuery,Persistent,Acquisition.Implicit): ...@@ -197,6 +213,9 @@ class Query(Aqueduct.Aqueduct.BaseQuery,Persistent,Acquisition.Implicit):
############################################################################## ##############################################################################
# #
# $Log: DA.py,v $ # $Log: DA.py,v $
# Revision 1.5 1997/08/08 22:55:32 jim
# Improved connection status management and added database close method.
#
# Revision 1.4 1997/08/06 18:19:29 jim # Revision 1.4 1997/08/06 18:19:29 jim
# Renamed description->title and name->id and other changes # Renamed description->title and name->id and other changes
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment