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.
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.
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)
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)
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.
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>
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.
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;
```
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.
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.