Commit Graph

247 Commits

Author SHA1 Message Date
Timothy Flynn
bf50881e61 LibCore+LibSQL+LibWebView: Move launching a singleton process to LibCore
This just moves the code to launch a single process such as SQLServer to
LibCore. This will allow re-using this feature for other processes, and
will allow moving the launching of SQLServer to Ladybird.
2024-04-22 14:46:10 -06:00
Timothy Flynn
c23060e21b Userland: Avoid some now-unneeded explicit conversions to Bytes 2024-04-04 11:23:21 +02:00
Sam Atkins
c6b9ce22ef LibSQL: Use Core::Environment instead of Core::System::*env() 2024-02-27 08:33:48 +00:00
Andrew Kaster
0a55749a39 Ladybird+Userland: Use ByteString for candidate server paths
We've adopted a stance that paths should be ByteStrings rather than
UTF-8 strings, so apply that to the Ladybird helpers.
2024-02-26 13:16:27 -07:00
Timothy Flynn
30fae8fa1d LibSQL: Allow constructing SQL values from a String
LibSQL still uses ByteString internally for storage, but to help outside
application port to String, add helpers to construct values from String
and to convert a value to a String.
2024-01-26 20:22:39 +01:00
Sergey Bugaev
1205f29a40 LibSQL: Don't try to fchmod() socket on GNU/Hurd
Because of the way sockets are implemented, a local socket object inside
pflocal has little to do with the filesystem node that has an ifsock
translator sitting on it; and the latter doesn't even exist until you
bind() the socket.

So it's not possible to set the socket's mode using Unix-level APIs
(other than by temporarily changing umask). It's still possible to do
this with Mach-level APIs, essentially doing the same thing as glibc's
bind() implementation does, but supplying the desired mode instead of
0666, but let's not go there.
2024-01-14 14:56:33 -07:00
Timothy Flynn
5c5cbeb491 LibSQL+LibWebView: Do not manually serialize time stamps in CookieJar
LibSQL supports serializing time stamps as of commit
effcd080ca.

However, that commit serializes the timestamps as milliseconds, whereas
the CookieJar was serializing them as seconds. In retrospect, these
should have been updated in unison, along with the SQL heap version (as
this is a serialization change that affects the file format). So this
patch also updates the version, as this is not a backwards compatible
change.
2024-01-10 23:26:40 +01:00
Timothy Flynn
7a912ca891 LibSQL: Reset the highest written block during the zeroth block init
Otherwise, when changing the SQL heap version, the value from the now-
stale heap file will continue to be used.
2024-01-10 23:26:40 +01:00
Timothy Flynn
cd0e07f6a4 LibSQL: Add a helper to convert a SQL::Value to a UnixDateTime
Support for constructing a Value from a UnixDateTime was added in commit
effcd080ca.

That constructor just stores the value as the number of milliseconds
since epoch. There's no way for outside users to know this, so this adds
a helper to retrieve the value as a UnixDateTime and let SQL::Value be
the source of truth for how the value is encoded/decoded.
2024-01-10 23:26:40 +01:00
Timothy Flynn
1205d39fc3 LibSQL+SQLServer: Inform SQLServer when the client has processed results
The architecture of SQLServer is currently such that it sends results
over IPC one row at a time. After the rows are exhausted, it sends a
completion IPC. However, it does not wait for the client to finish
processing a row before sending another row or the completion signal.

This can result in clients hanging if the completion comes in while a
row is being processed. At least in the case of WebView::Database, the
result is that the completion signal is dropped, and the browser then
hangs forever waiting for that signal (after it finishes processing the
row).

This patch makes SQLServer asynchronously wait for the client to tell it
that the row has been processed and the next row (or completion) may be
sent. We repurpose the `m_ongoing_executions` in SQLStatement for this
purpose (this member was oddly being written to, but otherwise unused).
2024-01-10 23:26:40 +01:00
Shannon Booth
e2e7c4d574 Everywhere: Use to_number<T> instead of to_{int,uint,float,double}
In a bunch of cases, this actually ends up simplifying the code as
to_number will handle something such as:

```
Optional<I> opt;
if constexpr (IsSigned<I>)
    opt = view.to_int<I>();
else
    opt = view.to_uint<I>();
```

For us.

The main goal here however is to have a single generic number conversion
API between all of the String classes.
2023-12-23 20:41:07 +01:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Ali Mohammad Pur
aeee98b3a1 AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
2023-10-13 18:33:21 +03:30
Ali Mohammad Pur
ba4db899d4 LibSyntax+Userland: Make LibSyntax not depend on LibGUI
This moves some stuff around to make LibGUI depend on LibSyntax instead
of the other way around, as not every application that wishes to do
syntax highlighting is necessarily a LibGUI (or even a GUI) application.
2023-08-29 07:57:39 -04:00
Timothy Flynn
3ea4c56d04 LibSQL: Remove Core::EventReceiver parent from SQL::Relation
This relationship was only used to provide a name, factory methods, and
parent-child relationships for the relations.
2023-08-07 14:38:38 -04:00
Timothy Flynn
5ad78cab8d LibSQL: Remove Core::EventReceiver parent from SQL::Index
This relationship was only used to provide factory methods for the index
(and its BTree child).
2023-08-07 14:38:38 -04:00
Timothy Flynn
1b40bf9783 LibSQL: Remove unused HashIndex and related classes
The features provided by these classes should be used eventually, but so
far we've been maintaining these classes for over 2 years without any
actual use. We can restore them when it comes time to actually use them.
2023-08-07 14:38:38 -04:00
Timothy Flynn
1151ba333a LibSQL+SQLServer: Remove Core::EventReceiver parent from SQL::Database
This relationship was only used to provide factory methods for the
database.
2023-08-07 14:38:38 -04:00
Timothy Flynn
4a04438e43 LibSQL: Remove Core::EventReceiver parent from SQL::Heap
This relationship was only used to provide a name and factory methods
for the heap.
2023-08-07 14:38:38 -04:00
Andreas Kling
ddbe6bd7b4 Userland: Rename Core::Object to Core::EventReceiver
This is a more precise description of what this class actually does.
2023-08-06 20:39:51 +02:00
Timothy Flynn
c911781c21 Everywhere: Remove needless trailing semi-colons after functions
This is a new option in clang-format-16.
2023-07-08 10:32:56 +01:00
Ben Wiederhake
0184fc5e43 Everywhere: Use AK_MAKE_DEFAULT_MOVABLE to avoid mistakes 2023-06-18 08:47:51 +01:00
Jelle Raaijmakers
70ca295404 LibSQL+SQLServer: Do not re-open databases
Both `Database` and `Heap` were allowed to be opened twice. Prevent
this, and change SQLServer to only open databases that are not already
opened.

This fixes a Ladybird crash where opening the application twice would
erroneously duplicate free heap block indices.
2023-06-13 16:33:42 -04:00
Jelle Raaijmakers
c05e08decb LibSQL: Prevent writing to free heap blocks
Each block index should have been requested before a write happens to
it. If this is not the case, return an error.
2023-06-13 16:33:42 -04:00
Jelle Raaijmakers
d3335d6ef8 LibSQL: Standardize some debugging statements in Heap 2023-06-13 16:33:42 -04:00
Jelle Raaijmakers
69e09fed39 LibSQL: Free heap storage when deleting rows 2023-05-25 06:19:16 -07:00
Jelle Raaijmakers
c58c87d7ef LibSQL: Implement freeing heap storage
This allows us to free entire chains of blocks in one go.
2023-05-25 06:19:16 -07:00
Jelle Raaijmakers
d7bbb8d64a LibSQL: Find free blocks when opening a database file
The free block list now gets populated on opening a database file.
Ideally we persist this list inside the heap itself, but for now this
prevents excessive heap growth.
2023-05-25 06:19:16 -07:00
Jelle Raaijmakers
a6abc1697f LibSQL: Keep track of free heap blocks when trimming storage
When overwriting existing heap storage that requires fewer blocks, make
sure to free all remaining blocks so they can be reused in the future.
2023-05-25 06:19:16 -07:00
Jelle Raaijmakers
c5ebc4bb40 LibSQL: Reuse heap blocks when overwriting storage
Previously, only the first block in a chain of blocks would be
overwritten while all subsequent blocks would be appended to the heap.
Now we make sure to reuse all existing blocks in the chain.
2023-05-25 06:19:16 -07:00
kleines Filmröllchen
effcd080ca Userland: Remove remaining users of Duration::now_realtime()
This is a clear sign that they want to use a UnixDateTime instead.

This also adds support for placing durations and date times into SQL
databases via their millisecond offset to UTC.
2023-05-24 23:18:07 +02:00
Lucas CHOLLET
8c34959b53 AK: Add the Input word to input-only buffered streams
This concerns both `BufferedSeekable` and `BufferedFile`.
2023-05-09 11:18:46 +02:00
Ben Wiederhake
715f4a8d7e LibSQL: Remove unused IODevice include 2023-05-07 14:04:55 +02:00
Tim Ledbetter
896d1e4f42 LibSQL: Handle statements with malformed exists expressions correctly
Previously, statements containing malformed exists expressions such as:

`INSERT INTO t(a) VALUES (SELECT 1)`;

could cause the parser to crash. The parser will now return an error
message instead.
2023-04-25 08:32:21 -04:00
Jelle Raaijmakers
71c98546b8 LibSQL: Add a note to Serializer about m_heap 2023-04-23 18:08:17 -04:00
Jelle Raaijmakers
fdac8331cc LibSQL: Use Block::Index everywhere; rename pointer to block_index
No functional changes.
2023-04-23 18:08:17 -04:00
Jelle Raaijmakers
6601ff9d65 LibSQL: Redesign heap storage to support arbitrary amounts of data
Previously, `Heap` would store serialized data in blocks of 1024 bytes
regardless of the actual length. Data longer than 1024 bytes was
silently truncated causing database corruption.

This changes the heap storage to prefix every block with two new fields:
the total data size in bytes, and the next block to retrieve if the data
is longer than what can be stored inside a single block. By chaining
blocks together, we can store arbitrary amounts of data without needing
to change anything of the logic in the rest of LibSQL.

As part of these changes, the "free list" is also removed from the heap
awaiting an actual implementation: it was never used.

Note that this bumps the database version from 3 to 4, and as such
invalidates (deletes) any database opened with LibSQL that is not
version 4.
2023-04-23 18:08:17 -04:00
Jelle Raaijmakers
194f846f12 LibSQL: Rename Heap constants to match our code style
No functional changes. The constants are moved to constexpr variables
inside `Heap`.
2023-04-23 18:08:17 -04:00
Jelle Raaijmakers
fcd35e824c LibSQL: Remove unused Tuple::is_compatible 2023-04-23 18:08:17 -04:00
Jelle Raaijmakers
a99c1297e0 LibSQL: Clean up code style and remove unused includes
No functional changes.
2023-04-23 18:08:17 -04:00
Jelle Raaijmakers
8992ff5aeb LibSQL: Remove and update VERIFYs
We are performing a lot of checks on pointers that are performed again
immediately afterwards because of a dereference. This removes the
redundant `VERIFY`s and simplifies a couple others.
2023-04-23 18:08:17 -04:00
Ben Wiederhake
560133a0c6 Everywhere: Remove unused DeprecatedString includes 2023-04-09 22:00:54 +02:00
Andrew Kaster
afb3a4a030 LibSQL: Block signals while forking SQLServer in Lagom
When debugging in Xcode, the waitpid() for the initial forked process
would always return EINTR or ECHILD. Work around this by blocking all
signals until we're ready to wait for the initial child.
2023-03-28 09:18:50 +01:00
Cameron Youell
1d24f394c6 Everywhere: Use LibFileSystem where trivial 2023-03-21 19:03:21 +00:00
Sam Atkins
406a7ea577 LibSyntax+Libraries: Replace TextStyle with Gfx::TextAttributes
Rather than creating a TextStyle struct, and then copying its fields
over to a TextAttributes, let's just create a TextAttributes to start
with. This also simplifies the syntax highlighting code by letting us
define underlines along with the other text styling.
2023-03-15 14:55:49 +01:00
Tim Schumacher
ae51c1821c Everywhere: Remove unintentional partial stream reads and writes 2023-03-13 15:16:20 +00:00
Tim Schumacher
26516ee160 LibSQL: Always read and write entire heap blocks 2023-03-13 15:16:20 +00:00
Tim Schumacher
d5871f5717 AK: Rename Stream::{read,write} to Stream::{read_some,write_some}
Similar to POSIX read, the basic read and write functions of AK::Stream
do not have a lower limit of how much data they read or write (apart
from "none at all").

Rename the functions to "read some [data]" and "write some [data]" (with
"data" being omitted, since everything here is reading and writing data)
to make them sufficiently distinct from the functions that ensure to
use the entire buffer (which should be the go-to function for most
usages).

No functional changes, just a lot of new FIXMEs.
2023-03-13 15:16:20 +00:00
Andreas Kling
a504ac3e2a Everywhere: Rename equals_ignoring_case => equals_ignoring_ascii_case
Let's make it clear that these functions deal with ASCII case only.
2023-03-10 13:15:44 +01:00
Andreas Kling
21db2b7b90 Everywhere: Remove NonnullOwnPtr.h includes 2023-03-06 23:46:35 +01:00