Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: reset modifications of sqlite3_vtab #1027

Merged
merged 6 commits into from
Feb 15, 2024
Merged

bugfix: reset modifications of sqlite3_vtab #1027

merged 6 commits into from
Feb 15, 2024

Conversation

avinassh
Copy link
Member

@avinassh avinassh commented Feb 14, 2024

fixes #865

Cause

Earlier, we had merged upstream changes from SQLite 3.44.0 to libsql. The upstream had modified sqlite3_module struct by adding a new field xIntegrity. Prior to this, we had added a custom function field xPreparedSql to sqlite3_module. This change broke the crsqlite extension.

To fix that, we added a new struct libsql_module and moved xPreparedSql in it. We also added helper functions like libsql_create_module and libsql_create_module_v2. This change also prompted to modify sqlite3_vtab by adding filed pointing to libsql_module. This fixed the crsqlite extension.

Unfortunately, it broke sqlite-vss extension. The sqlite-vss extended the sqlite3_vtab struct by adding new fields, due to our change, the memory layout assumption changed and caused the issue.

The broken commit: e56bdbd, PR of 3.44.0 merge: #625 (it also has more context and discussion)

Fix

I have reversed the e56bdbd commit, removed the libsql_module struct and the methods we had added. I moved xPreparedSql back to sqlite3_module and removed the erranous field libsql_module from sqlite3_vtab. Accordingly, I have modified crsqlite extension as well.

To avoid similar regressions in future, I have added tests for both the extensions.

Follow up PR: tests for other extensions, add cargo cache to the github workflow, and general speed up tricks

@avinassh avinassh changed the title Remove libsql_module field from sqlite3_vtab bugfix: reset modifications of sqlite3_vtab Feb 15, 2024
@avinassh avinassh force-pushed the 865-sqlite-vtab branch 5 times, most recently from 6cb741c to 040f6bb Compare February 15, 2024 13:49
Also removed the associated functions `libsql_create_module_v2`, `libsql_create_module` functions'.

The `libsql_module` had a function `xPreparedSql` which is now moved to `sqlite_module`. The `sqlite_module` might get changed in the upstream, so added some padding space for our custom functions
@avinassh avinassh force-pushed the 865-sqlite-vtab branch 3 times, most recently from 069b1e5 to 3201e83 Compare February 15, 2024 16:52
@avinassh avinassh marked this pull request as ready for review February 15, 2024 17:58
@glommer glommer added this pull request to the merge queue Feb 15, 2024
Merged via the queue into main with commit d178de8 Feb 15, 2024
16 checks passed
@glommer glommer deleted the 865-sqlite-vtab branch February 15, 2024 18:31
penberg added a commit that referenced this pull request Oct 21, 2024
The module struct initializer for xPrepareSql is wrong since commit
d178de8 ("bugfix: reset modifications of `sqlite3_vtab` (#1027)")
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')
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sqlite-vss fails with libsql
2 participants