Commit Graph

3069 Commits

Author SHA1 Message Date
PThorpe92
8070e51e26 Fix vdbe casting and rounding issues 2025-02-24 11:21:22 -05:00
PThorpe92
8f27a5fc92 Fix (fuzzing tests) casting text to integer to match sqlite behavior 2025-02-24 11:13:25 -05:00
Pekka Enberg
eb6019b453 cargo fmt 2025-02-24 17:39:21 +02:00
Pekka Enberg
92d19e95e7 Attempt to fix stale bot not to close issues 2025-02-24 17:22:20 +02:00
Pekka Enberg
2b002c4875 Merge 'extensions/time: normalize offset_sec' from meteorgan
normalize `offset_sec` in case it's outside its usual range.
It's done in a similar way in `sqlean`:
https://github.com/nalgeon/sqlean/blob/b9ba442909acea14eb0e3cd149d1448f8
4da1f9c/src/time/time.c#L300-L306

Closes #1041
2025-02-24 11:32:44 +02:00
Pekka Enberg
16306ee1f4 Merge 'Modify the LIKE function to work with all types' from Mohamed Hossam
This PR fixes
[#1040](https://github.com/tursodatabase/limbo/issues/1040) and modifies
the `LIKE` function in the VDBE to work on expressions of all types like
SQLite.
Looking at how SQLite handles this, it gets the text value of the
expression regardless of its affinity. I used `exec_cast(exp, "TEXT")`
to achieve the same effect. Since most `LIKE` queries will probably be
done on `TEXT` expressions, I avoid casting the expression if it's
already `TEXT`. If either of the expressions was `NULL`, SQLite returns
nothing i.e. `NULL`. I also changed the unreachable arm message from
`Like on non-text registers` to `Like failed`.
The following queries produced the same results in Limbo:
```
SQLite version 3.46.1 2024-08-13 09:16:08 (UTF-16 console I/O)
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> CREATE TABLE tbl (n NULL, i INTEGER, r REAL, t TEXT, b BLOB);
sqlite> INSERT INTO tbl VALUES(NULL,1,2.0,'a',X'0500');
sqlite> SELECT * FROM tbl;
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE n LIKE NULL;
sqlite> SELECT * FROM tbl WHERE n LIKE 'NULL';
sqlite> SELECT * FROM tbl WHERE n LIKE 1;
sqlite> SELECT * FROM tbl WHERE n LIKE 2.0;
sqlite> SELECT * FROM tbl WHERE n LIKE x'0500';
sqlite>
sqlite> SELECT * FROM tbl WHERE i LIKE NULL;
sqlite> SELECT * FROM tbl WHERE i LIKE 1;
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE i LIKE '1';
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE i LIKE 2.0;
sqlite> SELECT * FROM tbl WHERE i LIKE 1.0;
sqlite> SELECT * FROM tbl WHERE i LIKE x'0500';
sqlite>
sqlite> SELECT * FROM tbl WHERE r LIKE NULL;
sqlite> SELECT * FROM tbl WHERE r LIKE 2;
sqlite> SELECT * FROM tbl WHERE r LIKE 2.0;
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE r LIKE '2.0';
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE r LIKE 'a';
sqlite> SELECT * FROM tbl WHERE r LIKE x'0500';
sqlite>
sqlite> SELECT * FROM tbl WHERE t LIKE NULL;
sqlite> SELECT * FROM tbl WHERE t LIKE 1;
sqlite> SELECT * FROM tbl WHERE t LIKE 2.0;
sqlite> SELECT * FROM tbl WHERE t LIKE 'a';
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE t LIKE x'0500';
sqlite>
sqlite> SELECT * FROM tbl WHERE b LIKE NULL;
sqlite> SELECT * FROM tbl WHERE b LIKE 1;
sqlite> SELECT * FROM tbl WHERE b LIKE 2.0;
sqlite> SELECT * FROM tbl WHERE b LIKE 'a';
sqlite> SELECT * FROM tbl WHERE b LIKE x'0500';
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE b LIKE 'x''0500''';
sqlite> SELECT * FROM tbl WHERE b LIKE '♣';
sqlite>
sqlite> SELECT * FROM tbl WHERE 1 LIKE 1;
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE 2.0 LIKE 2.0;
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE 2.0 LIKE '2.0';
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE '2.0' LIKE 2.0;
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE '123.45' LIKE 123.45;
|1|2.0|a|♣
sqlite> SELECT * FROM tbl WHERE NULL LIKE NULL;
sqlite> SELECT * FROM tbl WHERE x'0500' LIKE x'0500';
|1|2.0|a|♣
sqlite> SELECT typeof(n), typeof(i), typeof(r), typeof(t), typeof(b) FROM tbl;
null|integer|real|text|blob
```
Though, these queries are very basic, and more testing could be done.

Closes #1044
2025-02-24 11:27:02 +02:00
Pekka Enberg
ebeb47e47a Merge 'bindings/java: Clean up ' from Kim Seon Woo
- Add finals to classes where we don't want users to inherit
- Make `JDBC4ResultSet` to implement `ResultSetMetaData` and add TODOs

Closes #1045
2025-02-24 11:20:44 +02:00
Pekka Enberg
4cefb222db Merge 'Fix cast_text_to_number compatibility' from Pedro Muniz
Modified  `cast_text_to_number` to be more compatible with SQLite. When
I was running some fuzz tests, I would eventually get errors due to
incorrect casting of text to `INTEGER` or `REAL`. Previously in code
there were 2 implementations of `cast_text_to_number`: one in
`core/vdbe/insn.rs` and one in `core/vdbe/mod.rs`. I consolidated the
casting to only one function. Previously, the `mod.rs` function was just
calling `checked_cast_text_to_numeric`, which was used in `MustBeInt`
opcode.  Hopefully this fixes some of the CI testing issues we are
having. This was the query that prompted me to do this: `SELECT  ( ( (
878352367 ) <> ( 29 ) ) ) = ( ( ( -4309097 ) / ( -37 || -149680985265412
) ) - 755066415 );`

Closes #1038
2025-02-24 11:20:14 +02:00
Pekka Enberg
600ce590fb Merge 'Handle parsing URI according to SQLite specification' from Preston Thorpe
closes #977
In order to properly get #960 merged and keep some sort of the same API
we have now, we need to support URIs/query parameters for opening new
databases.
This PR doesn't attempt to implement anything useful with this, it only
handles parsing, but it will allow #960 to properly open a new file with
a specific VFS without having to entirely re-design the `open_file`
method/API. The existing option in that PR right now is less than ideal.
e.g. All of the existing methods already accept an `IO` impl
```rust
    pub fn open_file(io: Arc<dyn IO>, path: &str) -> Result<Arc<Database>> {
// or
      pub fn open(
        io: Arc<dyn IO>,
        page_io: Rc<dyn DatabaseStorage>,
        wal: Rc<RefCell<dyn Wal>>,
        shared_wal: Arc<RwLock<WalFileShared>>,
        buffer_pool: Rc<BufferPool>,
    ) -> Result<Arc<Database>> {

```
Right now, most of the parsed query parameters are not options we
support yet, but I figured it's better to handle parsing them now and
using them later on when we support them.
Also, if this looks way overly complicated for what it does... that's
because the cross platform edge-cases are a super pain in the ass.

Closes #1039
2025-02-24 11:17:39 +02:00
Pekka Enberg
b391fb7073 Merge 'Bump rusqlite to 0.33.0 from 0.29.0' from Alperen Keleş
Closes #1036
2025-02-24 11:14:58 +02:00
m0hossam
2204d92a0b Modify LIKE to handle all affinities including Nulls 2025-02-22 04:43:43 +02:00
pedrocarlo
2e38aa1d6b remove dbg 2025-02-20 16:09:39 -03:00
pedrocarlo
13639899a5 more adjustments to parser to handle edge cases 2025-02-20 16:05:50 -03:00
pedrocarlo
033d0116d6 rewrote parsing from text to integer and real 2025-02-20 02:16:30 -03:00
m0hossam
2425b601f7 Cast the matching value into TEXT before matching 2025-02-20 04:57:01 +02:00
m0hossam
1935426509 Add support for Int columns in LIKE function 2025-02-20 00:42:41 +02:00
김선우
a99c4e2073 Nit 2025-02-19 22:38:38 +09:00
김선우
a28242a6b6 JDBC4ResultSet add ResultSetMetadata implementation 2025-02-19 22:29:44 +09:00
김선우
9e9c65d17d Add final 2025-02-19 22:27:51 +09:00
meteorgan
97337614db extensions/time: normalize offset_sec 2025-02-19 21:25:14 +08:00
PThorpe92
e86f00cb81 Add normalizing windows paths to sqlite spec 2025-02-18 22:41:35 -05:00
pedrocarlo
409297cfdd remove comment 2025-02-19 00:05:56 -03:00
PThorpe92
42a0c18574 Add parsing sqlite URI to prep for vfs 2025-02-18 21:02:48 -05:00
pedrocarlo
0c5696c26a remove comment 2025-02-18 21:43:57 -03:00
alpaylan
39b11812ea bump rusqlite to 0.33.0 from 0.29.0 2025-02-18 15:13:15 -05:00
pedrocarlo
0ca6bbab05 modified cast_text_to_number for more compatability with sqlite 2025-02-18 16:28:44 -03:00
Pekka Enberg
8ac09b73bf extensions/uuid: Fix mimalloc version 2025-02-18 20:08:30 +02:00
Pekka Enberg
a783a4d17c extensions/time: Fix mimalloc version 2025-02-18 20:08:17 +02:00
Pekka Enberg
11a93900e3 extensions/core: Fix mimalloc version in README.md 2025-02-18 20:07:45 +02:00
Pekka Enberg
25f0694dfc extensions/series: Fix mimalloc version 2025-02-18 20:07:09 +02:00
Pekka Enberg
bd6083c66d extensions/regexp: Fix mimalloc version 2025-02-18 20:06:43 +02:00
Pekka Enberg
89202f0be3 extensions/percentile: Fix mimalloc version 2025-02-18 20:05:51 +02:00
Pekka Enberg
45a015f5c2 extensions/crypto: Fix mimalloc version 2025-02-18 20:05:10 +02:00
Pekka Enberg
9973c22137 core: Specify mimalloc version
The "*" version is not allowed on crates.io.
2025-02-18 19:40:00 +02:00
Pekka Enberg
f76d059aa2 scripts/publish-crates.sh: Remove dry run option 2025-02-18 19:38:47 +02:00
Pekka Enberg
185826f9f9 bindings/rust: Add description to Cargo.toml 2025-02-18 19:38:36 +02:00
Pekka Enberg
19903bbe5f extensions/uuid: Add description to Cargo.toml 2025-02-18 19:38:25 +02:00
Pekka Enberg
6cb6f6308f extensions/time: Add description to Cargo.toml 2025-02-18 19:38:04 +02:00
Pekka Enberg
e8d98250c2 extensions/series: Add description to Cargo.toml 2025-02-18 19:37:42 +02:00
Pekka Enberg
215fc66360 extensions/regexp: Add description to Cargo.toml 2025-02-18 19:36:36 +02:00
Pekka Enberg
38c76f1831 extensions/percentile: Add description to Cargo.toml 2025-02-18 19:36:10 +02:00
Pekka Enberg
237246b3ca extensions/crypto: Add description to Cargo.toml 2025-02-18 19:35:42 +02:00
Pekka Enberg
9b84e7e919 extensions/core: Add description to Cargo.toml 2025-02-18 19:34:32 +02:00
Pekka Enberg
c983888d33 Revert "Merge 'build: Update cargo-dist to latest' from Pekka Enberg"
This reverts commit 248a369afc, reversing
changes made to e464f99234. This is an
attempt to fix release process.
2025-02-18 19:06:36 +02:00
Pekka Enberg
d0b5aca0b5 build: Don't publish some bindings crates
...attempt to fix "cargo dist" failure.
2025-02-18 19:00:11 +02:00
Pekka Enberg
6bd7d6752e Limbo 0.0.15 2025-02-18 18:51:39 +02:00
Pekka Enberg
98010517d5 Merge 'Add affinity() function to Column' from Jussi Saurio
This is a first step to supporting [sqlite column
affinity](https://www.sqlite.org/datatype3.html) properly in limbo --
just adds an `affinity()` function to `Column` that can then be used
elsewhere

Closes #1030
2025-02-18 17:44:38 +02:00
Pekka Enberg
28a85edbc8 Merge 'Fix incorrect CAST text->numeric if valid prefix is 1 char long' from Jussi Saurio
Closes #1031
2025-02-18 17:44:01 +02:00
Pekka Enberg
48e705fb53 Merge 'Fix invalid text columns generated by dump' from Kingsley Yung
Fix #1012
In the INSERT statement generated by dump function, if the type affinity
of the value is TEXT, replace each single quotation mark with two single
quotation marks, and wrap it with single quotation marks.
Example:
```plaintext
limbo> CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(100));
INSERT INTO users (id, name) VALUES
(1, 'Alice'),
(2, 'Bob'),
(3, 'Char''lie');
SELECT * FROM users;

1|Alice
2|Bob
3|Char'lie
limbo> .dump
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR (100));
INSERT INTO users VALUES(1,'Alice');
INSERT INTO users VALUES(2,'Bob');
INSERT INTO users VALUES(3,'Char''lie');
COMMIT;
```

Closes #1034
2025-02-18 17:43:25 +02:00
Kingsley Yung
67ff5c4ae1 Fix invalid text columns generated by dump
In the INSERT statement generated by dump function, if the type affinity
of the value is TEXT, replace each single quotation mark with two single
quotation marks, and wrap it with single quotation marks.
2025-02-18 23:26:56 +08:00