Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 41 additions & 7 deletions dump-parser/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ where

// 49 is an empirical number -
// not too large to avoid looping too much time, and not too small to avoid wrong end of query
if count_empty_lines > 49 {
// EOF?
break;
}
// if count_empty_lines > 49 {
// // EOF?
// break;
// }

match query_res {
ListQueryResult::Continue => {}
Expand Down Expand Up @@ -190,8 +190,6 @@ fn list_statements(query: &str) -> Vec<Statement> {
if stack.get(0) == Some(&b'\'') {
if (query.len() > next_idx) && &query[next_idx..next_idx] == "'" {
// do nothing because the ' char is escaped via a double ''
} else if idx > 0 && query.is_char_boundary(idx-1) && &query[idx-1..idx] == "\\" {
// do nothing because the ' char is escaped via a backslash
} else {
let _ = stack.remove(0);
}
Expand Down Expand Up @@ -524,7 +522,7 @@ Etiam augue augue, bibendum et molestie non, finibus non nulla. Etiam quis rhonc
assert!(false);
}
Statement::Query(s) => {
assert!(s.valid);
assert!(!s.valid);
}
}

Expand Down Expand Up @@ -796,6 +794,42 @@ CREATE TABLE public.toto2 (
}
}

#[test]
fn insert_queries_with_backslash_in_string_value() {
let s = list_statements(
r#"
INSERT INTO public.tbl (id, body, created_at, updated_at) VALUES (1, 'test@test.pl', 'is that a wild backslash here?\', '2016-03-14 17:32:53.505811');
INSERT INTO public.tbl (id, body, created_at, updated_at) VALUES (2, 'yet@anoher.test', 'not relevant comment', '2016-03-14 17:36:35.825205');
"#,
);
assert_eq!(s.len(), 5);
match s.get(0).unwrap() {
Statement::NewLine => { assert!(true); }
Statement::CommentLine(_) => { assert!(false); }
Statement::Query(_) => { assert!(false); }
}
match s.get(1).unwrap() {
Statement::NewLine => { assert!(false); }
Statement::CommentLine(_) => { assert!(false); }
Statement::Query(q) => { assert!(q.valid); }
}
match s.get(2).unwrap() {
Statement::NewLine => { assert!(true); }
Statement::CommentLine(_) => { assert!(false); }
Statement::Query(_) => { assert!(false); }
}
match s.get(3).unwrap() {
Statement::NewLine => { assert!(false); }
Statement::CommentLine(_) => { assert!(false); }
Statement::Query(q) => { assert!(q.valid); }
}
match s.get(4).unwrap() {
Statement::NewLine => { assert!(true); }
Statement::CommentLine(_) => { assert!(false); }
Statement::Query(_) => { assert!(false); }
}
}

#[test]
fn check_query_line_with_comment_at_the_end() {
let s = list_statements(
Expand Down
11 changes: 9 additions & 2 deletions replibyte/src/datastore/local_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,15 @@ impl Datastore for LocalDisk {
let dump = index_file.find_dump(options)?;
let entries = read_dir(format!("{}/{}", self.dir, dump.directory_name))?;

for entry in entries {
let entry = entry?;
let mut paths: Vec<_> = read_dir(format!("{}/{}", self.dir, dump.directory_name)).unwrap()
.map(|r| r.unwrap())
.collect();
paths.sort_by(|a, b| {
let a_int = a.path().file_stem().unwrap().to_os_string().to_str().unwrap().parse::<i32>().unwrap();
let b_int = b.path().file_stem().unwrap().to_os_string().to_str().unwrap().parse::<i32>().unwrap();
return a_int.cmp(&b_int)
});
for entry in paths {
let data = read(entry.path())?;

// decrypt data?
Expand Down
1 change: 0 additions & 1 deletion replibyte/src/source/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ pub fn read_and_transform<R: Read, F: FnMut(OriginalQuery, Query)>(

match list_sql_queries_from_dump_reader(reader, |query| {
let tokens = get_tokens_from_query_str(query);

match get_row_type(&tokens) {
RowType::InsertInto {
database_name,
Expand Down