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

Use imported constants

This commit is contained in:
Kenichi Ishigaki 2021-06-06 01:53:52 +09:00
parent 9e59c780a7
commit f14744d31a
12 changed files with 39 additions and 23 deletions

View file

@ -7,7 +7,9 @@ use SQLiteTest qw/connect_ok @CALL_FUNCS/;
use Test::More; use Test::More;
use if -d ".git", "Test::FailWarnings"; use if -d ".git", "Test::FailWarnings";
my $unicode_opt = DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT; use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
my $unicode_opt = DBD_SQLITE_STRING_MODE_UNICODE_STRICT;
my $show_diag = 0; my $show_diag = 0;
foreach my $call_func (@CALL_FUNCS) { foreach my $call_func (@CALL_FUNCS) {

View file

@ -8,7 +8,9 @@ use SQLiteTest;
use Test::More; use Test::More;
use if -d ".git", "Test::FailWarnings"; use if -d ".git", "Test::FailWarnings";
my $unicode_opt = DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT; use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
my $unicode_opt = DBD_SQLITE_STRING_MODE_UNICODE_STRICT;
BEGIN { requires_unicode_support() } BEGIN { requires_unicode_support() }

View file

@ -7,8 +7,9 @@ use Test::More;
use if -d ".git", "Test::FailWarnings"; use if -d ".git", "Test::FailWarnings";
use Encode qw/decode/; use Encode qw/decode/;
use DBD::SQLite; use DBD::SQLite;
use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
my $unicode_opt = DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT; my $unicode_opt = DBD_SQLITE_STRING_MODE_UNICODE_STRICT;
BEGIN { requires_unicode_support(); } BEGIN { requires_unicode_support(); }
@ -73,7 +74,7 @@ is($DBD::SQLite::COLLATION{foo}, \&by_num_desc, "overridden collation");
foreach my $call_func (@CALL_FUNCS) { foreach my $call_func (@CALL_FUNCS) {
for my $unicode_opt ( DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_BYTES, DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT) { for my $unicode_opt (DBD_SQLITE_STRING_MODE_BYTES, DBD_SQLITE_STRING_MODE_UNICODE_STRICT) {
# connect # connect
my $dbh = connect_ok( RaiseError => 1, sqlite_string_mode => $unicode_opt ); my $dbh = connect_ok( RaiseError => 1, sqlite_string_mode => $unicode_opt );
@ -86,7 +87,7 @@ foreach my $call_func (@CALL_FUNCS) {
HAT hâôer HAT hâôer
féôu fêôe fèöe ferme féôu fêôe fèöe ferme
}; };
if ($unicode_opt != DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_BYTES) { if ($unicode_opt != DBD_SQLITE_STRING_MODE_BYTES) {
utf8::upgrade($_) foreach @words; utf8::upgrade($_) foreach @words;
} }

View file

@ -10,7 +10,9 @@ use if -d ".git", "Test::FailWarnings";
use File::Temp (); use File::Temp ();
use File::Spec::Functions ':ALL'; use File::Spec::Functions ':ALL';
my $unicode_opt = DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT; use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
my $unicode_opt = DBD_SQLITE_STRING_MODE_UNICODE_STRICT;
BEGIN { requires_unicode_support() } BEGIN { requires_unicode_support() }

View file

@ -28,10 +28,11 @@ BEGIN {
use locale; use locale;
use DBD::SQLite; use DBD::SQLite;
use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
foreach my $call_func (@CALL_FUNCS) { foreach my $call_func (@CALL_FUNCS) {
for my $string_mode (DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_BYTES, DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT) { for my $string_mode (DBD_SQLITE_STRING_MODE_BYTES, DBD_SQLITE_STRING_MODE_UNICODE_STRICT) {
# connect # connect
my $dbh = connect_ok( RaiseError => 1, sqlite_string_mode => $string_mode ); my $dbh = connect_ok( RaiseError => 1, sqlite_string_mode => $string_mode );
@ -43,7 +44,7 @@ foreach my $call_func (@CALL_FUNCS) {
# populate test data # populate test data
my @vals = @words; my @vals = @words;
if ($string_mode == DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_BYTES) { if ($string_mode == DBD_SQLITE_STRING_MODE_BYTES) {
utf8::upgrade($_) foreach @vals; utf8::upgrade($_) foreach @vals;
} }

View file

@ -6,7 +6,7 @@ use SQLiteTest;
use Test::More; use Test::More;
use if -d ".git", "Test::FailWarnings"; use if -d ".git", "Test::FailWarnings";
use DBD::SQLite; use DBD::SQLite;
use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
my @texts = ("il était une bergère", my @texts = ("il était une bergère",
"qui gardait ses moutons", "qui gardait ses moutons",
@ -59,7 +59,7 @@ sub Unicode_Word_tokenizer { # see also: Search::Tokenizer
use DBD::SQLite; use DBD::SQLite;
for my $string_mode (DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_BYTES, DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT) { for my $string_mode (DBD_SQLITE_STRING_MODE_BYTES, DBD_SQLITE_STRING_MODE_UNICODE_STRICT) {
# connect # connect
my $dbh = connect_ok( RaiseError => 1, sqlite_string_mode => $string_mode ); my $dbh = connect_ok( RaiseError => 1, sqlite_string_mode => $string_mode );
@ -106,7 +106,7 @@ for my $string_mode (DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_BYTES, DBD::
# the 'offsets' function should return integer offsets for the words in the MATCH query # the 'offsets' function should return integer offsets for the words in the MATCH query
my $sql_offsets = "SELECT offsets(try_$fts) FROM try_$fts WHERE content MATCH ?"; my $sql_offsets = "SELECT offsets(try_$fts) FROM try_$fts WHERE content MATCH ?";
$result = $dbh->selectcol_arrayref($sql_offsets, undef, 'une'); $result = $dbh->selectcol_arrayref($sql_offsets, undef, 'une');
my $offset_une = $string_mode == DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT ? $ix_une_utf8 : $ix_une_native; my $offset_une = $string_mode == DBD_SQLITE_STRING_MODE_UNICODE_STRICT ? $ix_une_utf8 : $ix_une_native;
my $expected_offsets = "0 0 $offset_une 3"; my $expected_offsets = "0 0 $offset_une 3";
is_deeply($result, [$expected_offsets], "offsets ($fts, string_mode=$string_mode)"); is_deeply($result, [$expected_offsets], "offsets ($fts, string_mode=$string_mode)");

View file

@ -7,6 +7,8 @@ use Test::More;
BEGIN { requires_unicode_support() } BEGIN { requires_unicode_support() }
use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
# special case for multibyte (non-ASCII) character class, # special case for multibyte (non-ASCII) character class,
# which only works correctly under the unicode mode # which only works correctly under the unicode mode
my @words = ("\x{e3}\x{83}\x{86}\x{e3}\x{82}\x{b9}\x{e3}\x{83}\x{88}", "\x{e3}\x{83}\x{86}\x{e3}\x{83}\x{b3}\x{e3}\x{83}\x{88}"); # テスト テント my @words = ("\x{e3}\x{83}\x{86}\x{e3}\x{82}\x{b9}\x{e3}\x{83}\x{88}", "\x{e3}\x{83}\x{86}\x{e3}\x{83}\x{b3}\x{e3}\x{83}\x{88}"); # テスト テント
@ -15,15 +17,15 @@ my $regex = "\x{e3}\x{83}\x{86}[\x{e3}\x{82}\x{b9}\x{e3}\x{83}\x{b3}]\x{e3}\x{83
foreach my $call_func (@CALL_FUNCS) { foreach my $call_func (@CALL_FUNCS) {
for my $use_unicode (0, 1) { for my $string_mode (DBD_SQLITE_STRING_MODE_PV, DBD_SQLITE_STRING_MODE_UNICODE_STRICT) {
# connect # connect
my $dbh = connect_ok( RaiseError => 1, sqlite_unicode => $use_unicode ); my $dbh = connect_ok( RaiseError => 1, sqlite_string_mode => $string_mode );
# populate test data # populate test data
my @vals = @words; my @vals = @words;
my $re = $regex; my $re = $regex;
if ($use_unicode) { if ($string_mode == DBD_SQLITE_STRING_MODE_UNICODE_STRICT) {
utf8::decode($_) foreach @vals; utf8::decode($_) foreach @vals;
utf8::decode($re); utf8::decode($re);
} }

View file

@ -5,7 +5,9 @@ use SQLiteTest;
use Test::More; use Test::More;
use if -d ".git", "Test::FailWarnings"; use if -d ".git", "Test::FailWarnings";
my $unicode_opt = DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT; use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
my $unicode_opt = DBD_SQLITE_STRING_MODE_UNICODE_STRICT;
BEGIN { requires_unicode_support(); } BEGIN { requires_unicode_support(); }

View file

@ -5,7 +5,9 @@ use SQLiteTest;
use Test::More; use Test::More;
use if -d ".git", "Test::FailWarnings"; use if -d ".git", "Test::FailWarnings";
my $unicode_opt = DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT; use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
my $unicode_opt = DBD_SQLITE_STRING_MODE_UNICODE_STRICT;
BEGIN { requires_unicode_support() } BEGIN { requires_unicode_support() }

View file

@ -6,11 +6,11 @@ use Test::More;
use if -d ".git", "Test::FailWarnings"; use if -d ".git", "Test::FailWarnings";
use DBI qw/:sql_types/; use DBI qw/:sql_types/;
use DBD::SQLite::Constants; use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
BEGIN{ requires_unicode_support(); } BEGIN{ requires_unicode_support(); }
my $dbh = connect_ok(sqlite_string_mode => DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT); my $dbh = connect_ok(sqlite_string_mode => DBD_SQLITE_STRING_MODE_UNICODE_STRICT);
$dbh->do('create table test1 (id integer, b blob)'); $dbh->do('create table test1 (id integer, b blob)');
my $blob = "\x{82}\x{A0}"; my $blob = "\x{82}\x{A0}";

View file

@ -6,7 +6,7 @@ use Test::More;
use if -d ".git", "Test::FailWarnings"; use if -d ".git", "Test::FailWarnings";
use Encode; use Encode;
use DBD::SQLite::Constants; use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
BEGIN { requires_unicode_support() } BEGIN { requires_unicode_support() }
@ -22,7 +22,7 @@ sub unicode_test {
{ # tests for an environment where everything is encoded { # tests for an environment where everything is encoded
my $dbh = connect_ok(sqlite_string_mode => DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_BYTES); my $dbh = connect_ok(sqlite_string_mode => DBD_SQLITE_STRING_MODE_BYTES);
$dbh->do("pragma foreign_keys = on"); $dbh->do("pragma foreign_keys = on");
my $unicode_quoted = $dbh->quote_identifier($unicode_encoded); my $unicode_quoted = $dbh->quote_identifier($unicode_encoded);
$dbh->do("create table $unicode_quoted (id, $unicode_quoted primary key)"); $dbh->do("create table $unicode_quoted (id, $unicode_quoted primary key)");
@ -89,7 +89,7 @@ sub unicode_test {
} }
{ # tests for an environment where everything is decoded { # tests for an environment where everything is decoded
my $dbh = connect_ok(sqlite_string_mode => DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_STRICT); my $dbh = connect_ok(sqlite_string_mode => DBD_SQLITE_STRING_MODE_UNICODE_STRICT);
$dbh->do("pragma foreign_keys = on"); $dbh->do("pragma foreign_keys = on");
my $unicode_quoted = $dbh->quote_identifier($unicode); my $unicode_quoted = $dbh->quote_identifier($unicode);
$dbh->do("create table $unicode_quoted (id, $unicode_quoted primary key)"); $dbh->do("create table $unicode_quoted (id, $unicode_quoted primary key)");

View file

@ -11,8 +11,10 @@ use if -d ".git", "Test::FailWarnings";
BEGIN { requires_unicode_support() } BEGIN { requires_unicode_support() }
my $dbh = connect_ok( sqlite_string_mode => DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_NAIVE ); use DBD::SQLite::Constants ':dbd_sqlite_string_mode';
is( $dbh->{sqlite_string_mode}, DBD::SQLite::Constants::DBD_SQLITE_STRING_MODE_UNICODE_NAIVE, 'Unicode is on' );
my $dbh = connect_ok( sqlite_string_mode => DBD_SQLITE_STRING_MODE_UNICODE_NAIVE );
is( $dbh->{sqlite_string_mode}, DBD_SQLITE_STRING_MODE_UNICODE_NAIVE, 'Unicode is on' );
ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' ); ok( $dbh->do(<<'END_SQL'), 'CREATE TABLE' );
CREATE TABLE foo ( CREATE TABLE foo (