#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PragmaEntry {
pub name: &'static str,
pub writes: Option<(&'static str, &'static str)>,
}
const QUERY_TREE: &str = "query_tree";
pub static PRAGMAS: &[PragmaEntry] = &[
PragmaEntry { name: "disable_checkpoint_on_shutdown", writes: None },
PragmaEntry { name: "disable_object_cache", writes: None },
PragmaEntry { name: "disable_optimizer", writes: Some(("enable_optimizer", "false")) },
PragmaEntry {
name: "disable_print_progress_bar",
writes: Some(("enable_progress_bar_print", "false")),
},
PragmaEntry { name: "disable_profile", writes: Some(("enable_profiling", crate::UNSET)) },
PragmaEntry { name: "disable_profiling", writes: Some(("enable_profiling", crate::UNSET)) },
PragmaEntry { name: "disable_progress_bar", writes: Some(("enable_progress_bar", "false")) },
PragmaEntry { name: "disable_verification", writes: None },
PragmaEntry { name: "disable_verify_parallelism", writes: None },
PragmaEntry { name: "enable_checkpoint_on_shutdown", writes: None },
PragmaEntry { name: "enable_object_cache", writes: None },
PragmaEntry { name: "enable_optimizer", writes: Some(("enable_optimizer", "true")) },
PragmaEntry {
name: "enable_print_progress_bar",
writes: Some(("enable_progress_bar_print", "true")),
},
PragmaEntry { name: "enable_profile", writes: Some(("enable_profiling", QUERY_TREE)) },
PragmaEntry { name: "enable_profiling", writes: Some(("enable_profiling", QUERY_TREE)) },
PragmaEntry { name: "enable_progress_bar", writes: Some(("enable_progress_bar", "true")) },
PragmaEntry { name: "enable_verification", writes: None },
PragmaEntry { name: "force_checkpoint", writes: None },
PragmaEntry { name: "verify_parallelism", writes: None },
];
#[must_use]
pub fn pragma_named(name: &str) -> Option<&'static PragmaEntry> {
PRAGMAS.iter().find(|entry| entry.name.eq_ignore_ascii_case(name))
}
#[cfg(test)]
mod tests {
use super::{PRAGMAS, pragma_named};
use crate::{SETTINGS, UNSET};
#[test]
fn the_table_is_the_nineteen_the_pin_has_and_is_sorted() {
assert_eq!(PRAGMAS.len(), 19);
let mut sorted: Vec<&str> = PRAGMAS.iter().map(|entry| entry.name).collect();
let written = sorted.clone();
sorted.sort_unstable();
assert_eq!(sorted, written, "the table is in the order the pin lists it, which is by name");
assert_eq!(PRAGMAS.iter().filter(|entry| entry.writes.is_none()).count(), 9);
}
#[test]
fn every_pragma_writes_a_setting_that_exists_and_a_value_of_its_type() {
for entry in PRAGMAS {
let Some((name, value)) = entry.writes else {
continue;
};
let setting = SETTINGS
.iter()
.find(|it| it.name == name)
.unwrap_or_else(|| panic!("{} writes {name}, which is not a setting", entry.name));
match setting.input_type {
"BOOLEAN" => assert!(
value == "true" || value == "false",
"{} writes {value} into a boolean",
entry.name
),
"VARCHAR" => {}
other => panic!("{} writes a {other}, which nothing here does yet", entry.name),
}
}
}
#[test]
fn the_pair_that_turns_profiling_off_puts_it_back_to_nothing() {
assert_eq!(pragma_named("disable_profiling").unwrap().writes.unwrap().1, UNSET);
assert_eq!(pragma_named("DISABLE_PROFILE").unwrap().writes.unwrap().1, UNSET);
assert_eq!(pragma_named("enable_profiling").unwrap().writes.unwrap().1, "query_tree");
}
#[test]
fn a_name_that_is_not_one_of_them_is_not_found() {
assert!(pragma_named("enable_verify_parallelism").is_none());
assert!(pragma_named("enable_logging").is_none());
assert!(pragma_named("version").is_none());
}
}