Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 490d28c

Browse files
committedApr 26, 2023
query_analysis: allow CREATE FUNCTION statement
1 parent 6963ef6 commit 490d28c

File tree

1 file changed

+35
-13
lines changed

1 file changed

+35
-13
lines changed
 

‎sqld/src/query_analysis.rs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,47 @@ impl Statement {
200200
is_insert,
201201
})
202202
}
203+
204+
// Workaround for CREATE FUNCTION.
205+
// FIXME: this should be handled by the parser (or *at least* trimmed + case insensitive)
206+
let is_create_function = s.starts_with("CREATE FUNCTION");
207+
let mut maybe_create_function_stmt = is_create_function.then(|| {
208+
Ok(Statement {
209+
stmt: s.to_string(),
210+
kind: StmtKind::Other,
211+
is_iud: false,
212+
is_insert: false,
213+
})
214+
});
215+
203216
// The parser needs to be boxed because it's large, and you don't want it on the stack.
204217
// There's upstream work to make it smaller, but in the meantime the parser should remain
205218
// on the heap:
206219
// - https://github.com/gwenn/lemon-rs/issues/8
207220
// - https://github.com/gwenn/lemon-rs/pull/19
208221
let mut parser = Box::new(Parser::new(s.as_bytes()));
209-
std::iter::from_fn(move || match parser.next() {
210-
Ok(Some(cmd)) => Some(parse_inner(s, cmd)),
211-
Ok(None) => None,
212-
Err(sqlite3_parser::lexer::sql::Error::ParserError(
213-
ParserError::SyntaxError {
214-
token_type: _,
215-
found: Some(found),
216-
},
217-
Some((line, col)),
218-
)) => Some(Err(anyhow::anyhow!(
219-
"syntax error around L{line}:{col}: `{found}`"
220-
))),
221-
Err(e) => Some(Err(e.into())),
222+
std::iter::from_fn(move || {
223+
if is_create_function {
224+
let ret = maybe_create_function_stmt.take();
225+
println!("Ret {ret:?}");
226+
return ret;
227+
//return maybe_create_function_stmt.take();
228+
}
229+
230+
match parser.next() {
231+
Ok(Some(cmd)) => Some(parse_inner(s, cmd)),
232+
Ok(None) => None,
233+
Err(sqlite3_parser::lexer::sql::Error::ParserError(
234+
ParserError::SyntaxError {
235+
token_type: _,
236+
found: Some(found),
237+
},
238+
Some((line, col)),
239+
)) => Some(Err(anyhow::anyhow!(
240+
"syntax error around L{line}:{col}: `{found}`"
241+
))),
242+
Err(e) => Some(Err(e.into())),
243+
}
222244
})
223245
}
224246

0 commit comments

Comments
 (0)
This repository has been archived.