mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-20 06:00:15 +00:00
Support USE db
(#565)
This commit is contained in:
parent
71c3ec057b
commit
a9db6ed139
4 changed files with 25 additions and 0 deletions
|
@ -1016,6 +1016,10 @@ pub enum Statement {
|
|||
table_name: ObjectName,
|
||||
filter: Option<ShowStatementFilter>,
|
||||
},
|
||||
/// USE
|
||||
///
|
||||
/// Note: This is a MySQL-specific statement.
|
||||
Use { db_name: Ident },
|
||||
/// `{ BEGIN [ TRANSACTION | WORK ] | START TRANSACTION } ...`
|
||||
StartTransaction { modes: Vec<TransactionMode> },
|
||||
/// `SET TRANSACTION ...`
|
||||
|
@ -1825,6 +1829,10 @@ impl fmt::Display for Statement {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
Statement::Use { db_name } => {
|
||||
write!(f, "USE {}", db_name)?;
|
||||
Ok(())
|
||||
}
|
||||
Statement::StartTransaction { modes } => {
|
||||
write!(f, "START TRANSACTION")?;
|
||||
if !modes.is_empty() {
|
||||
|
|
|
@ -535,6 +535,7 @@ define_keywords!(
|
|||
UPDATE,
|
||||
UPPER,
|
||||
USAGE,
|
||||
USE,
|
||||
USER,
|
||||
USING,
|
||||
UUID,
|
||||
|
|
|
@ -177,6 +177,7 @@ impl<'a> Parser<'a> {
|
|||
Keyword::CLOSE => Ok(self.parse_close()?),
|
||||
Keyword::SET => Ok(self.parse_set()?),
|
||||
Keyword::SHOW => Ok(self.parse_show()?),
|
||||
Keyword::USE => Ok(self.parse_use()?),
|
||||
Keyword::GRANT => Ok(self.parse_grant()?),
|
||||
Keyword::REVOKE => Ok(self.parse_revoke()?),
|
||||
Keyword::START => Ok(self.parse_start_transaction()?),
|
||||
|
@ -3776,6 +3777,11 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn parse_use(&mut self) -> Result<Statement, ParserError> {
|
||||
let db_name = self.parse_identifier()?;
|
||||
Ok(Statement::Use { db_name })
|
||||
}
|
||||
|
||||
pub fn parse_table_and_joins(&mut self) -> Result<TableWithJoins, ParserError> {
|
||||
let relation = self.parse_table_factor()?;
|
||||
// Note that for keywords to be properly handled here, they need to be
|
||||
|
|
|
@ -138,6 +138,16 @@ fn parse_show_create() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_use() {
|
||||
assert_eq!(
|
||||
mysql_and_generic().verified_stmt("USE mydb"),
|
||||
Statement::Use {
|
||||
db_name: Ident::new("mydb")
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_auto_increment() {
|
||||
let sql = "CREATE TABLE foo (bar INT PRIMARY KEY AUTO_INCREMENT)";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue