I have a sample application in C connected to the sqlite database. I have to replicate this DB (transparent replication) on the same server (on different disks). To explain my question better, what I need is:
- Create one or two slave/backup databases which are synced with the main db. e.g., when I write in the main db, the backup db/dbs will be updated as well. Also, for read, if the main db crashed, the application should read from the other backup db.
I know sqlite does not support replication and I searched a lot and found some solutions but they are mostly for replication across multiple servers or for MySQL.
What came to my mind was creating a new DB and copy all data from the main db to the slave:
ATTACH '/root/litereplica/litereplica-master/sqlite3.6/fuel_transaction_1_backup.db' AS backup; //This attached a new empty db to the main db
CREATE TABLE backup.fuel_transaction_1 AS SELECT * FROM main.fuel_transaction_1;
Now, I need to synch this backup db with the main db. So, I have to update the slave based on the change on the main db. I know the update part should be s.th like this:
UPDATE backup.tableX SET columnX=(SELECT main.tableX.columnX FROM main.tableX WHERE main.tableX.id=backup.tableX.id)'
But I don't know how to tell this (in my C code), i.e., how to write if main db is changed then go and update the slave db..? for example, in PHP, you can check if a table is updated with if(mysql_affected_rows ($link)>0) {
}
.. I want it's equivalent in C.
Thanks,