Skip to content

Commit b26a78b

Browse files
committed
remove db schema name from vector vtab - as it make no sense for eponymous virtual tables
- see https://www.sqlite.org/vtab.html#epovtab
1 parent 93bac68 commit b26a78b

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

libsql-sqlite3/src/vectorvtab.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ typedef struct vectorVtab vectorVtab;
3333
struct vectorVtab {
3434
sqlite3_vtab base; /* Base class - must be first */
3535
sqlite3 *db; /* Database connection */
36-
char* zDbSName; /* Database schema name */
3736
};
3837

3938
typedef struct vectorVtab_cursor vectorVtab_cursor;
@@ -59,7 +58,6 @@ static int vectorVtabConnect(
5958
sqlite3_vtab **ppVtab,
6059
char **pzErr
6160
){
62-
char *zDbSName = NULL;
6361
vectorVtab *pVtab = NULL;
6462
int rc;
6563
/*
@@ -74,21 +72,17 @@ static int vectorVtabConnect(
7472
if( pVtab == NULL ){
7573
return SQLITE_NOMEM_BKPT;
7674
}
77-
zDbSName = sqlite3DbStrDup(db, argv[1]); // argv[1] is the database schema name by spec (see https://www.sqlite.org/vtab.html#the_xcreate_method)
78-
if( zDbSName == NULL ){
79-
sqlite3_free(pVtab);
80-
return SQLITE_NOMEM_BKPT;
81-
}
75+
// > Eponymous virtual tables exist in the "main" schema only, so they will not work if prefixed with a different schema name.
76+
// so, argv[1] always equal to "main" and we can safely ignore it
77+
// (see https://www.sqlite.org/vtab.html#epovtab)
8278
memset(pVtab, 0, sizeof(*pVtab));
8379
pVtab->db = db;
84-
pVtab->zDbSName = zDbSName;
8580
*ppVtab = (sqlite3_vtab*)pVtab;
8681
return SQLITE_OK;
8782
}
8883

8984
static int vectorVtabDisconnect(sqlite3_vtab *pVtab){
9085
vectorVtab *pVTab = (vectorVtab*)pVtab;
91-
sqlite3DbFree(pVTab->db, pVTab->zDbSName);
9286
sqlite3_free(pVtab);
9387
return SQLITE_OK;
9488
}
@@ -155,7 +149,7 @@ static int vectorVtabFilter(
155149
pCur->rows.aIntValues = NULL;
156150
pCur->rows.ppValues = NULL;
157151

158-
if( vectorIndexSearch(pVTab->db, pVTab->zDbSName, argc, argv, &pCur->rows, &pCur->nReads, &pCur->nWrites, &pVTab->base.zErrMsg) != 0 ){
152+
if( vectorIndexSearch(pVTab->db, argc, argv, &pCur->rows, &pCur->nReads, &pCur->nWrites, &pVTab->base.zErrMsg) != 0 ){
159153
return SQLITE_ERROR;
160154
}
161155

0 commit comments

Comments
 (0)