Add Table::column_is_rowid_alias() helper

We need to check for rowid alias elsewhere too with ORDER BY, for
example, so let's extract a small helper for that.
This commit is contained in:
Pekka Enberg
2024-07-07 12:27:08 +03:00
parent 77bfbd47be
commit 519e6b141f
2 changed files with 11 additions and 7 deletions

View File

@@ -39,6 +39,16 @@ pub struct Table {
}
impl Table {
pub fn column_is_rowid_alias(&self, col: &Column) -> bool {
let composite_primary_key = self
.columns
.iter()
.filter(|col| col.primary_key)
.count()
> 1;
col.primary_key && col.ty == Type::Integer && !composite_primary_key
}
pub fn get_column(&self, name: &str) -> Option<(usize, &Column)> {
let name = normalize_ident(name);
for (i, column) in self.columns.iter().enumerate() {

View File

@@ -266,14 +266,8 @@ fn translate_column(
}
sqlite3_parser::ast::ResultColumn::Star => {
let table = table.unwrap();
let composite_primary_key = table
.columns
.iter()
.filter(|col| col.primary_key)
.count()
> 1;
for (i, col) in table.columns.iter().enumerate() {
if col.primary_key && col.ty == Type::Integer && !composite_primary_key { // rowid alias
if table.column_is_rowid_alias(col) {
program.emit_insn(Insn::RowId {
cursor_id: cursor_id.unwrap(),
dest: target_register + i,