根据上面的数据库,帮我举一个cargo 表和 time表插入语句的例子
时间: 2024-03-27 14:37:35 浏览: 26
假设您的数据库中有两个表:`cargo`和`time`。下面是向这两个表插入数据的示例插入语句:
```
// 向cargo表插入数据
fn insert_into_cargo_table(conn: &Connection, name: &str, weight: i32) -> Result<(), rusqlite::Error> {
conn.execute(
"INSERT INTO cargo (name, weight) VALUES (?1, ?2)",
params![name, weight],
)?;
Ok(())
}
// 向time表插入数据
fn insert_current_time_into_time_table(conn: &Connection) -> Result<(), rusqlite::Error> {
let current_time = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
conn.execute(
"INSERT INTO time (timestamp) VALUES (?)",
params![current_time],
)?;
Ok(())
}
```
以上代码示例假设`cargo`表中有`name`和`weight`两个列,`time`表中有`timestamp`一列。您可以根据自己的需求修改这些代码。