| Crates.io | sqlite_dbhash |
| lib.rs | sqlite_dbhash |
| version | 0.1.0 |
| created_at | 2025-03-18 22:29:09.36186+00 |
| updated_at | 2025-03-18 22:29:09.36186+00 |
| description | sqlite dbhash as a library |
| homepage | |
| repository | https://github.com/johnmave126/sqlite_dbhash |
| max_upload_size | |
| id | 1597365 |
| size | 40,051 |
A Rust port of dbhash utility from sqlite repository so that it can be used as a library function instead of a standalone program.
Ported directly from dbhash.c.
use sqlite_dbhash::{dbhash, Selection};
use rusqlite::{Connection, Result};
fn main() -> Result<()> {
let conn = Connection::open("my_db.db")?;
// Equivalent to `dbhash my_db.db` (except for the output mat)
println!("{:02x?}", dbhash(&conn, None, Selection::SchemaAndContent)?);
// Equivalent to `dbhash --like "prefix% --schema-only my_db.db"
println!("{:02x?}", dbhash(&conn, Some("prefix%"), Selection::SchemaOnly)?);
// Equivalent to `dbhash --without-schema my_db.db`
println!("{:02x?}", dbhash(&conn, None, Selection::ContentOnly)?);
Ok(())
}
For the vast majority of the scenarios, the hash produced by this library agrees with the dbhash program from sqlite. However, the hash can be different when the table_pattern/--like parameter contains non-ASCII characters.
I consider it a bug in the sqlite implementation. Since the encoding of the arguments passed from the console is platform-dependent, and the sqlite dbhash implementation simply used sqlite3_vmprintf to interpolate the SQL statement using the raw argv, it could be the case that the argument is not in UTF-8 (on Windows for example), and thus dbhash matches no table with the pattern while it is a false negative.
Inheriting sqlite blessing license as follows
The author disclaims copyright to this source code. In place of a legal notice, here is a blessing:
May you do good and not evil.
May you find forgiveness for yourself and forgive others.
May you share freely, never taking more than you give.