Comments (2)
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")),
};
from rbatis.
The following code used to work to get the SQLite version:
match rb.query_decode("SELECT sqlite_version()", vec![]).await? { Some(v) => { eprintln!("b"); Ok(v) } None => Err(anyhow!("Unable to obtain database 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():
let conn = rb.acquire().await?; let v = conn.query("SELECT sqlite_version()", vec![]).await?; eprintln!("v: {:?}", v);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?
- this unit test work's well, did you delete
Cargo.lock
and run commandcargo update
to update rbatis version?
#[test]
fn test_decode_string() {
let v: String = rbatis::decode(Value::Array(vec![to_value!{
"a":"a",
}])).unwrap();
assert_eq!(v, "a");
}
Testing started at 10:29 ...
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.10s
Running tests/decode_test.rs (target/debug/deps/decode_test-96029c5cf93b50f4)
from rbatis.
Related Issues (20)
- Setting result error using py_sql with single result HOT 1
- Is there any synchronized Chinese document? HOT 3
- Unable to update column to null.
- test_decode_time_zone error
- Variable `recordsValue` should have snake_case name, e.g. `records_value` HOT 5
- Common field processing issues HOT 2
- The document needs to be updated HOT 2
- How to dynamically specify schema HOT 14
- add return primary key value in postgresql HOT 1
- How to use tracing log in rbatis-v4 version HOT 2
- field value with json string, return invalid type: map, expected String error HOT 2
- Setting the maximum connection pool doesn't work well HOT 3
- Hello, I encountered an issue with a plugin dynamically modifying SQL HOT 4
- MySQL keeps re-establishing connections HOT 5
- Does the latest version not support Option single result? HOT 4
- How to use rbatis to implement dynamic structure like Java return value map < string, Object > HOT 6
- rbatis::crud!(Book {},"t_book"); No effect HOT 1
- postgres page err HOT 1
- Mssql insert batch error HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rbatis.