Skip to content

Commit 9f2c698

Browse files
psarnaMarinPostma
authored andcommitted
sqlite3-parser: add support for ALTER TABLE ALTER COLUMN
Fixes #447
1 parent 2919db0 commit 9f2c698

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendored/sqlite3-parser/src/parser/ast/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,6 +1965,7 @@ pub enum AlterTableBody {
19651965
AddColumn(ColumnDefinition), // TODO distinction between ADD and ADD COLUMN
19661966
RenameColumn { old: Name, new: Name },
19671967
DropColumn(Name), // TODO distinction between DROP and DROP COLUMN
1968+
AlterColumn { old: Name, cd: ColumnDefinition },
19681969
}
19691970
impl ToTokens for AlterTableBody {
19701971
fn to_tokens<S: TokenStream>(&self, s: &mut S) -> Result<(), S::Error> {
@@ -1990,6 +1991,13 @@ impl ToTokens for AlterTableBody {
19901991
s.append(TK_COLUMNKW, None)?;
19911992
name.to_tokens(s)
19921993
}
1994+
AlterTableBody::AlterColumn { old, cd } => {
1995+
s.append(TK_ALTER, None)?;
1996+
s.append(TK_COLUMNKW, None)?;
1997+
old.to_tokens(s)?;
1998+
s.append(TK_TO, None)?;
1999+
cd.to_tokens(s)
2000+
}
19932001
}
19942002
}
19952003
}

vendored/sqlite3-parser/src/parser/parse.y

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,13 @@ cmd ::= ALTER TABLE fullname(X) DROP kwcolumn_opt nm(Y). {
13271327
self.ctx.stmt = Some(Stmt::AlterTable(X, AlterTableBody::DropColumn(Y)));
13281328
}
13291329

1330+
cmd ::= ALTER TABLE fullname(X) ALTER COLUMNKW columnname(Y) TO columnname(Z) carglist(C). {
1331+
let (colfrom_name, _) = Y;
1332+
let (col_name, col_type) = Z;
1333+
let cd = ColumnDefinition{ col_name, col_type, constraints: C };
1334+
self.ctx.stmt = Some(Stmt::AlterTable(X, AlterTableBody::AlterColumn{ old: colfrom_name, cd }));
1335+
}
1336+
13301337
kwcolumn_opt ::= .
13311338
kwcolumn_opt ::= COLUMNKW.
13321339
%endif SQLITE_OMIT_ALTERTABLE

0 commit comments

Comments
 (0)