mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-03 07:14:33 +01:00
Accept parsing SET statements with repeated names, like `.. SET (a, a) =
(1, 2)`
This commit is contained in:
@@ -557,7 +557,7 @@ impl ToTokens for UpdatePlan {
|
||||
.unwrap();
|
||||
|
||||
ast::Set {
|
||||
col_names: ast::DistinctNames::single(ast::Name::from_str(col_name)),
|
||||
col_names: ast::Names::single(ast::Name::from_str(col_name)),
|
||||
expr: set_expr.clone(),
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -825,7 +825,6 @@ fn emit_update_insns(
|
||||
});
|
||||
|
||||
// Check if rowid was provided (through INTEGER PRIMARY KEY as a rowid alias)
|
||||
|
||||
let rowid_alias_index = table_ref.columns().iter().position(|c| c.is_rowid_alias);
|
||||
|
||||
let has_user_provided_rowid = if let Some(index) = rowid_alias_index {
|
||||
|
||||
@@ -1292,6 +1292,39 @@ impl QualifiedName {
|
||||
}
|
||||
}
|
||||
|
||||
/// Ordered set of column names
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Names(Vec<Name>);
|
||||
|
||||
impl Names {
|
||||
/// Initialize
|
||||
pub fn new(name: Name) -> Self {
|
||||
let mut dn = Self(Vec::new());
|
||||
dn.0.push(name);
|
||||
dn
|
||||
}
|
||||
/// Single column name
|
||||
pub fn single(name: Name) -> Self {
|
||||
let mut dn = Self(Vec::with_capacity(1));
|
||||
dn.0.push(name);
|
||||
dn
|
||||
}
|
||||
/// Push name
|
||||
pub fn insert(&mut self, name: Name) -> Result<(), ParserError> {
|
||||
self.0.push(name);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for Names {
|
||||
type Target = Vec<Name>;
|
||||
|
||||
fn deref(&self) -> &Vec<Name> {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Ordered set of distinct column names
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
@@ -1319,6 +1352,7 @@ impl DistinctNames {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for DistinctNames {
|
||||
type Target = IndexSet<Name>;
|
||||
|
||||
@@ -1735,7 +1769,7 @@ pub enum InsertBody {
|
||||
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
|
||||
pub struct Set {
|
||||
/// column name(s)
|
||||
pub col_names: DistinctNames,
|
||||
pub col_names: Names,
|
||||
/// expression
|
||||
pub expr: Expr,
|
||||
}
|
||||
|
||||
@@ -802,22 +802,28 @@ cmd ::= with(C) UPDATE orconf(R) xfullname(X) indexed_opt(I) SET setlist(Y) from
|
||||
}
|
||||
%endif
|
||||
|
||||
%type reidlist {Names}
|
||||
|
||||
reidlist(A) ::= reidlist(A) COMMA nm(Y).
|
||||
{let id = Y; A.insert(id)?;}
|
||||
reidlist(A) ::= nm(Y).
|
||||
{ A = Names::new(Y); /*A-overwrites-Y*/}
|
||||
|
||||
%type setlist {Vec<Set>}
|
||||
|
||||
setlist(A) ::= setlist(A) COMMA nm(X) EQ expr(Y). {
|
||||
let s = Set{ col_names: DistinctNames::single(X), expr: Y };
|
||||
let s = Set{ col_names: Names::single(X), expr: Y };
|
||||
A.push(s);
|
||||
}
|
||||
setlist(A) ::= setlist(A) COMMA LP idlist(X) RP EQ expr(Y). {
|
||||
setlist(A) ::= setlist(A) COMMA LP reidlist(X) RP EQ expr(Y). {
|
||||
let s = Set{ col_names: X, expr: Y };
|
||||
A.push(s);
|
||||
}
|
||||
setlist(A) ::= nm(X) EQ expr(Y). {
|
||||
A = vec![Set{ col_names: DistinctNames::single(X), expr: Y }];
|
||||
A = vec![Set{ col_names: Names::single(X), expr: Y }];
|
||||
|
||||
}
|
||||
setlist(A) ::= LP idlist(X) RP EQ expr(Y). {
|
||||
setlist(A) ::= LP reidlist(X) RP EQ expr(Y). {
|
||||
A = vec![Set{ col_names: X, expr: Y }];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user