Commit Graph

73 Commits

Author SHA1 Message Date
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
psvri
18a1055088 Edit help message 2025-01-03 19:40:35 +05:30
psvri
1f21cf6a71 Feat: Import csv support 2025-01-03 15:20:22 +05:30
PThorpe92
f6cd707544 Add clippy CI, fix or ignore warnings where appropriate 2024-12-29 10:25:41 -05:00
Pekka Enberg
75992a84d8 cli: Fix unused result warnings 2024-12-27 10:55:29 +02:00
Pekka Enberg
f2ecebc357 Rename RowResult to StepResult
The name "row result" is confusing because it really *is* a result from
a step() call. The only difference is how a row is represented as we
return from VDBE or from a statement.

Therefore, rename RowResult to StepResult.
2024-12-27 10:20:41 +02:00
Pere Diaz Bou
aed14117c9 core: transaction support 2024-12-24 18:04:30 +01:00
Pekka Enberg
e93ac38e55 Add statement interruption support
This adds an interrupt() method to Statement that allows apps to
interrupt a running statement. Please note that this is different from
`sqlite3_interrupt()` which interrupts all ongoing operations in a
database. Although we want to support that too, per statement interrupt
is much more useful to apps.
2024-12-19 12:30:32 +02:00
Konstantinos Artopoulos
ba676b6ead fix: remove old help menu item that sneaked in on rebase 2024-12-18 00:13:42 +02:00
Konstantinos Artopoulos
969ab244c2 feat(cli): added .tables command 2024-12-18 00:00:29 +02:00
jussisaurio
783ec65c77 Merge 'Expression equality checking, some optimizations' from Preston Thorpe
This PR mainly adds custom logic to check equality in ast expressions.
Not sure if this belongs in the `vendored` parser or not, let me know
and I'll bring it out. Also replaces `Vec` arguments with slice refs
where possible, as well as some clippy warnings in the same `emitter`
file.
I'll write some more tests tomorrow to make sure this is as thorough as
possible.
EDIT: failed test same issue referenced in #484. Marking as draft until
more tests + cases added

Reviewed-by: Jussi Saurio <jussi.saurio@gmail.com>

Closes #488
2024-12-17 22:09:20 +02:00
yinheli
8271a323a1 Fix typos in CLI application 2024-12-17 13:26:50 +08:00
PThorpe92
1833dcb618 Shrink shell help msg and replace hardcoded path for shell tests 2024-12-16 20:14:04 -05:00
PThorpe92
66c44a021f Move ast expr equality check out of vendored, remove allocs and add cases 2024-12-16 19:39:06 -05:00
PThorpe92
7ca0abc61d Replace tcl with python tests and add to makefile 2024-12-15 21:40:42 -05:00
PThorpe92
d6c6b84d8f Add echo and quiet modes for shell 2024-12-15 18:21:16 -05:00
JeanArhancet
6bf8988fa0 Add display message for in-memory database 2024-12-15 11:30:27 +01:00
Pekka Enberg
9deea33afa cli: Add Limbo version back to shell 2024-12-15 09:26:07 +02:00
PThorpe92
ce2851ac8d Fix properly opening new connection in shell 2024-12-14 21:20:10 -05:00
PThorpe92
49f8429cc0 Enable :memory: as default option for cli when no DB provided 2024-12-14 20:52:45 -05:00
PThorpe92
7a9fe8ac88 Add cli command to set null value 2024-12-14 08:15:48 -05:00
PThorpe92
33c2d528f2 Refactor shell API for command extensibility 2024-12-13 11:48:18 -05:00
PThorpe92
f6473ea40d Add several cli commands, re-structure shell 2024-12-13 11:48:18 -05:00
PThorpe92
4dc71bc9ad Add buffered cli input to allow for incomplete statements 2024-12-12 11:01:14 -05:00
Pekka Enberg
617f95c7b6 Update clap to 4.5
The Github dependabot complains about anstream, which comes through `clap`:

https://github.com/tursodatabase/limbo/security/dependabot/8
2024-12-11 14:39:27 +02:00
Pere Diaz Bou
f5a1f7c800 various fixes in btree
* read_u8 now takes self.offset into account
* shift cell pointers left on balance_root with offset > 0
* fix wrong writes to page in degragment_page
2024-11-19 17:15:19 +01:00
Pere Diaz Bou
44e22c50cf sim: improve simulator 2024-11-18 13:40:37 +01:00
Pere Diaz Bou
c0e51c4ca6 wip wal 2024-11-05 15:29:53 +01:00
jussisaurio
02d6fa31d3 Fix .schema users not displaying indexes on the users table 2024-10-05 18:25:04 +03:00
Lauri Virtanen
0597c048fc Better support for BLOBs
- Limbo command line shell supports e.g. `SELECT x'616263';`
- `EXPLAIN SELECT x'616263';` lists the opcode

Missing:

- Command line shell not entirely compatible with SQLite when blobs have
  non-printable characters in the middle (e.g. `SELECT x'610062';`)
- Python bindings not supported (incoming soon)
2024-09-22 17:55:00 +03:00
김선우
28884181be Fix clippy 2024-09-15 16:23:27 +09:00
JeanArhancet
38a1b85094 fix: ctrl-c stop current query execution 2024-08-03 22:58:52 +02:00
Pere Diaz Bou
037e260682 core: add cacheflush in cli query 2024-07-31 17:27:02 +02:00
Pekka Enberg
341240740a cli: Improve CLI prompt
Let's print out Limbo version at CLI start and change the prompt to have
"limbo" prefix.
2024-07-25 15:25:46 +03:00
jussisaurio
c1f4f5879c Dont use ORDER BY in .schema 2024-07-24 12:41:48 +03:00
Bennett Clement
5b4bdc8aa3 Fix .schema
- Add tests for .schema
- Make command line sql arguments to allow .commands
2024-07-22 16:00:41 +08:00
Joan Martinez
642603b6c7 perf-latency: fix enabling to build multitenancy 2024-07-21 19:13:02 +02:00
Joan Martinez
4bcae54aa9 fix: use Arc to handle IO 2024-07-21 19:01:58 +02:00
Pekka Enberg
a6369982fe Enable cargo dist explicitly for the CLI only 2024-07-17 20:23:41 +03:00
Pekka Enberg
a0c92f6d80 Switch to workspace versioning 2024-07-17 08:39:36 +03:00
jussisaurio
d1eded0e90 Test with sqlite3 executable in CI as well 2024-07-15 17:27:04 +03:00
Raminder Singh
e4a9c5ce6e fix clippy warnings 2024-07-14 16:50:54 +05:30
Joan Martinez
346279f9bb add help message to CLI 2024-07-12 12:00:20 +02:00
Pere Diaz Bou
780908a771 cli: change float print
Signed-off-by: Pere Diaz Bou <pere-altea@hotmail.com>
2024-07-10 21:39:29 +02:00
Pekka Enberg
e5d55398db Merge pull request #104 from KunalSin9h/dot-commands 2024-07-08 20:51:50 +03:00
Kunal Singh
46cd1f067b fix: missing dot command description in unknown command message 2024-07-08 23:19:21 +05:30
Kunal Singh
00c26286ce fix: lint warnings 2024-07-08 22:43:11 +05:30
Pere Diaz Bou
c4f98e5f27 cli: add sqlite links in opcode description 2024-07-06 14:41:45 +02:00
Pere Diaz Bou
0b7226087b cli: added .opcodes helper
Improve quality of life while implementing core features.

```
Welcome to Limbo SQL shell!
> .opcodes
Abortable
---------
Verify that an Abort can happen. Assert if an Abort at this point might cause database corruption. This opcode only appears in debugging builds. An Abort is safe if either there have been no writes, or if there is an active statement journal.

Add
---------
Add the value in register P1 to the value in register P2 and store the result in register P3. If either input is NULL, the result is NULL.

AddImm
---------
Add the constant P2 to the value in register P1. The result is always an integer. To force any register to be an integer, just add 0.

Affinity
---------
Apply affinities to a range of P2 registers starting with P1. P4 is a string that is P2 characters long. The N-th character of the string indicates the column affinity that should be used for the N-th memory cell in the range.

AggFinal
---------
P1 is the memory location that is the accumulator for an aggregate or window function. Execute the finalizer function for an aggregate and store the result in P1. P2 is the number of arguments that the step function takes and P4 is a pointer to the FuncDef for this function. The P2 argument is not used by this opcode. It is only there to disambiguate functions that can take varying numbers of arguments. The P4 argument is only needed for the case where the step function was not previously called.
```

It can also search for specific opcode:
```
> .opcodes yield
Yield
---------
Swap the program counter with the value in register P1. This has the effect of yielding to a coroutine. If the coroutine that is launched by this instruction ends with Yield or Return then continue to the next instruction. But if the coroutine launched by this instruction ends with EndCoroutine, then jump to P2 rather than continuing with the next instruction. See also: InitCoroutine
```
2024-07-06 14:21:29 +02:00
Karan Janthe
c4e85cb8da .schema without args shows all table indexs 2024-07-06 11:09:29 +05:30