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

added new index constraint ops introduced in SQLite 3.21.0 to PerlData (GH#28)

This commit is contained in:
Kenichi Ishigaki 2017-11-21 03:25:30 +09:00
parent 7fb17683e2
commit da3306e443
2 changed files with 29 additions and 1 deletions

View file

@ -194,6 +194,18 @@ _constraint_op_to_string(unsigned char op) {
return "GLOB"; return "GLOB";
case SQLITE_INDEX_CONSTRAINT_REGEXP: case SQLITE_INDEX_CONSTRAINT_REGEXP:
return "REGEXP"; return "REGEXP";
#endif
#if SQLITE_VERSION_NUMBER >= 3021000
case SQLITE_INDEX_CONSTRAINT_NE:
return "NE";
case SQLITE_INDEX_CONSTRAINT_ISNOT:
return "ISNOT";
case SQLITE_INDEX_CONSTRAINT_ISNOTNULL:
return "ISNOTNULL";
case SQLITE_INDEX_CONSTRAINT_ISNULL:
return "ISNULL";
case SQLITE_INDEX_CONSTRAINT_IS:
return "IS";
#endif #endif
default: default:
return "unknown"; return "unknown";

View file

@ -6,6 +6,7 @@ use warnings;
use base 'DBD::SQLite::VirtualTable'; use base 'DBD::SQLite::VirtualTable';
use DBD::SQLite; use DBD::SQLite;
use constant SQLITE_3010000 => $DBD::SQLite::sqlite_version_number >= 3010000 ? 1 : 0; use constant SQLITE_3010000 => $DBD::SQLite::sqlite_version_number >= 3010000 ? 1 : 0;
use constant SQLITE_3021000 => $DBD::SQLite::sqlite_version_number >= 3021000 ? 1 : 0;
# private data for translating comparison operators from Sqlite to Perl # private data for translating comparison operators from Sqlite to Perl
my $TXT = 0; my $TXT = 0;
@ -23,6 +24,13 @@ my %SQLOP2PERLOP = (
'GLOB' => [ 'DBD::SQLite::strglob', 'DBD::SQLite::strglob' ], 'GLOB' => [ 'DBD::SQLite::strglob', 'DBD::SQLite::strglob' ],
'REGEXP'=> [ '=~', '=~' ], 'REGEXP'=> [ '=~', '=~' ],
) : ()), ) : ()),
(SQLITE_3021000 ? (
'NE' => [ 'ne', '!=' ],
'ISNOT' => [ 'defined', 'defined' ],
'ISNOTNULL' => [ 'defined', 'defined' ],
'ISNULL' => [ '!defined', '!defined' ],
'IS' => [ '!defined', '!defined' ],
) : ()),
); );
#---------------------------------------------------------------------- #----------------------------------------------------------------------
@ -101,7 +109,15 @@ sub BEST_INDEX {
$optype = $self->{optypes}[$col]; $optype = $self->{optypes}[$col];
} }
my $op = $SQLOP2PERLOP{$constraint->{op}}[$optype]; my $op = $SQLOP2PERLOP{$constraint->{op}}[$optype];
if (SQLITE_3010000 && $op =~ /str/) { if (SQLITE_3021000 && $op =~ /defined/) {
if ($constraint->{op} =~ /NULL/) {
push @conditions,
"($op($member))";
} else {
push @conditions,
"($op($member) && $op(\$vals[$ix]))";
}
} elsif (SQLITE_3010000 && $op =~ /str/) {
push @conditions, push @conditions,
"(defined($member) && defined(\$vals[$ix]) && !$op(\$vals[$ix], $member))"; "(defined($member) && defined(\$vals[$ix]) && !$op(\$vals[$ix], $member))";
} else { } else {