mirror of
https://github.com/tursodatabase/limbo.git
synced 2025-07-07 20:45:01 +00:00
Merge 'Support sqlite_master
schema table name alias' from Anton Harniakou
Related to #1641. Adds support for `sqlite_master` schema table name. Reviewed-by: Diego Reis (@el-yawd) Closes #1669
This commit is contained in:
commit
9c9869f485
2 changed files with 37 additions and 2 deletions
|
@ -14,6 +14,9 @@ use std::rc::Rc;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
|
const SCHEMA_TABLE_NAME: &str = "sqlite_schema";
|
||||||
|
const SCHEMA_TABLE_NAME_ALT: &str = "sqlite_master";
|
||||||
|
|
||||||
pub struct Schema {
|
pub struct Schema {
|
||||||
pub tables: HashMap<String, Arc<Table>>,
|
pub tables: HashMap<String, Arc<Table>>,
|
||||||
// table_name to list of indexes for the table
|
// table_name to list of indexes for the table
|
||||||
|
@ -26,7 +29,7 @@ impl Schema {
|
||||||
let indexes: HashMap<String, Vec<Arc<Index>>> = HashMap::new();
|
let indexes: HashMap<String, Vec<Arc<Index>>> = HashMap::new();
|
||||||
#[allow(clippy::arc_with_non_send_sync)]
|
#[allow(clippy::arc_with_non_send_sync)]
|
||||||
tables.insert(
|
tables.insert(
|
||||||
"sqlite_schema".to_string(),
|
SCHEMA_TABLE_NAME.to_string(),
|
||||||
Arc::new(Table::BTree(sqlite_schema_table().into())),
|
Arc::new(Table::BTree(sqlite_schema_table().into())),
|
||||||
);
|
);
|
||||||
Self { tables, indexes }
|
Self { tables, indexes }
|
||||||
|
@ -51,7 +54,12 @@ impl Schema {
|
||||||
|
|
||||||
pub fn get_table(&self, name: &str) -> Option<Arc<Table>> {
|
pub fn get_table(&self, name: &str) -> Option<Arc<Table>> {
|
||||||
let name = normalize_ident(name);
|
let name = normalize_ident(name);
|
||||||
self.tables.get(&name).cloned()
|
let name = if name.eq_ignore_ascii_case(&SCHEMA_TABLE_NAME_ALT) {
|
||||||
|
SCHEMA_TABLE_NAME
|
||||||
|
} else {
|
||||||
|
&name
|
||||||
|
};
|
||||||
|
self.tables.get(name).cloned()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_table(&mut self, table_name: &str) {
|
pub fn remove_table(&mut self, table_name: &str) {
|
||||||
|
|
|
@ -47,6 +47,33 @@ do_execsql_test pragma-table-info-call-syntax {
|
||||||
4|sql|TEXT|0||0
|
4|sql|TEXT|0||0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do_execsql_test pragma-table-info-alt-name-equal-syntax {
|
||||||
|
PRAGMA table_info=sqlite_master
|
||||||
|
} {0|type|TEXT|0||0
|
||||||
|
1|name|TEXT|0||0
|
||||||
|
2|tbl_name|TEXT|0||0
|
||||||
|
3|rootpage|INT|0||0
|
||||||
|
4|sql|TEXT|0||0
|
||||||
|
}
|
||||||
|
|
||||||
|
do_execsql_test pragma-table-info-alt-name-call-syntax {
|
||||||
|
PRAGMA table_info(sqlite_master)
|
||||||
|
} {0|type|TEXT|0||0
|
||||||
|
1|name|TEXT|0||0
|
||||||
|
2|tbl_name|TEXT|0||0
|
||||||
|
3|rootpage|INT|0||0
|
||||||
|
4|sql|TEXT|0||0
|
||||||
|
}
|
||||||
|
|
||||||
|
do_execsql_test pragma-function-table-info-alt-name {
|
||||||
|
SELECT * FROM pragma_table_info('sqlite_master')
|
||||||
|
} {0|type|TEXT|0||0
|
||||||
|
1|name|TEXT|0||0
|
||||||
|
2|tbl_name|TEXT|0||0
|
||||||
|
3|rootpage|INT|0||0
|
||||||
|
4|sql|TEXT|0||0
|
||||||
|
}
|
||||||
|
|
||||||
do_execsql_test pragma-function-table-info {
|
do_execsql_test pragma-function-table-info {
|
||||||
SELECT * FROM pragma_table_info('sqlite_schema')
|
SELECT * FROM pragma_table_info('sqlite_schema')
|
||||||
} {0|type|TEXT|0||0
|
} {0|type|TEXT|0||0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue