File: rt_50503_fts3.t

package info (click to toggle)
libdbd-sqlite3-perl 1.76-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,004 kB
  • sloc: ansic: 167,715; perl: 1,788; pascal: 277; makefile: 9
file content (50 lines) | stat: -rw-r--r-- 1,331 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use strict;
use warnings;
use lib "t/lib";
use SQLiteTest;
use Test::More;

BEGIN {
	requires_sqlite('3.6.6');
	plan skip_all => "FTS is disabled for this DBD::SQLite" unless has_fts();
}

use if -d ".git", "Test::FailWarnings";

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;
}

done_testing;