Skip to content

Commit

Permalink
Fix dropping unintended DB objects via accidental LIKE matches (#34)
Browse files Browse the repository at this point in the history
In deletion of a track, use a more precise substring matching approach
to finding the tables and views to drop, instead of an error-prone
LIKE pattern.

Signed-off-by: Christian W. Damus <[email protected]>
  • Loading branch information
cdamus authored Sep 15, 2023
1 parent ac0a5ac commit 3058eaf
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ui/src/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,13 @@ function unfilterTrackGroup(state: StateDraft, trackGroup: TrackGroupState) {
// by an explicit disposable-track protocol.
async function dropTables(engineId: string, trackId: string) {
const engine = assertExists(globals.engines.get(engineId));
const suffix = trackId.split('-').join('_');
const suffix = '_' + trackId.split('-').join('_');

const result = await engine.query(`
select name, type from sqlite_schema
where name like '%_${suffix}'
where substr(name, ${-suffix.length}) = '${suffix}'
union select name, type from sqlite_temp_schema
where name like '%_${suffix}'`);
where substr(name, ${-suffix.length}) = '${suffix}'`);

const it = result.iter({name: STR, type: STR});
const dropStmts: string[] = [];
Expand Down

0 comments on commit 3058eaf

Please sign in to comment.