0
0
mirror of https://github.com/tursodatabase/libsql.git synced 2025-06-03 23:31:50 +00:00

211 Commits

Author SHA1 Message Date
68d5000f9f Make libsql-ffi workspace dependency () 2025-03-20 11:54:11 +00:00
69370ba9d4 Merge branch 'main' into fix/fixup-markdown-documents 2025-03-20 13:56:52 +02:00
9bd7387495 libsql-sqlite3: Don't use pointer arithmetic
Let's be kind to Windows compiler.
2025-03-20 13:38:11 +02:00
02ac846814 libsql-sqlite3: Don't use variable length arrays
The C compiler on Windows does not like them...
2025-03-20 13:38:11 +02:00
e4a1a5abe4 libsql-sqlite3: Add conflict detection to libsql_wal_insert_frame() 2025-03-19 09:27:24 +02:00
628cceeebb disable checkpoint downgrade under LIBSQL_DISABLE_CHECKPOINT_DOWNGRADE compile time option 2025-02-27 13:04:00 +04:00
a07b9b12a8 libsql-sqlite3: Fix statement interruption signaling
We need to set some database and statement state to propagate the
interrupt error correctly.
2025-02-21 10:08:15 +02:00
1296132b72 libsql-sqlite3: Reset "isInterrupted" in sqlite3_reset() 2025-02-21 08:35:36 +02:00
8b9ea8e2db libsql-sqlite3: Add libsql_stmt_interrupt() API
This adds an API for interrupting a specific statement instead of all
pending operations like `sqlite3_interrupt()` does.
2025-02-21 08:35:33 +02:00
90f0751ff8 wal.c: do not ignore the result code of xCb in walCheckpoint
libsql exposes a WAL checkpoint callback that is called once for each
frame and right when checkpointing is about to finish.

before this change, the result code returned by the checkpoint callback
was ignored on the 'finish' invocation, which resulted in the checkpoint
completing successfully despite the callback returning an error.

this commit propagates the callback's error code and thus prevents the
wal_checkpoint() routine from returning SQLITE_OK in cases where the
callback failed.
2025-02-13 23:48:34 +02:00
6a5b840195 chore: fix minor style/grammar issues in markdown files 2025-01-23 12:48:15 +01:00
e2de2504b4 Revert "libsql: Wire up xCheckpointSeqCount"
This reverts commit bb7f011f79.
2025-01-23 13:01:39 +02:00
30ae41832b Revert "libsql-sqlite3: Add libsql_wal_checkpoint_seq_count() API"
This reverts commit b4cf7ef2ee. It is not
that useful because SQLite resets the generation when a database is
closed.
2025-01-23 13:00:46 +02:00
b8f5e89661 Merge pull request from tursodatabase/wal-checkpoint-seq-api
Add libsql_wal_checkpoint_seq_count() API
2024-12-17 17:49:53 +00:00
aabea5f779 sqlite3: fix missing pager causing SQLITE_MISUSE
This fixes a missing pager that `libsql_pager_codec` expects to not be
null. All this does is add the pager when we call `sqlite3PagerWalInsert`
to the wal frame we want to insert.

Fixes 
2024-12-12 21:16:05 -05:00
bb7f011f79 libsql: Wire up xCheckpointSeqCount 2024-12-11 10:37:23 +02:00
b4cf7ef2ee libsql-sqlite3: Add libsql_wal_checkpoint_seq_count() API
This adds libsql_wal_checkpoint_seq_count() API function for determining
the checkpoint sequence counter of a database WAL.
2024-12-10 10:12:54 +02:00
d798dd6ac6 libsql-sqlite3: Test case for syncing while reading
We need to make sure we test a case where page cache is non-empty.
2024-11-28 16:41:00 +02:00
49b5d26fc6 libsql-sqlite3: Reset pager in sqlite3PagerWalEndCommit()
We need to reset the pager in sqlite3PagerWalEndCommit() to make sure
page cache is invalidated after injecting frames to WAL to ensure
they're visible.
2024-11-28 16:41:00 +02:00
e6a4b1a91b libsql-sqlite3: End read transaction in sqlite3PagerWalEndCommit()
We have a problem with WAL API where in some scenarios, we seem to lose
WAL frames that were already applied. However, inspecting the external
WAL frame, the sync mechanics work fine and the problem is in SQLite's
in-memory state.

As it turnws out, the sqlite3PagerWalBeginCommit() function first begins
a read transaction and then upgrades it to a write transaction. However,
sqlite3PagerWalEndCommit() only ends the write transaction and therefore
leaves the pager in READER state. Let's call pager_unlock() to switch to
OPEN stte, fixing the issue of disappearing frames.
2024-11-28 13:21:25 +02:00
98ce757472 refactor wal sync tests 2024-11-27 20:20:09 +04:00
3c93f65623 libsql-sqlite3: Improve WAL API test
Make the test bit harder on the WAL API by generating more than one
frame per transaction.
2024-11-27 15:43:39 +02:00
98a5345794 libsql-sqlite3: Fix libsql_wal_frame_count() for empty databases
If a database is empty, the pagerUseWal() returns false. In that case,
make libsql_wal_frame_count() return zero instead of a logic error.
2024-11-26 15:24:54 +02:00
c9217dfbfe libsql-sqlite3: Unify database opening in test_walapi.c 2024-11-26 12:11:07 +02:00
36b37acdf2 libsql-sqlite3: Fix error reporting in WAL API
We need to call sqlite3Error() to report anything but "not an error" to
callers.
2024-11-26 12:06:04 +02:00
6c648338e8 libsql-sqlite3: Fix formatting in libsql_wal_get_frame() 2024-11-26 12:04:57 +02:00
27b3fc4d4e add anti-hacker test 2024-11-24 18:13:30 +04:00
644a91e5b2 fix comment in code 2024-11-24 18:07:31 +04:00
963256b36c add backward compatibility test for on-disk format of vector index 2024-11-24 18:01:49 +04:00
c4f37ad196 refine comment about format 2024-11-13 00:40:11 +04:00
abf43af447 introduce V3 on-disk vector index format with aligned metadata 2024-11-13 00:40:11 +04:00
848b08e4b8 make nodeMetadataSize/edgeMetadataSize dynamic 2024-11-13 00:40:11 +04:00
246667c7fd Merge pull request from tursodatabase/wal-api
libSQL WAL API
2024-11-11 12:00:39 +00:00
a1403ce441 libsql-sqlite: Document WAL API extension 2024-11-11 12:42:48 +02:00
cfd549bf26 libsql-sqlite3: Add WAL API tests 2024-11-11 12:42:48 +02:00
092fd3c679 libsql-sqlite3: Add libsql_wal_insert_frame() API
```c
static void sync_db(sqlite3 *db_primary, sqlite3 *db_backup){
  unsigned int max_frame;

  libsql_wal_frame_count(db_primary, &max_frame);
  libsql_wal_begin_commit(db_backup);
  for(int i=1; i<=max_frame; i++){
    char frame[4096+24];
    libsql_wal_get_frame(db_primary, i, frame, sizeof(frame));
    libsql_wal_insert_frame(db_backup, i, frame, sizeof(frame));
  }
  libsql_wal_end_commit(db_backup);
}
```
2024-11-11 12:42:48 +02:00
9280b8ee82 link math lib which necessary for LibSQL vector search 2024-10-31 13:19:49 +04:00
69001c546d fix test 2024-10-29 18:15:25 +04:00
45544bd7ec libsql-sqlite3: Add libsql_wal_get_frame() API
This patch adds a libsql_wal_get_frame() API to read the raw WAL frame
from a database.

You can use the API as follows (omitting error handling) to obtain all
the WAL frames in a database:

```c
static int sync_db(sqlite3 *db_primary, sqlite3 *db_backup){
  unsigned int max_frame;

  libsql_wal_frame_count(db_primary, &max_frame);

  for(int i=1; i<=max_frame; i++){
    char frame[4096+24];

    libsql_wal_get_frame(db_primary, i, frame, sizeof(frame));
  }
}
```
2024-10-29 13:30:27 +02:00
61558b2a9e libsql-{sqlite3,ffi}: Add xReadFrameRaw() to the virtual WAL API
This adds a new xReadFrameRaw() function to the virtual WAL API, which
upper layers can use to fetch the full frame, including the page number,
that is useful for appending frames to a WAL.
2024-10-29 13:30:27 +02:00
3ac4aa1689 libsql-{sqlite3,ffi}: Add xFrameCount() to the virtual WAL API 2024-10-29 13:30:27 +02:00
26ba2d969b properly lock schema in case when we work with attached DB 2024-10-29 15:13:06 +04:00
badbbe979f add test for unknown schema name 2024-10-29 15:10:16 +04:00
05fce74677 parse schema name from vector vtab index name string argument 2024-10-29 13:13:33 +04:00
b26a78b83c remove db schema name from vector vtab - as it make no sense for eponymous virtual tables
- see https://www.sqlite.org/vtab.html#epovtab
2024-10-29 13:13:04 +04:00
93bac68cb9 add test for vector search in ATTACHED db 2024-10-29 13:12:43 +04:00
abf339d180 libsql-sqlite3: Add libsql_wal_disable_checkpoint() API
SQLite unconditionally checkpoints when the last connection is closed to
a database. Let's add a libSQL extension API to give callers control
over that.
2024-10-24 13:03:03 +03:00
e75184bd1e libsql-sqlite3: Fix xPrepareSql init in test8.c
The module struct initializer for xPrepareSql is wrong since commit
d178de8f07 ("bugfix: reset modifications of `sqlite3_vtab` ()")
because it assings the xPrepareSql as the xIntegrity hook:

```
/home/runner/work/libsql/libsql/libsql-sqlite3/src/test8.c:1364:3: warning: initialization of 'int (*)(sqlite3_vtab *, const char *, const char *, int,  char **)' from incompatible pointer type 'int (*)(sqlite3_vtab_cursor *, const char *)' [-Wincompatible-pointer-types]
 1364 |   echoPreparedSql,
      |   ^~~~~~~~~~~~~~~
/home/runner/work/libsql/libsql/libsql-sqlite3/src/test8.c:1364:3: note: (near initialization for 'echoModuleV2.xIntegrity')
```
2024-10-21 14:39:45 +03:00
4091efb5b1 accept K parameter as float if there is no loss in the precision after rounding to the integer
- it cah be hard in some cliens (JS for example) to distinguish between INTEGERs and FLOATs - so we always bind FLOATs instead
- this create unnecessary error: "vector index(search): third parameter (k) must be a non-negative integer"
2024-09-29 15:09:47 +04:00
bd3e0d6904 Merge pull request from tursodatabase/vector-search-fix-integrity-check
vector search: fix integrity check
2024-08-23 11:21:53 +00:00