Re: [Vala] Equivalent for sqlitebck (sqlite backup) [SOLVED]



The following example works.

public int main (string[] args) {

    Sqlite.Database file_db;
    Sqlite.Database live_db;
    Sqlite.Backup   backup;
    int rc;

    rc = Sqlite.Database.open ("database_in.db", out file_db);
    if (rc != Sqlite.OK) {
        stderr.printf ("Can't open database: %d: %s\n", file_db.errcode
(), file_db.errmsg ());
        return -1;
    }
    
    /* create memory database */
    rc = Sqlite.Database.open (":memory:", out live_db);
    if (rc != Sqlite.OK) {
        stderr.printf ("Failed to create in-memory database");
        return -1;
    }
    
    /* load disk database into memory database */
    backup = new Sqlite.Backup(live_db, "main", file_db, "main");
    do {
      rc = backup.step(4); 
    } while (rc == Sqlite.OK);
    if (rc != Sqlite.DONE) {
        stderr.printf ("Error importing database");
        return -1;
    }
    backup = null;
    file_db = null;
    
    rc = Sqlite.Database.open ("database_out.db", out file_db);
    if (rc != Sqlite.OK) {
        stderr.printf ("Can't open database: %d: %s\n", file_db.errcode
(), file_db.errmsg ());
        return -1;
    }
    
    /* save memory databse to disk database */
    backup = new Sqlite.Backup(file_db, "main", live_db, "main");
    do {
      rc = backup.step(4); 
    } while (rc == Sqlite.OK);
    if (rc != Sqlite.DONE) {
        stderr.printf ("Error exporting database");
        return -1;
    }
    backup = null;
    return 0;
}
-- 
Meetings Coordinator, Michigan Association of Railroad Passengers
537 Shirley St NE Grand Rapids, MI 49503-1754 Phone: 616.581.8010
E-mail: awilliam whitemice org GPG#D95ED383 Web: http://www.marp.org




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]