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

Commit

Permalink
fix dump bug (#700)
Browse files Browse the repository at this point in the history
* fix quote col name in dump

* add regression test
  • Loading branch information
MarinPostma authored Sep 25, 2023
1 parent 9ec0c2f commit c6a4607
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
17 changes: 16 additions & 1 deletion sqld/src/connection/dump/exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<W: Write> DumpState<W> {

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

#[cfg(test)]
mod test {
use rusqlite::Connection;
use tempfile::tempdir;

use super::*;

#[test]
Expand All @@ -487,4 +490,16 @@ mod test {
assert_eq!("X'68656c6c6f0a'", Blob(b"hello\n").to_string());
assert_eq!("X''", Blob(b"").to_string());
}

#[test]
fn table_col_is_keyword() {
let tmp = tempdir().unwrap();
let conn = Connection::open(tmp.path().join("data")).unwrap();
conn.execute(r#"create table test ("limit")"#, ()).unwrap();

let mut out = Vec::new();
export_dump(conn, &mut out).unwrap();

insta::assert_snapshot!(std::str::from_utf8(&out).unwrap());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: sqld/src/connection/dump/exporter.rs
expression: "std::str::from_utf8(&out).unwrap()"
---
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE IF NOT EXISTS libsql_wasm_func_table (name text PRIMARY KEY, body text) WITHOUT ROWID;
CREATE TABLE IF NOT EXISTS test ("limit");
COMMIT;

5 changes: 4 additions & 1 deletion sqld/src/http/user/dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ where
*this.join_handle = Some(join_handle);
task::Poll::Pending
}
task::Poll::Ready(Ok(Err(err))) => task::Poll::Ready(Some(Err(err))),
task::Poll::Ready(Ok(Err(err))) => {
tracing::error!("error creating dump: {err}");
task::Poll::Ready(Some(Err(err)))
}
task::Poll::Ready(Err(err)) => {
task::Poll::Ready(Some(Err(anyhow::anyhow!(err)
.context("Dump task crashed")
Expand Down

0 comments on commit c6a4607

Please sign in to comment.