Adapt to sqlite-3.10.0 by adding DBD::SQLite::strlike()

f38
Petr Písař 9 years ago
parent 80b08693a9
commit 17af34c6db

@ -0,0 +1,115 @@
From b38e57a23b4e4b5c3b5b115558e12950f393b323 Mon Sep 17 00:00:00 2001
From: Kenichi Ishigaki <ishigaki@cpan.org>
Date: Thu, 7 Jan 2016 19:47:10 +0900
Subject: [PATCH] LIKE/GLOB/REGEXP are also required to be implemented for
SQLite 3.10.0 and above
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
SQLite.xs | 18 ++++++++++++++++++
dbdimp.c | 8 ++++++++
lib/DBD/SQLite/VirtualTable/PerlData.pm | 24 +++++++++++++++++-------
3 files changed, 43 insertions(+), 7 deletions(-)
diff --git a/SQLite.xs b/SQLite.xs
index abe3524..bc6644b 100644
--- a/SQLite.xs
+++ b/SQLite.xs
@@ -363,5 +363,23 @@ sqlite_status(reset = 0)
OUTPUT:
RETVAL
+#if SQLITE_VERSION_NUMBER >= 3010000
+
+int
+strglob(const char *zglob, const char *zstr)
+ CODE:
+ RETVAL = sqlite3_strglob(zglob, zstr);
+ OUTPUT:
+ RETVAL
+
+int
+strlike(const char *zglob, const char *zstr, unsigned int esc = 0)
+ CODE:
+ RETVAL = sqlite3_strlike(zglob, zstr, esc);
+ OUTPUT:
+ RETVAL
+
+#endif
+
INCLUDE: constants.inc
INCLUDE: SQLite.xsi
diff --git a/dbdimp.c b/dbdimp.c
index a4e426b..b441940 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -3129,6 +3129,14 @@ _constraint_op_to_string(unsigned char op) {
return "<=";
case SQLITE_INDEX_CONSTRAINT_MATCH:
return "MATCH";
+#if SQLITE_VERSION_NUMBER >= 3010000
+ case SQLITE_INDEX_CONSTRAINT_LIKE:
+ return "LIKE";
+ case SQLITE_INDEX_CONSTRAINT_GLOB:
+ return "GLOB";
+ case SQLITE_INDEX_CONSTRAINT_REGEXP:
+ return "REGEXP";
+#endif
default:
return "unknown";
}
diff --git a/lib/DBD/SQLite/VirtualTable/PerlData.pm b/lib/DBD/SQLite/VirtualTable/PerlData.pm
index 7bbcb0d..8151fe1 100644
--- a/lib/DBD/SQLite/VirtualTable/PerlData.pm
+++ b/lib/DBD/SQLite/VirtualTable/PerlData.pm
@@ -4,7 +4,8 @@ package DBD::SQLite::VirtualTable::PerlData;
use strict;
use warnings;
use base 'DBD::SQLite::VirtualTable';
-
+use DBD::SQLite;
+use constant SQLITE_3010000 => $DBD::SQLite::sqlite_version_number >= 3010000 ? 1 : 0;
# private data for translating comparison operators from Sqlite to Perl
my $TXT = 0;
@@ -17,6 +18,11 @@ my %SQLOP2PERLOP = (
'>' => [ 'gt', '>' ],
'>=' => [ 'ge', '>=' ],
'MATCH' => [ '=~', '=~' ],
+ (SQLITE_3010000 ? (
+ 'LIKE' => [ 'DBD::SQLite::strlike', 'DBD::SQLite::strlike' ],
+ 'GLOB' => [ 'DBD::SQLite::strglob', 'DBD::SQLite::strglob' ],
+ 'REGEXP'=> [ '=~', '=~' ],
+ ) : ()),
);
#----------------------------------------------------------------------
@@ -95,12 +101,16 @@ sub BEST_INDEX {
$optype = $self->{optypes}[$col];
}
my $op = $SQLOP2PERLOP{$constraint->{op}}[$optype];
- push @conditions,
- "(defined($member) && defined(\$vals[$ix]) && $member $op \$vals[$ix])";
- # Note : $vals[$ix] refers to an array of values passed to the
- # FILTER method (see below); so the eval-ed perl code will be a
- # closure on those values
-
+ if (SQLITE_3010000 && $op =~ /str/) {
+ push @conditions,
+ "(defined($member) && defined(\$vals[$ix]) && !$op(\$vals[$ix], $member))";
+ } else {
+ push @conditions,
+ "(defined($member) && defined(\$vals[$ix]) && $member $op \$vals[$ix])";
+ }
+ # Note : $vals[$ix] refers to an array of values passed to the
+ # FILTER method (see below); so the eval-ed perl code will be a
+ # closure on those values
# info passed back to the SQLite core -- see vtab.html in sqlite doc
$constraint->{argvIndex} = $ix++;
$constraint->{omit} = 1;
--
2.5.0

@ -0,0 +1,76 @@
From 54ebad9d0f2d1f91c7aec8991adb6c40edb9c430 Mon Sep 17 00:00:00 2001
From: Kenichi Ishigaki <ishigaki@cpan.org>
Date: Mon, 11 Jan 2016 19:44:21 +0900
Subject: [PATCH] added a note on strlike and strglob
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
lib/DBD/SQLite.pm | 42 ++++++++++++++++++++++++++----------------
1 file changed, 26 insertions(+), 16 deletions(-)
diff --git a/lib/DBD/SQLite.pm b/lib/DBD/SQLite.pm
index 8debee7..7d683f2 100644
--- a/lib/DBD/SQLite.pm
+++ b/lib/DBD/SQLite.pm
@@ -2151,22 +2151,6 @@ See also L<DBI::Profile> for better profiling options.
is for internal use only.
-=head2 DBD::SQLite::compile_options()
-
-Returns an array of compile options (available since SQLite 3.6.23,
-bundled in DBD::SQLite 1.30_01), or an empty array if the bundled
-library is old or compiled with SQLITE_OMIT_COMPILEOPTION_DIAGS.
-
-=head2 DBD::SQLite::sqlite_status()
-
-Returns a hash reference that holds a set of status information of SQLite runtime such as memory usage or page cache usage (see L<http://www.sqlite.org/c3ref/c_status_malloc_count.html> for details). Each of the entry contains the current value and the highwater value.
-
- my $status = DBD::SQLite::sqlite_status();
- my $cur = $status->{memory_used}{current};
- my $high = $status->{memory_used}{highwater};
-
-You may also pass 0 as an argument to reset the status.
-
=head2 $dbh->sqlite_db_status()
Returns a hash reference that holds a set of status information of database connection such as cache usage. See L<http://www.sqlite.org/c3ref/c_dbstatus_options.html> for details. You may also pass 0 as an argument to reset the status.
@@ -2187,6 +2171,32 @@ registered before creating a new virtual table using the module and
before using a preexisting virtual table for the module.
Virtual tables are explained in L<DBD::SQLite::VirtualTable>.
+=head1 DRIVER FUNCTIONS
+
+=head2 DBD::SQLite::compile_options()
+
+Returns an array of compile options (available since SQLite 3.6.23,
+bundled in DBD::SQLite 1.30_01), or an empty array if the bundled
+library is old or compiled with SQLITE_OMIT_COMPILEOPTION_DIAGS.
+
+=head2 DBD::SQLite::sqlite_status()
+
+Returns a hash reference that holds a set of status information of SQLite runtime such as memory usage or page cache usage (see L<http://www.sqlite.org/c3ref/c_status_malloc_count.html> for details). Each of the entry contains the current value and the highwater value.
+
+ my $status = DBD::SQLite::sqlite_status();
+ my $cur = $status->{memory_used}{current};
+ my $high = $status->{memory_used}{highwater};
+
+You may also pass 0 as an argument to reset the status.
+
+=head2 DBD::SQLite::strlike($pattern, $string, $escape_char), DBD::SQLite::strglob($pattern, $string)
+
+As of 1.49_05 (SQLite 3.10.0), you can use these two functions to
+see if a string matches a pattern. These may be useful when you
+create a virtual table or a custom function.
+See L<http://sqlite.org/c3ref/strlike.html> and
+L<http://sqlite.org/c3ref/strglob.html> for details.
+
=head1 DRIVER CONSTANTS
A subset of SQLite C constants are made available to Perl,
--
2.5.0

@ -0,0 +1,53 @@
From 0d52eae83d12ce49d377949dafda5d6a4d5c522c Mon Sep 17 00:00:00 2001
From: Kenichi Ishigaki <ishigaki@cpan.org>
Date: Mon, 11 Jan 2016 19:44:57 +0900
Subject: [PATCH] added a test for strlike
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
t/61_strlike.t | 30 ++++++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
create mode 100644 t/61_strlike.t
diff --git a/t/61_strlike.t b/t/61_strlike.t
new file mode 100644
index 0000000..22da44d
--- /dev/null
+++ b/t/61_strlike.t
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+use strict;
+BEGIN {
+ $| = 1;
+ $^W = 1;
+}
+
+use t::lib::Test qw/requires_sqlite/;
+use Test::More;
+use DBD::SQLite;
+
+BEGIN { requires_sqlite('3.10.0'); }
+
+use Test::NoWarnings;
+
+plan tests => 13;
+
+ok !DBD::SQLite::strlike("foo_bar", "FOO1BAR");
+ok !DBD::SQLite::strlike("foo_bar", "FOO_BAR");
+ok DBD::SQLite::strlike("foo\\_bar", "FOO1BAR", "\\");
+ok !DBD::SQLite::strlike("foo\\_bar", "FOO_BAR", "\\");
+ok DBD::SQLite::strlike("foo!_bar", "FOO1BAR", "!");
+ok !DBD::SQLite::strlike("foo!_bar", "FOO_BAR", "!");
+ok !DBD::SQLite::strlike("%foobar", "1FOOBAR");
+ok !DBD::SQLite::strlike("%foobar", "%FOOBAR");
+ok DBD::SQLite::strlike("\\%foobar", "1FOOBAR", "\\");
+ok !DBD::SQLite::strlike("\\%foobar", "%FOOBAR", "\\");
+ok DBD::SQLite::strlike("!%foobar", "1FOOBAR", "!");
+ok !DBD::SQLite::strlike("!%foobar", "%FOOBAR", "!");
--
2.5.0

@ -0,0 +1,37 @@
From f5aaef2594ed7fc84c226b18d5d3e5b705b8cb58 Mon Sep 17 00:00:00 2001
From: Kenichi Ishigaki <ishigaki@cpan.org>
Date: Mon, 11 Jan 2016 19:42:39 +0900
Subject: [PATCH] allowed strlike to take a letter as the third arg, instead of
a number
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Petr Písař <ppisar@redhat.com>
---
SQLite.xs | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/SQLite.xs b/SQLite.xs
index bc6644b..5b51aef 100644
--- a/SQLite.xs
+++ b/SQLite.xs
@@ -373,9 +373,13 @@ strglob(const char *zglob, const char *zstr)
RETVAL
int
-strlike(const char *zglob, const char *zstr, unsigned int esc = 0)
+strlike(const char *zglob, const char *zstr, const char *esc = NULL)
CODE:
- RETVAL = sqlite3_strlike(zglob, zstr, esc);
+ if (esc) {
+ RETVAL = sqlite3_strlike(zglob, zstr, (unsigned int)(*esc));
+ } else {
+ RETVAL = sqlite3_strlike(zglob, zstr, 0);
+ }
OUTPUT:
RETVAL
--
2.5.0

@ -1,6 +1,6 @@
Name: perl-DBD-SQLite
Version: 1.48
Release: 2%{?dist}
Release: 3%{?dist}
Summary: SQLite DBI Driver
Group: Development/Libraries
License: (GPL+ or Artistic) and Public Domain
@ -9,6 +9,19 @@ Source0: http://search.cpan.org/CPAN/authors/id/I/IS/ISHIGAKI/DBD-SQLite-
Patch0: perl-DBD-SQLite-bz543982.patch
# Remove notes about bundled sqlite C source from man page and README
Patch1: DBD-SQLite-1.42-Remove-bundled-source-extentions.patch
# Adapt to sqlite-3.10.0, bug #1298628, in upstream 1.49_05
# This is minimal patch needed to pass tests with sqlite-3.10.0, but following
# patches align DBD::SQLite API to recent upstream intention
Patch2: DBD-SQLite-1.48-LIKE-GLOB-REGEXP-are-also-required-to-be-implemented.patch
# Adapt to sqlite-3.10.0, bug #1298628, in upstream 1.49_05
# Align DBD::SQLite API to recent upstream intention
Patch3: DBD-SQLite-1.49_04-allowed-strlike-to-take-a-letter-as-the-third-arg-in.patch
# Adapt to sqlite-3.10.0, bug #1298628, in upstream 1.49_05
# Document DBD::SQLite::strlike
Patch4: DBD-SQLite-1.48-added-a-note-on-strlike-and-strglob.patch
# Adapt to sqlite-3.10.0, bug #1298628, in upstream 1.49_05
# Add DBD::SQLite::strlike tests
Patch5: DBD-SQLite-1.49_04-added-a-test-for-strlike.patch
# if sqlite >= 3.1.3 then
# perl-DBD-SQLite uses the external library
# else
@ -57,6 +70,10 @@ libraries.
%setup -q -n DBD-SQLite-%{version}
%patch0 -p1 -b .bz543982
%patch1 -p1
%patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
# Remove bundled sqlite libraries (BZ#1059154)
# System libraries will be used
rm sqlite*
@ -82,6 +99,9 @@ make test
%{_mandir}/man3/*.3pm*
%changelog
* Fri Jan 15 2016 Petr Pisar <ppisar@redhat.com> - 1.48-3
- Adapt to sqlite-3.10.0 by adding DBD::SQLite::strlike() (bug #1298628)
* Fri Jun 19 2015 Jitka Plesnikova <jplesnik@redhat.com> -1.48-2
- Updated patch

Loading…
Cancel
Save