-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain-patch.cpp
43 lines (31 loc) · 875 Bytes
/
main-patch.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "patch.h"
#include "sqlite3.h"
#include <iostream>
using namespace std;
void trace_callback( void* udp, const char* sql ) { printf("{SQL} [%s]\n", sql); }
const char* usage = "Usage: sqlite-patch [db] [patchfile]";
int main(int argc, char const *argv[])
{
if (argc != 3) {
cerr << "Wrong number of arguments" << endl << usage << endl;
return 1;
}
const char* dbFile = argv[1];
const char* patchFile = argv[2];
int rc;
sqlite3* db;
rc = sqlite3_open_v2(dbFile, &db, SQLITE_OPEN_READWRITE, nullptr);
if (rc != SQLITE_OK) {
cerr << "Could not open sqlite DB " << dbFile << ": " << sqlite3_errstr(rc) << endl;
sqlite3_close(db);
return 2;
}
rc = applyChangeset(db, patchFile);
if (rc != SQLITE_OK) {
cerr << "Could not apply changeset " << patchFile << endl;
sqlite3_close(db);
return 2;
}
sqlite3_close(db);
return 0;
}