From 454fbf11ea4f479c029a7cfb22d1df030a9d4f74 Mon Sep 17 00:00:00 2001 From: Arteiimis Date: Mon, 29 Jan 2024 16:52:09 +0800 Subject: [PATCH] Fix bugs where the sample code does not compile and run correctly. --- src/database/sqlite/initialization.md | 5 ++--- src/database/sqlite/insert_select.md | 4 +--- src/database/sqlite/transactions.md | 7 +++---- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/database/sqlite/initialization.md b/src/database/sqlite/initialization.md index a27c536..845b08b 100644 --- a/src/database/sqlite/initialization.md +++ b/src/database/sqlite/initialization.md @@ -9,7 +9,6 @@ Use the `rusqlite` crate to open SQLite databases. See ```rust,edition2018,no_run use rusqlite::{Connection, Result}; -use rusqlite::NO_PARAMS; fn main() -> Result<()> { let conn = Connection::open("cats.db")?; @@ -19,7 +18,7 @@ fn main() -> Result<()> { id integer primary key, name text not null unique )", - NO_PARAMS, + (), )?; conn.execute( "create table if not exists cats ( @@ -27,7 +26,7 @@ fn main() -> Result<()> { name text not null, color_id integer not null references cat_colors(id) )", - NO_PARAMS, + (), )?; Ok(()) diff --git a/src/database/sqlite/insert_select.md b/src/database/sqlite/insert_select.md index a1d4bb1..cc86961 100644 --- a/src/database/sqlite/insert_select.md +++ b/src/database/sqlite/insert_select.md @@ -6,8 +6,6 @@ This recipe inserts data into `cat_colors` and `cats` tables using the [`execute`] method of `Connection`. First, the data is inserted into the `cat_colors` table. After a record for a color is inserted, [`last_insert_rowid`] method of `Connection` is used to get `id` of the last color inserted. This `id` is used while inserting data into the `cats` table. Then, the select query is prepared using the [`prepare`] method which gives a [`statement`] struct. Then, query is executed using [`query_map`] method of [`statement`]. ```rust,no_run - -use rusqlite::NO_PARAMS; use rusqlite::{Connection, Result}; use std::collections::HashMap; @@ -44,7 +42,7 @@ fn main() -> Result<()> { ON cc.id = c.color_id;", )?; - let cats = stmt.query_map(NO_PARAMS, |row| { + let cats = stmt.query_map((), |row| { Ok(Cat { name: row.get(0)?, color: row.get(1)?, diff --git a/src/database/sqlite/transactions.md b/src/database/sqlite/transactions.md index 6eb1605..268411b 100644 --- a/src/database/sqlite/transactions.md +++ b/src/database/sqlite/transactions.md @@ -11,9 +11,8 @@ In the following example, colors add to a table having a unique constraint on the color name. When an attempt to insert a duplicate color is made, the transaction rolls back. - ```rust,edition2018,no_run -use rusqlite::{Connection, Result, NO_PARAMS}; +use rusqlite::{Connection, Result}; fn main() -> Result<()> { let mut conn = Connection::open("cats.db")?; @@ -29,7 +28,7 @@ fn main() -> Result<()> { fn successful_tx(conn: &mut Connection) -> Result<()> { let tx = conn.transaction()?; - tx.execute("delete from cat_colors", NO_PARAMS)?; + tx.execute("delete from cat_colors", ())?; tx.execute("insert into cat_colors (name) values (?1)", &[&"lavender"])?; tx.execute("insert into cat_colors (name) values (?1)", &[&"blue"])?; @@ -39,7 +38,7 @@ fn successful_tx(conn: &mut Connection) -> Result<()> { fn rolled_back_tx(conn: &mut Connection) -> Result<()> { let tx = conn.transaction()?; - tx.execute("delete from cat_colors", NO_PARAMS)?; + tx.execute("delete from cat_colors", ())?; tx.execute("insert into cat_colors (name) values (?1)", &[&"lavender"])?; tx.execute("insert into cat_colors (name) values (?1)", &[&"blue"])?; tx.execute("insert into cat_colors (name) values (?1)", &[&"lavender"])?;