mirror of
https://github.com/aljazceru/turso.git
synced 2026-01-26 19:34:24 +01:00
sqlite3-parser: box AlterTable
This commit is contained in:
@@ -103,22 +103,28 @@ impl Stmt {
|
||||
/// check for extra rules
|
||||
pub fn check(&self) -> Result<(), ParserError> {
|
||||
match self {
|
||||
Self::AlterTable(old_name, AlterTableBody::RenameTo(new_name)) => {
|
||||
if *new_name == old_name.name {
|
||||
return Err(custom_err!(
|
||||
"there is already another table or index with this name: {}",
|
||||
new_name
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Self::AlterTable(.., AlterTableBody::AddColumn(cd)) => {
|
||||
for c in cd {
|
||||
if let ColumnConstraint::PrimaryKey { .. } = c {
|
||||
return Err(custom_err!("Cannot add a PRIMARY KEY column"));
|
||||
} else if let ColumnConstraint::Unique(..) = c {
|
||||
return Err(custom_err!("Cannot add a UNIQUE column"));
|
||||
Self::AlterTable(alter_table) => {
|
||||
let (old_name, body) = &**alter_table;
|
||||
match body {
|
||||
AlterTableBody::RenameTo(new_name) => {
|
||||
if *new_name == old_name.name {
|
||||
return Err(custom_err!(
|
||||
"there is already another table or index with this name: {}",
|
||||
new_name
|
||||
));
|
||||
}
|
||||
}
|
||||
AlterTableBody::AddColumn(cd) => {
|
||||
for c in cd {
|
||||
if let ColumnConstraint::PrimaryKey { .. } = c {
|
||||
return Err(custom_err!("Cannot add a PRIMARY KEY column"));
|
||||
}
|
||||
if let ColumnConstraint::Unique(..) = c {
|
||||
return Err(custom_err!("Cannot add a UNIQUE column"));
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -119,7 +119,8 @@ impl Display for Cmd {
|
||||
impl ToTokens for Stmt {
|
||||
fn to_tokens<S: TokenStream>(&self, s: &mut S) -> Result<(), S::Error> {
|
||||
match self {
|
||||
Self::AlterTable(tbl_name, body) => {
|
||||
Self::AlterTable(alter_table) => {
|
||||
let (tbl_name, body) = &**alter_table;
|
||||
s.append(TK_ALTER, None)?;
|
||||
s.append(TK_TABLE, None)?;
|
||||
tbl_name.to_tokens(s)?;
|
||||
|
||||
@@ -71,7 +71,7 @@ pub(crate) enum ExplainKind {
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub enum Stmt {
|
||||
/// `ALTER TABLE`: table name, body
|
||||
AlterTable(QualifiedName, AlterTableBody),
|
||||
AlterTable(Box<(QualifiedName, AlterTableBody)>),
|
||||
/// `ANALYSE`: object name
|
||||
Analyze(Option<QualifiedName>),
|
||||
/// `ATTACH DATABASE`
|
||||
|
||||
Reference in New Issue
Block a user