- 
                Notifications
    You must be signed in to change notification settings 
- Fork 0
Open
Description
@wyhaya
can u check and pls help?
fn main() -> crossdb::Result<()> {
    // Open a connection to CrossDB
    let mut conn = crossdb::Connection::open("./db")?;
    println!("Connection opened successfully");
    // Create table with new schema
    conn.execute(
        "CREATE TABLE IF NOT EXISTS data(i VARBINARY PRIMARY KEY, m BIGINT UNSIGNED, n VARBINARY, s TINYINT UNSIGNED)"
    )?;
    println!("Table created successfully");
    // Insert data using prepared statement
    let mut stmt = conn.prepare("INSERT INTO data (i, m, n, s) VALUES (?, ?, ?, ?)")?;
    stmt.execute((b"key1", 1000u64, b"value1", 1u8))?;
    stmt.execute((b"key2", 2000u64, b"value2", 2u8))?;
    stmt.execute((b"key3", 3000u64, b"value3", 3u8))?;
    println!("Data inserted successfully");
    // Query data
    let mut query = conn.query("SELECT * FROM data")?;
    println!("Query executed successfully");
    // Print columns
    for col in query.columns() {
        println!("Column: {}", col);
    }
    // Print rows
    println!("All data:");
    while let Some(row) = query.fetch_row() {
        let i: Vec<u8> = row.get(0);
        let m: u64 = row.get(1);
        let n: Vec<u8> = row.get(2);
        let s: u8 = row.get(3);
        println!(
            "i: {:?}, m: {}, n: {:?}, s: {}",
            String::from_utf8_lossy(&i),
            m,
            String::from_utf8_lossy(&n),
            s
        );
    }
    // Clean up
    let affected = conn.execute("DELETE FROM data")?;
    println!("Deleted {} rows", affected);
    assert_eq!(affected, 3);
    Ok(())
}
Metadata
Metadata
Assignees
Labels
No labels