Closed psarna closed 8 months ago
I cannot reproduce with your example:
% cargo run --example sql_cmd
Running `target/debug/examples/sql_cmd`
SELECT * FROM sqlite_master a LEFT OUTER JOIN sqlite_master b;
Hm, maybe I went too far with minimizing it, let me double-check
I'm confused, it fails in our sqld and points to this unreachable instruction, but I also see it work just fine with the sql_cmd
example.
@gwenn hey I think this is an issue with the flavor of the parser that takes ownership of its data. I realized that in my experiments I used that flavor. I modified the example by adding a to_vec()
:
use fallible_iterator::FallibleIterator;
use sqlite3_parser::lexer::sql::Parser;
/// Parse a string.
// RUST_LOG=sqlite3Parser=debug
fn main() {
env_logger::init();
let arg = "PRAGMA parser_trace=ON;";
let mut parser = Parser::new(arg.as_bytes().to_vec());
loop {
match parser.next() {
Ok(None) => break,
Err(err) => {
eprintln!("Err: {err} in {arg}");
break;
}
Ok(Some(cmd)) => {
println!("{cmd}");
}
}
}
}
... and then the example returns garbage:
[sarna@sarna-pc lemon-rs]$ RUST_LOG=info cargo run --release --example sql_cmd
Finished release [optimized] target(s) in 0.02s
Running `target/release/examples/sql_cmd`
PRAGMA =ON;er_trace = ON;
Thanks for your investigation.
The issue should be related to this unsafe block: https://github.com/gwenn/lemon-rs/blob/master/src/lexer/scan.rs#L270-L271
See https://github.com/gwenn/lemon-rs/pull/26/files#diff-3f786ccab1066df60ecf2d56744fa4fbc9b94efe78a12f66d0a5f986e81038baR100 (no unsafe / transmute anymore but no streaming anymore)
@psarna, @MarinPostma could you please check / review PR #26.
Version 0.7.0 released
Hi! The following legal statement in sqlite:
causes the parser to panic on unreachable code: