Skip to content

Commit

Permalink
Item13803: Merge branch 'master' into Item13803
Browse files Browse the repository at this point in the history
  • Loading branch information
vrurg committed Oct 27, 2015
2 parents 3f70c53 + cb28aff commit 9adc43b
Show file tree
Hide file tree
Showing 5 changed files with 236 additions and 262 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -5,3 +5,4 @@ DBIQueryPlugin.txt
DBIQueryPlugin.zip
DBIQueryPlugin_installer
DBIQueryPlugin_installer.pl
test/unit/DBIQueryPlugin/testlogs/
18 changes: 9 additions & 9 deletions data/System/DBIQueryPlugin.txt
@@ -1,14 +1,14 @@
%META:TOPICINFO{author="VadimBelman" comment="" date="1443825457" format="1.1" reprev="2" version="2"}%
%META:TOPICPARENT{name="Plugins"}%
---+!! Empty Plugin
---+!! DBIQueryPlugin

%SHORTDESCRIPTION%

%TOC%

---++ Overview

This plugin is intended to provide Foswiki with ability to make complex database requests using DBI Perl module.
This plugin is intended to provide %WIKITOOLNAME% with ability to make complex database requests using DBI Perl module.

%X% Any help with this documentation is very much welcome as it's really pretty far from being ideal. Thanks a lot!

Expand Down Expand Up @@ -67,10 +67,10 @@ possible?
With this view in mind we come to the following procedure:

1. Every query definition within topic is parsed and stored for further processing. This is done in two major steps:
1. Query statement is exctracted from the definition.
1. Query statement is extracted from the definition.
1. Every newline within =.header=, =.body=, and =.footer= gets changed with space except for the last ones. They're removed. Whereas newline is needed =\n= escape sequence must be used. Consequently, =\\n= is translated into =\n=.
1. All queries are processed except for those declared as subqueries:
1. =.header= filter is expanded with [[#VariableExpansion][variable expansion]] mechanizm and put into the output.
1. =.header= filter is expanded with [[#VariableExpansion][variable expansion]] mechanism and put into the output.
1. The query statement is expanded using !DBIQueryPlugin and %WIKITOOLNAME% variable expansion mechanisms in the order they are mentioned here.
1. Database is queried and data is fetched row-by-row. Each row data get [[#ValueQuoting][quoted]] and then used for setting !DBIQueryPlugin variables. =.body= filter is expanded using these values.
1. =.footer= filter is expanded with !DBIQueryPlugin mechanism and put into the output.
Expand Down Expand Up @@ -100,7 +100,7 @@ would provide us with variables =%name%=, =%personalid%=, =%someotherinfo%=.

There are some special cases like !MySQL's =SHOW CREATE PROCEDURE= where
column names may contain spaces within them. These spaces are changed with
undersocre sign making it possible to refer to them as to database columns.
underscore sign making it possible to refer to them as to database columns.
I.e. 'Create Procedure' field may be referred as =%<nop>create_procedure%=.

The second step is [[#ProcSubqueries][subquery processing]].
Expand Down Expand Up @@ -359,21 +359,21 @@ effects.

The biggest compromise was usage of Perl inlines for =%<nop>DBI_DO%=. The
first approach was to make it working much like =%<nop>DBI_QUERY%=, using
sections of declarations. But the more quiestions like:
sections of declarations. But the more questions like:

* how to check data consistency?
* how to validate data?
* how to generate error messages?

and several others of the kind was arising, the more final structure was
And several others of the kind was arising, the more final structure was
looking like a new language. So, why developing a new one when Perl is out
there? But then again, as it was mentioned before, this way is not
secure-enough and an administrator must take serious considerations before
allowing usage of =%<nop>DBI_DO%= to a user.

The other issue is about plugin execution order. As one can see from
!MessageBoard example, attached to this topic, usage of other plugins could
significally improve control over !DBIQueryPlugin output. However, it is
significantly improve control over !DBIQueryPlugin output. However, it is
not guaranteed that another plugin would not be called in first place
causing unpredictable results like unwanted changes in a Perl script.

Expand Down Expand Up @@ -408,7 +408,7 @@ Databases available to end user have to be preconfigured with
[[DatabaseContrib#DatabaseConfig][DatabaseConfig database configuration]]
using %WIKITOOLNAME% configure script.

Additionally the following coniguration keys of ={Plugins}{DBIQueryPlugin}= configuration section are available:
Additionally the following configuration keys of ={Plugins}{DBIQueryPlugin}= configuration section are available:

|*Configuration Key* | *Default value*|*Description*|
|*Debug* | =false=|Generate additional debug output|
Expand Down
16 changes: 8 additions & 8 deletions lib/Foswiki/Plugins/DBIQueryPlugin.pm
Expand Up @@ -29,7 +29,7 @@ use Foswiki::Contrib::DatabaseContrib;
# v1.2.1_001 -> v1.2.2 -> v1.2.2_001 -> v1.2.3
# 1.21_001 -> 1.22 -> 1.22_001 -> 1.23
#
use version; our $VERSION = version->parse('1.06_002');
use version; our $VERSION = version->parse('1.06.1_001');

# $RELEASE is used in the "Find More Extensions" automation in configure.
# It is a manually maintained string used to identify functionality steps.
Expand All @@ -44,7 +44,7 @@ use version; our $VERSION = version->parse('1.06_002');
# It is preferred to keep this compatible with $VERSION. At some future
# date, Foswiki will deprecate RELEASE and use the VERSION string.
#
our $RELEASE = '1.06_002';
our $RELEASE = '1.06.1_001';

# One line description of the module
our $SHORTDESCRIPTION =
Expand Down Expand Up @@ -483,7 +483,7 @@ sub doQuery {

dprint "doQuery()\n";

return wikiErrMsg("No access to modify $conname DB at $web.$topic.")
return wikiErrMsg("No access to modify $conname DB at $baseweb.$basetopic.")
unless $dbc->access_allowed( $conname, "$baseweb.$basetopic",
'allow_do' );

Expand All @@ -499,7 +499,7 @@ sub doQuery {
my $request = Foswiki::Func::getRequestObject();
dprint( "REQUEST ACTIONS: ", $request->action, " thru ", $request->method );
dprint( "REQUEST PARAMETERS: {", join( "}{", $request->param ), "}\n" );
dprint("REQUEST TOPC: $web.$topic\n");
dprint("REQUEST TOPC: $baseweb.$basetopic\n");
my $sub_code = <<EOC;
sub {
my (\$dbc, \$request, \$varParams, \$dbRecord) = \@_;
Expand All @@ -508,7 +508,7 @@ sub {
my \%httpParams;
foreach my \$cgiParam (\@cgiParams) {
dprint("QUERYING CGI parameter \$cgiParam");
my \@val = \$request->param(\$cgiParam);
my \@val = \$request->multi_param(\$cgiParam);
\$httpParams{\$cgiParam} = (\$multivalued{\$cgiParam} || (\@val > 1)) ? \\\@val : \$val[0];
}
dprint( "doQuery code for $web.$topic\n" );
Expand Down Expand Up @@ -577,9 +577,6 @@ sub handleQueries {
sub processPage {
state $level = 0;

$baseweb = Foswiki::Func::getPreferencesValue('BASEWEB');
$basetopic = Foswiki::Func::getPreferencesValue('BASETOPIC');

$level++;
dprint "### $level\n\n";

Expand Down Expand Up @@ -662,6 +659,9 @@ sub initPlugin {
acl_inheritance => { allow_query => 'allow_do', }, )
|| return 0;

$baseweb = $web;
$basetopic = $topic;

# Example code of how to get a preference value, register a macro
# handler and register a RESTHandler (remove code you do not need)

Expand Down

0 comments on commit 9adc43b

Please sign in to comment.