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
Prior code to get SQLite version using sqlite_version() works. Now broken. [Solved Manually. See comments] #503
Comments
This code works. It manually decodes it properly step by step. I'm sure you probably have a better way of doing this in the libraries but I'm not familiar enough with how your library works internally. Hopefully this code will help and there is an easier way to solve this. let conn = rb.acquire().await?;
let encoded_value = conn.query("SELECT sqlite_version()", vec![]).await;
let array_value = match encoded_value {
Ok(rbs::Value::Array(array_value)) => array_value,
Ok(_) => return Err(anyhow!("Expected array but got something else")),
Err(e) => return Err(anyhow!("Query error: {}", e)),
};
let first_array_value = match array_value.len() {
1 => array_value[0].clone(),
_ => {
return Err(anyhow!(
"Expected only one element in the array--got {}",
array_value.len()
))
}
};
let map_value = match first_array_value {
rbs::Value::Map(map_value) => map_value,
_ => return Err(anyhow!("Expected map but got something else")),
};
let first_map_element_value = match map_value.into_iter().next() {
Some(value) => value.1,
None => return Err(anyhow!("Expected map to contain one element it has none")),
};
let version = match first_map_element_value {
rbs::Value::String(decoded_version) => decoded_version,
_ => return Err(anyhow!("Expected string but got something else")),
}; |
#[test]
fn test_decode_string() {
let v: String = rbatis::decode(Value::Array(vec![to_value!{
"a":"a",
}])).unwrap();
assert_eq!(v, "a");
}
|
The following code used to work to get the SQLite version:
It fails with the following error: "Database error: Sqlite: invalid type: map, expected a string"
To get more information, I used the following code extracted from query_decode():
What I get for v is:
v: Array([Map({String("sqlite_version()"): String("3.45.0")})])
So, apparently decode() [which is what is called next in query_decode] cannot handle that return structure from SQLite.
Any ideas on how to resolve?
The text was updated successfully, but these errors were encountered: