Sqlite3 的扩展:实现 REGEXP函数和包含字符串查找的函数 CONTAIN

前端之家收集整理的这篇文章主要介绍了Sqlite3 的扩展:实现 REGEXP函数和包含字符串查找的函数 CONTAIN前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

// 再来一个 sqlite3 的扩展:实现 REGEXP函数和包含字符串查找的函数 CONTAIN

// ************************************* //// sqlite3 extend// By Ceja// ************************************* //#include "../public/pcre_7.9/pcrecpp.h"#include "sqlite3.h"#include "regexpExt.h"// 这个文件是我做的扩展#include "../public/debugoption.h"// 这个也是扩展,以后放出#include "../public/charset.h"// 用 PCRE 实现sqlite3的正则查询函数 REGEXPstatic void icuRegexpFunc(sqlite3_context *p,int nArg,sqlite3_value **apArg){//UErrorCode status = U_ZERO_ERROR;//URegularExpression *pExpr;//UBool res;//PcreMatch(_T("abcdefg"),_T("ab"),&objMath,1,&nCoutn);//const WCHAR * pExpr = (const WCHAR *)sqlite3_get_auxdata(p,0);const WCHAR * zPattern = (const WCHAR *)sqlite3_value_text16(apArg[1]);const WCHAR * zString = (const WCHAR *)sqlite3_value_text16(apArg[0]);/* If the left hand side of the regexp operator is NULL,** then the result is also NULL. */if( !zString ){ return;}USES_CONVERSION_S;pcrecpp::RE reObj(T2A_S(zPattern));BOOL bMatch = reObj.PartialMatch(T2A_S(zString));USES_CONVERSION_CLEAR;#ifdef _DIS_MY_DEBUGchar szTemp[1024];memset(szTemp,sizeof(szTemp));memcpy(szTemp,zString,10);if (bMatch){ //MYDEBUGMSG(zString); MYDEBUGOUTCONTENT(zPattern,_T("data_2.txt")); MYDEBUGOUTCONTENT(_T("/t"),_T("data_2.txt")); MYDEBUGOUTCONTENT(zString,_T("data_2.txt")); MYDEBUGOUTCONTENT(pExpr,_T("data_2.txt")); MYDEBUGOUTCONTENT(_T("/r/n"),_T("data_2.txt"));}#endif/* Return 1 or 0. */sqlite3_result_int(p,bMatch ? 1 : 0);}// 自定义一个查询函数用法 select * from `table1` where containi('abcde',`DataSection`) limit 100;static void icuContainiFunc(sqlite3_context *p,0);const WCHAR * lpszSource = (const WCHAR *)sqlite3_value_text16(apArg[0]);const WCHAR * lpszDest = (const WCHAR *)sqlite3_value_text16(apArg[1]);/* If the left hand side of the regexp operator is NULL,** then the result is also NULL. */if( !lpszSource || !lpszDest ){ return;}USES_CONVERSION_S;//pcrecpp::RE reObj(T2A_S(zPattern));//BOOL bMatch = reObj.PartialMatch(T2A_S(zString));BOOL bMatch = FALSE;if (-1 < KMP_i(lpszSource,lpszDest)){ bMatch = TRUE;}USES_CONVERSION_CLEAR;#ifdef _DIS_MY_DEBUGchar szTemp[1024];memset(szTemp,bMatch ? 1 : 0);}int AddExFunction(sqlite3 *db){int nResult = 0;nResult = sqlite3_create_function(db,"regexp",-1,sqlITE_ANY,icuRegexpFunc,0);nResult = sqlite3_create_function(db,"containi",icuContainiFunc,0);return nResult;}

原文链接:https://www.f2er.com/sqlite/203122.html

猜你在找的Sqlite相关文章