Blame t/rt_50503_fts3.t

Packit 723767
#!/usr/bin/perl
Packit 723767
Packit 723767
use strict;
Packit 723767
BEGIN {
Packit 723767
	$|  = 1;
Packit 723767
	$^W = 1;
Packit 723767
}
Packit 723767
Packit 723767
use lib "t/lib";
Packit 723767
use SQLiteTest;
Packit 723767
use Test::More;
Packit 723767
Packit 723767
BEGIN {
Packit 723767
	use DBD::SQLite;
Packit 723767
	unless ($DBD::SQLite::sqlite_version_number && $DBD::SQLite::sqlite_version_number >= 3006006) {
Packit 723767
		plan skip_all => "this test requires SQLite 3.6.6 and newer";
Packit 723767
		exit;
Packit 723767
	}
Packit 723767
	if (!grep /^ENABLE_FTS3/, DBD::SQLite::compile_options()) {
Packit 723767
		plan skip_all => "FTS3 is disabled for this DBD::SQLite";
Packit 723767
	}
Packit 723767
}
Packit 723767
Packit 723767
use Test::NoWarnings;
Packit 723767
Packit 723767
plan tests => 6;
Packit 723767
Packit 723767
my $dbh = connect_ok( RaiseError => 1, AutoCommit => 0 );
Packit 723767
Packit 723767
$dbh->do(<
Packit 723767
CREATE VIRTUAL TABLE incident_fts
Packit 723767
USING fts3 (incident_id VARCHAR, all_text VARCHAR, TOKENIZE simple)
Packit 723767
EOF
Packit 723767
$dbh->commit;
Packit 723767
Packit 723767
insert_data($dbh, '595', time(), "sample text foo bar baz");
Packit 723767
insert_data($dbh, '595', time(), "sample text foo bar baz");
Packit 723767
insert_data($dbh, '595', time(), "sample text foo bar baz");
Packit 723767
insert_data($dbh, '595', time(), "sample text foo bar baz");
Packit 723767
$dbh->commit;
Packit 723767
Packit 723767
{
Packit 723767
	my $sth = $dbh->prepare("SELECT * FROM incident_fts WHERE all_text MATCH 'bar'");
Packit 723767
	$sth->execute();
Packit 723767
Packit 723767
	while (my $row = $sth->fetchrow_hashref("NAME_lc")) {
Packit 723767
		# The result may vary with or without an output,
Packit 723767
		# but anyway, either case seems failing at the destruction.
Packit 723767
		ok %$row;
Packit 723767
		#ok %$row, join ',', %$row;
Packit 723767
	}
Packit 723767
}
Packit 723767
Packit 723767
$dbh->commit;
Packit 723767
Packit 723767
sub insert_data {
Packit 723767
	my($dbh, $inc_num, $date, $text) = @_;
Packit 723767
	# "OR REPLACE" isn't standard SQL, but it sure is useful
Packit 723767
	my $sth = $dbh->prepare('INSERT OR REPLACE INTO incident_fts (incident_id, all_text) VALUES (?, ?)');
Packit 723767
	$sth->execute($inc_num, $text) || die "execute failed\n";
Packit 723767
	$dbh->commit;
Packit 723767
}