Skip to content

Commit

Permalink
sqlite3-parser: add support for ALTER TABLE ALTER COLUMN
Browse files Browse the repository at this point in the history
Fixes #447
  • Loading branch information
psarna authored and MarinPostma committed Jan 18, 2024
1 parent 2919db0 commit 9f2c698
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions vendored/sqlite3-parser/src/parser/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1965,6 +1965,7 @@ pub enum AlterTableBody {
AddColumn(ColumnDefinition), // TODO distinction between ADD and ADD COLUMN
RenameColumn { old: Name, new: Name },
DropColumn(Name), // TODO distinction between DROP and DROP COLUMN
AlterColumn { old: Name, cd: ColumnDefinition },
}
impl ToTokens for AlterTableBody {
fn to_tokens<S: TokenStream>(&self, s: &mut S) -> Result<(), S::Error> {
Expand All @@ -1990,6 +1991,13 @@ impl ToTokens for AlterTableBody {
s.append(TK_COLUMNKW, None)?;
name.to_tokens(s)
}
AlterTableBody::AlterColumn { old, cd } => {
s.append(TK_ALTER, None)?;
s.append(TK_COLUMNKW, None)?;
old.to_tokens(s)?;
s.append(TK_TO, None)?;
cd.to_tokens(s)
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions vendored/sqlite3-parser/src/parser/parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -1327,6 +1327,13 @@ cmd ::= ALTER TABLE fullname(X) DROP kwcolumn_opt nm(Y). {
self.ctx.stmt = Some(Stmt::AlterTable(X, AlterTableBody::DropColumn(Y)));
}

cmd ::= ALTER TABLE fullname(X) ALTER COLUMNKW columnname(Y) TO columnname(Z) carglist(C). {
let (colfrom_name, _) = Y;
let (col_name, col_type) = Z;
let cd = ColumnDefinition{ col_name, col_type, constraints: C };
self.ctx.stmt = Some(Stmt::AlterTable(X, AlterTableBody::AlterColumn{ old: colfrom_name, cd }));
}

kwcolumn_opt ::= .
kwcolumn_opt ::= COLUMNKW.
%endif SQLITE_OMIT_ALTERTABLE
Expand Down

0 comments on commit 9f2c698

Please sign in to comment.