0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rust: sqlite3 のデータを削除 (Delete)

Posted at

フォルダー構造

$ 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 ***
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?