/* * The BFileFullPathFunc() SQL function returns full path of a BFile */ static void BFileFullPathFunc( sqlite3_context *context, int argc, sqlite3_value **argv) { int rc; sqlite3 *db; int loc_size; char *pLoc, *full_path; assert(context != NULL && argc == 1 && argv != NULL); loc_size = sqlite3_value_bytes(argv[0]); if (loc_size == 0) { sqlite3_result_null(context); return; } pLoc = (char *)sqlite3_value_text(argv[0]); db = (sqlite3 *)sqlite3_user_data(context); rc = get_full_path(db, pLoc, loc_size, &full_path); if (rc) { if (rc == SQLITE_NOMEM) sqlite3_result_error_nomem(context); else sqlite3_result_error(context, "internal error", -1); return; } sqlite3_result_text(context, full_path, strlen(full_path), sqlite3_free); }
static void php_sqlite3_func_step_callback(sqlite3_context *context, int argc, sqlite3_value **argv) { struct pdo_sqlite_func *func = (struct pdo_sqlite_func*)sqlite3_user_data(context); do_callback(&func->astep, &func->step, argc, argv, context, 1); }
/* ** If the library is compiled to omit the full-scale date and time ** handling (to get a smaller binary), the following minimal version ** of the functions current_time(), current_date() and current_timestamp() ** are included instead. This is to support column declarations that ** include "DEFAULT CURRENT_TIME" etc. ** ** This function uses the C-library functions time(), gmtime() ** and strftime(). The format string to pass to strftime() is supplied ** as the user-data for the function. */ static void currentTimeFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ time_t t; char *zFormat = (char *)sqlite3_user_data(context); sqlite3 *db; sqlite3_int64 iT; struct tm *pTm; struct tm sNow; char zBuf[20]; UNUSED_PARAMETER(argc); UNUSED_PARAMETER(argv); iT = sqlite3StmtCurrentTime(context); if( iT<=0 ) return; t = iT/1000 - 10000*(sqlite3_int64)21086676; #if HAVE_GMTIME_R pTm = gmtime_r(&t, &sNow); #else sqlite3_mutex_enter(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); pTm = gmtime(&t); if( pTm ) memcpy(&sNow, pTm, sizeof(sNow)); sqlite3_mutex_leave(sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER)); #endif if( pTm ){ strftime(zBuf, 20, zFormat, &sNow); sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); } }
/* ** If the library is compiled to omit the full-scale date and time ** handling (to get a smaller binary), the following minimal version ** of the functions current_time(), current_date() and current_timestamp() ** are included instead. This is to support column declarations that ** include "DEFAULT CURRENT_TIME" etc. ** ** This function uses the C-library functions time(), gmtime() ** and strftime(). The format string to pass to strftime() is supplied ** as the user-data for the function. */ static void currentTimeFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ time_t t; char *zFormat = (char *)sqlite3_user_data(context); char zBuf[20]; time(&t); #ifdef SQLITE_TEST { extern int sqlite3_current_time; /* See os_XXX.c */ if( sqlite3_current_time ){ t = sqlite3_current_time; } } #endif sqlite3OsEnterMutex(); strftime(zBuf, 20, zFormat, gmtime(&t)); sqlite3OsLeaveMutex(); sqlite3_result_text(context, zBuf, -1, SQLITE_TRANSIENT); }
/* ** Implementation of the like() SQL function. This function implements ** the build-in LIKE operator. The first argument to the function is the ** pattern and the second argument is the string. So, the SQL statements: ** ** A LIKE B ** ** is implemented as like(B,A). ** ** This same function (with a different compareInfo structure) computes ** the GLOB operator. */ static void likeFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ const unsigned char *zA = sqlite3_value_text(argv[0]); const unsigned char *zB = sqlite3_value_text(argv[1]); int escape = 0; if( argc==3 ){ /* The escape character string must consist of a single UTF-8 character. ** Otherwise, return an error. */ const unsigned char *zEsc = sqlite3_value_text(argv[2]); if( sqlite3utf8CharLen((char*)zEsc, -1)!=1 ){ sqlite3_result_error(context, "ESCAPE expression must be a single character", -1); return; } escape = sqlite3ReadUtf8(zEsc); } if( zA && zB ){ struct compareInfo *pInfo = sqlite3_user_data(context); #ifdef SQLITE_TEST sqlite3_like_count++; #endif sqlite3_result_int(context, patternCompare(zA, zB, pInfo, escape)); } }
static void func_callback_wrapper(int which, sqlite3_context * ctx, int num_args, sqlite3_value ** values) { CB_Data * cb_data = sqlite3_user_data(ctx); DB * db = cb_data->db; lua_State * L = db->L; switch(which) { case 0: push_callback(L, db, KEY_XFUNC(cb_data)); break; case 1: push_callback(L, db, KEY_XSTEP(cb_data)); break; case 2: push_callback(L, db, KEY_XFINAL(cb_data)); break; } if (lua_isnil(L, -1)) { lua_pop(L, 1); fprintf(stderr, "libluasqlite3: func_callback_wrapper: Warning: function is null\n"); return; } lua_pushlightuserdata(L, ctx); if (values) { lua_pushnumber(L, num_args); lua_pushlightuserdata(L, values); } if (lua_pcall(L, values ? 3 : 1, 0, 0)) { fprintf(stderr, "libluasqlite3: func_callback_wrapper: Warning: user function error: %s\n", lua_tostring(L, -1)); sqlite3_result_error(ctx, lua_tostring(L, -1), lua_strlen(L, -1)); lua_pop(L, 1); } }
/* ** Implementation of the scalar function icu_load_collation(). ** ** This scalar function is used to add ICU collation based collation ** types to an SQLite database connection. It is intended to be called ** as follows: ** ** SELECT icu_load_collation(<locale>, <collation-name>); ** ** Where <locale> is a string containing an ICU locale identifier (i.e. ** "en_AU", "tr_TR" etc.) and <collation-name> is the name of the ** collation sequence to create. */ static void icuLoadCollation( sqlite3_context *p, int nArg, sqlite3_value **apArg ){ sqlite3 *db = (sqlite3 *)sqlite3_user_data(p); UErrorCode status = U_ZERO_ERROR; const char *zLocale; /* Locale identifier - (eg. "jp_JP") */ const char *zName; /* SQL Collation sequence name (eg. "japanese") */ UCollator *pUCollator; /* ICU library collation object */ int rc; /* Return code from sqlite3_create_collation_x() */ assert(nArg==2); zLocale = (const char *)sqlite3_value_text(apArg[0]); zName = (const char *)sqlite3_value_text(apArg[1]); if( !zLocale || !zName ){ return; } pUCollator = ucol_open(zLocale, &status); if( !U_SUCCESS(status) ){ icuFunctionError(p, "ucol_open", status); return; } assert(p); rc = sqlite3_create_collation_v2(db, zName, SQLITE_UTF16, (void *)pUCollator, icuCollationColl, icuCollationDel ); if( rc!=SQLITE_OK ){ ucol_close(pUCollator); sqlite3_result_error(p, "Error registering collation function", -1); } }
/* ** Routines to implement min() and max() aggregate functions. */ static void minmaxStep( sqlite3_context *context, int NotUsed, sqlite3_value **argv ){ Mem *pArg = (Mem *)argv[0]; Mem *pBest; UNUSED_PARAMETER(NotUsed); if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; pBest = (Mem *)sqlite3_aggregate_context(context, sizeof(*pBest)); if( !pBest ) return; if( pBest->flags ){ int max; int cmp; CollSeq *pColl = sqlite3GetFuncCollSeq(context); /* This step function is used for both the min() and max() aggregates, ** the only difference between the two being that the sense of the ** comparison is inverted. For the max() aggregate, the ** sqlite3_user_data() function returns (void *)-1. For min() it ** returns (void *)db, where db is the sqlite3* database pointer. ** Therefore the next statement sets variable 'max' to 1 for the max() ** aggregate, or 0 for min(). */ max = sqlite3_user_data(context)!=0; cmp = sqlite3MemCompare(pBest, pArg, pColl); if( (max && cmp<0) || (!max && cmp>0) ){ sqlite3VdbeMemCopy(pBest, pArg); } }else{ sqlite3VdbeMemCopy(pBest, pArg); } }
/* ** Implementation of the scalar function fts3_tokenizer_internal_test(). ** This function is used for testing only, it is not included in the ** build unless SQLITE_TEST is defined. ** ** The purpose of this is to test that the fts3_tokenizer() function ** can be used as designed by the C-code in the queryTokenizer and ** registerTokenizer() functions above. These two functions are repeated ** in the README.tokenizer file as an example, so it is important to ** test them. ** ** To run the tests, evaluate the fts3_tokenizer_internal_test() scalar ** function with no arguments. An assert() will fail if a problem is ** detected. i.e.: ** ** SELECT fts3_tokenizer_internal_test(); ** */ static void intTestFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ int rc; const sqlite3_tokenizer_module *p1; const sqlite3_tokenizer_module *p2; sqlite3 *db = (sqlite3 *)sqlite3_user_data(context); UNUSED_PARAMETER(argc); UNUSED_PARAMETER(argv); /* Test the query function */ sqlite3Fts3SimpleTokenizerModule(&p1); rc = queryTokenizer(db, "simple", &p2); assert( rc==SQLITE_OK ); assert( p1==p2 ); rc = queryTokenizer(db, "nosuchtokenizer", &p2); assert( rc==SQLITE_ERROR ); assert( p2==0 ); assert( 0==strcmp(sqlite3_errmsg(db), "unknown tokenizer: nosuchtokenizer") ); /* Test the storage function */ #ifdef SQLITE_ENABLE_FTS3_TOKENIZER rc = registerTokenizer(db, "nosuchtokenizer", p1); assert( rc==SQLITE_OK ); rc = queryTokenizer(db, "nosuchtokenizer", &p2); assert( rc==SQLITE_OK ); assert( p2==p1 ); #endif sqlite3_result_text(context, "ok", -1, SQLITE_STATIC); }
static void test_destructor( sqlite3_context *pCtx, int nArg, sqlite3_value **argv ){ char *zVal; int len; sqlite3 *db = sqlite3_user_data(pCtx); test_destructor_count_var++; assert( nArg==1 ); if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; len = sqlite3ValueBytes(argv[0], ENC(db)); zVal = sqliteMalloc(len+3); zVal[len] = 0; zVal[len-1] = 0; assert( zVal ); zVal++; memcpy(zVal, sqlite3ValueText(argv[0], ENC(db)), len); if( ENC(db)==SQLITE_UTF8 ){ sqlite3_result_text(pCtx, zVal, -1, destructor); #ifndef SQLITE_OMIT_UTF16 }else if( ENC(db)==SQLITE_UTF16LE ){ sqlite3_result_text16le(pCtx, zVal, -1, destructor); }else{ sqlite3_result_text16be(pCtx, zVal, -1, destructor); #endif /* SQLITE_OMIT_UTF16 */ } }
/* ** Implementation of the non-aggregate min() and max() functions */ static void minmaxFunc( sqlite3_context *context, int argc, sqlite3_value **argv ){ int i; int mask; /* 0 for min() or 0xffffffff for max() */ int iBest; CollSeq *pColl; if( argc==0 ) return; mask = sqlite3_user_data(context)==0 ? 0 : -1; pColl = sqlite3GetFuncCollSeq(context); assert( pColl ); assert( mask==-1 || mask==0 ); iBest = 0; if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; for(i=1; i<argc; i++){ if( sqlite3_value_type(argv[i])==SQLITE_NULL ) return; if( (sqlite3MemCompare(argv[iBest], argv[i], pColl)^mask)>=0 ){ iBest = i; } } sqlite3_result_value(context, argv[iBest]); }
void validate_double_udf(sqlite3_context* ctx, int nargs, sqlite3_value** values) { sqlite3 *db; const char *value; char *tmp; db = (sqlite3*)sqlite3_user_data(ctx); value = sqlite3_value_text(values[0]); /* Assuming NULL values for type checked columns not allowed */ if(value == NULL) { sqlite3_result_int(ctx, 0); return; } // Validate type: tmp = NULL; strtod(value, &tmp); if(*tmp != '\0') { // Value does not conform to type sqlite3_result_int(ctx, 0); return; } // If we got this far value is valid. sqlite3_result_int(ctx, 1); }
static void wrapped_func(sqlite3_context *context, int argc, sqlite3_value *values[]) { struct function_wrapper_baton_t *fwb = sqlite3_user_data(context); svn_sqlite__context_t sctx; svn_sqlite__value_t **local_vals = apr_palloc(fwb->scratch_pool, sizeof(svn_sqlite__value_t *) * argc); svn_error_t *err; int i; sctx.context = context; for (i = 0; i < argc; i++) { local_vals[i] = apr_palloc(fwb->scratch_pool, sizeof(*local_vals[i])); local_vals[i]->value = values[i]; } err = fwb->func(&sctx, argc, local_vals, fwb->scratch_pool); svn_pool_clear(fwb->scratch_pool); if (err) { char buf[256]; sqlite3_result_error(context, svn_err_best_message(err, buf, sizeof(buf)), -1); svn_error_clear(err); } }
static void sqlite_callback_final(sqlite3_context *ctx) { RefNode *klass = (RefNode*)sqlite3_user_data(ctx); Value *v = sqlite3_aggregate_context(ctx, sizeof(Value)); if (*v == VALUE_NULL) { if (!sqlite_aggrigate_new(v, klass)) { goto ERROR_END; } } fs->Value_push("v", v); if (!fs->call_member_func(fs->intern("final", -1), 0, TRUE)) { goto ERROR_END; } // 戻り値の設定 if (!sqlite_callback_return(fg->stk_top[-1], ctx)) { goto ERROR_END; } fs->Value_pop(); fs->unref(*v); *v = VALUE_NULL; return; ERROR_END: if (fg->error == VALUE_NULL) { sqlite3_result_error_code(ctx, SQLITE_ERROR_USER); } return; }
static void ST_SRID(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_GEOM_ARG(geomblob); FUNCTION_START_STATIC(context, 256); spatialdb = (spatialdb_t *)sqlite3_user_data(context); FUNCTION_GET_GEOM_ARG_UNSAFE(context, spatialdb, geomblob, 0); if (nbArgs == 1) { sqlite3_result_int(context, geomblob.srid); } else { FUNCTION_GET_INT_ARG(geomblob.srid, 1); if (binstream_seek(&FUNCTION_GEOM_ARG_STREAM(geomblob), 0) != SQLITE_OK) { sqlite3_result_error(context, "Error writing geometry blob header", -1); goto exit; } if (spatialdb->write_blob_header(&FUNCTION_GEOM_ARG_STREAM(geomblob), &geomblob, FUNCTION_ERROR) != SQLITE_OK) { if (error_count(FUNCTION_ERROR) == 0) { error_append(FUNCTION_ERROR, "Error writing geometry blob header"); } goto exit; } binstream_seek(&FUNCTION_GEOM_ARG_STREAM(geomblob), 0); sqlite3_result_blob(context, binstream_data(&FUNCTION_GEOM_ARG_STREAM(geomblob)), (int) binstream_available(&FUNCTION_GEOM_ARG_STREAM(geomblob)), SQLITE_TRANSIENT); } FUNCTION_END(context); FUNCTION_FREE_GEOM_ARG(geomblob); }
void R_callFinalFunc(sqlite3_context *ctxt) { SEXP *expressions = (SEXP *) sqlite3_user_data(ctxt); SEXP ans = Rf_eval(expressions[1], R_GlobalEnv); convertRResult(ans, ctxt); }
static void OGR2SQLITE_Transform(sqlite3_context* pContext, int argc, sqlite3_value** argv) { if( argc != 3 ) { sqlite3_result_null (pContext); return; } if( sqlite3_value_type (argv[0]) != SQLITE_BLOB ) { sqlite3_result_null (pContext); return; } if( sqlite3_value_type (argv[1]) != SQLITE_INTEGER ) { sqlite3_result_null (pContext); return; } if( sqlite3_value_type (argv[2]) != SQLITE_INTEGER ) { sqlite3_result_null (pContext); return; } int nSrcSRSId = sqlite3_value_int(argv[1]); int nDstSRSId = sqlite3_value_int(argv[2]); OGRSQLiteExtensionData* poModule = (OGRSQLiteExtensionData*) sqlite3_user_data(pContext); OGRCoordinateTransformation* poCT = poModule->GetTransform(nSrcSRSId, nDstSRSId); if( poCT == NULL ) { sqlite3_result_null (pContext); return; } GByte* pabySLBLOB = (GByte *) sqlite3_value_blob (argv[0]); int nBLOBLen = sqlite3_value_bytes (argv[0]); OGRGeometry* poGeom = NULL; if( OGRSQLiteLayer::ImportSpatiaLiteGeometry( pabySLBLOB, nBLOBLen, &poGeom ) == CE_None && poGeom->transform(poCT) == OGRERR_NONE && OGRSQLiteLayer::ExportSpatiaLiteGeometry( poGeom, nDstSRSId, wkbNDR, FALSE, FALSE, FALSE, &pabySLBLOB, &nBLOBLen ) == CE_None ) { sqlite3_result_blob(pContext, pabySLBLOB, nBLOBLen, CPLFree); } else { sqlite3_result_null (pContext); } delete poGeom; }
/* ** Implementation of the last_insert_rowid() SQL function. The return ** value is the same as the sqlite3_last_insert_rowid() API function. */ static void last_insert_rowid( sqlite3_context *context, int arg, sqlite3_value **argv ){ sqlite3 *db = sqlite3_user_data(context); sqlite3_result_int64(context, sqlite3_last_insert_rowid(db)); }
/* ** Implementation of the total_changes() SQL function. The return value is ** the same as the sqlite3_total_changes() API function. */ static void total_changes( sqlite3_context *context, int arg, sqlite3_value **argv ){ sqlite3 *db = sqlite3_user_data(context); sqlite3_result_int(context, sqlite3_total_changes(db)); }
static void OGR2SQLITE_ogr_geocode(sqlite3_context* pContext, int argc, sqlite3_value** argv) { OGRSQLiteExtensionData* poModule = (OGRSQLiteExtensionData*) sqlite3_user_data(pContext); if( argc < 1 || sqlite3_value_type (argv[0]) != SQLITE_TEXT ) { sqlite3_result_null (pContext); return; } const char* pszQuery = (const char*)sqlite3_value_text(argv[0]); CPLString osField = "geometry"; if( argc >= 2 && sqlite3_value_type (argv[1]) == SQLITE_TEXT ) { osField = (const char*)sqlite3_value_text(argv[1]); } int i; char** papszOptions = NULL; for(i = 2; i < argc; i++) { if( sqlite3_value_type (argv[i]) == SQLITE_TEXT ) { papszOptions = CSLAddString(papszOptions, (const char*)sqlite3_value_text(argv[i])); } } OGRGeocodingSessionH hSession = poModule->GetGeocodingSession(); if( hSession == NULL ) { hSession = OGRGeocodeCreateSession(papszOptions); if( hSession == NULL ) { sqlite3_result_null (pContext); CSLDestroy(papszOptions); return; } poModule->SetGeocodingSession(hSession); } if( osField == "raw" ) papszOptions = CSLAddString(papszOptions, "RAW_FEATURE=YES"); if( CSLFindString(papszOptions, "LIMIT") == -1 ) papszOptions = CSLAddString(papszOptions, "LIMIT=1"); OGRLayerH hLayer = OGRGeocode(hSession, pszQuery, NULL, papszOptions); OGR2SQLITE_ogr_geocode_set_result(pContext, hLayer, osField); CSLDestroy(papszOptions); return; }
/* * rank_func -- * Sqlite user defined function for ranking the documents. * For each phrase of the query, it computes the tf and idf and adds them over. * It computes the final rank, by multiplying tf and idf together. * Weight of term t for document d = (term frequency of t in d * * inverse document frequency of t) * * Term Frequency of term t in document d = Number of times t occurs in d / * Number of times t appears in all * documents * * Inverse document frequency of t = log(Total number of documents / * Number of documents in which t occurs) */ static void rank_func(sqlite3_context *pctx, int nval, sqlite3_value **apval) { inverse_document_frequency *idf = sqlite3_user_data(pctx); double tf = 0.0; const unsigned int *matchinfo; int ncol; int nphrase; int iphrase; int ndoc; int doclen = 0; const double k = 3.75; /* Check that the number of arguments passed to this function is correct. */ assert(nval == 1); matchinfo = (const unsigned int *) sqlite3_value_blob(apval[0]); nphrase = matchinfo[0]; ncol = matchinfo[1]; ndoc = matchinfo[2 + 3 * ncol * nphrase + ncol]; for (iphrase = 0; iphrase < nphrase; iphrase++) { int icol; const unsigned int *phraseinfo = &matchinfo[2 + ncol+ iphrase * ncol * 3]; for(icol = 1; icol < ncol; icol++) { /* nhitcount: number of times the current phrase occurs in the current * column in the current document. * nglobalhitcount: number of times current phrase occurs in the current * column in all documents. * ndocshitcount: number of documents in which the current phrase * occurs in the current column at least once. */ int nhitcount = phraseinfo[3 * icol]; int nglobalhitcount = phraseinfo[3 * icol + 1]; int ndocshitcount = phraseinfo[3 * icol + 2]; doclen = matchinfo[2 + icol ]; double weight = col_weights[icol - 1]; if (idf->status == 0 && ndocshitcount) idf->value += log(((double)ndoc / ndocshitcount))* weight; /* Dividing the tf by document length to normalize the effect of * longer documents. */ if (nglobalhitcount > 0 && nhitcount) tf += (((double)nhitcount * weight) / (nglobalhitcount * doclen)); } } idf->status = 1; /* Final score = (tf * idf)/ ( k + tf) * Dividing by k+ tf further normalizes the weight leading to better * results. * The value of k is experimental */ double score = (tf * idf->value/ ( k + tf)) ; sqlite3_result_double(pctx, score); return; }
static void ST_Point(sqlite3_context *context, int nbArgs, sqlite3_value **args) { fromtext_t *fromtext = (fromtext_t *)sqlite3_user_data(context); if (sqlite3_value_type(args[0]) == SQLITE_TEXT) { geometry_constructor(context, fromtext->spatialdb, geom_from_wkt, fromtext->locale, GEOM_POINT, nbArgs, args); } else if (sqlite3_value_type(args[0]) == SQLITE_BLOB) { geometry_constructor(context, fromtext->spatialdb, geom_from_wkb, NULL, GEOM_POINT, nbArgs, args); } else { geometry_constructor(context, fromtext->spatialdb, point_from_coords, NULL, GEOM_POINT, nbArgs, args); } }
void PibDb::keyDeletedFun(sqlite3_context* context, int argc, sqlite3_value** argv) { BOOST_ASSERT(argc == 1); PibDb* pibDb = reinterpret_cast<PibDb*>(sqlite3_user_data(context)); Name keyName(Block(sqlite3_value_blob(argv[0]), sqlite3_value_bytes(argv[0]))); pibDb->keyDeleted(keyName); }
void PibDb::certInsertedFun(sqlite3_context* context, int argc, sqlite3_value** argv) { BOOST_ASSERT(argc == 1); PibDb* pibDb = reinterpret_cast<PibDb*>(sqlite3_user_data(context)); Name certName(Block(sqlite3_value_blob(argv[0]), sqlite3_value_bytes(argv[0]))); pibDb->certificateInserted(certName); }
static void php_sqlite3_callback_final(sqlite3_context *context) { php_sqlite3_agg_context *agg_context = (php_sqlite3_agg_context *)sqlite3_aggregate_context (context, sizeof(php_sqlite3_agg_context)); agg_context->row_count = 0; c_SQLite3::UserDefinedFunc *udf = (c_SQLite3::UserDefinedFunc*)sqlite3_user_data(context); sqlite3_do_callback(context, udf->fini, 0, NULL, true); }
static void GPKG_SpatialDBType(sqlite3_context *context, int nbArgs, sqlite3_value **args) { spatialdb_t *spatialdb; FUNCTION_START(context); spatialdb = (spatialdb_t *)sqlite3_user_data(context); sqlite3_result_text(context, spatialdb->name, -1, SQLITE_STATIC); FUNCTION_END(context); }
static void php_sqlite3_callback_step(sqlite3_context *context, int argc, sqlite3_value **argv) { php_sqlite3_agg_context *agg_context = (php_sqlite3_agg_context *)sqlite3_aggregate_context (context, sizeof(php_sqlite3_agg_context)); agg_context->row_count++; c_SQLite3::UserDefinedFunc *udf = (c_SQLite3::UserDefinedFunc*)sqlite3_user_data(context); sqlite3_do_callback(context, udf->step, argc, argv, true); }
void R_mkCallFunc(sqlite3_context *ctxt, int nargs,sqlite3_value** vals) { SEXP r_func = (SEXP) sqlite3_user_data(ctxt); SEXP expr; PROTECT(expr = allocVector(LANGSXP, nargs + 1)); SETCAR(expr, r_func); R_doCall(ctxt, nargs, vals, expr); UNPROTECT(1); }
ikptr ik_sqlite3_user_data (ikptr s_context, ikpcb * pcb) { #ifdef HAVE_SQLITE3_USER_DATA sqlite3_context * context = IK_SQLITE_CONTEXT(s_context); void * rv; rv = sqlite3_user_data(context); return (rv)? ika_pointer_alloc(pcb, (ik_ulong)rv) : IK_FALSE_OBJECT; #else feature_failure(__func__); #endif }
/* ** Implementations of scalar functions for case mapping - upper() and ** lower(). Function upper() converts its input to upper-case (ABC). ** Function lower() converts to lower-case (abc). ** ** ICU provides two types of case mapping, "general" case mapping and ** "language specific". Refer to ICU documentation for the differences ** between the two. ** ** To utilise "general" case mapping, the upper() or lower() scalar ** functions are invoked with one argument: ** ** upper('ABC') -> 'abc' ** lower('abc') -> 'ABC' ** ** To access ICU "language specific" case mapping, upper() or lower() ** should be invoked with two arguments. The second argument is the name ** of the locale to use. Passing an empty string ("") or SQL NULL value ** as the second argument is the same as invoking the 1 argument version ** of upper() or lower(). ** ** lower('I', 'en_us') -> 'i' ** lower('I', 'tr_tr') -> '\u131' (small dotless i) ** ** http://www.icu-project.org/userguide/posix.html#case_mappings */ static void icuCaseFunc16(sqlite3_context *p, int nArg, sqlite3_value **apArg){ const UChar *zInput; /* Pointer to input string */ UChar *zOutput = 0; /* Pointer to output buffer */ int nInput; /* Size of utf-16 input string in bytes */ int nOut; /* Size of output buffer in bytes */ int cnt; int bToUpper; /* True for toupper(), false for tolower() */ UErrorCode status; const char *zLocale = 0; assert(nArg==1 || nArg==2); bToUpper = (sqlite3_user_data(p)!=0); if( nArg==2 ){ zLocale = (const char *)sqlite3_value_text(apArg[1]); } zInput = sqlite3_value_text16(apArg[0]); if( !zInput ){ return; } nOut = nInput = sqlite3_value_bytes16(apArg[0]); if( nOut==0 ){ sqlite3_result_text16(p, "", 0, SQLITE_STATIC); return; } for(cnt=0; cnt<2; cnt++){ UChar *zNew = sqlite3_realloc(zOutput, nOut); if( zNew==0 ){ sqlite3_free(zOutput); sqlite3_result_error_nomem(p); return; } zOutput = zNew; status = U_ZERO_ERROR; if( bToUpper ){ nOut = 2*u_strToUpper(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); }else{ nOut = 2*u_strToLower(zOutput,nOut/2,zInput,nInput/2,zLocale,&status); } if( U_SUCCESS(status) ){ sqlite3_result_text16(p, zOutput, nOut, xFree); }else if( status==U_BUFFER_OVERFLOW_ERROR ){ assert( cnt==0 ); continue; }else{ icuFunctionError(p, bToUpper ? "u_strToUpper" : "u_strToLower", status); } return; } assert( 0 ); /* Unreachable */ }