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)
Commit 59bfb15f3 added .gitattributes with '*.bat text eol=crlf', but
bindings/java/gradlew.bat and examples/react-native/android/gradlew.bat
were committed with crlf blobs and missed by the renormalize pass. Git
stores text files with lf in the index and only converts to crlf on
checkout, so the stale crlf blobs made these files show up as fully
modified whenever anything renormalized them.
git add --renormalize rewrites the blobs to lf; checkouts still produce
crlf on disk via the eol=crlf attribute.
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.