From: Carl N Baldwin Date: Tue, 18 Oct 2005 03:14:42 +0000 (-0600) Subject: Routine commit X-Git-Tag: release-0.4~101 X-Git-Url: http://git.pippins.net/embedvideo/.git/static/images/%7Blink_ppi%7D?a=commitdiff_plain;h=e0c6c331bc17ad8b85fd9db1be947a5c89064906;p=backups%2F.git Routine commit --- diff --git a/main.cc b/main.cc index 89c1742..9224f00 100644 --- a/main.cc +++ b/main.cc @@ -72,24 +72,15 @@ int main() { const char *dbname = "test.db"; int rc = sqlite3_open( dbname, &db ); - if( SQLITE_OK != rc ) { - cerr << "Cannot open database: " << dbname << ". Error message is..." << endl; - cerr << sqlite3_errmsg(db) << endl; - } + assert( SQLITE_OK == rc ); char *sqliteErrMsg = 0; file_set backed_up; rc = sqlite3_exec( db, "select * from filedata;", populate_set, &backed_up, &sqliteErrMsg ); - if( SQLITE_OK != rc ) { - cerr << "Problem with database. Message is..." << endl; - cerr << sqliteErrMsg << endl; - } + assert( SQLITE_OK == rc ); - sqlite3_close( db ); - - for( file_set::iterator i = backed_up.begin(); i != backed_up.end(); ++i ) { - cout << (*i)->getFileName() << endl; - } + rc = sqlite3_close( db ); + assert( SQLITE_OK == rc ); // Now divide the two sets into three sets (new, deleted and updated ) FileDataPtrCmp cmp; @@ -119,8 +110,7 @@ int main() { // backup all new files copy( new_set.begin(), new_set.end(), inserter( backup_list, backup_list.begin() ) ); - // backup all the already backed-up files that have changed since the last - // backup date. + // backup already backed-up files that have changed since the last backup date. for( file_set::iterator i = updated.begin(); i != updated.end(); ++i ) { if( (*i)->getLastBackupDate() < (*i)->getModifiedDate() ) { backup_list.insert( *i ); @@ -129,10 +119,26 @@ int main() { // Now, sort the backup_list by filesize and build a list of up to SIZE - // // Now, sort the non-backed-up list my last_backup_date and back-fill // Remove deleted files from the database. + const char *delete_sql = "delete from filedata where filename = :filename"; + sqlite3_stmt *ppStmt; + + sqlite3_prepare( db, delete_sql, -1, &ppStmt, NULL ); + assert( NULL != ppStmt ); + + for( file_set::iterator i = deleted.begin(); i != deleted.end(); ++i ) { + const string &name = (*i)->getFileName(); + + rc = sqlite3_bind_text( ppStmt, 1, name.data(), name.size(), SQLITE_TRANSIENT ); + assert( SQLITE_OK == rc ); + + rc = sqlite3_step( ppStmt ); + assert( SQLITE_OK == rc ); + } + rc = sqlite3_finalize( ppStmt ); + assert( SQLITE_OK == rc ); // Now, use the current set to update values in the database. You should copy // last_backup_date dates from the backed_up set first. This will get all of diff --git a/schema.sql b/schema.sql index 42bf811..73f6e76 100644 --- a/schema.sql +++ b/schema.sql @@ -6,5 +6,7 @@ CREATE TABLE filedata ( filesize INTEGER, modified_date INTEGER, -- e.g. 20051016194000 for Oct 10, 2005 at 7:40pm filename VARCHAR, - last_backup_date INTEGER + last_backup_date INTEGER -- same format as modified_date ); + +CREATE INDEX filename ON filedata