Thanks a lot for your time. I applied the modifications you mentioned in your response, but when I compile and run my code, it creates the empty database "fuel_transaction_1_backup.db". Do you know why is it empty? (previously, when I used ATTACH inside sqlite3 command prompt, it created the copy of the db which was not empty, but now that I used it within sqlite3_exec command, it just creates an empty db)
Here is the code that I run:
#include <stdio.h>
#include <sqlite3.h>
#include "litereplica.h"
int main(int argc, char* argv[])
{
sqlite3 *db;
//char *zErrMsg = 0;
char *errmsg = 0;
int rc;
rc = sqlite3_open("fuel_transaction_1.db", &db);
sqlite3_exec(db, "ATTACH '/root/litereplica/litereplica-master/sqlite3.6/fuel_transaction_1_backup.db' AS backup", NULL, NULL, &errmsg);
sqlite3_add_replica(db, "main", REPLICA_MASTER, REPLICA_CONNECT, "inproc://replica");
sqlite3_add_replica(db, "backup", REPLICA_SLAVE, REPLICA_BIND, "inproc://replica");
if( rc ){
fprintf(stderr, "Can't open database: %s
", sqlite3_errmsg(db));
return(0);
}else{
fprintf(stderr, "Opened database successfully
");
}
sqlite3_close(db);
}
PS. as the result of running this code, it prints "Opened database successfully", and also creates the "fuel_transaction_1_backup.db" which is empty.
Thanks for your support,