Commit Graph

59 Commits

Author SHA1 Message Date
Pekka Enberg
16bc28b0af sqlite3-parser: Change debug logging to trace level
SQL scanner at debug level spams the logs pretty hard when debugging...
2025-04-03 07:46:07 +03:00
PThorpe92
9c8083231c Implement create virtual table and VUpdate opcode 2025-02-17 20:44:44 -05:00
Glauber Costa
fbe439f6c2 Implement the legacy_file_format pragma
easy implementation, sqlite claims it is a noop now

"This pragma no longer functions. It has become a no-op. The capabilities
formerly provided by PRAGMA legacy_file_format are now available using
the SQLITE_DBCONFIG_LEGACY_FILE_FORMAT option to the sqlite3_db_config()
C-language interface."
2025-02-14 09:50:29 -05:00
Pekka Enberg
ac54c35f92 Switch to workspace dependencies
...makes it easier to specify a version, which is needed for `cargo publish`.
2025-02-12 17:28:04 +02:00
Pekka Enberg
d221f158cc Merge 'Add read implementation of user_version pragma with ReadCookie opcode' from Jonathan Webb
Just a bare bones implementation of ReadCookie and support for the
user_version pragma

Closes #909
2025-02-10 12:12:15 +02:00
Aarni Koskela
eaea02c567 Fix a handful of typos 2025-02-09 18:08:29 +02:00
Jussi Saurio
a8685c8086 sqlite3-parser: box the Expr in Vacuum 2025-02-09 14:24:55 +02:00
Jussi Saurio
9b0997a60d sqlite3-parser: separate boxed CreateVirtualTable struct 2025-02-09 14:24:55 +02:00
Jussi Saurio
36a3cb1d5e sqlite3-parser: box AlterTable 2025-02-09 14:11:34 +02:00
Jussi Saurio
72a055e5fe sqlite3-parser: box Pragma 2025-02-09 13:10:52 +02:00
Jussi Saurio
23c4106433 sqlite3-parser: separate boxed Insert struct 2025-02-09 13:10:21 +02:00
Jussi Saurio
f0d7d82e1d sqlite3-parser: Box the Expr in Detach 2025-02-09 13:10:21 +02:00
Jussi Saurio
32887518ce sqlite3-parser: separate boxed Delete struct 2025-02-09 13:10:21 +02:00
Jussi Saurio
40a8dc14cd sqlite3-parser: separate boxed SelectInner struct 2025-02-09 12:54:30 +02:00
Jussi Saurio
f75aca67bb sqlite3-parser: separate boxed TriggerCmd struct variants 2025-02-09 12:53:12 +02:00
Jussi Saurio
af920a317c sqlite3-parser: separate boxed Update struct 2025-02-09 12:53:12 +02:00
Jussi Saurio
575b484740 sqlite3-parser: separate boxed CreateTrigger struct 2025-02-09 12:50:00 +02:00
Jussi Saurio
358fda2ec7 sqlite3-parser: box the create table body 2025-02-09 12:42:53 +02:00
Jussi Saurio
d177f6195b sqlite3-parser: box big members of createindex 2025-02-09 12:34:53 +02:00
Jussi Saurio
4faadd86b0 sqlite3-parser: box the InsertBody 2025-02-08 18:10:26 +02:00
Jussi Saurio
781aa3b5d6 sqlite3-parser: box the having clause in GroupBy 2025-02-08 18:10:26 +02:00
Jussi Saurio
2a82091cb3 sqlite3-parser: box the where clause in Update 2025-02-08 18:10:26 +02:00
Jussi Saurio
7426204204 sqlite3-parser: box Following and Preceding in FrameBound 2025-02-08 18:10:26 +02:00
Jussi Saurio
ac7f9d67b7 sqlite3-parser: box large members of Upsert 2025-02-08 18:10:25 +02:00
Jussi Saurio
f341474fee sqlite3-parser: box large members of CreateTrigger 2025-02-08 18:10:25 +02:00
Jussi Saurio
0dba39b025 sqlite3-parser: box everything in Attach 2025-02-08 18:10:25 +02:00
Jussi Saurio
670dac5939 sqlite3-parser: box the where clause in Delete 2025-02-08 18:10:25 +02:00
Jonathan Webb
98e9d33478 Add read implementation of user_version pragma with ReadCookie opcode 2025-02-07 09:23:48 -05:00
krishvishal
a88a5353a3 Add unit test for checking SELECT FROM foo;
returns only one error and stops parsing.
2025-02-04 04:51:38 +05:30
krishvishal
2faaa9f719 Add fix for paser not stopping at first error encounter.
Fix is to track the state of encountering error in the `Parser` struct and set it to true whereever/whenever
we encounter an error. And the beginning of the next() we return `Ok(None)` to signal to `FallibleIterator` that we should stop parsing.

Fixes https://github.com/tursodatabase/limbo/issues/865
2025-02-04 04:45:34 +05:30
Glauber Costa
a3387cfd5f implement the pragma page_count
To do that, we also have to implement the vdbe opcode Pagecount.
2025-02-01 19:39:46 -05:00
Glauber Costa
b37317f68b avoid allocations during pragma_list
If we keep the pragma list sorted when declaring it, we can avoid
a vector allocation when printing the pragma_list.
2025-01-31 11:35:51 -05:00
Glauber Costa
62efbde661 use strum package to simplify PragmaName enum management
The pragma list will only grow. The strum crate can be used to:
* automatically convert to string from enum
* automatically convert to enum from string
* implement an iterator over all elements of the enum
2025-01-31 06:44:56 -05:00
Glauber Costa
016b815b59 implement pragma table_info
Both () and = variants covered. It is important to make sure that
the transaction is a read transaction, so we cannot hide all that logic
inside update_pragma, and have to make our decision before that.
2025-01-30 20:00:20 -05:00
Jussi Saurio
a26fc1619a Merge 'Fix select X'1'; causes limbo to go in infinite loop' from Krishna Vishal
Closes https://github.com/tursodatabase/limbo/issues/730.
Fixed `blog_literal` function to make it return `TK_ILLEGAL` token which
in turn now causes parser to stop and return `UnrecognizedTokenError`.
Added `TK_ILLEGAL` to `TokenType` Enum.
Behavior now:
```sql
SELECT X'1';  -- Odd number of hex digits -> TK_ILLEGAL -> unrecognized token error

  × unrecognized token at (1, 12)
   ╭────
 1 │ SELECT X'1';
   ·        ▲
   ·        ╰── here
   ╰────

SELECT X'AB'; -- Valid blob -> TK_BLOB -> parses successfully
�
SELECT X'G1'; -- Invalid hex digit -> TK_ILLEGAL -> unrecognized token error

  × unrecognized token at (1, 13)
   ╭────
 1 │ SELECT X'G1';
   ·        ▲
   ·        ╰── here
   ╰────

```

Reviewed-by: Jussi Saurio (@jussisaurio)

Closes #736
2025-01-21 11:32:10 +02:00
Krishna Vishal
b43c1544d4 Tokenizer::split() function returns TK_ILLEGAL instead of Error. 2025-01-20 19:37:15 +05:30
Krishna Vishal
04fd5a40d6 Finalize the parser in the case of Error while running queries. This resets the parser stack and prevents triggering the assertion and thereby panic.
Closes https://github.com/tursodatabase/limbo/issues/742
2025-01-20 16:10:35 +05:30
sonhmai
66d6291f32 add scaffolding for supporting wal checkpoint 2025-01-20 08:34:13 +07:00
Krishna Vishal
ee88781c2a chore: cargo fmt 2025-01-19 06:23:19 +05:30
Krishna Vishal
5aee588078 Fixed blog_literal function to make it return UnrecognisedToken error.
Added `TK_ILLEGAL` to `TokenType` Enum
2025-01-19 06:11:45 +05:30
Jorge Hermo
f5616f5ddb Update vendored/sqlite3-parser/Cargo.toml 2025-01-15 23:50:28 +01:00
Jorge Hermo
15f7928551 chore: enable all features in clippy ci and fix more clippy lints 2025-01-15 23:23:12 +01:00
Levy A.
9b8722f38e refactor: more well rounded implementation
`?0` parameters are now handled by the parser.
2025-01-15 16:53:26 -03:00
Kould
5305a9d0fd feat: support keyword rowid 2025-01-14 22:41:40 +08:00
Pekka Enberg
3bfc4ce820 sqlite3-parser: Use trace-level logging for syntax errors
Spamming the error logs for syntax errors is not nice for a library...
2025-01-05 21:12:01 +02:00
Pekka Enberg
2cd3c47691 Merge 'Nicer parse errors using miette' from Samyak Sarnayak
I noticed that the parse errors were a bit hard to read - only the
nearest token and the line/col offsets were printed.
I made a first attempt at improving the errors using
[miette](https://github.com/zkat/miette).
- Added derive for `miette::Diagnostic` to both the parser's error type
and LimboError.
- Added miette dependency to both sqlite3_parser and core. The `fancy`
feature is only enabled for the CLI. So the overhead on the libraries
(core, parser) should be minimal.
Some future improvements that can be made further:
- Add spans to AST nodes so that errors can better point to the correct
token. See upstream issue: https://github.com/gwenn/lemon-rs/issues/33
- Construct more errors with offset information. I noticed that most
parser errors are constructed with `None` as the offset.
- The messages are a bit redundant (example "syntax error at (1, 6)").
This can improved.
Comparisons.
Before:
```
❯ cargo run --package limbo --bin limbo database.db --output-mode pretty
...
limbo> selet * from a;
[2025-01-05T11:22:55Z ERROR sqlite3Parser] near "Token([115, 101, 108, 101, 116])": syntax error
Parse error: near "selet": syntax error at (1, 6)
```
<img width="969" alt="image" src="https://github.com/user-
attachments/assets/82651a77-f5ac-4eee-b208-88c6ea7fc9b7" />
After:
```
❯ cargo run --package limbo --bin limbo database.db --output-mode pretty
...
limbo> selet * from a;
[2025-01-05T12:25:52Z ERROR sqlite3Parser] near "Token([115, 101, 108, 101, 116])": syntax error

  × near "selet": syntax error at (1, 6)
   ╭────
 1 │ selet * from a
   ·     ▲
   ·     ╰── syntax error
   ╰────

```
<img width="980" alt="image" src="https://github.com/user-
attachments/assets/747a90e5-5085-41f9-b0fe-25864179ca35" />

Closes #618
2025-01-05 21:09:52 +02:00
Samyak S Sarnayak
c09a0bcbf3 Nicer parse errors using miette
I noticed that the parse errors were a bit hard to read - only the nearest token and the line/col offsets were printed.

I made a first attempt at improving the errors using [miette](https://github.com/zkat/miette).
- Added derive for `miette::Diagnostic` to both the parser's error type and LimboError.
- Added miette dependency to both sqlite3_parser and core. The `fancy` feature is only enabled for CLI.

Some future improvements that can be made further:
- Add spans to AST nodes so that errors can better point to the correct token. See upstream issue: https://github.com/gwenn/lemon-rs/issues/33
- Construct more errors with offset information. I noticed that most parser errors are constructed with `None` as the offset.

Comparisons.
Before:
```
❯ cargo run --package limbo --bin limbo database.db --output-mode pretty
...
limbo> selet * from a;
[2025-01-05T11:22:55Z ERROR sqlite3Parser] near "Token([115, 101, 108, 101, 116])": syntax error
Parse error: near "selet": syntax error at (1, 6)
```

After:
```
❯ cargo run --package limbo --bin limbo database.db --output-mode pretty
...
limbo> selet * from a;
[2025-01-05T12:25:52Z ERROR sqlite3Parser] near "Token([115, 101, 108, 101, 116])": syntax error

  × near "selet": syntax error at (1, 6)
   ╭────
 1 │ selet * from a
   ·     ▲
   ·     ╰── syntax error
   ╰────

```
2025-01-05 17:56:59 +05:30
Jussi Saurio
97eae13d0a boxed limit (by ignatz) 2025-01-05 13:51:02 +02:00
Jussi Saurio
f5540e9602 boxed select and selectbody (by gwenn and jussisaurio) 2025-01-05 13:50:32 +02:00
Jussi Saurio
d35eadb22c preallocate capacity for yystack (by krishvishal) 2025-01-05 13:46:30 +02:00