summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSQL/Result.h
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-12-11 11:44:11 -0500
committerTim Flynn <trflynn89@pm.me>2022-12-14 09:21:30 -0500
commit72e41a7dbd07196314244c899e74bb193b2f976e (patch)
tree57e67f5c3e6afa38310f08c79d85f60fef594465 /Userland/Libraries/LibSQL/Result.h
parenta1007c37a4ce0103373e2a22c192412f2d7b0ab9 (diff)
downloadserenity-72e41a7dbd07196314244c899e74bb193b2f976e.zip
LibSQL: Support 64-bit integer values and handle overflow errors
Currently, integers are stored in LibSQL as 32-bit signed integers, even if the provided type is unsigned. This resulted in a series of unchecked unsigned-to-signed conversions, and prevented storing 64-bit values. Further, mathematical operations were performed without similar checks, and without checking for overflow. This changes SQL::Value to behave like SQLite for INTEGER types. In SQLite, the INTEGER type does not imply a size or signedness of the underlying type. Instead, SQLite determines on-the-fly what type is needed as values are created and updated. To do so, the SQL::Value variant can now hold an i64 or u64 integer. If a specific type is requested, invalid conversions are now explictly an error (e.g. converting a stored -1 to a u64 will fail). When binary mathematical operations are performed, we now try to coerce the RHS value to a type that works with the LHS value, failing the operation if that isn't possible. Any overflow or invalid operation (e.g. bitshifting a 64-bit value by more than 64 bytes) is an error.
Diffstat (limited to 'Userland/Libraries/LibSQL/Result.h')
-rw-r--r--Userland/Libraries/LibSQL/Result.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/Userland/Libraries/LibSQL/Result.h b/Userland/Libraries/LibSQL/Result.h
index d5d8f781a7..e965ada00b 100644
--- a/Userland/Libraries/LibSQL/Result.h
+++ b/Userland/Libraries/LibSQL/Result.h
@@ -48,6 +48,7 @@ constexpr char const* command_tag(SQLCommand command)
S(DatabaseDoesNotExist, "Database '{}' does not exist") \
S(DatabaseUnavailable, "Database Unavailable") \
S(IntegerOperatorTypeMismatch, "Cannot apply '{}' operator to non-numeric operands") \
+ S(IntegerOverflow, "Operation would cause integer overflow") \
S(InternalError, "{}") \
S(InvalidDatabaseName, "Invalid database name '{}'") \
S(InvalidNumberOfPlaceholderValues, "Number of values does not match number of placeholders") \