Skip to content

Commit eb8f152

Browse files
lucasvrMarinPostma
authored andcommitted
Document xPreparedSql virtual table callback (tursodatabase#93)
Enhance documentation by describing the new xPreparedSql callback for virtual tables. Refs tursodatabase#87
1 parent 1782261 commit eb8f152

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

doc/libsql_extensions.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,30 @@ int libsql_open(
338338
### Example
339339

340340
An example implementation can be browsed in the Rust test suite, at `test/rust_suite/src/virtual_wal.rs`
341+
342+
## xPreparedSql virtual table callback
343+
344+
Virtual tables provide an interface to expose different data sources. Several callbacks are already defined via function pointers on `struct sqlite3_module`, including xConnect and xBestIndex. libSQL introduces a new callback named `xPreparedSql` that allows a virtual table implementation to receive the SQL string submitted by the application for execution.
345+
346+
### How to enable
347+
348+
In order to enable this callback, applications must define a value for `iVersion >= 700` on `struct sqlite3_module`.
349+
350+
### Usage
351+
352+
The following C99 snippet shows how to declare a virtual table that implements the new callback.
353+
354+
```sql
355+
static int helloPreparedSql(sqlite3_vtab_cursor *cur, const char *sql) {
356+
printf("Prepared SQL: %s\n", sql);
357+
return SQLITE_OK;
358+
}
359+
360+
static sqlite3_module helloModule = {
361+
.iVersion = 700,
362+
.xCreate = helloCreate,
363+
.xConnect = helloConnect,
364+
// ...
365+
.xPreparedSql = helloPreparedSql,
366+
};
367+
```

src/wal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4092,7 +4092,7 @@ static void libsqlGetWalPathname(char *buf, const char *orig, int orig_len) {
40924092
memcpy(buf + orig_len, "-wal", 4);
40934093
}
40944094

4095-
static int libsqlPreMainDbOpen(struct libsql_wal_methods*, const char *) {
4095+
static int libsqlPreMainDbOpen(struct libsql_wal_methods *methods, const char *main_db_path) {
40964096
return SQLITE_OK;
40974097
}
40984098

0 commit comments

Comments
 (0)