Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion mordant-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@

[bun_sql_jsc]
"bare_bool_args:src/sql_jsc/shared/datetime_text.rs" = 1
"same_match_twice:src/sql_jsc/mysql/protocol/ResultSet.rs" = 1

[bun_sys]
"error_collapsed_to_bool:src/sys/lib.rs" = 4
26 changes: 5 additions & 21 deletions src/sql_jsc/mysql/protocol/ResultSet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use bun_sql::mysql::protocol::any_mysql_error::AnyMySQLError;
use bun_sql::mysql::protocol::column_definition41::ColumnFlags;
use bun_sql::mysql::protocol::encode_int::decode_length_int;
use bun_sql::mysql::protocol::new_reader::{NewReader, ReaderContext};
use bun_sql::shared::ColumnIdentifier as NameOrIndex;
use bun_sql::shared::Data;
use bun_sql::shared::SQLQueryResultMode;

Expand Down Expand Up @@ -224,16 +223,10 @@ impl<'a> Row<'a> {
self.parse_value_and_set_cell(value, column, &string_data);
}
}
value.index = match column.name_or_index {
// The indexed columns can be out of order.
NameOrIndex::Index(i) => i,
_ => u32::try_from(index).expect("int cast"),
};
value.is_indexed_column = match column.name_or_index {
NameOrIndex::Duplicate => 2,
NameOrIndex::Index(_) => 1,
NameOrIndex::Name(_) => 0,
};
value.set_column(
u32::try_from(index).expect("int cast"),
&column.name_or_index,
);
} else {
return Err(AnyMySQLError::InvalidResultRow);
}
Expand Down Expand Up @@ -291,16 +284,7 @@ impl<'a> Row<'a> {
.unwrap_or(AnyMySQLError::InvalidBinaryValue),
})?;
}
value.index = match column.name_or_index {
// The indexed columns can be out of order.
NameOrIndex::Index(idx) => idx,
_ => u32::try_from(i).expect("int cast"),
};
value.is_indexed_column = match column.name_or_index {
NameOrIndex::Duplicate => 2,
NameOrIndex::Index(_) => 1,
NameOrIndex::Name(_) => 0,
};
value.set_column(u32::try_from(i).expect("int cast"), &column.name_or_index);
}

self.values = scopeguard::ScopeGuard::into_inner(cells);
Expand Down
13 changes: 1 addition & 12 deletions src/sql_jsc/postgres/DataCell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use bun_sql::shared::sql_query_result_mode::SQLQueryResultMode as PostgresSQLQue

pub(crate) use crate::shared::sql_data_cell::SQLDataCell;
pub use crate::shared::sql_data_cell::{Array, Flags, Raw, Tag, TypedArray, Value};
use bun_sql::shared::column_identifier::ColumnIdentifier;

type Result<T, E = AnyPostgresError> = core::result::Result<T, E>;

Expand Down Expand Up @@ -1272,20 +1271,10 @@ impl<'a> Putter<'a> {
};
}
self.count += 1;
cell.index = match &field.name_or_index {
// The indexed columns can be out of order.
ColumnIdentifier::Index(i) => *i,
_ => index,
};

// TODO: when duplicate and we know the result will be an object
// and not a .values() array, we can discard the data
// immediately.
cell.is_indexed_column = match &field.name_or_index {
ColumnIdentifier::Duplicate => 2,
ColumnIdentifier::Index(_) => 1,
ColumnIdentifier::Name(_) => 0,
};
cell.set_column(index, &field.name_or_index);
Ok(true)
}

Expand Down
33 changes: 21 additions & 12 deletions src/sql_jsc/shared/SQLDataCell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,18 +269,27 @@ impl SQLDataCell {
/// the right named/indexed/duplicate flag into `toJS`.
#[inline]
pub(crate) fn null_for_column(position: u32, column: &ColumnIdentifier) -> SQLDataCell {
SQLDataCell {
is_indexed_column: match column {
ColumnIdentifier::Duplicate => 2,
ColumnIdentifier::Index(_) => 1,
ColumnIdentifier::Name(_) => 0,
},
index: match column {
ColumnIdentifier::Index(i) => *i,
_ => position,
},
..SQLDataCell::default()
}
let mut cell = SQLDataCell::null();
cell.set_column(position, column);
cell
}

/// Tags the cell with the column it was decoded for, in the encoding
/// SQLClient.cpp's `DataCell` reads: `is_indexed_column` is 0 for a named
/// column, 1 for an all-digits name (the object key is that number, not the
/// ordinal `position`, so indexed cells can land out of order) and 2 for a
/// duplicate, which object-mode results skip.
#[inline]
pub(crate) fn set_column(&mut self, position: u32, column: &ColumnIdentifier) {
self.is_indexed_column = match column {
ColumnIdentifier::Duplicate => 2,
ColumnIdentifier::Index(_) => 1,
ColumnIdentifier::Name(_) => 0,
};
self.index = match column {
ColumnIdentifier::Index(i) => *i,
_ => position,
};
}

#[inline]
Expand Down
Loading