@@ -63,9 +63,7 @@ impl StmtKind {
6363 ) => Some ( Self :: Write ) ,
6464 Cmd :: Stmt ( Stmt :: Select { .. } ) => Some ( Self :: Read ) ,
6565 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 ( ) ) {
66+ if is_pragma_allowed ( name, body. as_ref ( ) ) {
6967 Some ( Self :: Write )
7068 } else {
7169 None
@@ -76,20 +74,66 @@ impl StmtKind {
7674 }
7775}
7876
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- }
77+ fn is_pragma_allowed ( name : & QualifiedName , body : Option < & PragmaBody > ) -> bool {
78+ let name = name. name . 0 . as_str ( ) ;
79+ match name {
80+ // always ok
81+ "foreign_key" | "foreign_key_list" | "foreign_key_check" | "collation_list"
82+ | "compile_options" | "data_version" | "database_list" | "freelist_count"
83+ | "function_list" | "index_list" | "index_xinfo" | "integrity_check"
84+ | "legacy_file_format" | "page_count" | "pragma_list" | "quick_check" | "stats" | "table_info" | "table_list" | "table_xinfo" => true ,
85+ // ok without args
86+ "analysis_limit"
87+ | "application_id"
88+ | "auto_vacuum"
89+ | "automatic_index"
90+ | "busy_timeout"
91+ | "cache_size"
92+ | "cache_spill"
93+ | "cell_size_check"
94+ | "checkpoint_fullfsync"
95+ | "defer_foreign_keys"
96+ | "encoding"
97+ | "fullfsync"
98+ | "hard_heap_limit"
99+ | "journal_mode"
100+ | "journal_size_limit"
101+ | "legacy_alter_table"
102+ | "locking_mode"
103+ | "max_page_count"
104+ | "mmap_size"
105+ | "page_size"
106+ | "query_only"
107+ | "read_uncommitted"
108+ | "recursive_triggers"
109+ | "reverse_unordered_selects"
110+ | "schema_version"
111+ | "secure_delete"
112+ | "soft_heap_limit"
113+ | "synchronous"
114+ | "temp_store"
115+ | "threads"
116+ | "trusted_schema"
117+ | "user_version"
118+ | "wal_autocheckpoint"
119+
120+ if body. is_none ( ) =>
121+ {
122+ true
123+ }
124+ // changes the state of the connection, and can't be allowed rn:
125+ "case_sensitive_like" | "ignore_check_constraints" | "incremental_vacuum"
126+ // TODO: check if optimize can be safely performed
127+ | "optimize"
128+ | "parser_trace"
129+ | "shrink_memory"
130+ | "wal_checkpoint"
86131
87- fn is_pragma_allowed ( name : & QualifiedName , _body : Option < & PragmaBody > ) -> bool {
88- matches ! ( name, QualifiedName {
89- db_name: None ,
90- name,
91- alias: None ,
92- } if name. 0 == "writable_schema" || name. 0 . starts_with( "foreign_key" ) )
132+ => {
133+ false
134+ }
135+ _ => false ,
136+ }
93137}
94138
95139/// The state of a transaction for a series of statement
0 commit comments