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

Commit affef5e

Browse files
author
Glauber Costa
committed
parse multiline when loading dump
SQLite dumps are often multi-line, so accumulate on a buffer and only send when the line ends with ; Fixes #354
1 parent b6db9d0 commit affef5e

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

sqld/src/database/dump/loader.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,23 +68,37 @@ const WASM_TABLE_CREATE: &str =
6868

6969
fn perform_load_dump(conn: &rusqlite::Connection, path: PathBuf) -> anyhow::Result<()> {
7070
let mut f = BufReader::new(File::open(path)?);
71+
let mut curr = String::new();
7172
let mut line = String::new();
7273
let mut skipped_wasm_table = false;
73-
while let Ok(n) = f.read_line(&mut line) {
74+
while let Ok(n) = f.read_line(&mut curr) {
7475
if n == 0 {
7576
break;
7677
}
78+
let frag = curr.trim();
79+
80+
if frag.is_empty() || frag.starts_with("--") {
81+
curr.clear();
82+
continue;
83+
}
84+
85+
line.push_str(frag);
86+
curr.clear();
7787

7888
// This is a hack to ignore the libsql_wasm_func_table table because it is already created
7989
// by the system.
80-
if !skipped_wasm_table && line.trim() == WASM_TABLE_CREATE {
90+
if !skipped_wasm_table && line == WASM_TABLE_CREATE {
8191
skipped_wasm_table = true;
8292
line.clear();
8393
continue;
8494
}
8595

86-
conn.execute(&line, ())?;
87-
line.clear();
96+
if line.ends_with(';') {
97+
conn.execute(&line, ())?;
98+
line.clear();
99+
} else {
100+
line.push(' ');
101+
}
88102
}
89103

90104
Ok(())

0 commit comments

Comments
 (0)