From 61ad8da9d6d4575a65db9815871c561e70db1c01 Mon Sep 17 00:00:00 2001 From: ShanePerron <35239305+ShanePerron@users.noreply.github.com> Date: Sat, 2 May 2020 11:42:42 -0400 Subject: [PATCH] Fix for early termination of returned rows (#805) Once the regex encountered the first instance of a non-match, it would return without processing the rest of the rows in the statement. This change allows it to process the remaining, only setting the sqlite3_result_int to zero then continuing. This worked fine for the example as it only had one item to process. --- _example/mod_regexp/sqlite3_mod_regexp.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/_example/mod_regexp/sqlite3_mod_regexp.c b/_example/mod_regexp/sqlite3_mod_regexp.c index 277764d..d3ad149 100644 --- a/_example/mod_regexp/sqlite3_mod_regexp.c +++ b/_example/mod_regexp/sqlite3_mod_regexp.c @@ -13,9 +13,13 @@ static void regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv int vec[500]; int n, rc; pcre* re = pcre_compile(pattern, 0, &errstr, &erroff, NULL); + if (!re) { + sqlite3_result_error(context, errstr, 0); + return; + } rc = pcre_exec(re, NULL, target, strlen(target), 0, 0, vec, 500); if (rc <= 0) { - sqlite3_result_error(context, errstr, 0); + sqlite3_result_int(context, 0); return; } sqlite3_result_int(context, 1);