mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-07 01:04:26 +01:00
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:
@@ -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() {
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user