Skip to content

Commit

Permalink
format, pragma_table_list -> sqlite_master
Browse files Browse the repository at this point in the history
  • Loading branch information
asg017 committed Jun 25, 2024
1 parent feea3bf commit 9dc772e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
18 changes: 10 additions & 8 deletions sqlite-vec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2837,7 +2837,6 @@ struct vec0_vtab {
sqlite3_blob *vectorBlobs[VEC0_MAX_VECTOR_COLUMNS];
};


void vec0_free_resources(vec0_vtab *p) {
for (int i = 0; i < p->numVectorColumns; i++) {
sqlite3_blob_close(p->vectorBlobs[i]);
Expand Down Expand Up @@ -3596,34 +3595,37 @@ static int vec0Destroy(sqlite3_vtab *pVtab) {

// TODO evidence-of here

zSql = sqlite3_mprintf("DROP TABLE " VEC0_SHADOW_CHUNKS_NAME, p->schemaName, p->tableName);
zSql = sqlite3_mprintf("DROP TABLE " VEC0_SHADOW_CHUNKS_NAME, p->schemaName,
p->tableName);
rc = sqlite3_prepare_v2(p->db, zSql, -1, &stmt, 0);
sqlite3_free((void *)zSql);
if((rc != SQLITE_OK) || (sqlite3_step(stmt) != SQLITE_DONE)) {
if ((rc != SQLITE_OK) || (sqlite3_step(stmt) != SQLITE_DONE)) {
rc = SQLITE_ERROR;
goto done;
}

zSql = sqlite3_mprintf("DROP TABLE " VEC0_SHADOW_ROWIDS_NAME, p->schemaName, p->tableName);
zSql = sqlite3_mprintf("DROP TABLE " VEC0_SHADOW_ROWIDS_NAME, p->schemaName,
p->tableName);
rc = sqlite3_prepare_v2(p->db, zSql, -1, &stmt, 0);
sqlite3_free((void *)zSql);
if((rc != SQLITE_OK) || (sqlite3_step(stmt) != SQLITE_DONE)) {
if ((rc != SQLITE_OK) || (sqlite3_step(stmt) != SQLITE_DONE)) {
rc = SQLITE_ERROR;
goto done;
}

for (int i = 0; i < p->numVectorColumns; i++) {
zSql = sqlite3_mprintf("DROP TABLE \"%w\".\"%w\"" , p->schemaName, p->shadowVectorChunksNames[i]);
zSql = sqlite3_mprintf("DROP TABLE \"%w\".\"%w\"", p->schemaName,
p->shadowVectorChunksNames[i]);
rc = sqlite3_prepare_v2(p->db, zSql, -1, &stmt, 0);
sqlite3_free((void *)zSql);
if((rc != SQLITE_OK) || (sqlite3_step(stmt) != SQLITE_DONE)) {
if ((rc != SQLITE_OK) || (sqlite3_step(stmt) != SQLITE_DONE)) {
rc = SQLITE_ERROR;
goto done;
}
}

rc = SQLITE_OK;
done:
done:
sqlite3_free(p);
sqlite3_finalize(stmt);
return rc;
Expand Down
29 changes: 20 additions & 9 deletions tests/test-loadable.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,18 +748,29 @@ def test_vec0_update_insert_errors2():

def test_vec0_drops():
db = connect(EXT_PATH)
db.execute("create virtual table t1 using vec0(aaa float[4], bbb float[4], chunk_size=8)")
assert [row['name'] for row in execute_all(db, "select name from pragma_table_list where name like 't1%' order by 1")] == [
't1',
't1_chunks',
't1_rowids',
't1_vector_chunks00',
't1_vector_chunks01',
db.execute(
"create virtual table t1 using vec0(aaa float[4], bbb float[4], chunk_size=8)"
)
assert [
row["name"]
for row in execute_all(
db, "select name from sqlite_master where name like 't1%' order by 1"
)
] == [
"t1",
"t1_chunks",
"t1_rowids",
"t1_vector_chunks00",
"t1_vector_chunks01",
]
db.execute("drop table t1")
assert [row['name'] for row in execute_all(db, "select name from pragma_table_list where name like 't1%' order by 1")] == [
assert [
row["name"]
for row in execute_all(
db, "select name from sqlite_master where name like 't1%' order by 1"
)
] == []

]

def test_vec0_update_deletes():
db = connect(EXT_PATH)
Expand Down

0 comments on commit 9dc772e

Please sign in to comment.