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)
- How to use the function that supports sqlite to set password? HOT 7
- Transactton Token error: 'Incorrect syntax near 'begin'.' on server HOT 5
- Removed local dependencies. Re-cargo build reports an error! Version rbatis: 4.5.11 HOT 5
- method `set_timeout` is not a member of trait `Pool` HOT 17
- add duckdb support HOT 4
- Hello, I have encountered a question: functions in traits cannot be declared `async` HOT 2
- When using enumeration, can it support automatic conversion to integer when saving or updating, and automatically convert integer to enumeration when selecting? HOT 2
- Intermittent Delays in Query Execution After Periods of Inactivity HOT 4
- MSSQL using transactions error: token error: 'Incorrect syntax near 'begin'.' on server MSSQL2016 executing on line 1 (code: 102, state: 1, class: 15) HOT 2
- crud insert is error when the primary key column name is not id
- html_sql can't trim uppercase "and|or" after where HOT 1
- htmlsql_select_page field is filtered problem HOT 2
- The json field of the database is returned as an escaped string HOT 2
- 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
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.