Skip to content

Commit

Permalink
Call dpiStmt_define() inside of SqlValue::for_column()
Browse files Browse the repository at this point in the history
(Preparation for closing #44)
  • Loading branch information
kubo committed Jun 15, 2024
1 parent 33046c9 commit 887efee
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
23 changes: 20 additions & 3 deletions src/sql_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,26 @@ impl SqlValue<'_> {
pub(crate) fn for_column(
conn: Conn,
query_params: QueryParams,
array_size: u32,
) -> SqlValue<'static> {
SqlValue::new(conn, query_params.lob_bind_type, query_params, array_size)
shared_buffer_row_index: Arc<AtomicU32>,
oratype: &OracleType,
stmt_handle: *mut dpiStmt,
pos: u32,
) -> Result<SqlValue<'static>> {
let array_size = query_params.fetch_array_size;
let mut val = SqlValue::new(conn, query_params.lob_bind_type, query_params, array_size);
let oratype_i64 = OracleType::Int64;
let oratype = match oratype {
// When the column type is number whose prec is less than 18
// and the scale is zero, define it as int64.
OracleType::Number(prec, 0) if 0 < *prec && *prec < DPI_MAX_INT64_PRECISION as u8 => {
&oratype_i64
}
_ => oratype,
};
val.buffer_row_index = BufferRowIndex::Shared(shared_buffer_row_index);
val.init_handle(oratype)?;
chkerr!(val.ctxt(), dpiStmt_define(stmt_handle, pos, val.handle()?));
Ok(val)
}

// for object type
Expand Down
31 changes: 8 additions & 23 deletions src/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,31 +409,16 @@ impl Stmt {
let mut column_values = Vec::with_capacity(num_cols);

for i in 0..num_cols {
// set column info
let ci = ColumnInfo::new(self, i)?;
column_info.push(ci);
// setup column value
let mut val = SqlValue::for_column(
let info = ColumnInfo::new(self, i)?;
let val = SqlValue::for_column(
self.conn.clone(),
self.query_params.clone(),
self.query_params.fetch_array_size,
);
val.buffer_row_index = BufferRowIndex::Shared(self.shared_buffer_row_index.clone());
let oratype = column_info[i].oracle_type();
let oratype_i64 = OracleType::Int64;
let oratype = match *oratype {
// When the column type is number whose prec is less than 18
// and the scale is zero, define it as int64.
OracleType::Number(prec, 0) if 0 < prec && prec < DPI_MAX_INT64_PRECISION as u8 => {
&oratype_i64
}
_ => oratype,
};
val.init_handle(oratype)?;
chkerr!(
self.ctxt(),
dpiStmt_define(self.handle(), (i + 1) as u32, val.handle()?)
);
self.shared_buffer_row_index.clone(),
info.oracle_type(),
self.handle(),
(i + 1) as u32,
)?;
column_info.push(info);
column_values.push(val);
}
self.row = Some(Row::new(column_info, column_values)?);
Expand Down

0 comments on commit 887efee

Please sign in to comment.