summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibSQL
AgeCommit message (Collapse)Author
2022-10-03SystemServer+LoginServer+Userland: Switch to sid-based socketsPeter Elliott
This commit does three things atomically: - switch over Core::Account+SystemServer+LoginServer to sid based socket names. - change socket names with %uid to %sid. - add/update necessary pledges and unveils. Userland: Switch over servers to sid based sockets Userland: Properly pledge and unveil for sid based sockets
2022-08-14Base: Launch SQLServer at session start-upLucas CHOLLET
2022-08-14LibCore+LibIPC: Recognise %uid in pathLucas CHOLLET
This patch allows to insert "%uid" in `IPC_CLIENT_CONNECTION` declaration and in SystemServer's ini files. This pattern is replaced then replaced by the UID of the owner of the service. It opens a path for seamlessly managed, per-user portal.
2022-07-12Everywhere: Replace single-char StringView op. arguments with charssin-ack
This prevents us from needing a sv suffix, and potentially reduces the need to run generic code for a single character (as contains, starts_with, ends_with etc. for a char will be just a length and equality check). No functional changes.
2022-07-12Everywhere: Add sv suffix to strings relying on StringView(char const*)sin-ack
Each of these strings would previously rely on StringView's char const* constructor overload, which would call __builtin_strlen on the string. Since we now have operator ""sv, we can replace these with much simpler versions. This opens the door to being able to remove StringView(char const*). No functional changes.
2022-07-12Everywhere: Split Error::from_string_literal and Error::from_string_viewsin-ack
Error::from_string_literal now takes direct char const*s, while Error::from_string_view does what Error::from_string_literal used to do: taking StringViews. This change will remove the need to insert `sv` after error strings when returning string literal errors once StringView(char const*) is removed. No functional changes.
2022-06-13AK/ByteBuffer+Everywhere: Handle errors in ByteBuffer::slice()Matthias Zimmerman
2022-04-01Everywhere: Run clang-formatIdan Horowitz
2022-03-18Userland: Change static const variables to static constexprLenny Maiorani
`static const` variables can be computed and initialized at run-time during initialization or the first time a function is called. Change them to `static constexpr` to ensure they are computed at compile-time. This allows some removal of `strlen` because the length of the `StringView` can be used which is pre-computed at compile-time.
2022-03-13Libraries: Use default constructors/destructors in LibSQLLenny Maiorani
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules "The compiler is more likely to get the default semantics right and you cannot implement these functions better than the compiler."
2022-02-25Userland: Rename IPC::ServerConnection=>IPC::ConnectionToServerItamar
This was done with CLion's automatic rename feature.
2022-02-13LibSQL: Convert binary SQL operations to be fallibleTimothy Flynn
Now that expression evaluation can use TRY, we can allow binary operator methods to fail as well. This also fixes a few instances of converting a Value to a double when we meant to convert to an integer.
2022-02-13LibSQL: Short-circuit single-element tuple comparisonsTimothy Flynn
If a tuple has a single value, perform a comparison using that singular value. This allows, for example, comparisons of the form "(1) < 4", where (1) is a single element tuple.
2022-02-13LibSQL: Implement converting float and tuple values to a booleanTimothy Flynn
2022-02-13LibSQL: Use absolute value when comparing against floating point epsilonTimothy Flynn
Otherwise, any value that is less than another value would be considered about equal by mistake.
2022-02-13LibSQL: Return a not-yet-implemented error for unimplemented expressionsTimothy Flynn
Easier to debug than returning a NULL value.
2022-02-10LibSQL: Return unimplemented errors from unimplemented MATCH expressionsTimothy Flynn
A bit friendlier than crashing the entire SQLService process.
2022-02-10LibSQL: Remove the now-unused ExecutionContext::result objectTimothy Flynn
The INSERT and SELECT statements set up this object for any expression evaluation to indicate errors. This is no longer needed.
2022-02-10LibSQL: Convert SQL expression evaluation to use ResultOrTimothy Flynn
Instead of setting an error in the execution context, we can directly return that error or the successful value. This lets all callers, who were already TRY-capable, simply TRY the expression evaluation.
2022-02-10LibSQL+SQLServer: Introduce and use ResultOr<ValueType>Timothy Flynn
The result of a SQL statement execution is either: 1. An error. 2. The list of rows inserted, deleted, selected, etc. (2) is currently represented by a combination of the Result class and the ResultSet list it holds. This worked okay, but issues start to arise when trying to use Result in non-statement contexts (for example, when introducing Result to SQL expression execution). What we really need is for Result to be a thin wrapper that represents both (1) and (2), and to not have any explicit members like a ResultSet. So this commit removes ResultSet from Result, and introduces ResultOr, which is just an alias for AK::ErrorOrr. Statement execution now returns ResultOr<ResultSet> instead of Result. This further opens the door for expression execution to return ResultOr<Value> in the future. Lastly, this moves some other context held by Result over to ResultSet. This includes the row count (which is really just the size of ResultSet) and the command for which the result is for.
2022-02-10LibSQL: Do not crash when SELECTing from an empty tableTimothy Flynn
The crash was caused by getting the first element of an empty vector.
2022-02-10LibSQL+SQLServer: Move LibSQL/SQLResult.[h,cpp] to LibSQL/Result.[h,cpp]Timothy Flynn
Rename the file to match the new class name.
2022-02-10LibSQL: Remove now-unused SQLResult classTimothy Flynn
2022-02-10LibSQL+SQLServer: Return the new Result class from statement executionsTimothy Flynn
We can now TRY anything that returns a SQL::Result or an AK::Error.
2022-02-10LibSQL: Add a new Result class to replace SQLResultTimothy Flynn
The existing SQLResult class predates our TRY semantics. As a result, in the AST execution methods, there is a lot of is_error checking on values that could instead be wrapped with TRY. This new class will allow such semantics, and is also stack allocated (no need to be a RefPtr). It is heavily based on LibJS's completion class.
2022-02-10LibSQL: Do not return copies of vectors from table/index definitionsTimothy Flynn
2022-02-09LibSQL: Update list of expected statementsDaniel van Gerpen
Add an entry for the DESCRIBE TABLE statement and add an Oxford comma.
2022-02-05LibSQL: Implement a DESCRIBE TABLE statementMahmoud Mandour
This statement (for now) outputs the name and types of the different attributes in a table. It's not standard SQL but all DBMSs that I know of implement a sort of statement for such functionality. Since the output of DESCRIBE TABLE is just a relation, an internal schema, `master` was created and a table definition for DESCRIBE into it. The table definition and the master schema are not accessible by the user.
2022-02-05LibSQL: Avoid signed arithmetic in `IntegerImpl::compare`Mahmoud Mandour
2022-01-31Everywhere: Update copyrights with my new serenityos.org e-mail :^)Timothy Flynn
2022-01-24Everywhere: Convert ByteBuffer factory methods from Optional -> ErrorOrSam Atkins
Apologies for the enormous commit, but I don't see a way to split this up nicely. In the vast majority of cases it's a simple change. A few extra places can use TRY instead of manual error checking though. :^)
2022-01-23LibSQL: Add simple REGEXP matchmnlrsn
The implementation of LIKE uses regexes under the hood, and this implementation of REGEXP takes the same approach. It employs PosixExtended from LibRegex with case insensitive and Unicode flags set. The implementation of LIKE is based on SQLlite specs, but SQLlite does not offer directions for a built-in regex functionality, so this one uses LibRegex.
2022-01-16LibSQL: Introduce SELECT ... LIMIT xxx OFFSET yyyJan de Visser
What it says on the tin.
2022-01-16LibSQL+SQLServer: Implement first cut of SELECT ... ORDER BY fooJan de Visser
Ordering is done by replacing the straight Vector holding the query result in the SQLResult object with a dedicated Vector subclass that inserts result rows according to their sort key using a binary search. This is done in the ResultSet class. There are limitations: - "SELECT ... ORDER BY 1" (or 2 or 3 etc) is supposed to sort by the n-th result column. This doesn't work yet - "SELECT ... column-expression alias ... ORDER BY alias" is supposed to sort by the column with the given alias. This doesn't work yet What does work however is something like ```SELECT foo FROM bar SORT BY quux``` i.e. sorted by a column not in the result set. Once functions are supported it should be possible to sort by random functions.
2022-01-15LibCore+LibIPC+Everywhere: Return Stream::LocalSocket from LocalServersin-ack
This change unfortunately cannot be atomically made without a single commit changing everything. Most of the important changes are in LibIPC/Connection.cpp, LibIPC/ServerConnection.cpp and LibCore/LocalServer.cpp. The notable changes are: - IPCCompiler now generates the decode and decode_message functions such that they take a Core::Stream::LocalSocket instead of the socket fd. - IPC::Decoder now uses the receive_fd method of LocalSocket instead of doing system calls directly on the fd. - IPC::ConnectionBase and related classes now use the Stream API functions. - IPC::ServerConnection no longer constructs the socket itself; instead, a convenience macro, IPC_CLIENT_CONNECTION, is used in place of C_OBJECT and will generate a static try_create factory function for the ServerConnection subclass. The subclass is now responsible for passing the socket constructed in this function to its ServerConnection base; the socket is passed as the first argument to the constructor (as a NonnullOwnPtr<Core::Stream::LocalServer>) before any other arguments. - The functionality regarding taking over sockets from SystemServer has been moved to LibIPC/SystemServerTakeover.cpp. The Core::LocalSocket implementation of this functionality hasn't been deleted due to my intention of removing this class in the near future and to reduce noise on this (already quite noisy) PR.
2022-01-07LibSQL: Implement LIKE SQL expressionsGuilherme Gonçalves
2022-01-07LibSQL: Properly parse ESCAPE expressionsGuilherme Gonçalves
The evaluation order of method parameters is unspecified in C++, and so we couldn't rely on parse_statement() being called before parse_escape() when building a MatchExpression. With this patch, we explicitly parse what we need in the right order, before building the MatchExpression object.
2022-01-01LibSQL: Avoid unnecessary copies in HeapBen Wiederhake
2021-12-11Everywhere: Fix -Winconsistent-missing-override warnings from ClangDaniel Bertalan
This option is already enabled when building Lagom, so let's enable it for the main build too. We will no longer be surprised by Lagom Clang CI builds failing while everything compiles locally. Furthermore, the stronger `-Wsuggest-override` warning is enabled in this commit, which enforces the use of the `override` keyword in all classes, not just those which already have some methods marked as `override`. This works with both GCC and Clang.
2021-12-08LibSQL: Avoid implicitly copying ByteBufferBen Wiederhake
2021-12-04LibSQL: Gracefully react to unimplemented valid SQLJan de Visser
Fixes a crash that was caused by a syntax error which is difficult to catch by the parser: usually identifiers are accepted in column lists, but they are not in a list of column values to be inserted in an INSERT. Fixed this by putting in a heuristic check; we probably need a better way to do this. Included tests for this case. Also introduced a new SQL Error code, `NotYetImplemented`, and return that instead of crashing when encountering unimplemented SQL.
2021-12-04LibSQL: Improve error handlingJan de Visser
The handling of filesystem level errors was basically non-existing or consisting of `VERIFY_NOT_REACHED` assertions. Addressed this by * Adding `open` methods to `Heap` and `Database` which return errors. * Changing the interface of methods of these classes and clients downstream to propagate these errors. The constructors of `Heap` and `Database` don't open the underlying filesystem file anymore. The SQL statement handlers return an `SQLErrorCode::InternalError` error code if an error comes back from the lower levels. Note that some of these errors are things like duplicate index entry errors that should be caught before the SQL layer attempts to actually update the database. Added tests to catch attempts to open weird or non-existent files as databases. Finally, in between me writing this patch and submitting the PR the AK::Result<Foo, Bar> template got deprecated in favour of ErrorOr<Foo>. This resulted in more busywork.
2021-11-10AK: Make ByteBuffer::try_* functions return ErrorOr<void>Andreas Kling
Same as Vector, ByteBuffer now also signals allocation failure by returning an ENOMEM Error instead of a bool, allowing us to use the TRY() and MUST() patterns.
2021-11-10LibSQL: Implement table joinsJan de Visser
This patch introduces table joins. It uses a pretty dumb algorithm- starting with a singleton '__unity__' row consisting of a single boolean value, a cartesian product of all tables in the 'FROM' clause is built. This cartesian product is then filtered through the 'WHERE' clause, again without any smarts just using brute force. This patch required a bunch of busy work to allow for example the ColumnNameExpression having to deal with multiple tables potentially having columns with the same name.
2021-11-10LibSQL: Relax assignment rules for Null ValuesJan de Visser
It should be possible to assign a Value of any type to a Value which currently is Null.
2021-11-10LibSQL: Add current statement to the ExecutionContextJan de Visser
Because SQL is the craptastic language that it is, sometimes expressions need to know details about the calling statement. For example the tables in the 'FROM' clause may be needed to determine which columns are referenced in 'WHERE' expressions. So the current statement is added to the ExecutionContext and a new 'execute' overload on Statement is created which takes the Database and the Statement and builds an ExecutionContaxt from those.
2021-11-10LibSQL: Add 'schema' and 'table' to TupleElementDescriptorJan de Visser
These are needed to distinguish columns from different tables with the same column name in one and the same (joined) Tuple. Not quite happy yet with this API; I think some sort of hierarchical structure would be better but we'll burn that bridge when we get there :^)
2021-11-10LibSQL: Add the 'extend' operation to the Tuple classJan de Visser
Tuple::extend is similar to the Vector method of the same name; it concatenates a second Tuple to the current one.
2021-11-08LibSQL: Replace Result<T, E> use with ErrorOr<T>Andreas Kling
2021-11-08LibCore: Use ErrorOr<T> for Core::File::open()Andreas Kling