Skip to content

Commit 01eaf60

Browse files
committed
Possibly translate both sides of expr in update
1 parent 1346223 commit 01eaf60

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

core/translate/update.rs

+27-13
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,37 @@ pub fn translate_update(
9999
if let Some(where_clause) = &body.where_clause {
100100
let expr = if let ast::Expr::Binary(lhs, op, rhs) = where_clause.as_ref() {
101101
// we don't support Expr::Id in translate_expr, so we rewrite to an Expr::Column
102-
if let ast::Expr::Id(col_name) = lhs.as_ref() {
102+
let lhs = if let ast::Expr::Id(col_name) = lhs.as_ref() {
103103
let Some((col_idx, col)) = btree_table.get_column(&col_name.0) else {
104104
bail_parse_error!("column {} not found", col_name.0);
105105
};
106-
&ast::Expr::Binary(
107-
Box::new(ast::Expr::Column {
108-
table: 0, // one table in our [referenced_tables]
109-
database: None,
110-
column: col_idx,
111-
is_rowid_alias: col.is_rowid_alias,
112-
}),
113-
*op,
114-
rhs.clone(),
115-
)
106+
&ast::Expr::Column {
107+
table: 0, // one table in our [referenced_tables]
108+
database: None,
109+
column: col_idx,
110+
is_rowid_alias: col.is_rowid_alias,
111+
}
116112
} else {
117-
where_clause
118-
}
113+
&lhs
114+
};
115+
let rhs = if let ast::Expr::Id(col_name) = rhs.as_ref() {
116+
let Some((col_idx, col)) = btree_table.get_column(&col_name.0) else {
117+
bail_parse_error!("column {} not found", col_name.0);
118+
};
119+
&ast::Expr::Column {
120+
table: 0,
121+
database: None,
122+
column: col_idx,
123+
is_rowid_alias: col.is_rowid_alias,
124+
}
125+
} else {
126+
&rhs
127+
};
128+
&Box::new(ast::Expr::Binary(
129+
Box::new(lhs.clone()),
130+
*op,
131+
Box::new(rhs.clone()),
132+
))
119133
} else {
120134
where_clause
121135
};

0 commit comments

Comments
 (0)