Skip to content

Conversation

riazus
Copy link

@riazus riazus commented Aug 28, 2025

Resolves #2150.

Test cases implemented as well.

}
}

fn tokenize_sql_keywords(text: &str) -> Vec<String> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the risk here is that the tokenizer has some subtle bugs. Did you consider the sqlite-parser we already use elsewhere in the server?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Firstly, I thought about the tradeoff of rewriting the load_dump function using existing parsers, like sqlite-parser, versus slightly modifying this function by introducing manual parsing with tokens but with potential pitfalls. I chose the latter. However, now I'm thinking that rewriting the initial function is not as bad as I imagined. I pushed the changes.

Copy link
Author

@riazus riazus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented the dump parser function using sqlite3_parser. The tradeoffs are mentioned in the comments. Open to discussion if needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: given the new approach I think the previous message doesn't make sense anymore.

snapshot_kind: text
---
{"error":"The passed dump sql is invalid: msg: near \"COMMIT\": syntax error, sql: SELECT abs(-9223372036854775808) \n COMMIT;, offset: 43"}
{"error":"The passed dump sql is invalid: syntax error near 'COMMIT' at line 7, column 11"}
Copy link
Author

@riazus riazus Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: following the previous snapshot message, I ought to introduce a lot of unpleasant changes in the code. I believe the new message is clear enough with reasonable code modifications.

Comment on lines +299 to +302
reader
.read_to_string(&mut dump_content)
.await
.map_err(|e| LoadDumpError::Internal(format!("Failed to read dump content: {}", e)))?;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm aware of the memory allocation here, but given that we need to provide the object from the heap to sqlite3_parser I decided to go with this option. Not sure if it is the best one though.

@riazus riazus requested a review from penberg September 26, 2025 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DB creation from dump with triggers is failing
2 participants