Rust: sqlite3 のデータを削除 (Delete)
フォルダー構造
$ tree -L 2
.
├── Cargo.lock
├── Cargo.toml
├── src
│ └── main.rs
└── target
└── debug
Cargo.toml
[package]
name = "sqlite3_delete"
version = "0.1.0"
edition = "2018"
[dependencies]
rusqlite = "*"
src/main.rs
// --------------------------------------------------------------------
/*
sqlite3_delete/src/main.rs
Jul/23/2020
*/
// --------------------------------------------------------------------
use std::env;
use rusqlite::{params, Connection, Result};
// --------------------------------------------------------------------
fn main() -> Result<()> {
eprintln! ("*** start ***");
let args: Vec<_> = env::args().collect();
let file_sqlite3 = &args[1];
let key = &args[2];
eprintln!("{}",file_sqlite3);
eprintln!("{}",key);
let conn = Connection::open(file_sqlite3).unwrap();
let sql_str = "delete from cities where id = '".to_owned() + key + "'";
conn.execute(&sql_str,params![],)?;
eprintln! ("*** end ***");
Ok(())
}
// --------------------------------------------------------------------
実行
$ cargo run /var/tmp/sqlite3/cities.db t0716
Finished dev [unoptimized + debuginfo] target(s) in 0.92s
Running `target/debug/sqlite3_delete /var/tmp/sqlite3/cities.db t0716`
*** start ***
/var/tmp/sqlite3/cities.db
t0716
*** end ***
Author And Source
この問題について(Rust: sqlite3 のデータを削除 (Delete)), 我々は、より多くの情報をここで見つけました https://qiita.com/ekzemplaro/items/7a49a08fc631012922c5著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .