Skip to content

Commit

Permalink
Fix todo panic
Browse files Browse the repository at this point in the history
  • Loading branch information
wyhaya committed Sep 1, 2023
1 parent 8f66a69 commit dd68187
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ pub enum Error {
#[error("BULK UPLOAD input failure: {0}")]
/// Invalid input in Bulk Upload
BulkInput(Cow<'static, str>),
#[error("Unimplemented: {0}")]
/// Not yet implemented
///
/// NOTE: It may be removed in the future.
Unimplemented(Cow<'static, str>),
}

impl Error {
Expand Down
10 changes: 7 additions & 3 deletions src/tds/codec/column_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use super::{Encode, FixedLenType, TypeInfo, VarLenType};
use crate::tds::time::{Date, DateTime2, DateTimeOffset, Time};
use crate::{
tds::{time::DateTime, time::SmallDateTime, xml::XmlData, Numeric},
SqlReadBytes,
Error, SqlReadBytes,
};
use bytes::BufMut;
pub(crate) use bytes_mut_with_type_info::BytesMutWithTypeInfo;
Expand Down Expand Up @@ -133,7 +133,11 @@ impl<'a> ColumnData<'a> {
VarLenType::Decimaln | VarLenType::Numericn => {
ColumnData::Numeric(Numeric::decode(src, *scale).await?)
}
_ => todo!(),
_ => {
return Err(Error::Unimplemented(
format!("not yet implemented for {:?}", ty).into(),
))
}
},
TypeInfo::Xml { schema, size } => xml::decode(src, *size, schema.clone()).await?,
};
Expand Down Expand Up @@ -656,7 +660,7 @@ impl<'a> Encode<BytesMutWithTypeInfo<'a>> for ColumnData<'a> {
{
if let Some(num) = opt {
if scale != &num.scale() {
todo!("this still need some work, if client scale not aligned with server, we need to do conversion but will lose precision")
return Err(Error::Unimplemented("this still need some work, if client scale not aligned with server, we need to do conversion but will lose precision".into()));
}
num.encode(&mut *dst)?;
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/tds/codec/rpc_request.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::{AllHeaderTy, Encode, ALL_HEADERS_LEN_TX};
use crate::{tds::codec::ColumnData, BytesMutWithTypeInfo, Result};
use crate::{tds::codec::ColumnData, BytesMutWithTypeInfo, Error, Result};
use bytes::{BufMut, BytesMut};
use enumflags2::{bitflags, BitFlags};
use std::borrow::BorrowMut;
Expand Down Expand Up @@ -106,7 +106,7 @@ impl<'a> Encode<BytesMut> for TokenRpcRequest<'a> {
RpcProcIdValue::Name(ref _name) => {
//let (left_bytes, _) = try!(write_varchar::<u16>(&mut cursor, name, 0));
//assert_eq!(left_bytes, 0);
todo!()
return Err(Error::Unimplemented("".into()));
}
}

Expand Down
29 changes: 21 additions & 8 deletions src/tds/codec/token/token_col_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
use crate::{
error::Error,
tds::codec::{Encode, FixedLenType, TokenType, TypeInfo, VarLenType},
Column, ColumnData, ColumnType, SqlReadBytes,
Column, ColumnData, ColumnType, Result, SqlReadBytes,
};
use asynchronous_codec::BytesMut;
use bytes::BufMut;
Expand Down Expand Up @@ -119,8 +119,8 @@ pub struct BaseMetaDataColumn {
}

impl BaseMetaDataColumn {
pub(crate) fn null_value(&self) -> ColumnData<'static> {
match &self.ty {
pub(crate) fn null_value(&self) -> Result<ColumnData<'static>> {
let val = match &self.ty {
TypeInfo::FixedLen(ty) => match ty {
FixedLenType::Null => ColumnData::I32(None),
FixedLenType::Int1 => ColumnData::U8(None),
Expand Down Expand Up @@ -167,11 +167,17 @@ impl BaseMetaDataColumn {
VarLenType::NVarchar => ColumnData::String(None),
VarLenType::NChar => ColumnData::String(None),
VarLenType::Xml => ColumnData::Xml(None),
VarLenType::Udt => todo!("User-defined types not supported"),
VarLenType::Udt => {
return Err(Error::Unimplemented(
"User-defined types not supported".into(),
))
}
VarLenType::Text => ColumnData::String(None),
VarLenType::Image => ColumnData::Binary(None),
VarLenType::NText => ColumnData::String(None),
VarLenType::SSVariant => todo!(),
VarLenType::SSVariant => {
return Err(Error::Unimplemented("SSVariant type not supported".into()))
}
},
TypeInfo::VarLenSizedPrecision { ty, .. } => match ty {
VarLenType::Guid => ColumnData::Guid(None),
Expand All @@ -197,14 +203,21 @@ impl BaseMetaDataColumn {
VarLenType::NVarchar => ColumnData::String(None),
VarLenType::NChar => ColumnData::String(None),
VarLenType::Xml => ColumnData::Xml(None),
VarLenType::Udt => todo!("User-defined types not supported"),
VarLenType::Udt => {
return Err(Error::Unimplemented(
"User-defined types not supported".into(),
))
}
VarLenType::Text => ColumnData::String(None),
VarLenType::Image => ColumnData::Binary(None),
VarLenType::NText => ColumnData::String(None),
VarLenType::SSVariant => todo!(),
VarLenType::SSVariant => {
return Err(Error::Unimplemented("SSVariant type not supported".into()))
}
},
TypeInfo::Xml { .. } => ColumnData::Xml(None),
}
};
Ok(val)
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/tds/codec/token/token_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ impl TokenRow<'static> {

for (i, column) in col_meta.columns.iter().enumerate() {
let data = if row_bitmap.is_null(i) {
column.base.null_value()
column.base.null_value()?
} else {
ColumnData::decode(src, &column.base.ty).await?
};
Expand Down
12 changes: 10 additions & 2 deletions src/tds/codec/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ impl Encode<BytesMut> for VarLenContext {
dst.put_u32_le(self.len() as u32);
}
VarLenType::Xml => (),
typ => todo!("encoding {:?} is not supported yet", typ),
typ => {
return Err(Error::Unimplemented(
format!("encoding {:?} is not supported yet", typ).into(),
))
}
}

if let Some(collation) = self.collation() {
Expand Down Expand Up @@ -314,7 +318,11 @@ impl TypeInfo {
VarLenType::Image | VarLenType::Text | VarLenType::NText => {
src.read_u32_le().await? as usize
}
_ => todo!("not yet implemented for {:?}", ty),
_ => {
return Err(Error::Unimplemented(
format!("not yet implemented for {:?}", ty).into(),
));
}
};

let collation = match ty {
Expand Down

0 comments on commit dd68187

Please sign in to comment.