Commit 83a58eff authored by Jeffrey Shell's avatar Jeffrey Shell

Added new test-tab-feature on database connection objects

parent 2d5ab3c7
##############################################################################
7##############################################################################
#
# Zope Public License (ZPL) Version 1.0
# -------------------------------------
......@@ -84,8 +84,8 @@
##############################################################################
__doc__='''Shared classes and functions
$Id: Aqueduct.py,v 1.36 1999/07/21 19:43:39 michel Exp $'''
__version__='$Revision: 1.36 $'[11:-2]
$Id: Aqueduct.py,v 1.37 1999/09/21 15:43:18 jeffrey Exp $'''
__version__='$Revision: 1.37 $'[11:-2]
import Globals, os
from Globals import HTMLFile, Persistent
......@@ -289,8 +289,8 @@ def custom_default_report(id, result, action='', no_table=0,
row=[]
for c in columns:
n=c['name']
if goofy(n) >= 0: n='expr="_vars[\'%s]"' % (`'"'+n`[2:])
row.append(' %s<!--#var %s%s-->%s'
if goofy(n) >= 0: n='expr="_[\'%s]"' % (`'"'+n`[2:])
row.append(' %s<dtml-var %s%s>%s'
% (td,n,c['type']!='s' and ' null=""' or '',_td))
row=(' %s\n%s\n %s' % (tr,string.joinfields(row,delim), _tr))
......
......@@ -85,14 +85,17 @@
__doc__='''Generic Database Connection Support
$Id: Connection.py,v 1.18 1999/03/25 16:07:28 jim Exp $'''
__version__='$Revision: 1.18 $'[11:-2]
$Id: Connection.py,v 1.19 1999/09/21 15:43:18 jeffrey Exp $'''
__version__='$Revision: 1.19 $'[11:-2]
import Globals, OFS.SimpleItem, AccessControl.Role, Acquisition, sys
from DateTime import DateTime
from App.Dialogs import MessageDialog
from Globals import HTMLFile
from string import find, join, split
from Aqueduct import custom_default_report
from Results import Results
import DocumentTemplate
class Connection(
Globals.Persistent,
......@@ -105,6 +108,7 @@ class Connection(
manage_options=(
{'label':'Status', 'action':'manage_main'},
{'label':'Properties', 'action':'manage_properties'},
{'label':'Test', 'action':'manage_testForm'},
{'label':'Security', 'action':'manage_access'},
)
......@@ -112,6 +116,7 @@ class Connection(
__ac_permissions__=(
('View management screens', ('manage_main',)),
('Change Database Connections', ('manage_edit',)),
('Test Database Connections', ('manage_testForm','manage_test')),
('Open/Close Database Connection',
('manage_open_connection', 'manage_close_connection')),
)
......@@ -164,6 +169,31 @@ class Connection(
action ='./manage_main',
)
manage_testForm=HTMLFile('connectionTestForm', globals())
def manage_test(self, query, REQUEST=None):
"Executes the SQL in parameter 'query' and returns results"
dbc=self() #get our connection
res=dbc.query(query)
result=Results(res)
if REQUEST is None:
return result #return unadulterated result objects
if result._searchable_result_columns():
r=custom_default_report(self.id, result)
else:
r='This was not a query.'
report=DocumentTemplate.HTML(
'<html><body bgcolor="#ffffff" link="#000099" vlink="#555555">\n'
'<dtml-var name="manage_tabs">\n<hr>\n%s\n\n'
'<hr><h4>SQL Used:</strong><br>\n<pre>\n%s\n</pre>\n<hr>\n'
'</body></html>'
% (r, query))
report=apply(report,(self,REQUEST),{self.id:result})
return report
manage_main=HTMLFile('connectionStatus', globals())
......
<html>
<head><title>Test &dtml-title_or_id;</title></head>
<body bgcolor="#FFFFFF" link="#000099" vlink="#555555" alink="#77003B">
<dtml-var manage_tabs>
<h2>Test query on <dtml-var title_or_id></h2>
<form action="manage_test" method="post">
<table border="0">
<tr valign="top">
<th align="left">Query:</th>
<td><textarea rows="10" cols="60" name="query:text" wrap="off" accesskey="e" tabindex="1"></textarea></td>
</tr>
<tr>
<th align="left">&nbsp;</th>
<td><input type="submit" value="Submit Query"></td>
</tr>
</table>
</form>
</body>
</html>
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