Skip to content

Commit

Permalink
remove more deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
pacman82 committed Nov 28, 2022
1 parent aba06b6 commit 1307101
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 26 deletions.
10 changes: 9 additions & 1 deletion odbc-api/src/buffers/any_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ use super::{
},
columnar::ColumnBuffer,
text_column::TextColumnSliceMut,
BinColumn, BinColumnView, BufferDesc, BufferDescription, CharColumn, ColumnarBuffer, Item,
BinColumn, BinColumnView, BufferDesc, CharColumn, ColumnarBuffer, Item,
NullableSlice, NullableSliceMut, TextColumn, TextColumnView, WCharColumn,
};

#[allow(deprecated)]
use super::BufferDescription;

/// Since buffer shapes are same for all time / timestamps independent of the precision and we do
/// not know the precise SQL type. In order to still be able to bind time / timestamp buffer as
/// input without requiring the user to separately specify the precision, we declare 100 Nano second
Expand Down Expand Up @@ -67,6 +70,7 @@ pub enum AnyBuffer {
impl AnyBuffer {
/// Map buffer description to actual buffer.
#[deprecated = "Use try_from_desc instead"]
#[allow(deprecated)]
pub fn try_from_description(
max_rows: usize,
desc: BufferDescription,
Expand All @@ -83,6 +87,7 @@ impl AnyBuffer {

/// Map buffer description to actual buffer.
#[deprecated = "Use form_desc instead"]
#[allow(deprecated)]
pub fn from_description(max_rows: usize, desc: BufferDescription) -> Self {
let fallible_allocations = false;
Self::impl_from_desc(max_rows, desc.into(), fallible_allocations).unwrap()
Expand Down Expand Up @@ -323,6 +328,7 @@ pub type ColumnarAnyBuffer = ColumnarBuffer<AnyBuffer>;
impl ColumnarAnyBuffer {
/// Allocates a [`ColumnarBuffer`] fitting the buffer descriptions.
#[deprecated = "Use from_descs instead"]
#[allow(deprecated)]
pub fn from_description(
capacity: usize,
descs: impl IntoIterator<Item = BufferDescription>,
Expand All @@ -349,6 +355,7 @@ impl ColumnarAnyBuffer {
/// [`Error::TooLargeColumnBufferSize`]. This function is slower than [`Self::from_description`]
/// which would just panic if not enough memory is available for allocation.
#[deprecated = "Use try from descs"]
#[allow(deprecated)]
pub fn try_from_description(
capacity: usize,
descs: impl Iterator<Item = BufferDescription>,
Expand Down Expand Up @@ -382,6 +389,7 @@ impl ColumnarAnyBuffer {
/// result set, by not binding them at all. There is no restriction on the order of column
/// indices passed, but the function will panic, if the indices are not unique.
#[deprecated = "use from_descs_and_indices"]
#[allow(deprecated)]
pub fn from_description_and_indices(
max_rows: usize,
description: impl Iterator<Item = (u16, BufferDescription)>,
Expand Down
46 changes: 29 additions & 17 deletions odbc-api/src/buffers/description.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl BufferDesc {
/// if choosing the a buffer for the cursor type. E.g. if you intend to print a date to standard out
/// it may be more reasonable to bind it as `Text` rather than `Date`.
#[deprecated = "Use BufferDesc instead."]
#[allow(deprecated)]
#[derive(Clone, Copy, Debug)]
pub struct BufferDescription {
/// This indicates whether or not the buffer will be able to represent NULL values. This will
Expand All @@ -190,6 +191,7 @@ pub struct BufferDescription {
pub kind: BufferKind,
}

#[allow(deprecated)]
impl BufferDescription {
/// Returns the element size of such a buffer if bound as a columnar row. Can be used to
/// estimate memory for columnar bindings.
Expand All @@ -199,6 +201,7 @@ impl BufferDescription {
}
}

#[allow(deprecated)]
impl From<BufferDescription> for BufferDesc {
fn from(source: BufferDescription) -> Self {
let nullable = source.nullable;
Expand Down Expand Up @@ -278,6 +281,7 @@ pub enum BufferKind {
Bit,
}

#[allow(deprecated)]
impl BufferKind {
/// Describe a buffer which fits best the SQL Data Type.
///
Expand Down Expand Up @@ -361,6 +365,7 @@ impl BufferKind {
/// );
/// ```
#[deprecated = "Use BufferDesc::from_data_type instead"]
#[allow(deprecated)]
pub fn from_data_type(data_type: DataType) -> Option<Self> {
let buffer_kind = match data_type {
DataType::Numeric { precision, scale }
Expand Down Expand Up @@ -408,22 +413,29 @@ mod tests {
#[test]
#[cfg(target_pointer_width = "64")] // Indicator size is platform dependent.
fn bytes_per_row() {
let bpr = |kind, nullable| BufferDescription { nullable, kind }.bytes_per_row();

assert_eq!(5 + 8, bpr(BufferKind::Binary { length: 5 }, false));
assert_eq!(5 + 1 + 8, bpr(BufferKind::Text { max_str_len: 5 }, false));
assert_eq!(10 + 2 + 8, bpr(BufferKind::WText { max_str_len: 5 }, false));
assert_eq!(6, bpr(BufferKind::Date, false));
assert_eq!(6, bpr(BufferKind::Time, false));
assert_eq!(16, bpr(BufferKind::Timestamp, false));
assert_eq!(1, bpr(BufferKind::Bit, false));
assert_eq!(1 + 8, bpr(BufferKind::Bit, true));
assert_eq!(4, bpr(BufferKind::F32, false));
assert_eq!(8, bpr(BufferKind::F64, false));
assert_eq!(1, bpr(BufferKind::I8, false));
assert_eq!(2, bpr(BufferKind::I16, false));
assert_eq!(4, bpr(BufferKind::I32, false));
assert_eq!(8, bpr(BufferKind::I64, false));
assert_eq!(1, bpr(BufferKind::U8, false));
assert_eq!(5 + 8, BufferDesc::Binary { length: 5 }.bytes_per_row());
assert_eq!(
5 + 1 + 8,
BufferDesc::Text { max_str_len: 5 }.bytes_per_row()
);
assert_eq!(
10 + 2 + 8,
BufferDesc::WText { max_str_len: 5 }.bytes_per_row()
);
assert_eq!(6, BufferDesc::Date { nullable: false }.bytes_per_row());
assert_eq!(6, BufferDesc::Time { nullable: false }.bytes_per_row());
assert_eq!(
16,
BufferDesc::Timestamp { nullable: false }.bytes_per_row()
);
assert_eq!(1, BufferDesc::Bit { nullable: false }.bytes_per_row());
assert_eq!(1 + 8, BufferDesc::Bit { nullable: true }.bytes_per_row());
assert_eq!(4, BufferDesc::F32 { nullable: false }.bytes_per_row());
assert_eq!(8, BufferDesc::F64 { nullable: false }.bytes_per_row());
assert_eq!(1, BufferDesc::I8 { nullable: false }.bytes_per_row());
assert_eq!(2, BufferDesc::I16 { nullable: false }.bytes_per_row());
assert_eq!(4, BufferDesc::I32 { nullable: false }.bytes_per_row());
assert_eq!(8, BufferDesc::I64 { nullable: false }.bytes_per_row());
assert_eq!(1, BufferDesc::U8 { nullable: false }.bytes_per_row());
}
}
7 changes: 6 additions & 1 deletion odbc-api/src/buffers/item.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
use odbc_sys::{Date, Time, Timestamp};

use super::{AnySlice, AnySliceMut, BufferDesc, BufferKind, NullableSlice, NullableSliceMut};
use super::{AnySlice, AnySliceMut, BufferDesc, NullableSlice, NullableSliceMut};
use crate::Bit;

#[allow(deprecated)]
use super::BufferKind;

/// Can either be extracted as a slice or a [`NullableSlice`] from an [`AnySlice`]. This allows
/// the user to avoid matching on all possibile variants of an [`AnySlice`] in case the
/// buffered type is known at compile time.
pub trait Item: Sized + Copy {
/// E.g. [`BufferKind::I64`] for `i64`. The kind can be used in a buffer description to
/// instantiate a [`super::ColumnarBuffer`].
#[deprecated = "Use associated method buffer_desc instead."]
#[allow(deprecated)]
const BUFFER_KIND: BufferKind;

/// Can be used to instantiate a [`super::ColumnarBuffer`].
Expand All @@ -30,6 +34,7 @@ pub trait Item: Sized + Copy {
macro_rules! impl_item {
($t:ident, $plain:ident, $null:ident) => {
impl Item for $t {
#[allow(deprecated)]
const BUFFER_KIND: BufferKind = BufferKind::$plain;

fn buffer_desc(nullable: bool) -> BufferDesc {
Expand Down
6 changes: 5 additions & 1 deletion odbc-api/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
buffers::{BufferDesc, BufferDescription, BufferKind},
buffers::BufferDesc,
execute::{
execute_columns, execute_tables, execute_with_parameters, execute_with_parameters_polling,
},
Expand All @@ -10,6 +10,9 @@ use crate::{
use odbc_sys::HDbc;
use std::{borrow::Cow, mem::ManuallyDrop, str, thread::panicking};

#[allow(deprecated)]
use crate::buffers::{BufferDescription, BufferKind};

impl<'conn> Drop for Connection<'conn> {
fn drop(&mut self) {
match self.connection.disconnect().into_result(&self.connection) {
Expand Down Expand Up @@ -673,6 +676,7 @@ impl<'c> Connection<'c> {
/// * `remarks_max_len` - The maximum expected length of remarks.
/// * `column_default_max_len` - The maximum expected length of column defaults.
#[deprecated = "Use columns_buffer_descs instead"]
#[allow(deprecated)]
pub fn columns_buffer_description(
&self,
type_name_max_len: usize,
Expand Down
5 changes: 4 additions & 1 deletion odbc-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub use self::{
connection::{escape_attribute_value, Connection},
cursor::{
BlockCursor, BlockCursorPolling, Cursor, CursorImpl, CursorPolling, CursorRow,
RowSetBuffer, RowSetCursor, RowSetCursorPolling,
RowSetBuffer
},
driver_complete_option::DriverCompleteOption,
environment::{DataSourceInfo, DriverInfo, Environment},
Expand All @@ -54,3 +54,6 @@ pub use force_send_sync;
/// crate.
pub use odbc_sys as sys;
pub use widestring::{U16Str, U16String};

#[allow(deprecated)]
pub use crate::cursor::{RowSetCursor, RowSetCursorPolling};
7 changes: 6 additions & 1 deletion odbc-api/src/prepared.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::{
buffers::{AnyBuffer, BufferDesc, BufferDescription, ColumnBuffer, TextColumn},
buffers::{AnyBuffer, BufferDesc, ColumnBuffer, TextColumn},
execute::execute_with_parameters,
handles::{AsStatementRef, HasDataType, ParameterDescription, Statement, StatementRef},
ColumnarBulkInserter, CursorImpl, Error, ParameterCollectionRef, ResultSetMetadata,
};

#[allow(deprecated)]
use crate::buffers::BufferDescription;

/// A prepared query. Prepared queries are useful if the similar queries should executed more than
/// once. See [`crate::Connection::prepare`].
pub struct Prepared<S> {
Expand Down Expand Up @@ -188,6 +191,7 @@ where
/// }
/// ```
#[deprecated = "Use into_column_inserter instead"]
#[allow(deprecated)]
pub fn into_any_column_inserter(
self,
capacity: usize,
Expand Down Expand Up @@ -271,6 +275,7 @@ where
/// chunks. In such usecases you may only want to borrow the prepared statemnt, so it can be
/// reused with a different set of parameter buffers.
#[deprecated = "Use column_inserter instead."]
#[allow(deprecated)]
pub fn any_column_inserter(
&mut self,
capacity: usize,
Expand Down
7 changes: 3 additions & 4 deletions odbc-api/tests/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,13 +925,12 @@ fn columnar_insert_varchar(profile: &Profile) {
let prepared = conn
.prepare(&format!("INSERT INTO {} (a) VALUES (?)", table_name))
.unwrap();
let desc = BufferDescription {
let desc = BufferDesc::Text {
// Buffer size purposefully chosen too small, so we would get a panic if `set_max_len` would
// not work.
kind: BufferKind::Text { max_str_len: 5 },
nullable: true,
max_str_len: 5
};
let mut prebound = prepared.into_any_column_inserter(4, [desc]).unwrap();
let mut prebound = prepared.into_column_inserter(4, [desc]).unwrap();
// Fill buffer with values
// Input values to insert. Note that the last element has > 5 chars and is going to trigger a
// reallocation of the underlying buffer.
Expand Down

0 comments on commit 1307101

Please sign in to comment.