tokio-rs / rdbc

Rust DataBase Connectivity (RDBC) :: Common Rust API for database drivers
Apache License 2.0
566 stars 25 forks source link

prepared Statement Convert Date Type fail in Mysql error.but create Statement is success. #63

Open zhuxiujia opened 4 years ago

zhuxiujia commented 4 years ago
Connection.prepare(sql);
create_statement.execute_query(&arg_array);

Err(General("Couldn\'t convert the value `Date(\"\\\'2019-12-12\\\'\")` to a desired type"))

/// Result set from executing a query against a statement pub trait ResultSet { /// get meta data about this result set fn meta_data(&self) -> Result<Box>;

/// Move the cursor to the next available row if one exists and return true if it does
fn next(&mut self) -> bool;

fn get_i8(&self, i: u64) -> Result<Option<i8>>;
fn get_i16(&self, i: u64) -> Result<Option<i16>>;
fn get_i32(&self, i: u64) -> Result<Option<i32>>;
fn get_i64(&self, i: u64) -> Result<Option<i64>>;
fn get_f32(&self, i: u64) -> Result<Option<f32>>;
fn get_f64(&self, i: u64) -> Result<Option<f64>>;
fn get_string(&self, i: u64) -> Result<Option<String>>;
fn get_bytes(&self, i: u64) -> Result<Option<Vec<u8>>>;

fn get_date(&self, i: u64) -> Result<Option<String>>; // this code impl to support date

}


``` rust
impl <'a>MySQLResultSet<'a>{
    fn get_my_date(&self, i: u64) -> Result<Option<my::Value>, Error> {
        match &self.row {
            Some(Ok(row)) => row
                .get_opt(i as usize)
                .expect("we will never `take` the value so the outer `Option` is always `Some`")
                .map(|v| Some(v))
                .map_err(value_to_rdbc_err),
            _ => Ok(None),
        }
    }
}

//get_date impl
impl<'a> rdbc::ResultSet for MySQLResultSet<'a> {
fn get_date(&self, i: u64) -> Result<Option<String>, Error> {
         let date=self.get_my_date(i)?;
         if date.is_some(){
             let v=date.unwrap();
            return Ok(Option::from(v.as_sql(true)));
         }else{
             return Ok(None);
         }
    }
}