mirror of
https://git.sr.ht/~cismonx/bookmarkfs
synced 2025-06-07 19:58:50 +00:00
db: allow non-integer argument for safeincr
This commit is contained in:
parent
35d4a93a41
commit
3b45900157
2 changed files with 11 additions and 11 deletions
18
src/db.c
18
src/db.c
|
@ -98,16 +98,16 @@ safeincr (
|
|||
debug_assert(argc == 1);
|
||||
sqlite3_value *val = argv[0];
|
||||
|
||||
if (unlikely(SQLITE_INTEGER != sqlite3_value_type(val))) {
|
||||
sqlite3_result_error(dbctx, "value is not an integer", -1);
|
||||
return;
|
||||
int64_t ival = 0;
|
||||
if (SQLITE_INTEGER == sqlite3_value_type(val)) {
|
||||
ival = sqlite3_value_int64(val);
|
||||
if (unlikely(ival == INT64_MAX)) {
|
||||
sqlite3_result_error(dbctx, "integer overflow", -1);
|
||||
return;
|
||||
}
|
||||
++ival;
|
||||
}
|
||||
int64_t ival = sqlite3_value_int64(val);
|
||||
if (unlikely(ival == INT64_MAX)) {
|
||||
sqlite3_result_error(dbctx, "integer overflow", -1);
|
||||
return;
|
||||
}
|
||||
sqlite3_result_int64(dbctx, ival + 1);
|
||||
sqlite3_result_int64(dbctx, ival);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
4
src/db.h
4
src/db.h
|
@ -155,8 +155,8 @@ db_query_i64_cb (
|
|||
* SQLite converts the result to REAL upon integer overflow.
|
||||
* See: <https://www.sqlite.org/datatype3.html#operators>.
|
||||
*
|
||||
* The `safeincr()` function fails if given a non-integer
|
||||
* argument, or if the argument value equals to INT64_MAX.
|
||||
* The `safeincr()` function returns 0 if given a non-integer
|
||||
* argument, and fails if the argument value equals to INT64_MAX.
|
||||
*/
|
||||
int
|
||||
db_register_safeincr (
|
||||
|
|
Loading…
Add table
Reference in a new issue