Commit Graph

118 Commits

Author SHA1 Message Date
Nikita Sivukhin
759ffc1770 fix clippy 2025-09-30 14:03:25 +04:00
Nikita Sivukhin
30a9b2b860 auto-assign anonymous parameters directly in the Parser
- otherwise it will be easy to mess up with the traversal order
2025-09-30 13:58:59 +04:00
Jussi Saurio
13ca94755e Merge 'correct span in ParseUnexpectedToken' from Lâm Hoàng Phúc
Closes #3447
2025-09-30 10:35:49 +03:00
TcMits
04beead7fe correct span in ParseUnexpectedToken 2025-09-30 12:49:26 +07:00
TcMits
4211460ef3 fmt 2025-09-30 12:28:24 +07:00
TcMits
d3d6a015ec fix issue 3425 2025-09-30 12:25:20 +07:00
Nikita Sivukhin
86a95e813d Merge branch 'main' into quoting-fix-attempt-2 2025-09-29 10:58:51 +04:00
PThorpe92
30f80c2000 Correct spelling issue in ForeignKey ast node 2025-09-27 17:38:45 -04:00
PThorpe92
9bd852297a Allow in parser using rowid explicitly for a col when creating table 2025-09-26 17:31:02 -04:00
Nikita Sivukhin
faf3a970a7 fix clippy 2025-09-26 13:02:35 +04:00
Nikita Sivukhin
27c9506059 do not auto-lowercase Name identifiers
- this is complicated because column names must preserve case
2025-09-26 13:01:49 +04:00
Nikita Sivukhin
c4b3074575 format 2025-09-26 13:01:49 +04:00
Nikita Sivukhin
ae24d637a8 adjust edge-cases 2025-09-26 13:01:49 +04:00
Nikita Sivukhin
12b89fd2f1 do not use Name::new 2025-09-26 13:01:49 +04:00
Nikita Sivukhin
68fd940d73 small fix to make pragmas work 2025-09-26 13:01:49 +04:00
Nikita Sivukhin
f3f9219795 completely remove usage of enum variants 2025-09-26 13:01:49 +04:00
Nikita Sivukhin
fdf8ca88fd introduce exact(...) function - because enum variant will disappear 2025-09-26 13:01:49 +04:00
Jussi Saurio
064cc04b69 Merge 'Fix CREATE INDEX with quoted identifiers' from Iaroslav Zeigerman
Discovered this one while working on #3322
It was a bit more elusive because the original error was essentially a
red herring:
```
turso> CREATE INDEX idx ON "t t" (`a a`);
  × unexpected token at SourceSpan { offset: SourceOffset(22), length: 1 }
   ╭────
 1 │ CREATE INDEX idx ON "t t" (`a a`);
   ·                       ┬
   ·                       ╰── here
   ╰────
  help: expected [TK_LP] but found TK_ID
```

Reviewed-by: Preston Thorpe <preston@turso.tech>

Closes #3345
2025-09-26 09:13:30 +03:00
Iaroslav Zeigerman
b34e53d6c6 Fix CREATE INDEX with quoted identifiers 2025-09-25 12:55:06 -07:00
Pekka Enberg
b3a0008950 Merge 'parser: fix incorrect LIMIT/OFFSET parsing of form LIMIT x,y' from Jussi Saurio
In this case x is the OFFSET and y is the LIMIT, not the other way
around.
Closes #3303

Closes #3339
2025-09-25 21:01:40 +03:00
Diego Reis
7a56c93b81 Makes clippy happy 2025-09-25 10:42:14 -03:00
Jussi Saurio
152074d2d7 fix LIMIT OFFSET test 2025-09-25 15:42:32 +03:00
Jussi Saurio
bb082c25f5 Fix incorrect LIMIT/OFFSET parsing of form LIMIT x,y
In this case x is the OFFSET and y is the LIMIT, not the
other way around.
2025-09-25 15:10:14 +03:00
Nikita Sivukhin
57e52077be add link to the docs 2025-09-19 16:48:43 +04:00
Nikita Sivukhin
c63c820bb7 add busy_timeout pragma 2025-09-19 16:48:12 +04:00
Glauber Costa
cb7c04ffad return error instead of panic for invalid syntax on views
I have accidentally typed "create materialized views", and noticed
that this panics, instead of returning an error. Fix it.
2025-09-19 03:59:28 -05:00
Pekka Enberg
d8f07fe3da core: Panic on fsync() error by default
Retrying fsync() on error was historically not safe ("fsyncgate") and
Postgres still defaults to panicing on fsync(). Therefore, add a
"data_sync_retry" pragma (disabled by default) and use it to determine
whether to panic on fsync() error or not.
2025-09-13 10:21:12 +03:00
Pekka Enberg
433b60555f Add BEGIN CONCURRENT support for MVCC mode
Currently, when MVCC is enabled, every transaction mode supports
concurrent reads and writes, which makes it hard to adopt for existing
applications that use `BEGIN DEFERRED` or `BEGIN IMMEDIATE`.

Therefore, add support for `BEGIN CONCURRENT` transactions when MVCC is
enabled. The transaction mode allows multiple concurrent read/write
transactions that don't block each other, with conflicts resolved at
commit time. Furthermore, implement the correct semantics for `BEGIN
DEFERRED` and `BEGIN IMMEDIATE` by taking advantage of the pager level
write lock when transaction upgrades to write. This means that now
concurrent MVCC transactions are serialized against the legacy ones when
needed.

The implementation includes:

- Parser support for CONCURRENT keyword in BEGIN statements

- New Concurrent variant in TransactionMode to distinguish from regular
  read/write transactions

- MVCC store tracking of exclusive transactions to support IMMEDIATE and
  EXCLUSIVE modes alongside CONCURRENT

- Proper transaction state management for all transaction types in MVCC

This enables better concurrency for applications that can handle
optimistic concurrency control, while still supporting traditional
SQLite transaction semantics via IMMEDIATE and EXCLUSIVE modes.
2025-09-11 16:05:52 +03:00
TcMits
e725814ce8 fix test 2025-09-05 13:38:33 +07:00
TcMits
0f9ae5853c test 2025-09-05 13:19:22 +07:00
TcMits
4726ffaa74 only check 'e' in eat_number 2025-09-05 13:08:42 +07:00
TcMits
168f6dcbb5 unrelated comments 2025-09-05 13:00:07 +07:00
TcMits
f2d4087462 support float without fractional part 2025-09-05 12:58:28 +07:00
Pekka Enberg
1de647758f Merge 'refactor parser fmt' from Lâm Hoàng Phúc
@penberg this PR try to clean up `turso_parser`'s`fmt` code.
- `get_table_name` and `get_column_name` should return None when
table/column does not exist.
```rust
/// Context to be used in ToSqlString
pub trait ToSqlContext {
    /// Given an id, get the table name
    /// First Option indicates whether the table exists
    ///
    /// Currently not considering aliases
    fn get_table_name(&self, _id: TableInternalId) -> Option<&str> {
        None
    }

    /// Given a table id and a column index, get the column name
    /// First Option indicates whether the column exists
    /// Second Option indicates whether the column has a name
    fn get_column_name(&self, _table_id: TableInternalId, _col_idx: usize) -> Option<Option<&str>> {
        None
    }

    // help function to handle missing table/column names
    fn get_table_and_column_names(
        &self,
        table_id: TableInternalId,
        col_idx: usize,
    ) -> (String, String) {
        let table_name = self
            .get_table_name(table_id)
            .map(|s| s.to_owned())
            .unwrap_or_else(|| format!("t{}", table_id.0));

        let column_name = self
            .get_column_name(table_id, col_idx)
            .map(|opt| {
                opt.map(|s| s.to_owned())
                    .unwrap_or_else(|| format!("c{col_idx}"))
            })
            .unwrap_or_else(|| format!("c{col_idx}"));

        (table_name, column_name)
    }
}
```
- remove `FmtTokenStream` because it is same as `WriteTokenStream `
- remove useless functions and simplify `ToTokens`
```rust
/// Generate token(s) from AST node
/// Also implements Display to make sure devs won't forget Display
pub trait ToTokens: Display {
    /// Send token(s) to the specified stream with context
    fn to_tokens<S: TokenStream + ?Sized, C: ToSqlContext>(
        &self,
        s: &mut S,
        context: &C,
    ) -> Result<(), S::Error>;

    // Return displayer representation with context
    fn displayer<'a, 'b, C: ToSqlContext>(&'b self, ctx: &'a C) -> SqlDisplayer<'a, 'b, C, Self>
    where
        Self: Sized,
    {
        SqlDisplayer::new(ctx, self)
    }
}
```

Closes #2748
2025-09-02 18:35:43 +03:00
Pekka Enberg
adc6cb008a Merge 'introduce match_ignore_ascii_case macro' from Lâm Hoàng Phúc
this PR converts generate code in `turso_parser`'s `build.rs` into macro
for reusability. `match_ignore_ascii_case` will generate trie-like tree
matching from normal match expression.
example:
```rust
    match_ignore_ascii_case!(match input {
        b"AB" => TokenType::TK_ABORT,
        b"AC" => TokenType::TK_ACTION,
        _ => TokenType::TK_ID,
    })
```
will generate:
```rust
    match input.get(0) {
        Some(b'A') | Some(b'a') => match input.get(1) {
            Some(b'B') | Some(b'b') => match input.get(2) {
                None => TokenType::TK_ABORT,
                _ => TokenType::TK_ID,
            },
            Some(b'C') | Some(b'c') => match input.get(2) {
                None => TokenType::TK_ACTION,
                _ => TokenType::TK_ID,
            },
            _ => TokenType::TK_ID,
        },
        _ => TokenType::TK_ID,
    }
```

Closes #2865
2025-09-02 18:34:55 +03:00
TcMits
d0cb3d0d08 CURRENT_TIMESTAMP can fallback TK_ID 2025-09-02 20:50:58 +07:00
TcMits
06e14c8ace merge main 2025-09-02 18:17:37 +07:00
TcMits
d298480e4a Merge branch 'main' into perf-3 2025-09-02 18:13:58 +07:00
TcMits
33a04fbaf7 resolve conflict 2025-09-02 17:30:10 +07:00
Pekka Enberg
cfaba4ab10 Merge 'Implement libSQL's ALTER COLUMN extension' from Levy A.
Implement `ALTER COLUMN` as described here:
https://github.com/tursodatabase/libsql/blob/main/libsql-
sqlite3/doc/libsql_extensions.md#altering-columns
- [x] Add `ALTER COLUMN` to parser
- [x] Implement `Insn::AlterColumn`
- [x] Add tests

Closes #2814
2025-09-02 09:06:03 +03:00
PThorpe92
b76f9b7733 Use eq_ignore_ascii_case in place of allocating new string in parser 2025-09-01 12:32:33 -04:00
PThorpe92
4bb2497d36 Parser: translate true and false to 0 and 1 literals 2025-09-01 11:24:12 -04:00
TcMits
190e9bcc95 add match_ignore_ascii_case macro 2025-08-31 14:35:03 +07:00
Levy A.
5b378e3730 feat: add AlterColumn instruction
also refactor `RenameColumn` to reuse the logic from `AlterColumn`
2025-08-30 03:10:39 -03:00
Levy A.
678ca8d33b feat(parser): add ALTER COLUMN 2025-08-30 03:10:39 -03:00
Pekka Enberg
44ed4d562f core: Initial pass on synchronous pragma
This adds support for "OFF" and "FULL" (default) synchronous modes. As
future work, we need to add NORMAL and EXTRA as well because
applications expect them.
2025-08-28 16:02:41 +03:00
TcMits
1b048b2628 clippy+fmt 2025-08-27 15:08:32 +07:00
TcMits
bfff90b70e unrelated changes 2025-08-27 15:02:58 +07:00
TcMits
4ddfdb2a62 finish 2025-08-27 14:58:35 +07:00
TcMits
50bdaec6d0 merge main 2025-08-27 13:36:54 +07:00