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;
// 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 );
// 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