-
Notifications
You must be signed in to change notification settings - Fork 12
Update SQLite to version 3.52.0 #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -291,12 +291,36 @@ static void decimal_result(sqlite3_context *pCtx, Decimal *p){ | |
| sqlite3_result_text(pCtx, z, i, sqlite3_free); | ||
| } | ||
|
|
||
| /* | ||
| ** Round a decimal value to N significant digits. N must be positive. | ||
| */ | ||
| static void decimal_round(Decimal *p, int N){ | ||
| int i; | ||
| int nZero; | ||
| if( N<1 ) return; | ||
| for(nZero=0; nZero<p->nDigit && p->a[nZero]==0; nZero++){} | ||
| N += nZero; | ||
| if( p->nDigit<=N ) return; | ||
| if( p->a[N]>4 ){ | ||
| p->a[N-1]++; | ||
| for(i=N-1; i>0 && p->a[i]>9; i--){ | ||
| p->a[i] = 0; | ||
| p->a[i-1]++; | ||
| } | ||
| if( p->a[0]>9 ){ | ||
| p->a[0] = 1; | ||
| p->nFrac--; | ||
| } | ||
| } | ||
| memset(&p->a[N], 0, p->nDigit - N); | ||
| } | ||
|
|
||
| /* | ||
| ** Make the given Decimal the result in an format similar to '%+#e'. | ||
| ** In other words, show exponential notation with leading and trailing | ||
| ** zeros omitted. | ||
| */ | ||
| static void decimal_result_sci(sqlite3_context *pCtx, Decimal *p){ | ||
| static void decimal_result_sci(sqlite3_context *pCtx, Decimal *p, int N){ | ||
| char *z; /* The output buffer */ | ||
| int i; /* Loop counter */ | ||
| int nZero; /* Number of leading zeros */ | ||
|
|
@@ -314,7 +338,8 @@ static void decimal_result_sci(sqlite3_context *pCtx, Decimal *p){ | |
| sqlite3_result_null(pCtx); | ||
| return; | ||
| } | ||
| for(nDigit=p->nDigit; nDigit>0 && p->a[nDigit-1]==0; nDigit--){} | ||
| if( N<1 ) N = 0; | ||
| for(nDigit=p->nDigit; nDigit>N && p->a[nDigit-1]==0; nDigit--){} | ||
| for(nZero=0; nZero<nDigit && p->a[nZero]==0; nZero++){} | ||
| nFrac = p->nFrac + (nDigit - p->nDigit); | ||
| nDigit -= nZero; | ||
|
|
@@ -677,10 +702,16 @@ static void decimalFunc( | |
| sqlite3_value **argv | ||
| ){ | ||
| Decimal *p = decimal_new(context, argv[0], 0); | ||
| UNUSED_PARAMETER(argc); | ||
| int N; | ||
| if( argc==2 ){ | ||
| N = sqlite3_value_int(argv[1]); | ||
| if( N>0 ) decimal_round(p, N); | ||
| }else{ | ||
| N = 0; | ||
| } | ||
| if( p ){ | ||
| if( sqlite3_user_data(context)!=0 ){ | ||
| decimal_result_sci(context, p); | ||
| decimal_result_sci(context, p, N); | ||
| }else{ | ||
| decimal_result(context, p); | ||
| } | ||
|
|
@@ -850,7 +881,7 @@ static void decimalPow2Func( | |
| UNUSED_PARAMETER(argc); | ||
| if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){ | ||
| Decimal *pA = decimalPow2(sqlite3_value_int(argv[0])); | ||
| decimal_result_sci(context, pA); | ||
| decimal_result_sci(context, pA, 0); | ||
| decimal_free(pA); | ||
| } | ||
| } | ||
|
|
@@ -871,7 +902,9 @@ int sqlite3_decimal_init( | |
| void (*xFunc)(sqlite3_context*,int,sqlite3_value**); | ||
| } aFunc[] = { | ||
| { "decimal", 1, 0, decimalFunc }, | ||
| { "decimal", 2, 0, decimalFunc }, | ||
| { "decimal_exp", 1, 1, decimalFunc }, | ||
| { "decimal_exp", 2, 1, decimalFunc }, | ||
|
Comment on lines
904
to
+907
|
||
| { "decimal_cmp", 2, 0, decimalCmpFunc }, | ||
| { "decimal_add", 2, 0, decimalAddFunc }, | ||
| { "decimal_sub", 2, 0, decimalSubFunc }, | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -179,9 +179,9 @@ static void ieee754func( | |||||
| } | ||||||
|
|
||||||
| if( m<0 ){ | ||||||
| if( m<(-9223372036854775807LL) ) return; | ||||||
| isNeg = 1; | ||||||
| m = -m; | ||||||
| if( m<0 ) return; | ||||||
| }else if( m==0 && e>-1000 && e<1000 ){ | ||||||
| sqlite3_result_double(context, 0.0); | ||||||
| return; | ||||||
|
|
@@ -259,6 +259,38 @@ static void ieee754func_to_blob( | |||||
| } | ||||||
| } | ||||||
|
|
||||||
| /* | ||||||
| ** Functions to convert between 64-bit integers and floats. | ||||||
| ** | ||||||
| ** The bit patterns are copied. The numeric values are different. | ||||||
| */ | ||||||
| static void ieee754func_from_int( | ||||||
| sqlite3_context *context, | ||||||
| int argc, | ||||||
| sqlite3_value **argv | ||||||
| ){ | ||||||
| UNUSED_PARAMETER(argc); | ||||||
| if( sqlite3_value_type(argv[0])==SQLITE_INTEGER ){ | ||||||
| double r; | ||||||
| sqlite3_int64 v = sqlite3_value_int64(argv[0]); | ||||||
| memcpy(&r, &v, sizeof(r)); | ||||||
| sqlite3_result_double(context, r); | ||||||
| } | ||||||
| } | ||||||
| static void ieee754func_to_int( | ||||||
| sqlite3_context *context, | ||||||
| int argc, | ||||||
| sqlite3_value **argv | ||||||
| ){ | ||||||
| UNUSED_PARAMETER(argc); | ||||||
| if( sqlite3_value_type(argv[0])==SQLITE_FLOAT ){ | ||||||
| double r = sqlite3_value_double(argv[0]); | ||||||
| sqlite3_uint64 v; | ||||||
|
||||||
| sqlite3_uint64 v; | |
| sqlite3_int64 v; |
Copilot
AI
Mar 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New SQL functions ieee754_to_int/ieee754_from_int are registered here, but the existing Swift extension tests only cover ieee754(...). Please add coverage that validates round-trip behavior and bit-pattern preservation (including NaN payloads / sign-bit cases if applicable).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decimalFunccallsdecimal_round(p, N)before checking whetherdecimal_new(...)returned NULL.decimal_newcan legitimately return NULL (e.g., SQLITE_NULL input, invalid blob length, NaN/Infinity, OOM), which makes this a NULL dereference crash whenargc==2andN>0. Move the rounding call behind theif (p)check (and ideally also skip rounding forp->isNull/p->oom).