16 const char* errorMsg =
"REGEXP requires exactly two arguments.";
17 sqlite3_result_error(context, errorMsg, -1);
23 const unsigned char* pattern_uch = sqlite3_value_text(argv[0]);
24 const unsigned char* text_uch = sqlite3_value_text(argv[1]);
28 if (!pattern_uch || !text_uch) {
29 sqlite3_result_int(context, 0);
33 const char* pattern =
reinterpret_cast<const char*
>(pattern_uch);
34 const char* text =
reinterpret_cast<const char*
>(text_uch);
40 std::regex regex_pattern(pattern);
43 bool match_found = std::regex_search(text, regex_pattern);
46 sqlite3_result_int(context, match_found ? 1 : 0);
48 }
catch (
const std::regex_error& e) {
50 std::string errorMsg =
"REGEXP pattern error: "s + e.what();
51 sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
52 }
catch (
const std::exception& e) {
54 std::string errorMsg =
"REGEXP unexpected error: "s + e.what();
55 sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
void sqlite_regexp_func(sqlite3_context *context, int argc, sqlite3_value **argv)
Implements the REGEXP operator for SQLite. Called by SQLite when expr REGEXP pattern is evaluated.