Skip to content

Commit

Permalink
Item9808: further refinements to the personality modules, and fixed t…
Browse files Browse the repository at this point in the history
…he ref operator. All but regexp escapes now working correctly on all DBs.

git-svn-id: http://svn.foswiki.org/trunk/DBIStoreContrib@17276 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
CrawfordCurrie authored and CrawfordCurrie committed Feb 11, 2014
1 parent 6b7da34 commit d6eca6a
Show file tree
Hide file tree
Showing 13 changed files with 352 additions and 172 deletions.
13 changes: 13 additions & 0 deletions data/System/DBIStoreContrib.txt
Expand Up @@ -110,6 +110,19 @@ Integer indexes are not supported. Use queries instead.
* Select Foswiki::Store::QueryAlgorithms::DBIStoreContrib for the ={Store}{QueryAlgorithm}= configuration setting
* enable the integrated =DBIStorePlugin=

---+++ Testing

Basic tests for queries can be found in the DBIStoreTest topic.

---+++ Reloading the database

Should it become necessary to reload the DBI database - for example, because
changes to topics have been made outside of Foswiki - then you can click on the following link to re-load the database. *WARNING* on a large site this may take a very long time. You may have to run it from the command-line,
using a command like this:
<verbatim>
./view topic=System.DBIStoreTest skin=text dbistore_reset=1
</verbatim>

---+++ !MySQL Notes
The !MySQL database user needs at least the following privileges:
SELECT, INSERT, CREATE, and DROP.
Expand Down
54 changes: 54 additions & 0 deletions data/System/DBIStoreTest.txt
@@ -0,0 +1,54 @@
<!--
<verbatim>
* Set SOP = topic="DBIStoreTest*" nonoise="on" format="" footer="$ntopics" separator=""
* Set QOP = type="query" %SOP%
* Set TA = %IF{"
* Set TB = =0%SEARCH{
* Set TC = %QOP%}%" then="OK" else=" $percntRED$percnt *FAIL* $percntENDCOLOR$percnt "}%
</verbatim>
-->
This topic is used for testing the DBIStoreContrib.
Note that this topic, and the DBIStoreTestForm topic,
have to be present in the database cache for the tests to work.

To reset the cache, click on %SCRIPTURL{"view"}%/%WEB%/%WOPIC%?dbistore_init=1 (slow)

<!-- TA number of hist TB search query TC -->
* Non-query: %IF{"2=0%SEARCH{"1" %SOP%}%" then="OK" else="$percntRED$percnt *FAIL* $percntENDCOLOR$percnt"}%
* False: %TA% 0 %TB% "0" %TC%
* True: %TA% 2 %TB% "1" %TC%
* Table.selector: %TA% 2 %TB% "form.name='DBIStoreTestForm' AND length('x')=1" %TC%
* Array: %TA% 1 %TB% "fields[name='string'].value='String'" %TC%
* Field: %TA% 2 %TB% "number" %TC%
* Boolean field: %TA% 0 %TB% "boolean" %TC%
* Field cmp: %TA% 1 %TB% "number=99" %TC%
* Simple regex: %TA% 2 %TB% "'AA'=~'A'" %TC%
* Simple LIKE: %TA% 1 %TB% "name~'DBIStoreT*orm'" %TC%
* Simple AND: %TA% 1 %TB% "number=99 AND string='String'" %TC%
* Simple OR: %TA% 1 %TB% "number=99 OR string='String'" %TC%
* Const-table cmp: %TA% 1 %TB% "666=fields[name='number'].value" %TC%
* Table-const cmp: %TA% 1 %TB% "fields[name='number'].value=666" %TC%
* Simple ref true: %TA% 2 %TB% "'DBIStoreTestForm'/number=666" %TC%
* Simple ref false: %TA% 0 %TB% "'DBIStoreTest'/number=666" %TC%
* Complex re: %TA% 1 %TB% "fields[name="string" AND value=~'^St.(i|n).*'].name!=''" %TC%
* Constant op field: %TA% 1 %TB% "fields[99=value].name" %TC%
* Complex conjunction: %TA% 2 %TB% "number=99 OR ( string='test' AND not boolean )" %TC%
* name=undefined: %TA% 0 %TB% "name=undefined" %TC%
* undefined=name: %TA% 0 %TB% "undefined=name" %TC%
* undefined=undefined: %TA% 2 %TB% "undefined=undefined" %TC%
* Length(num): %TA% 2 %TB% "length(99)" %TC%
* Length(str): %TA% 2 %TB% "length('99')>0" %TC%
* Deep where: %TA% 2 %TB% "fields[value=fields[name='number'].value].name" %TC%
* No such field: %TA% 0 %TB% "fields['x'].name='x'" %TC%
* Numeric index %#TA% 1 %#TB% "fields[0].name='number'" %#TC%
* Table Ref %TA% 2 %TB% "'DBIStoreTest'/META:FORM.name='DBIStoreTestForm'" %TC%
* Complex ref %TA% 2 %TB% "(fields[name='Other'].value)/META:FORM.name='DBIStoreTestForm'" %TC%
* Escapes %TA% 0 %TB% "name =~ '\\\' OR name ~ '\\\' OR name = '\\\'" %TC%
* Table=Table %TA% 0 %TB% "fields=attachments" %TC%

%META:FORM{name="DBIStoreTestForm"}%
%META:FIELD{name="number" attributes="" title="number" value="99"}%
%META:FIELD{name="string" attributes="" title="string" value="String"}%
%META:FIELD{name="boolean" attributes="" title="boolean" value=""}%
%META:FIELD{name="Other" attributes="" title="Other" value="DBIStoreTestForm"}%
%META:PREFERENCE{name="Red" value="0"}%
16 changes: 16 additions & 0 deletions data/System/DBIStoreTestForm.txt
@@ -0,0 +1,16 @@
%META:TOPICINFO{author="SimianApe" comment="pending" date="1392048186" format="1.1" version="2"}%
| *Name* | *Type* | *Size* | *Values* | *Tooltip message* | *Attributes* |
| number | text | 10 | | A Number | |
| string | text | 32 | | A String | |
| boolean | checkbox | | | A Checkbox |
| Other | text | 32 | | Another topic |

This topic defines a form used for testing the DBIStoreContrib.
Note that this topic, and the DBIStoreTest topic,
have to be present in the cache for the tests to work.

%META:FORM{name="DBIStoreTestForm"}%
%META:FIELD{name="number" attributes="" title="number" value="666"}%
%META:FIELD{name="string" attributes="" title="string" value="test"}%
%META:FIELD{name="boolean" attributes="" title="boolean" value=""}%
%META:FIELD{name="Other" attributes="" title="Other" value="DBIStoreTest"}%
5 changes: 3 additions & 2 deletions lib/Foswiki/Contrib/DBIStoreContrib.pm
Expand Up @@ -4,10 +4,11 @@ package Foswiki::Contrib::DBIStoreContrib;
use strict;
use Foswiki ();

our $VERSION = '1.1'; # version of *this file*.

our $VERSION = '1.1'; # version of *this file*.
our $RELEASE = '12 Dec 2013';

use constant MONITOR => 0;

our $SHORTDESCRIPTION =
'Use DBI to implement searching using an SQL database. Supports SQL queries over Form data.';

4 changes: 2 additions & 2 deletions lib/Foswiki/Contrib/DBIStoreContrib/DBIStore.pm
Expand Up @@ -26,7 +26,7 @@ use Error ':try';
use Assert;
use Encode;

use constant MONITOR => 1;
use constant MONITOR => Foswiki::Contrib::DBIStoreContrib::MONITOR;

# TODO: SMELL: convert to using $session->{store} perhaps?
our $db; # singleton instance of this class
Expand Down Expand Up @@ -211,7 +211,7 @@ sub _preload {
my $web = $wit->next();
$this->_preloadWeb( $web, $session );
}
$this->{handle}->do('COMMIT') if personality()->requires_commit();
$this->{handle}->do('COMMIT') if personality()->requires_COMMIT();
}

# Preload a single web - PRIVATE
Expand Down

0 comments on commit d6eca6a

Please sign in to comment.