1
0
Fork 0
mirror of https://github.com/DBD-SQLite/DBD-SQLite synced 2025-06-07 06:08:38 -04:00

test the example described in L<DBD::SQLite::VirtualTable::PerlData/"Hashref example : unicode characters">

This commit is contained in:
Laurent Dami 2014-07-20 20:29:02 +02:00
parent 0ec13083f1
commit ab008be4e3
2 changed files with 53 additions and 0 deletions

View file

@ -116,6 +116,7 @@ t/virtual_table/02_find_function.t
t/virtual_table/10_filecontent.t
t/virtual_table/11_filecontent_fulltext.t
t/virtual_table/20_perldata.t
t/virtual_table/21_perldata_charinfo.t
typemap
util/getsqlite.pl
xt/meta.t

View file

@ -0,0 +1,52 @@
#!/usr/bin/perl
use strict;
BEGIN {
$| = 1;
$^W = 1;
}
# test the example described in
# L<DBD::SQLite::VirtualTable::PerlData/"Hashref example : unicode characters">
use t::lib::Test qw/connect_ok/;
use Test::More;
use Test::NoWarnings;
use Unicode::UCD 'charinfo';
our $chars = [map {charinfo($_)} 0x300..0x400];
plan tests => 10;
my $dbh = connect_ok( RaiseError => 1, AutoCommit => 1 );
ok $dbh->sqlite_create_module(perl => "DBD::SQLite::VirtualTable::PerlData"),
"create_module";
ok $dbh->do(<<""), "create table";
CREATE VIRTUAL TABLE charinfo USING perl(
code, name, block, script, category,
hashrefs="main::chars")
my $sql = "SELECT * FROM charinfo WHERE script='Greek' AND name LIKE '%SIGMA%'";
my $res = $dbh->selectall_arrayref($sql, {Slice => {}});
ok scalar(@$res), "found sigma letters";
is $res->[0]{block}, "Greek and Coptic", "letter in proper block";
# The former example used SQLite's LIKE operator; now do the same with MATCH
# which gets translated to a Perl regex
$sql = "SELECT * FROM charinfo WHERE script='Greek' AND name MATCH 'SIGMA'";
$res = $dbh->selectall_arrayref($sql, {Slice => {}});
ok scalar(@$res), "found sigma letters";
is $res->[0]{block}, "Greek and Coptic", "letter in proper block";
# the following does not work because \b gets escaped as a literal
#$sql = "SELECT * FROM charinfo WHERE script='Greek' AND name MATCH '\\bSIGMA\\b'";
# but the following does work because the REGEXP operator is handled
# outside of the BEST_INDEX / FILTER methods
$sql = "SELECT * FROM charinfo WHERE script='Greek' AND name REGEXP '\\bSIGMA\\b'";
$res = $dbh->selectall_arrayref($sql, {Slice => {}});
ok scalar(@$res), "found sigma letters";
is $res->[0]{block}, "Greek and Coptic", "letter in proper block";