void sqlite_ext_uid(sqlite3_context *db, int row, sqlite3_value **value) { char *uid = malloc(256); char *chars = "0123456789abcdefghijklmnopqrstuvwxyz"; int max_length = 8; if ( uid == NULL ) { sqlite3_result_error_nomem(db); return; } if ( value != NULL && value[0] != NULL ) { int type = sqlite3_value_numeric_type(value[0]); if ( type == SQLITE_INTEGER ) { max_length = sqlite3_value_int(value[0]); if ( max_length > 256 ) { sqlite3_result_error_nomem(db); } } } sqlite_ext_uid_randomizer(chars, max_length, uid); sqlite3_result_text(db, uid, strlen(uid), sqlite_ext_uid_destroy); return; }
ikptr ik_sqlite3_value_numeric_type (ikptr s_value, ikpcb * pcb) { #ifdef HAVE_SQLITE3_VALUE_NUMERIC_TYPE sqlite3_value * value = IK_SQLITE_VALUE(s_value); int rv; rv = sqlite3_value_numeric_type(value); return ika_integer_from_int(pcb, rv); #else feature_failure(__func__); #endif }
/* ** Routines used to compute the sum, average, and total. ** ** The SUM() function follows the (broken) SQL standard which means ** that it returns NULL if it sums over no inputs. TOTAL returns ** 0.0 in that case. In addition, TOTAL always returns a float where ** SUM might return an integer if it never encounters a floating point ** value. ** ** I am told that SUM() should raise an exception if it encounters ** a integer overflow. But after pondering this, I decided that ** behavior leads to brittle programs. So instead, I have coded ** SUM() to revert to using floating point if it encounters an ** integer overflow. The answer may not be exact, but it will be ** close. If the SUM() function returns an integer, the value is ** exact. If SUM() returns a floating point value, it means the ** value might be approximated. */ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){ SumCtx *p; int type; assert( argc==1 ); p = sqlite3_aggregate_context(context, sizeof(*p)); type = sqlite3_value_numeric_type(argv[0]); if( p && type!=SQLITE_NULL ){ p->cnt++; if( type==SQLITE_INTEGER ){ p->sum += sqlite3_value_int64(argv[0]); if( !p->approx ){ i64 iVal; p->approx = p->sum!=(LONGDOUBLE_TYPE)(iVal = (i64)p->sum); } }else{ p->sum += sqlite3_value_double(argv[0]); p->approx = 1; } } }
/* ** Routines used to compute the sum, average, and total. ** ** The SUM() function follows the (broken) SQL standard which means ** that it returns NULL if it sums over no inputs. TOTAL returns ** 0.0 in that case. In addition, TOTAL always returns a float where ** SUM might return an integer if it never encounters a floating point ** value. TOTAL never fails, but SUM might through an exception if ** it overflows an integer. */ static void sumStep(sqlite3_context *context, int argc, sqlite3_value **argv){ SumCtx *p; int type; assert( argc==1 ); UNUSED_PARAMETER(argc); p = sqlite3_aggregate_context(context, sizeof(*p)); type = sqlite3_value_numeric_type(argv[0]); if( p && type!=SQLITE_NULL ){ p->cnt++; if( type==SQLITE_INTEGER ){ i64 v = sqlite3_value_int64(argv[0]); p->rSum += v; if( (p->approx|p->overflow)==0 && sqlite3AddInt64(&p->iSum, v) ){ p->overflow = 1; } }else{ p->rSum += sqlite3_value_double(argv[0]); p->approx = 1; } } }
int sqlite3Fts5ConfigSetValue( Fts5Config *pConfig, const char *zKey, sqlite3_value *pVal, int *pbBadkey ){ int rc = SQLITE_OK; if( 0==sqlite3_stricmp(zKey, "pgsz") ){ int pgsz = 0; if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){ pgsz = sqlite3_value_int(pVal); } if( pgsz<=0 || pgsz>FTS5_MAX_PAGE_SIZE ){ *pbBadkey = 1; }else{ pConfig->pgsz = pgsz; } } else if( 0==sqlite3_stricmp(zKey, "hashsize") ){ int nHashSize = -1; if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){ nHashSize = sqlite3_value_int(pVal); } if( nHashSize<=0 ){ *pbBadkey = 1; }else{ pConfig->nHashSize = nHashSize; } } else if( 0==sqlite3_stricmp(zKey, "automerge") ){ int nAutomerge = -1; if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){ nAutomerge = sqlite3_value_int(pVal); } if( nAutomerge<0 || nAutomerge>64 ){ *pbBadkey = 1; }else{ if( nAutomerge==1 ) nAutomerge = FTS5_DEFAULT_AUTOMERGE; pConfig->nAutomerge = nAutomerge; } } else if( 0==sqlite3_stricmp(zKey, "crisismerge") ){ int nCrisisMerge = -1; if( SQLITE_INTEGER==sqlite3_value_numeric_type(pVal) ){ nCrisisMerge = sqlite3_value_int(pVal); } if( nCrisisMerge<0 ){ *pbBadkey = 1; }else{ if( nCrisisMerge<=1 ) nCrisisMerge = FTS5_DEFAULT_CRISISMERGE; pConfig->nCrisisMerge = nCrisisMerge; } } else if( 0==sqlite3_stricmp(zKey, "rank") ){ const char *zIn = (const char*)sqlite3_value_text(pVal); char *zRank; char *zRankArgs; rc = sqlite3Fts5ConfigParseRank(zIn, &zRank, &zRankArgs); if( rc==SQLITE_OK ){ sqlite3_free(pConfig->zRank); sqlite3_free(pConfig->zRankArgs); pConfig->zRank = zRank; pConfig->zRankArgs = zRankArgs; }else if( rc==SQLITE_ERROR ){ rc = SQLITE_OK; *pbBadkey = 1; } }else{ *pbBadkey = 1; } return rc; }
if ((result = strcmp(a->order, b->order)) != 0) { // Ascending return result; } else { // Descending return b->value - a->value; } } void bcsum_step(sqlite3_context *context, int argc, sqlite3_value **argv) { BCSumNode* head, * new, * curr, * prev; int t1, t2; head = (BCSumNode*)sqlite3_aggregate_context(context, sizeof(*head)); t1 = sqlite3_value_numeric_type(argv[0]); t2 = sqlite3_value_type(argv[1]); if (t1 != SQLITE_NULL && t2 != SQLITE_NULL) { new = malloc(sizeof(*new)); new->value = sqlite3_value_int(argv[0]); new->order = strdup((char*)sqlite3_value_text(argv[1])); new->next = NULL; // Insert the node in the right order if (head->next == NULL) { head->next = new; } else { prev = head; curr = prev->next; while (curr != NULL && bcsum_cmp_node(curr, new) < 0) {
DLL_FUNCTION(int32_t) BU_SQLite_Value_Numeric_Type(sqlite3_value* pValue) { return sqlite3_value_numeric_type(pValue); }