Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.

reserve table names #381

Merged
merged 1 commit into from
May 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions sqld/src/query_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ fn is_temp(name: &QualifiedName) -> bool {
name.db_name.as_ref().map(|n| n.0.as_str()) == Some("TEMP")
}

fn is_reserved_tbl(name: &QualifiedName) -> bool {
let n = name.name.0.to_lowercase();
n == "_litestream_seq" || n == "_litestream_lock" || n == "libsql_wasm_func_table"
}

fn write_if_not_reserved(name: &QualifiedName) -> Option<StmtKind> {
(!is_reserved_tbl(name)).then_some(StmtKind::Write)
}

impl StmtKind {
fn kind(cmd: &Cmd) -> Option<Self> {
match cmd {
Expand All @@ -51,12 +60,30 @@ impl StmtKind {
},
) if !is_temp(tbl_name) => Some(Self::Write),
Cmd::Stmt(
Stmt::Insert { .. }
| Stmt::Update { .. }
| Stmt::Delete { .. }
| Stmt::DropTable { .. }
| Stmt::DropIndex { .. }
| Stmt::AlterTable { .. }
Stmt::Insert {
with: _,
or_conflict: _,
tbl_name,
..
}
| Stmt::Update {
with: _,
or_conflict: _,
tbl_name,
..
},
) => write_if_not_reserved(tbl_name),

Cmd::Stmt(Stmt::Delete {
with: _, tbl_name, ..
}) => write_if_not_reserved(tbl_name),
Cmd::Stmt(Stmt::DropTable {
if_exists: _,
tbl_name,
}) => write_if_not_reserved(tbl_name),
Cmd::Stmt(Stmt::AlterTable(tbl_name, _)) => write_if_not_reserved(tbl_name),
Cmd::Stmt(
Stmt::DropIndex { .. }
| Stmt::CreateTrigger {
temporary: false, ..
}
Expand Down