Commit Graph

382 Commits

Author SHA1 Message Date
Jussi Saurio
e782f30ffe Add expect_arguments_min!() and use expect_arguments_* macros more universally 2025-01-11 09:55:07 +02:00
Peter Sooley
b5fed15997 implement json_error_position 2025-01-10 11:12:30 -08:00
Kacper Madej
1a46988a73 Fix hardcoded numbers in macros 2025-01-10 14:50:38 +07:00
Kacper Madej
91d4ac3ac0 Fix expression chaining 2025-01-10 12:14:57 +07:00
Kacper Madej
743a8b2d94 Merge branch 'main' into right-arrow-json 2025-01-10 11:28:13 +07:00
Pekka Enberg
317acb842b Merge 'Implement json_type' from Kacper Madej
Closes #631
2025-01-09 14:25:32 +02:00
Kacper Madej
dd533414ef Implement -> and ->> operators for json 2025-01-09 15:38:32 +07:00
Kacper Madej
eebf9bfaac Implement json_type 2025-01-09 11:29:17 +07:00
PThorpe92
97d0fc68b2 Add macro and helper to clean up expression translations 2025-01-08 19:29:56 -05:00
PThorpe92
183797898b Add tests for nested conditional expressions 2025-01-08 17:19:37 -05:00
PThorpe92
fa0e7d5729 Support nested parenthesized conditional exprs in translator 2025-01-08 17:16:17 -05:00
Jussi Saurio
731ff1480f Simplify working with labels
TLDR: no need to call either of:

program.emit_insn_with_label_dependency() -> just call program.emit_insn()
program.defer_label_resolution() -> just call program.resolve_label()

Changes:

- make BranchOffset an explicit enum (Label, Offset, Placeholder)
- remove program.emit_insn_with_label_dependency() - label dependency is automatically detected
- for label to offset mapping, use a hashmap from label(negative i32) to offset (positive u32)
- resolve all labels in program.build()
- remove program.defer_label_resolution() - all labels are resolved in build()
2025-01-07 12:53:10 +02:00
Pekka Enberg
ba28999d05 Merge 'Add partial support for datetime() function' from Preston Thorpe
This PR adds the `datetime` function, with all the support currently
that date/time have for modifiers, and `julianday` function, as well as
some additional modifiers for date/time/datetime.
There are a couple considerations here, I left a couple comments but
essentially there is going to have to be some more work done to track
the state of the expression during the application of modifiers, to
handle a bunch of edge-cases like re-applying the same timezone modifier
to itself, or converting an integer automatically assumed to be
julianday, into epoch, or `ceiling`/`floor` which will determine
relative addition of time in cases like
```
2024-01-31 +1 month = 2024-03-02
```
which was painful enough to get working to begin with.
I couldn't get the `julianday_converter` library to get the exact same
float precision as sqlite, so function is included that matches their
output, for some reason floating point math + `.floor()` would give the
correct result. They seem to 'round' to 8 decimal places, and I was able
to get this to work with the same output as sqlite, except in cases like
`2234.5`, in which case we return `2234.5000000` because of the `fmt`
precision:
```rust
pub fn exec_julianday(time_value: &OwnedValue) -> Result<String> {
    let dt = parse_naive_date_time(time_value);
    match dt {
        // if we did something heinous like: parse::<f64>().unwrap().to_string()
        // that would solve the precision issue, but dear lord...
        Some(dt) => Ok(format!("{:.1$}", to_julian_day_exact(&dt), 8)),
        None => Ok(String::new()),
    }
}
```
Suggestions would be appreciated on the float precision issue.

Reviewed-by: Sonny <14060682+sonhmai@users.noreply.github.com>

Closes #600
2025-01-05 20:13:13 +02:00
psvri
9340c8f0b1 Change sanitize_string comments to doc string 2025-01-05 17:16:18 +05:30
psvri
a11f4b2b10 Refactor escape string literal logic to a function 2025-01-05 14:21:11 +05:30
psvri
2d84956fda Fix quote escape in literals 2025-01-05 01:35:29 +05:30
PThorpe92
ca428b3dda Julianday function and additional tests/comments 2025-01-04 10:42:34 -05:00
PThorpe92
7c4a780cc2 Add DateTime func and support more modifiers 2025-01-04 08:41:03 -05:00
Jussi Saurio
9a8156753e core/translate: break emitter.rs into smaller modules 2025-01-04 14:52:46 +02:00
Jussi Saurio
d1f74fa3cb Emitter cleanup part 2: add Resolver 2025-01-04 12:23:19 +02:00
Pekka Enberg
bd5f081ea8 Merge 'Add support for changes() and total_changes() functions' from Lemon-Peppermint
#525
- Adds the necessary `ScalarFunc` variants to support the `changes()` &
`total_changes()` SQLite function.
- Adds the necessary fields to the `Connection` struct to track changes.
- Modify the `InsertAwait` OpCode behaviour to affect the changes
counter.

Closes #589
2025-01-04 10:14:06 +02:00
Jussi Saurio
a934ead904 Merge 'Json extract' from Kacper Madej
Implements the `json_extract` function.
In the meantime, the json path has already been implemented by
@petersooley in https://github.com/tursodatabase/limbo/pull/555 which is
a requirement for `json_extract`.
However, this PR takes a different approach and parses the JSON path
using the JSON grammar, because there are a lot of quirks in how a JSON
`key` can look (see the JSON grammar in the Pest file).
The downside is that it allocates more memory than the current
implementation, but might be easier to maintain in the long run.
I included a lot of tests with some quirky behavior of the
`json_extract` (some of them still need some work). I also noticed that
these changed between sqlite versions (had `SQLite 3.43.2` locally and
`3.45` gave different results). Due to this, I'm not sure how much value
there is in trying to be fully compatible with SQLite. Perhaps the
approach taken by @petersooley solves 99% of use-cases?

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

Closes #524
2025-01-03 23:53:29 +02:00
Lemon-Peppermint
9109dbf8ec Add changes tracking to the 'Connection' struct + 'Insn::InsertAwait' now affects changes counter 2025-01-03 00:04:20 +02:00
Lemon-Peppermint
abd8e6af43 Add early 'changes()' & 'total_changes()' support 2025-01-02 23:35:19 +02:00
Kacper Madej
92af5b4544 Fix build 2025-01-02 15:09:20 +07:00
Kacper Madej
4fc1b66225 Merge branch 'main' into json-extract 2025-01-02 15:04:16 +07:00
Jussi Saurio
2066475e03 feat: subqueries in FROM clause 2024-12-31 14:18:29 +02:00
Pekka Enberg
0aabcddf18 ext/uuid: Convert uuid4() to external function 2024-12-31 13:56:32 +02:00
Pekka Enberg
33dbd6c892 core: External functions 2024-12-31 13:56:32 +02:00
Kacper Madej
692301e72c Merge branch 'main' into json-extract 2024-12-31 15:53:08 +07:00
Kacper Madej
2e730ead25 Merge branch 'main' into json-extract 2024-12-31 15:41:18 +07:00
Kacper Madej
ad9acf7400 Add support for json_extract 2024-12-31 15:11:36 +07:00
Lauri Virtanen
db384c6828 Simplify init of delimiter_exprs
Clippy:
https://rust-lang.github.io/rust-clippy/master/index.html#needless_late_init
2024-12-29 19:22:45 +02:00
PThorpe92
f6cd707544 Add clippy CI, fix or ignore warnings where appropriate 2024-12-29 10:25:41 -05:00
PThorpe92
f08d62b446 Add Remainder vdbe oppcode 2024-12-27 15:39:02 -05:00
Pekka Enberg
8352dcd582 Merge 'Fix sqlite_version() out of bound panics' from Diego Reis
#560
Changes to `translate_expr` function:
* [`core/translate/expr.rs`](diffhunk://#diff-
371865d5d7b8bcaed649413c687492e61e94f21387cd9b2c47d989a033888c8bL1558-
R1560): Changed the `amount` parameter in the `Insn::Copy` instruction
from `1` to `0`.
Enhancements to the testing framework:
* [`testing/scalar-functions.test`](diffhunk://#diff-
a046d58ab24eee8207f0ce3199f8d0a609edcef9c24b8ed7f242f7a60e6c1e61R812-
R815): Added a new test `do_execsql_test_regex` to validate that the
`sqlite_version` function returns a valid output.
* [`testing/tester.tcl`](diffhunk://#diff-
316cca92d85df3f78558cc3e60d7420c1fd19a23ecf2bbea534db93ab08ea3ecR29-
R45): Introduced a new procedure `do_execsql_test_regex` to support
regex-based validation of SQL outputs.

Closes #561
2024-12-27 18:34:47 +02:00
Diego Reis
2d0c16c428 Fix sqlite_version() out of bound 2024-12-27 11:39:33 -03:00
Peter Sooley
28244b10d6 implement json_array_length 2024-12-26 15:08:11 -08:00
jussisaurio
3ab7f7a0b8 Merge 'Use custom expr equality check in translation and planning' from Preston Thorpe
Idk how I missed these during the initial PR 👍

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

Closes #541
2024-12-23 22:58:03 +02:00
PThorpe92
fbf42458b8 Use custom expr equality check in translation and planner 2024-12-22 21:46:31 -05:00
PThorpe92
c06c4115f1 Adapt OwnedValues in uuid ext to new LimboText 2024-12-21 09:17:53 -05:00
PThorpe92
2fcae80902 Create ext directory for outside funcs, add uuid to ext dir 2024-12-21 09:16:04 -05:00
PThorpe92
f96f289609 Remove unnecessary nanos arg from uuid7, add insn const 2024-12-21 09:13:48 -05:00
PThorpe92
c1561ecbb0 Tests for uuid funcitons, add compat docs 2024-12-21 09:13:48 -05:00
PThorpe92
fcab0ae299 Add uuid support for v4 and v7 2024-12-21 09:13:46 -05:00
Kacper Madej
cdb24d3de1 Handle issues with nested arguments 2024-12-20 11:32:57 +01:00
Kacper Madej
19ae42dfa3 Implement json_array 2024-12-20 11:15:48 +01:00
Lauri Virtanen
e69ee80fac Support log(X) and log(B,X) math functions 2024-12-17 00:14:25 +02:00
Lauri Virtanen
89d0289444 Support pi() function 2024-12-17 00:14:25 +02:00
Lauri Virtanen
5e426a7624 Support binary math functions 2024-12-16 22:29:05 +02:00