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

Commit fdd4817

Browse files
bors[bot]Glauber Costa
andauthored
Merge #356
356: be more permissive with pragmas r=psarna a=glommer Especially read only, just let them go! Co-authored-by: Glauber Costa <[email protected]>
2 parents b6db9d0 + 8106ee3 commit fdd4817

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

sqld/src/query_analysis.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,34 @@ impl StmtKind {
6262
| Stmt::CreateIndex { .. },
6363
) => Some(Self::Write),
6464
Cmd::Stmt(Stmt::Select { .. }) => Some(Self::Read),
65-
Cmd::Stmt(Stmt::Pragma(name, body)) if is_pragma_allowed(name, body.as_ref()) => {
66-
Some(Self::Write)
65+
Cmd::Stmt(Stmt::Pragma(name, body)) => {
66+
if is_ro_pragma(name, body.as_ref()) {
67+
Some(Self::Read)
68+
} else if is_pragma_allowed(name, body.as_ref()) {
69+
Some(Self::Write)
70+
} else {
71+
None
72+
}
6773
}
6874
_ => None,
6975
}
7076
}
7177
}
7278

79+
fn is_ro_pragma(name: &QualifiedName, _body: Option<&PragmaBody>) -> bool {
80+
matches!(name, QualifiedName {
81+
db_name: None,
82+
name,
83+
alias: None,
84+
} if name.0.starts_with("index_")|| name.0 == "encoding" || name.0 == "function_list" || name.0 == "module_list" || name.0.starts_with("table_"))
85+
}
86+
7387
fn is_pragma_allowed(name: &QualifiedName, _body: Option<&PragmaBody>) -> bool {
7488
matches!(name, QualifiedName {
7589
db_name: None,
7690
name,
7791
alias: None,
78-
} if name.0 == "writable_schema" || name.0 == "foreign_keys")
92+
} if name.0 == "writable_schema" || name.0.starts_with("foreign_key"))
7993
}
8094

8195
/// The state of a transaction for a series of statement

0 commit comments

Comments
 (0)