sqlite3-parser: separate boxed CreateVirtualTable struct

This commit is contained in:
Jussi Saurio
2025-02-09 14:11:00 +02:00
parent 36a3cb1d5e
commit 9b0997a60d
4 changed files with 27 additions and 33 deletions

View File

@@ -283,12 +283,13 @@ impl ToTokens for Stmt {
s.append(TK_AS, None)?;
select.to_tokens(s)
}
Self::CreateVirtualTable {
if_not_exists,
tbl_name,
module_name,
args,
} => {
Self::CreateVirtualTable(create_virtual_table) => {
let CreateVirtualTable {
if_not_exists,
tbl_name,
module_name,
args,
} = &**create_virtual_table;
s.append(TK_CREATE, None)?;
s.append(TK_VIRTUAL, None)?;
s.append(TK_TABLE, None)?;

View File

@@ -130,16 +130,7 @@ pub enum Stmt {
select: Box<Select>,
},
/// `CREATE VIRTUAL TABLE`
CreateVirtualTable {
/// `IF NOT EXISTS`
if_not_exists: bool,
/// table name
tbl_name: QualifiedName,
/// module
module_name: Name,
/// args
args: Option<Vec<String>>, // TODO smol str
},
CreateVirtualTable(Box<CreateVirtualTable>),
/// `DELETE`
Delete(Box<Delete>),
/// `DETACH DATABASE`: db name
@@ -197,7 +188,17 @@ pub enum Stmt {
/// `UPDATE`
Update(Box<Update>),
/// `VACUUM`: database name, into expr
Vacuum(Option<Name>, Option<Expr>),
/// `CREATE VIRTUAL TABLE`
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CreateVirtualTable {
/// `IF NOT EXISTS`
pub if_not_exists: bool,
/// table name
pub tbl_name: QualifiedName,
/// module name
pub module_name: Name,
/// args
pub args: Option<Vec<String>>, // TODO smol str
}
/// `CREATE TRIGGER

View File

@@ -1329,15 +1329,15 @@ kwcolumn_opt ::= COLUMNKW.
cmd ::= create_vtab(X). {self.ctx.stmt = Some(X);}
cmd ::= create_vtab(X) LP vtabarglist RP. {
let mut stmt = X;
if let Stmt::CreateVirtualTable{ ref mut args, .. } = stmt {
*args = self.ctx.module_args();
if let Stmt::CreateVirtualTable(ref mut create_virtual_table) = stmt {
create_virtual_table.args = self.ctx.module_args();
}
self.ctx.stmt = Some(stmt);
}
%type create_vtab {Stmt}
create_vtab(A) ::= createkw VIRTUAL TABLE ifnotexists(E)
fullname(X) USING nm(Z). {
A = Stmt::CreateVirtualTable{ if_not_exists: E, tbl_name: X, module_name: Z, args: None };
A = Stmt::CreateVirtualTable(Box::new(CreateVirtualTable{ if_not_exists: E, tbl_name: X, module_name: Z, args: None }));
}
vtabarglist ::= vtabarg.
vtabarglist ::= vtabarglist COMMA vtabarg.