1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use bigdecimal::BigDecimal;
use std::str::FromStr;
use oracle::sql_type::OracleType;
use rbs::Value;
use rbdc::{Error, datetime::FastDateTime};
use crate::OracleData;
pub trait Decode {
fn decode(row: &OracleData) -> Result<Value, Error>;
}
impl Decode for Value {
fn decode(row: &OracleData) -> Result<Value, Error> {
let s = row.str.as_ref();
if s.is_none() {
return Ok(Value::Null);
}
let value = s.unwrap().clone();
let result:Value = match row.column_type {
OracleType::Number(_v,_i) => {
let dec = BigDecimal::from_str(&value).map_err(|e|Error::from(e.to_string()))?;
Value::String(dec.to_string()).into_ext("Decimal")
}
OracleType::Int64 => {
let a = value.parse::<i32>()?;
Value::I32(a)
}
OracleType::Long => {
let a = value.parse::<i64>()?;
Value::I64(a)
}
OracleType::Date => {
let a = FastDateTime::from_str(&value)?;
Value::from(a)
}
_=>{
Value::String(value)
}
};
Ok(result)
}
}