2 * add a file/files to an sqlite db
3 * in the 'files' table.
19 void *compresslzma(void *buf, size_t bufsize, size_t *len) {
25 outsize = lzma_stream_buffer_bound(bufsize);
26 outbuf = malloc(outsize);
31 /* TODO adjust encoding level for size */
32 lzma_easy_buffer_encode(6, LZMA_CHECK_CRC64, NULL,
34 outbuf, &outlen, outsize
40 static int callback(void *NotUsed, int argc, char **argv, char **azColName){
42 for(i=0; i<argc; i++){
43 printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
49 static char *create_table = "create table if not exists files (hash text primary key, size integer, compression text, content blob)";
57 #define SQLERROR(x) fprintf(stderr, "%s %d: %s\n", __func__, __LINE__, (x))
58 static int begin(sqlite3 *db) {
62 rc = sqlite3_exec(db, "begin;", callback, 0, &err);
63 if (rc != SQLITE_OK) {
70 static int commit(sqlite3 *db) {
74 rc = sqlite3_exec(db, "commit;", callback, 0, &err);
75 if (rc != SQLITE_OK) {
81 static int rollback(sqlite3 *db) {
85 rc = sqlite3_exec(db, "rollback;", callback, 0, &err);
86 if (rc != SQLITE_OK) {