mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-08 17:54:22 +01:00
use virtual root page for sqlite_schema
This commit is contained in:
29
cli/app.rs
29
cli/app.rs
@@ -1126,15 +1126,6 @@ impl Limbo {
|
||||
}
|
||||
|
||||
fn display_schema(&mut self, table: Option<&str>) -> anyhow::Result<()> {
|
||||
if !self.conn.is_db_initialized() {
|
||||
if let Some(table_name) = table {
|
||||
self.write_fmt(format_args!("-- Error: Table '{table_name}' not found."))?;
|
||||
} else {
|
||||
self.writeln("-- No tables or indexes found in the database.")?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
match table {
|
||||
Some(table_spec) => {
|
||||
// Parse table name to handle database prefixes (e.g., "db.table")
|
||||
@@ -1188,15 +1179,6 @@ impl Limbo {
|
||||
}
|
||||
|
||||
fn display_indexes(&mut self, maybe_table: Option<String>) -> anyhow::Result<()> {
|
||||
if !self.conn.is_db_initialized() {
|
||||
if let Some(tbl_name) = &maybe_table {
|
||||
self.write_fmt(format_args!("-- Error: Table '{tbl_name}' not found."))?;
|
||||
} else {
|
||||
self.writeln("-- No indexes found in the database.")?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let sql = match maybe_table {
|
||||
Some(ref tbl_name) => format!(
|
||||
"SELECT name FROM sqlite_schema WHERE type='index' AND tbl_name = '{tbl_name}' ORDER BY 1"
|
||||
@@ -1245,17 +1227,6 @@ impl Limbo {
|
||||
}
|
||||
|
||||
fn display_tables(&mut self, pattern: Option<&str>) -> anyhow::Result<()> {
|
||||
if !self.conn.is_db_initialized() {
|
||||
if let Some(pattern) = pattern {
|
||||
self.write_fmt(format_args!(
|
||||
"-- Error: Tables with pattern '{pattern}' not found."
|
||||
))?;
|
||||
} else {
|
||||
self.writeln("-- No tables found in the database.")?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let sql = match pattern {
|
||||
Some(pattern) => format!(
|
||||
"SELECT name FROM sqlite_schema WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name LIKE '{pattern}' ORDER BY 1"
|
||||
|
||||
@@ -40,40 +40,18 @@ impl<'a> ImportFile<'a> {
|
||||
args.table
|
||||
);
|
||||
|
||||
let mut table_exists = false;
|
||||
if self.conn.is_db_initialized() {
|
||||
table_exists = 'check: {
|
||||
match self.conn.query(table_check_query) {
|
||||
Ok(rows) => {
|
||||
if let Some(mut rows) = rows {
|
||||
loop {
|
||||
match rows.step() {
|
||||
Ok(turso_core::StepResult::Row) => {
|
||||
break 'check true;
|
||||
}
|
||||
Ok(turso_core::StepResult::Done) => break 'check false,
|
||||
Ok(turso_core::StepResult::IO) => {
|
||||
if let Err(e) = rows.run_once() {
|
||||
let _ = self.writer.write_all(
|
||||
format!("Error checking table existence: {e:?}\n")
|
||||
.as_bytes(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Ok(
|
||||
turso_core::StepResult::Interrupt
|
||||
| turso_core::StepResult::Busy,
|
||||
) => {
|
||||
if let Err(e) = rows.run_once() {
|
||||
let _ = self.writer.write_all(
|
||||
format!("Error checking table existence: {e:?}\n")
|
||||
.as_bytes(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let table_exists = 'check: {
|
||||
match self.conn.query(table_check_query) {
|
||||
Ok(rows) => {
|
||||
if let Some(mut rows) = rows {
|
||||
loop {
|
||||
match rows.step() {
|
||||
Ok(turso_core::StepResult::Row) => {
|
||||
break 'check true;
|
||||
}
|
||||
Ok(turso_core::StepResult::Done) => break 'check false,
|
||||
Ok(turso_core::StepResult::IO) => {
|
||||
if let Err(e) = rows.run_once() {
|
||||
let _ = self.writer.write_all(
|
||||
format!("Error checking table existence: {e:?}\n")
|
||||
.as_bytes(),
|
||||
@@ -81,19 +59,38 @@ impl<'a> ImportFile<'a> {
|
||||
return;
|
||||
}
|
||||
}
|
||||
Ok(
|
||||
turso_core::StepResult::Interrupt
|
||||
| turso_core::StepResult::Busy,
|
||||
) => {
|
||||
if let Err(e) = rows.run_once() {
|
||||
let _ = self.writer.write_all(
|
||||
format!("Error checking table existence: {e:?}\n")
|
||||
.as_bytes(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
let _ = self.writer.write_all(
|
||||
format!("Error checking table existence: {e:?}\n")
|
||||
.as_bytes(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
Err(e) => {
|
||||
let _ = self.writer.write_all(
|
||||
format!("Error checking table existence: {e:?}\n").as_bytes(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
false
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(e) => {
|
||||
let _ = self
|
||||
.writer
|
||||
.write_all(format!("Error checking table existence: {e:?}\n").as_bytes());
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
let file = match File::open(args.file) {
|
||||
Ok(file) => file,
|
||||
Err(e) => {
|
||||
|
||||
Reference in New Issue
Block a user