Rust: sqlite3 のデータを更新 (Update)
フォルダー構造
$ tree -L 2
.
├── Cargo.lock
├── Cargo.toml
├── src
│ └── main.rs
└── target
└── debug
Cargo.toml
[package]
name = "sqlite3_update"
version = "0.1.0"
edition = "2018"
[dependencies]
rusqlite = "*"
chrono = "0.4"
src/main.rs
// --------------------------------------------------------------------
/*
sqlite3_update/src/main.rs
Jul/23/2020
*/
// --------------------------------------------------------------------
use std::env;
use rusqlite::{params, Connection, Result};
use chrono::{Local, Date};
// --------------------------------------------------------------------
fn main() -> Result<()> {
eprintln! ("*** start ***");
let args: Vec<_> = env::args().collect();
let file_sqlite3 = &args[1];
let key_in = &args[2];
let population_in = &args[3];
eprintln!("{}",file_sqlite3);
eprintln!("{}",key_in);
eprintln!("{}",population_in);
let date_mod: Date<Local> = Local::today();
println!("{}", date_mod);
let conn = Connection::open(file_sqlite3).unwrap();
let sql_str = "update cities set population = ".to_owned()
+ population_in + &", date_mod = '".to_owned()
+ &date_mod.to_string()
+ &"' where id = '".to_owned() + key_in + "'";
eprintln!("{}",sql_str);
conn.execute(&sql_str,params![],)?;
eprintln! ("*** end ***");
Ok(())
}
// --------------------------------------------------------------------
実行
$ cargo run /var/tmp/sqlite3/cities.db t0713 3512600
Finished dev [unoptimized + debuginfo] target(s) in 1.24s
Running `target/debug/sqlite3_update /var/tmp/sqlite3/cities.db t0713 3512600`
*** start ***
/var/tmp/sqlite3/cities.db
t0713
3512600
2020-07-23+09:00
update cities set population = 3512600, date_mod = '2020-07-23+09:00' where id = 't0713'
*** end ***
Author And Source
この問題について(Rust: sqlite3 のデータを更新 (Update)), 我々は、より多くの情報をここで見つけました https://qiita.com/ekzemplaro/items/1beedfbaddf0d3822a51著者帰属:元の著者の情報は、元の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 .