summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSQL
AgeCommit message (Collapse)Author
2023-01-04LibIPC+Everywhere: Change IPC::encode's return type to ErrorOrTimothy Flynn
In doing so, this removes all uses of the Encoder's stream operator, except for where it is currently still used in the generated IPC code. So the stream operator currently discards any errors, which is the existing behavior. A subsequent commit will propagate the errors.
2023-01-02Everywhere: Remove unused includes of AK/Format.hBen Wiederhake
These instances were detected by searching for files that include AK/Format.h, but don't match the regex: \\b(CheckedFormatString|critical_dmesgln|dbgln|dbgln_if|dmesgln|FormatBu ilder|__FormatIfSupported|FormatIfSupported|FormatParser|FormatString|Fo rmattable|Formatter|__format_value|HasFormatter|max_format_arguments|out |outln|set_debug_enabled|StandardFormatter|TypeErasedFormatParams|TypeEr asedParameter|VariadicFormatParams|v_critical_dmesgln|vdbgln|vdmesgln|vf ormat|vout|warn|warnln|warnln_if)\\b (Without the linebreaks.) This regex is pessimistic, so there might be more files that don't actually use any formatting functions. Observe that this revealed that Userland/Libraries/LibC/signal.cpp is missing an include. In theory, one might use LibCPP to detect things like this automatically, but let's do this one step after another.
2023-01-02Everywhere: Move AK/Debug.h include to using files or removeBen Wiederhake
2023-01-01LibSQL: Add parsing and evaluation of BOOLEAN type literalsTimothy Flynn
This allows you to enter TRUE or FALSE in a SQL statement for BOOLEAN types. Note that this differs from SQLite, which requires entering 1 or 0 for BOOLEANs; having explicit keywords feels a bit more natural.
2022-12-26LibIPC+Everywhere: Change IPC decoders to construct values in-placeTimothy Flynn
Currently, the generated IPC decoders will default-construct the type to be decoded, then pass that value by reference to the concrete decoder. This, of course, requires that the type is default-constructible. This was an issue for decoding Variants, which had to require the first type in the Variant list is Empty, to ensure it is default constructible. Further, this made it possible for values to become uninitialized in user-defined decoders. This patch makes the decoder interface such that the concrete decoders themselves contruct the decoded type upon return from the decoder. To do so, the default decoders in IPC::Decoder had to be moved to the IPC namespace scope, as these decoders are now specializations instead of overloaded methods (C++ requires specializations to be in a namespace scope).
2022-12-23LibSQL: Output a more specific error on failed socket creationYedaya Katsman
This can fail if /run/user/$pid/ doesn't exist, which can happen on wsl without systemd.
2022-12-14LibSQL: Convert string values to a double in a locale-independent mannerTimothy Flynn
This currently uses strtod, which is locale-dependent. Use the locale- independent method added in 65ee9b4134225398f0a5109eb79b0baba98c9cd6.
2022-12-14LibSQL: Support 64-bit integer values and handle overflow errorsTimothy Flynn
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.
2022-12-14LibSQL: Sort the list of SQL error codes alphabeticallyTimothy Flynn
2022-12-14LibSQL: Remove unnecessary values from the ENUMERATE_SQL_TYPES macroTimothy Flynn
Removing the bitmask-esque values from the enumeration necessitates a Heap version bump.
2022-12-14LibSQL: Ungracefully handle database version incompatibilitiesTimothy Flynn
In the long run, this is obviously a bad way to handle version changes to the SQL database files. We will want to migrate old databases to new formats. Until we figure out a good way to do that, wipe old databases so that we don't crash trying to read incompatible data.
2022-12-14Everywhere: Stop shoving things into ::std and mentioning them as suchAli Mohammad Pur
Note that this still keeps the old behaviour of putting things in std by default on serenity so the tools can be happy, but if USING_AK_GLOBALLY is unset, AK behaves like a good citizen and doesn't try to put things in the ::std namespace. std::nothrow_t and its friends get to stay because I'm being told that compilers assume things about them and I can't yeet them into a different namespace...for now.
2022-12-12LibCore: Rename `Stream::read_all` to `read_until_eof`Tim Schumacher
This generally seems like a better name, especially if we somehow also need a better name for "read the entire buffer, but not the entire file" somewhere down the line.
2022-12-11LibSQL: Don't use the SQL socket file path as its descriptorTimothy Flynn
This is just used to key the socket fd for system server takeover. On macOS, this file path has a space in it, which trips up the parsing as it splits on spaces. That parsing should be fixed (probably shouldn't rely on spaces as a delimter), but for now, we can change the key to avoid spaces.
2022-12-11LibSQL: Do not fchmod the SQL socket on macOSTimothy Flynn
Similar to: 9a4ee9aa1a6d947c720b5a550d1d5e81e715ba98.
2022-12-11LibSQL: Support launching a singleton SQLServer instance for Lagom hostsTimothy Flynn
On Serenity, SQLServer is started by SystemServer. But on Lagom, it is manually started by e.g. Ladybird when the application is started, and killed when the application exits. This means every Ladybird process starts its own SQLServer, which defeats the purpose of SQLServer acting as the single process interacting with the database files. This patch will allow SQLClient to start up a single SQLServer instance, first checking if one already exists. If it does exist, SQLClient will simply connect to SQLServer's socket. If it does not exist, SQLClient will launch SQLServer much like SystemServer would (with a local socket file, etc.). The child SQLServer process is double-forked; the grandchild process becomes the SQLServer process, which the middle child process simply exits to "detach" the grandchild process from the SQLClient process.
2022-12-08LibSQL+SQLServer+SQLStudio+sql: Give ID types a distinct nameTimothy Flynn
Makes it clearer what is being stored, especially in future clients that will store a bunch of statement IDs.
2022-12-08LibSQL: Mark SQLClient's constructor as publicTimothy Flynn
Similar to WebContent, this is needed to construct the SQLClient manually in Ladybird.
2022-12-08LibSQL+SQLServer: Generate SQLServer's IPC sources with LibSQL on LagomTimothy Flynn
Exclude SQLServer from Lagom, and instead generate its IPC sources with LibSQL.
2022-12-07LibSQL+SQLServer+sql: Send and parse the correct number of changed rowsTimothy Flynn
The sql REPL had the created/updated rows swapped by mistake. Also make sure SQLServer fills in the correct value depending on the executed command, and that the DELETE command indicates the rows it deleted.
2022-12-07LibSQL+SQLServer+SQLStudio+sql: Send result rows over IPC as SQL::ValueTimothy Flynn
We've been sending the values converted to a string, but now that the Value type is transferrable over IPC, send the values themselves. Any client that wants the value as a string may do so easily, whereas this will allow less trivial clients to avoid string parsing.
2022-12-07LibSQL+SQLServer+SQLStudio+sql: Propagate connection errors immediatelyTimothy Flynn
Currently, when clients connect to SQL server, we inform them of any errors opening the database via an asynchronous IPC. But we already know about these errors before returning from the connect() IPC, so this roundabout propagation is a bit unnecessary. Now if we fail to open the database, we will simply not send back a valid connection ID. Disconnect has a similar story. Rather than disconnecting and invoking an asynchronous IPC to inform the client of the disconnect, make the disconnect() IPC synchronous (because all it does is remove the database from the map of open databases). Further, the only user of this command is the SQL REPL when it wants to connect to a different database, so it makes sense to block it. This did require moving a bit of logic around in the REPL to accommodate this change.
2022-12-07LibSQL+SQLServer+SQLStudio+sql: Allocate per-statement-execution IDsTimothy Flynn
In order to execute a prepared statement multiple times, and track each execution's results, clients will need to be provided an execution ID. This will create a monotonically increasing ID each time a prepared statement is executed for this purpose.
2022-12-07LibSQL+SQLServer+SQLStudio+sql: Use proper types for SQL IPC and IDsTimothy Flynn
When storing IDs and sending values over IPC, this changes SQLServer to: 1. Stop using -1 as a nominal "bad" ID. Store the IDs as unsigned, and use Optional in the one place that the IPC needs to indicate an ID was not allocated. 2. Let LibIPC encode/decode enumerations (SQLErrorCode) on our behalf. 3. Use size_t for array sizes.
2022-12-07LibSQL: Add an IPC encoder/decoder for SQL::ValueTimothy Flynn
This will allow clients to send placeholder values for prepared statements over IPC.
2022-12-07LibSQL: Parse and execute sequential placeholder valuesTimothy Flynn
This partially implements SQLite's bind-parameter expression to support indicating placeholder values in a SQL statement. For example: INSERT INTO table VALUES (42, ?); In the above statement, the '?' identifier is a placeholder. This will allow clients to compile statements a single time while running those statements any number of times with different placeholder values. Further, this will help mitigate SQL injection attacks.
2022-12-07LibSQL: Partially implement the UPDATE commandTimothy Flynn
This implements enough to update rows filtered by a WHERE clause.
2022-12-06Everywhere: Rename to_{string => deprecated_string}() where applicableLinus Groh
This will make it easier to support both string types at the same time while we convert code, and tracking down remaining uses. One big exception is Value::to_string() in LibJS, where the name is dictated by the ToString AO.
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-11-30LibSQL: Partially implement the DELETE commandTimothy Flynn
This implements enough to delete rows filtered by a WHERE clause.
2022-11-30LibSQL: Store a NonnullRefPtr to the table definition in SQL::RowTimothy Flynn
Also return a direct reference to the table from its getter.
2022-11-30LibSQL: Remove unused SQL::Row constructors/methodsTimothy Flynn
2022-11-30LibSQL+SQLServer: Return a NonnullRefPtr from Database::get_tableTimothy Flynn
Database::get_table currently either returns a RefPtr to an existing table, a nullptr if the table doesn't exist, or an Error if some internal error occured. Change this to return a NonnullRefPtr to an exisiting table, or a SQL::Result with any error, including if the table was not found. Callers can then handle that specific error code if they want. Returning a NonnullRefPtr will enable some further cleanup. This had some fallout of needing to change some other methods' return types from AK::ErrorOr to SQL::Result so that TRY may continue to be used.
2022-11-30LibSQL+SQLServer: Return a NonnullRefPtr from Database::get_schemaTimothy Flynn
Database::get_schema currently either returns a RefPtr to an existing schema, a nullptr if the schema doesn't exist, or an Error if some internal error occured. Change this to return a NonnullRefPtr to an exisiting schema, or a SQL::Result with any error, including if the schema was not found. Callers can then handle that specific error code if they want. Returning a NonnullRefPtr will enable some further cleanup. This had some fallout of needing to change some other methods' return types from AK::ErrorOr to SQL::Result so that TRY may continue to be used.
2022-11-30LibSQL: Add missing definition of Value's u32 comparatorTimothy Flynn
This was declared but not defined (nor was it used, but an upcoming commit will be using it).
2022-11-30LibSQL: Don't copy strings when searching for a column's indexTimothy Flynn
Also don't cast the return value to an int.
2022-11-30LibSQL: Rename Row::next_pointer setter to Row::set_next_pointerTimothy Flynn
2022-11-30LibSQL: Immediately commit database modifications (for now)Timothy Flynn
This ensures tables survive the database connection quitting. LibSQL does not have transactional sessions yet, and probably won't for a while, so let's just commit each modification as it comes.
2022-11-30LibSQL: Support BOOLEAN column types in the CREATE TABLE commandTimothy Flynn
The database already supports BOOLEAN, this just hooks up the executor as well.
2022-11-27LibSyntax: Teach each highlighter about it's comment syntaxKyle Lanmon
2022-11-26LibSQL: Fix BTree corruption in `TreeNode::split`Jelle Raaijmakers
After splitting a node, the new node was written to the same pointer as the current node - probably a copy / paste error. This new code requires a `.pointer() -> u32` to exist on the object to be serialized, preventing this issue from happening again. Fixes #15844.
2022-11-26LibSQL: Remove unused method `Heap::has_block`Jelle Raaijmakers
2022-11-26LibSQL: Remove superfluous `VERIFY`s for `Vector` accessingJelle Raaijmakers
Remove some `[]` operators' out-of-bounds checks which are already performed by the underlying `Vector`.
2022-11-06Everywhere: Remove redundant inequality comparison operatorsDaniel Bertalan
C++20 can automatically synthesize `operator!=` from `operator==`, so there is no point in writing such functions by hand if all they do is call through to `operator==`. This fixes a compile error with compilers that implement P2468 (Clang 16 currently). This paper restores the C++17 behavior that if both `T::operator==(U)` and `T::operator!=(U)` exist, `U == T` won't be rewritten in reverse to call `T::operator==(U)`. Removing `!=` operators makes the rewriting possible again. See https://reviews.llvm.org/D134529#3853062
2022-11-01LibSQL: Replace DownPointer copy constructor with move constructorTimothy Flynn
Avoids awkwardly const-casting the "other" DownPointer.
2022-11-01LibSQL: Fix typo in debugging statementTimothy Flynn
Also put new lines between these statements as that was the only way I saw the typo.
2022-11-01LibSQL: Compute byte buffer offsets using size_tTimothy Flynn
Also compute specific offset indices rather than hard-coding them.
2022-11-01LibSQL: Port the backend SQL file to use Core::StreamTimothy Flynn
This allows surrounding IO operations with TRY, making the code much easier to reason about. This also replaces surrounding dbgln_if statements to use "{:hex-dump}" instead of individually writing out bytes.
2022-11-01Everywhere: Mark dependencies of most targets as PRIVATETim Schumacher
Otherwise, we end up propagating those dependencies into targets that link against that library, which creates unnecessary link-time dependencies. Also included are changes to readd now missing dependencies to tools that actually need them.
2022-10-16CMake+Userland: Use CMakeLists from Userland to build Lagom LibrariesAndrew Kaster
Also do this for Shell. This greatly simplifies the CMakeLists in Lagom, replacing many glob patterns with a big list of libraries. There are still a few special libraries that need some help to conform to the pattern, like LibELF and LibWebView. It also lets us remove essentially all of the Serenity or Lagom binary directory detection logic from code generators, as now both projects directories enter the generator logic from the same place.