Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
zhuxiujia opened this issue Jan 22, 2020 · 0 comments

Comments

@zhuxiujia
Copy link

zhuxiujia commented Jan 22, 2020

  • rust error
Connection.prepare(sql);
create_statement.execute_query(&arg_array);

Err(General("Couldn\'t convert the value `Date(\"\\\'2019-12-12\\\'\")` to a desired type"))
  • mysql data row
date   `2019-12-12 00:00:00`

so i check the code. maybe you need add a mothed support the date. and i use this code ,query date success.

//just like 

/// 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<dyn ResultSetMetaData>>;

    /// 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
}
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);
         }
    }
}
@zhuxiujia zhuxiujia changed the title prepared Statement select date fail in Mysql error.but create Statement is success. prepared Statement select convert date fail in Mysql error.but create Statement is success. Jan 22, 2020
@zhuxiujia zhuxiujia changed the title prepared Statement select convert date fail in Mysql error.but create Statement is success. prepared Statement Convert Date Type fail in Mysql error.but create Statement is success. Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant