83 Commits

Author SHA1 Message Date
Pekka Enberg
4de24b0c62 core: Pass connection settings to Database::connect as ConnectOpts
Database had five public ways to open a connection: connect,
connect_with_encryption, connect_with_page_codec, connect_async and
connect_with_encryption_async. Every new connection setting needs more
variants, and the async path doubles them again.

Database::connect and Database::connect_async now take a ConnectOpts
that holds the encryption key and the page codec, and the other three
variants are removed. ConnectOpts has no Default, so every caller goes
through ConnectOpts::new() and a required argument added there later
makes the compiler find every call site.
2026-10-12 10:05:12 +03:00
Pekka Enberg
a7244a67df bindings/java: throw on a null statement pointer in columns instead of panicking
columns() was the one native statement function that unwrapped the pointer
check, so a zero pointer would abort the JVM instead of surfacing a Java
exception like every other entry point does.

Add an InvalidStatementPointer error so statement pointer failures no longer
report themselves as connection pointer failures.
2026-09-28 18:37:07 +03:00
Pekka Enberg
b2cf785055 bindings/java: reject use of a closed connection or statement instead of using freed memory
TursoConnection.close() and TursoStatement.close() freed their native boxes
but kept the stale address in a final pointer field. prepare() on a closed
connection, and step, bind, columns, reset, changes and parameterCount on a
closed statement, all passed the freed pointer to native code, which
dereferenced it.

Zero the pointer on close and treat a zero pointer as the closed state, so
there is one source of truth for whether the native handle exists. Every
native call now checks that first. Close and the native entry points are
synchronized so two threads cannot race a close against a use or free the
box twice. The connection takes its monitor only around the free and the
prepare call, never while holding transactionLock, so the lock order stays
transactionLock then connection for close, commit and rollback.

The native _close functions reject a zero pointer with an exception instead
of passing it to Box::from_raw.

Closing a connection before its statements stays safe because each native
statement holds its own clone of the connection; a test covers that ordering.

Tests: bindings/java TursoConnectionTest and TursoStatementTest
(make -C bindings/java test)
2026-09-28 18:37:07 +03:00
Pekka Enberg
6869716df3 bindings/java: reject connect on a closed TursoDB instead of using freed memory
TursoDB.close() freed the native TursoDB box but kept the stale address in
dbPointer, and connect() never checked whether the database was still open.
Calling connect() after close(), including through
new TursoConnection(url, db), passed the freed pointer to connect0, which
dereferenced it to reach the Arc<Database>.

Zero the pointer on close and treat a zero pointer as the closed state, so
there is one source of truth for whether the native handle exists. connect()
now throws on a closed database, and close() and connect() are synchronized
so two threads cannot race a close against a connect or free the box twice.
The native close0 rejects a zero pointer with an exception instead of
passing it to Box::from_raw.

Closing the database before its connections stays safe because each native
connection holds its own Arc<Database>; a test covers that ordering.

Tests: bindings/java TursoDBTest (make -C bindings/java test)
2026-09-28 17:22:17 +03:00
Pekka Enberg
9b10c496db core: add Dialect trait and route schema loading through it
Introduce the Dialect trait as the boundary between the engine and the
SQL dialect a frontend speaks. The engine hardcodes SQLite behavior in
many places; the trait is the seam where a frontend substitutes its own
surface, growing one hook per behavior that moves behind it, with
SqliteDialect in core/dialect/sqlite.rs as the SQLite implementation.

The first hook is schema loading: every path that parses a
sqlite_schema table row back into a table definition now goes through
Dialect::parse_table_sql instead of calling BTreeTable::from_sql
directly. Rows written by internal engine paths (sequence backing
tables, sqlite_sequence) are plain SQLite text with no frontend marker,
so every dialect falls back to SQLite parsing for text it does not
recognize as its own.

The dialect is a mandatory, explicit argument on every database
constructor — open_file, open, open_new, from_uri, and the async and
bypass-registry variants — with no defaulting convenience wrappers:
SQLite-compatible callers state Arc::new(SqliteDialect) at the call
site, so the dialect a database runs under is always visible where it
is opened. It is fixed at open time because the schema is parsed during
open itself; a dialect installed later could never see rows stored by
another frontend. The process-wide database registry rejects an open
whose dialect name differs from the already-open instance, and
engine-initiated secondary opens (ATTACH) propagate the parent
database's dialect instead of assuming SQLite.
2026-07-16 10:36:39 +03:00
pedrocarlo
07a3120ac3 migrate callers that were affected by Extendable change 2026-05-25 20:16:27 -03:00
Jussi Saurio
6847bf211d core: make statement reset fallible and keep drop best-effort 2026-02-23 10:42:56 +02:00
pedrocarlo
9a4dce40f2 remove Null variant from Numeric 2026-02-10 15:19:56 -03:00
pedrocarlo
a4ca81733e make Numeric variant present in Value instead of Float and Integer 2026-02-10 11:49:01 -03:00
Nikita Sivukhin
b45ae2108d get rid of redundant clones 2026-02-07 16:31:34 +01:00
Avinash Sajjanshetty
9315c47497 Fix bindings to pass encryption ctx 2026-01-28 11:34:14 +05:30
Avinash Sajjanshetty
e9b6ae92a7 Add local encryption support in java bindings 2026-01-20 16:55:52 +05:30
Jussi Saurio
ff3b1276a0 fix: reject literal-only index expressions and fix JNI panic
SQLancer found that literal-only expressions like `CREATE INDEX i ON t('foo')`
were accepted as index columns. This caused "no such column" errors when
SQLite tried to load the schema, as it interprets the literal as a column
reference. Index expressions must reference at least one column from the table.

Also fixes a JNI panic in the Java bindings where creating an error result
after a pending exception would cause unwrap() to fail.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-12 12:25:40 +02:00
Kim Seon Woo
5816f40cb8 Implement transaction support for turso jdbc 2026-01-02 16:01:23 +09:00
pedrocarlo
10577dd6c5 adjust run_one_step_blocking 2025-12-19 17:20:46 -03:00
pedrocarlo
848c529653 fix more places to avoid using run_once 2025-12-19 17:20:45 -03:00
Pekka Enberg
edd45ff7b8 Improve MVCC DX by dropping --experimental-mvcc flag
The DX is right now pretty terrible:

```
penberg@vonneumann turso % cargo run -- hello.db
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.15s
     Running `target/debug/tursodb hello.db`
Turso v0.4.0-pre.18
Enter ".help" for usage hints.
Did you know that Turso supports live materialized views? Type .manual materialized-views to learn more.
This software is in BETA, use caution with production data and ensure you have backups.
turso> PRAGMA journal_mode = 'experimental_mvcc';
  × Invalid argument supplied: MVCC is not enabled. Enable it with `--experimental-mvcc` flag in the CLI or by setting the MVCC option in `DatabaseOpts`

turso>
```

To add insult to the injury, many SDKs don't even have a way to enable
MVCC via database options. Therefore, let's remove the flag altogether.
2025-12-19 12:59:42 +02:00
Jussi Saurio
c49625f9f0 java bindings fixes
- if step returns error, include err msg in thrown exception
- support ResultSet.getStatement()
2025-12-11 17:18:11 +02:00
Jussi Saurio
826ca4d44d chore: remove experimental_indexes feature flags 2025-12-08 13:00:37 +02:00
Duckulus
7e89772326 reset statement instead of recreating it when executing preparedstatement batch 2025-11-19 23:47:15 +01:00
Duckulus
f7cc402dfc add batching support to JDBC4PreparedStatement 2025-11-16 15:22:17 +01:00
pedrocarlo
1db13889e3 Change Value::Text to use a Cow<'static, str> instead of Vec<u8> 2025-11-11 16:11:46 -03:00
zongkx
5d6e97b46b add executeUpdate updated count 2025-09-11 12:17:05 +00:00
Nikita Sivukhin
d1eab18670 enable indices in java sdk 2025-08-13 16:46:25 +04:00
Jussi Saurio
a48b6d049a Another post-rebase clippy round with 1.88.0 2025-07-12 19:10:56 +03:00
Nils Koch
828d4f5016 fix clippy errors for rust 1.88.0 (auto fix) 2025-07-12 18:58:41 +03:00
pedrocarlo
711b1ef114 make all run_once be run under statement or connection so that rollback is called 2025-07-07 11:51:25 -03:00
Diego Reis
4b32577f80 bind/java: Rename to Turso 2025-07-03 10:56:05 -03:00
Pekka Enberg
53ba3ff926 Rename limbo_core crate to turso_core 2025-06-29 09:59:17 +03:00
Pekka Enberg
2fc5c0ce5c Switch to runtime flag for enabling indexes
Makes it easier to test the feature:

```
$ cargo run --  --experimental-indexes
Limbo v0.0.22
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database
limbo> CREATE TABLE t(x);
limbo> CREATE INDEX t_idx ON t(x);
limbo> DROP INDEX t_idx;
```
2025-06-26 10:07:28 +03:00
Nils Koch
2827b86917 chore: fix clippy warnings 2025-06-23 19:52:13 +01:00
Pekka Enberg
90c1e3fc06 Switch Connection to use Arc instead of Rc
Connection needs to be Arc so that bindings can wrap it with `Mutex` for
multi-threading.
2025-06-16 10:43:19 +03:00
Pekka Enberg
e3f71259d8 Rename OwnedValue -> Value
We have not had enough merge conflicts for a while so let's do a
tree-wide rename.
2025-05-15 09:59:46 +03:00
Timo Kösters
68d8b86bb7 fix: get name of rowid column 2025-04-22 08:46:37 +02:00
Pere Diaz Bou
ee55116ca6 return row as reference to registers 2025-03-29 22:04:08 +01:00
Pere Diaz Bou
5b7fcd27bd make column reuse blob/text fields 2025-03-29 22:02:49 +01:00
Pere Diaz Bou
bf37fd3314 wip 2025-03-29 22:02:49 +01:00
Pere Diaz Bou
9291f60722 Introduce Register struct
OwnedValue has become a powerhouse of madness, mainly because I decided
to do it like that when I first introduced AggContext. I decided it was
enough and I introduced a `Register` struct that contains `OwnedValue`,
`Record` and `Aggregation`, this way we don't use `OwnedValue` for
everything make everyone's life harder.

This is the next step towards making ImmutableRecords the default
because I want to remove unnecessary allocations. Right now we clone
OwnedValues when we generate a record more than needed.
2025-03-27 17:53:02 +01:00
Pekka Enberg
96175cccf7 cli: Add --experimental-mvcc option to enable MVCC 2025-03-06 10:16:42 +02:00
Pere Diaz Bou
8daf7666d1 Make database Sync + Send 2025-03-05 14:07:48 +01:00
김선우
412bdf5585 Apply cargo formatting 2025-03-03 21:55:10 +09:00
김선우
f8052a9860 Implement totalChanges 2025-03-03 14:35:23 +09:00
Pekka Enberg
936ae307b7 core: Kill value type
We currently have two value types, `Value` and `OwnedValue`. The
original thinking was that `Value` is external type and `OwnedValue` is
internal type. However, this just results in unnecessary transformation
between the types as data crosses the Limbo library boundary.

Let's just follow SQLite here and consolidate on a single value type
(where `sqlite3_value` is just an alias for the internal `Mem` type).
The way this will eventually work is that we can have bunch of
pre-allocated `OwnedValue` objects in `ProgramState` and basically
return a reference to them all the way to the application itself, which
extracts the actual value.
2025-02-26 10:57:45 +02:00
김선우
14280680c0 Apply rust lint 2025-02-12 10:36:43 +09:00
김선우
cb7bd3d211 Change package name from org.github.tursodatabase to tech.turso 2025-02-12 09:58:25 +09:00
wyhaya
351a032cc1 core: Add default column name 2025-02-11 07:03:51 +00:00
Tiago Ribeiro
729524efbd Update java bindings to use the new retrieval methods to access Record values. 2025-02-10 00:27:51 -07:00
김선우
2fa3a1e6ae Apply lint 2025-02-09 22:46:48 +09:00
김선우
e0b0a667bb Implement close 2025-02-09 18:40:50 +09:00
김선우
21d6f33c6b Implement bindXXX functions on rust and java side 2025-02-07 11:25:23 +09:00