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

Commit c6a4607

Browse files
authored
fix dump bug (#700)
* fix quote col name in dump * add regression test
1 parent 9ec0c2f commit c6a4607

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

sqld/src/connection/dump/exporter.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<W: Write> DumpState<W> {
8484

8585
let mut iter = colss.iter().peekable();
8686
while let Some(col) = iter.next() {
87-
write!(&mut select, "{col}")?;
87+
write!(&mut select, "{}", Quoted(col))?;
8888
if iter.peek().is_some() {
8989
select.push(',');
9090
}
@@ -462,6 +462,9 @@ AND type IN ('index','trigger','view')";
462462

463463
#[cfg(test)]
464464
mod test {
465+
use rusqlite::Connection;
466+
use tempfile::tempdir;
467+
465468
use super::*;
466469

467470
#[test]
@@ -487,4 +490,16 @@ mod test {
487490
assert_eq!("X'68656c6c6f0a'", Blob(b"hello\n").to_string());
488491
assert_eq!("X''", Blob(b"").to_string());
489492
}
493+
494+
#[test]
495+
fn table_col_is_keyword() {
496+
let tmp = tempdir().unwrap();
497+
let conn = Connection::open(tmp.path().join("data")).unwrap();
498+
conn.execute(r#"create table test ("limit")"#, ()).unwrap();
499+
500+
let mut out = Vec::new();
501+
export_dump(conn, &mut out).unwrap();
502+
503+
insta::assert_snapshot!(std::str::from_utf8(&out).unwrap());
504+
}
490505
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
source: sqld/src/connection/dump/exporter.rs
3+
expression: "std::str::from_utf8(&out).unwrap()"
4+
---
5+
PRAGMA foreign_keys=OFF;
6+
BEGIN TRANSACTION;
7+
CREATE TABLE IF NOT EXISTS libsql_wasm_func_table (name text PRIMARY KEY, body text) WITHOUT ROWID;
8+
CREATE TABLE IF NOT EXISTS test ("limit");
9+
COMMIT;
10+

sqld/src/http/user/dump.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ where
5555
*this.join_handle = Some(join_handle);
5656
task::Poll::Pending
5757
}
58-
task::Poll::Ready(Ok(Err(err))) => task::Poll::Ready(Some(Err(err))),
58+
task::Poll::Ready(Ok(Err(err))) => {
59+
tracing::error!("error creating dump: {err}");
60+
task::Poll::Ready(Some(Err(err)))
61+
}
5962
task::Poll::Ready(Err(err)) => {
6063
task::Poll::Ready(Some(Err(anyhow::anyhow!(err)
6164
.context("Dump task crashed")

0 commit comments

Comments
 (0)