diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2012-09-24 10:15:50 +0000 |
---|---|---|
committer | Lorry <lorry@roadtrain.codethink.co.uk> | 2012-09-26 13:46:46 +0000 |
commit | 485b97be9f2f2abf5a40923b5fd85f75714a8c02 (patch) | |
tree | ca05cb0ecf3828d909a898c3e5805804a0aff5f8 /t/rt_50503_fts3.t | |
download | perl-dbd-sqlite-tarball-master.tar.gz |
Imported from /srv/lorry/lorry-area/perl-dbd-sqlite-tarball/DBD-SQLite-1.38_01.tar.gz.HEADDBD-SQLite-1.38_01masterbaserock/morph
Diffstat (limited to 't/rt_50503_fts3.t')
-rw-r--r-- | t/rt_50503_fts3.t | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/t/rt_50503_fts3.t b/t/rt_50503_fts3.t new file mode 100644 index 0000000..5900784 --- /dev/null +++ b/t/rt_50503_fts3.t @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +use strict; +BEGIN { + $| = 1; + $^W = 1; +} + +use t::lib::Test; +use Test::More; + +BEGIN { + use DBD::SQLite; + unless ($DBD::SQLite::sqlite_version_number && $DBD::SQLite::sqlite_version_number >= 3006006) { + plan skip_all => "this test requires SQLite 3.6.6 and newer"; + exit; + } + if (!grep /^ENABLE_FTS3/, DBD::SQLite::compile_options()) { + plan skip_all => "FTS3 is disabled for this DBD::SQLite"; + } +} + +use Test::NoWarnings; + +plan tests => 6; + +my $dbh = connect_ok( RaiseError => 1, AutoCommit => 0 ); + +$dbh->do(<<EOF); +CREATE VIRTUAL TABLE incident_fts +USING fts3 (incident_id VARCHAR, all_text VARCHAR, TOKENIZE simple) +EOF +$dbh->commit; + +insert_data($dbh, '595', time(), "sample text foo bar baz"); +insert_data($dbh, '595', time(), "sample text foo bar baz"); +insert_data($dbh, '595', time(), "sample text foo bar baz"); +insert_data($dbh, '595', time(), "sample text foo bar baz"); +$dbh->commit; + +{ + my $sth = $dbh->prepare("SELECT * FROM incident_fts WHERE all_text MATCH 'bar'"); + $sth->execute(); + + while (my $row = $sth->fetchrow_hashref("NAME_lc")) { + # The result may vary with or without an output, + # but anyway, either case seems failing at the destruction. + ok %$row; + #ok %$row, join ',', %$row; + } +} + +$dbh->commit; + +sub insert_data { + my($dbh, $inc_num, $date, $text) = @_; + # "OR REPLACE" isn't standard SQL, but it sure is useful + my $sth = $dbh->prepare('INSERT OR REPLACE INTO incident_fts (incident_id, all_text) VALUES (?, ?)'); + $sth->execute($inc_num, $text) || die "execute failed\n"; + $dbh->commit; +} |