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

Commit 8794ea9

Browse files
committed
query_analysis: allow CREATE FUNCTION statement
1 parent 6963ef6 commit 8794ea9

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

sqld/src/query_analysis.rs

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,25 +200,44 @@ 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+
return maybe_create_function_stmt.take();
225+
}
226+
227+
match parser.next() {
228+
Ok(Some(cmd)) => Some(parse_inner(s, cmd)),
229+
Ok(None) => None,
230+
Err(sqlite3_parser::lexer::sql::Error::ParserError(
231+
ParserError::SyntaxError {
232+
token_type: _,
233+
found: Some(found),
234+
},
235+
Some((line, col)),
236+
)) => Some(Err(anyhow::anyhow!(
237+
"syntax error around L{line}:{col}: `{found}`"
238+
))),
239+
Err(e) => Some(Err(e.into())),
240+
}
222241
})
223242
}
224243

0 commit comments

Comments
 (0)