#Sqlite call with eGui

12 messages · Page 1 of 1 (latest)

rustic siren
#

Hello,
i try to add something to my DB, but it doesnt seem to work.
This is how i tried to implement the connection execution:

if *geklickt {
                print!("Hall2");

                let text = ui.label(format!("{} {} wurde zur Einkaufsliste hinzugefügt.", value, label));
                let conn = Connection::open("einkaufsliste.db");
                match conn.execute("INSERT INTO table_name (Item, Amount, User) VALUES (?1, ?2, ?3); ", [label, &value.to_string(), &"Hallo".to_string()]) {
                    Ok(updated) => println!("{} rows were updated", updated),
                    Err(err) => println!("update failed: {}", err),
                }
                
                
            }```
But i get E0599 for conn.execute(). Idk what is wrong tbh, can someone help me?
lethal elbow
#

can you copy/paste the exact error? and what library is that Connection coming from?

#

my guess is Connection::open returns a Result that you need to handle

rustic siren
# lethal elbow can you copy/paste the exact error? and what library is that `Connection` coming...

error[E0531]: cannot find tuple struct or tuple variant Connect in this scope
--> src\app.rs:118:21
|
118 | Connect(updated) => println!("{} rows were updated", updated),
| ^^^^^^^ not found in this scope

error[E0599]: no method named execute found for enum Result in the current scope
--> src\app.rs:117:28
|
117 | ... match conn.execute("INSERT INTO table_name (Item, Amount, User) VALUES (?1, ?2, ?3); ", [label, &value.to_string(), &"Hallo".to_str...
| ^^^^^^^ method not found in Result<Connection, rusqlite::Error>
|
note: the method execute exists on the type Connection
--> C:\Users\Johann.cargo\registry\src\github.com-1ecc6299db9ec823\rusqlite-0.28.0\src\lib.rs:582:5
|
582 | pub fn execute<P: Params>(&self, sql: &str, params: P) -> Result<usize> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider using Result::expect to unwrap the Connection value, panicking if the value is a Result::Err
|
117 | match conn.expect("REASON").execute("INSERT INTO table_name (Item, Amount, User) VALUES (?1, ?2, ?3); ", [label, &value.to_string(), &"Hallo".to_string()]) {
| +++++++++++++++++

#

its from rusqlite

#

i thought i do handle the error

#

with match

lethal elbow
#

you handle the result of .execute

#

you need to handle the result of opening the connection, too

rustic siren
lethal elbow
#

not necessarily with match

#

you could use something like ?