Skip to content

Instantly share code, notes, and snippets.

@kawasin73
Last active August 7, 2023 15:46
Show Gist options
  • Save kawasin73/7de8da2d46f59afde1eca42cf7fdae5c to your computer and use it in GitHub Desktop.
Save kawasin73/7de8da2d46f59afde1eca42cf7fdae5c to your computer and use it in GitHub Desktop.
$ hexdump ./test.db
0000000 5153 694c 6574 6620 726f 616d 2074 0033
0000010 0010 0101 4000 2020 0000 0200 0000 0200
0000020 0000 0000 0000 0000 0000 0100 0000 0400
0000030 0000 0000 0000 0000 0000 0100 0000 0000
0000040 0000 0000 0000 0000 0000 0000 0000 0000
0000050 0000 0000 0000 0000 0000 0000 0000 0200
0000060 2e00 1d5f 000d 0000 0f01 00cb cb0f 0000
0000070 0000 0000 0000 0000 0000 0000 0000 0000
*
0000fc0 0000 0000 0000 0000 0000 3300 0601 1b17
0000fd0 011b 743f 6261 656c 7865 6d61 6c70 6565
0000fe0 6178 706d 656c 4302 4552 5441 2045 4154
0000ff0 4c42 2045 7865 6d61 6c70 2865 6f63 296c
0001000 000d 0000 0f01 00fa fa0f 0000 0000 0000
0001010 0000 0000 0000 0000 0000 0000 0000 0000
*
0001ff0 0000 0000 0000 0000 0000 0104 1102 8080
0002000
use rusqlite::Connection;
const FILE_PATH: &str = "./test.db";
fn main() {
std::fs::remove_file(FILE_PATH);
let queries = vec!["CREATE TABLE example(col);"];
let conn = Connection::open(FILE_PATH).unwrap();
for query in queries {
conn.execute(query, []).unwrap();
}
let mut sql: Vec<u8> = "INSERT INTO example(col) VALUES ('".as_bytes().to_vec();
sql.push(0x80);
sql.push(0x80);
// let mut sql = String::from_utf8(sql).unwrap();
let mut sql = unsafe { String::from_utf8_unchecked(sql) };
sql += "');";
conn.execute(&sql, []).unwrap();
let mut sql = "SELECT * FROM example WHERE '".as_bytes().to_vec();
sql.push(0x80);
sql.push(0x80);
// let mut sql = String::from_utf8(sql).unwrap();
let mut sql = unsafe { String::from_utf8_unchecked(sql) };
sql += "' = col;";
let mut stmt = conn.prepare(&sql).unwrap();
let mut rows = stmt.query([]).unwrap();
while let Some(row) = rows.next().unwrap() {
println!("row: {:?}", 1);
}
// conn.close().unwrap();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment