mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 15:04:04 +00:00
Support SHOW <var>
and SET <var>
This commit is contained in:
parent
f64928e994
commit
e1ded184f8
4 changed files with 168 additions and 9 deletions
|
@ -16,6 +16,7 @@
|
|||
|
||||
use sqlparser::ast::*;
|
||||
use sqlparser::dialect::{GenericDialect, PostgreSqlDialect};
|
||||
use sqlparser::parser::ParserError;
|
||||
use sqlparser::test_utils::*;
|
||||
|
||||
#[test]
|
||||
|
@ -251,6 +252,102 @@ PHP ₱ USD $
|
|||
//assert_eq!(sql, ast.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_set() {
|
||||
let stmt = pg_and_generic().verified_stmt("SET a = b");
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::SetVariable {
|
||||
local: false,
|
||||
variable: "a".into(),
|
||||
value: SetVariableValue::Ident("b".into()),
|
||||
}
|
||||
);
|
||||
|
||||
let stmt = pg_and_generic().verified_stmt("SET a = 'b'");
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::SetVariable {
|
||||
local: false,
|
||||
variable: "a".into(),
|
||||
value: SetVariableValue::Literal(Value::SingleQuotedString("b".into())),
|
||||
}
|
||||
);
|
||||
|
||||
let stmt = pg_and_generic().verified_stmt("SET a = 0");
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::SetVariable {
|
||||
local: false,
|
||||
variable: "a".into(),
|
||||
value: SetVariableValue::Literal(Value::Long(0)),
|
||||
}
|
||||
);
|
||||
|
||||
let stmt = pg_and_generic().verified_stmt("SET a = DEFAULT");
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::SetVariable {
|
||||
local: false,
|
||||
variable: "a".into(),
|
||||
value: SetVariableValue::Ident("DEFAULT".into()),
|
||||
}
|
||||
);
|
||||
|
||||
let stmt = pg_and_generic().verified_stmt("SET LOCAL a = b");
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::SetVariable {
|
||||
local: true,
|
||||
variable: "a".into(),
|
||||
value: SetVariableValue::Ident("b".into()),
|
||||
}
|
||||
);
|
||||
|
||||
pg_and_generic().one_statement_parses_to("SET a TO b", "SET a = b");
|
||||
pg_and_generic().one_statement_parses_to("SET SESSION a = b", "SET a = b");
|
||||
|
||||
assert_eq!(
|
||||
pg_and_generic().parse_sql_statements("SET"),
|
||||
Err(ParserError::ParserError(
|
||||
"Expected identifier, found: EOF".to_string()
|
||||
)),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
pg_and_generic().parse_sql_statements("SET a b"),
|
||||
Err(ParserError::ParserError(
|
||||
"Expected equals sign or TO, found: b".to_string()
|
||||
)),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
pg_and_generic().parse_sql_statements("SET a ="),
|
||||
Err(ParserError::ParserError(
|
||||
"Expected variable value, found: EOF".to_string()
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_show() {
|
||||
let stmt = pg_and_generic().verified_stmt("SHOW a");
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::ShowVariable {
|
||||
variable: "a".into()
|
||||
}
|
||||
);
|
||||
|
||||
let stmt = pg_and_generic().verified_stmt("SHOW ALL");
|
||||
assert_eq!(
|
||||
stmt,
|
||||
Statement::ShowVariable {
|
||||
variable: "ALL".into()
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fn pg() -> TestedDialects {
|
||||
TestedDialects {
|
||||
dialects: vec![Box::new(PostgreSqlDialect {})],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue