mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-12-23 11:12:51 +00:00
Fix displaying WORK or TRANSACTION after BEGIN (#1565)
This commit is contained in:
parent
6517da6b7d
commit
c761f0babb
5 changed files with 44 additions and 10 deletions
|
|
@ -2944,6 +2944,7 @@ pub enum Statement {
|
|||
StartTransaction {
|
||||
modes: Vec<TransactionMode>,
|
||||
begin: bool,
|
||||
transaction: Option<BeginTransactionKind>,
|
||||
/// Only for SQLite
|
||||
modifier: Option<TransactionModifier>,
|
||||
},
|
||||
|
|
@ -4519,16 +4520,20 @@ impl fmt::Display for Statement {
|
|||
Statement::StartTransaction {
|
||||
modes,
|
||||
begin: syntax_begin,
|
||||
transaction,
|
||||
modifier,
|
||||
} => {
|
||||
if *syntax_begin {
|
||||
if let Some(modifier) = *modifier {
|
||||
write!(f, "BEGIN {} TRANSACTION", modifier)?;
|
||||
write!(f, "BEGIN {}", modifier)?;
|
||||
} else {
|
||||
write!(f, "BEGIN TRANSACTION")?;
|
||||
write!(f, "BEGIN")?;
|
||||
}
|
||||
} else {
|
||||
write!(f, "START TRANSACTION")?;
|
||||
write!(f, "START")?;
|
||||
}
|
||||
if let Some(transaction) = transaction {
|
||||
write!(f, " {transaction}")?;
|
||||
}
|
||||
if !modes.is_empty() {
|
||||
write!(f, " {}", display_comma_separated(modes))?;
|
||||
|
|
@ -5023,6 +5028,24 @@ pub enum TruncateCascadeOption {
|
|||
Restrict,
|
||||
}
|
||||
|
||||
/// Transaction started with [ TRANSACTION | WORK ]
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
#[cfg_attr(feature = "visitor", derive(Visit, VisitMut))]
|
||||
pub enum BeginTransactionKind {
|
||||
Transaction,
|
||||
Work,
|
||||
}
|
||||
|
||||
impl Display for BeginTransactionKind {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
BeginTransactionKind::Transaction => write!(f, "TRANSACTION"),
|
||||
BeginTransactionKind::Work => write!(f, "WORK"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Can use to describe options in create sequence or table column type identity
|
||||
/// [ MINVALUE minvalue | NO MINVALUE ] [ MAXVALUE maxvalue | NO MAXVALUE ]
|
||||
#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord, Hash)]
|
||||
|
|
|
|||
|
|
@ -12123,6 +12123,7 @@ impl<'a> Parser<'a> {
|
|||
Ok(Statement::StartTransaction {
|
||||
modes: self.parse_transaction_modes()?,
|
||||
begin: false,
|
||||
transaction: Some(BeginTransactionKind::Transaction),
|
||||
modifier: None,
|
||||
})
|
||||
}
|
||||
|
|
@ -12139,10 +12140,15 @@ impl<'a> Parser<'a> {
|
|||
} else {
|
||||
None
|
||||
};
|
||||
let _ = self.parse_one_of_keywords(&[Keyword::TRANSACTION, Keyword::WORK]);
|
||||
let transaction = match self.parse_one_of_keywords(&[Keyword::TRANSACTION, Keyword::WORK]) {
|
||||
Some(Keyword::TRANSACTION) => Some(BeginTransactionKind::Transaction),
|
||||
Some(Keyword::WORK) => Some(BeginTransactionKind::Work),
|
||||
_ => None,
|
||||
};
|
||||
Ok(Statement::StartTransaction {
|
||||
modes: self.parse_transaction_modes()?,
|
||||
begin: true,
|
||||
transaction,
|
||||
modifier,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue