13 int main(int ac, char **av){
19 fprintf(stderr, "usage: db hash file\n");
22 zpm_open(&pkg, av[1]);
23 rv = zpm_extract(&pkg, av[2], av[3], mode);
29 int main(int ac, char **av) {
44 fprintf(stderr, "usage: db hash file\n");
48 rc = sqlite3_open(av[1], &db);
50 SQLERROR(sqlite3_errmsg(db));
55 rc = sqlite3_prepare(db, "select size, content from files where hash = ?", -1, &ifile,0);
56 if (rc != SQLITE_OK) {
57 SQLERROR(sqlite3_errmsg(db));
65 sqlite3_bind_text(ifile, 1, hash, 64, SQLITE_STATIC);
67 rc = sqlite3_step(ifile);
69 if (rc == SQLITE_DONE) {
70 /* didn't find a row */
71 sqlite3_finalize(ifile);
73 fprintf(stderr, "no such hash\n");
76 /* either way we're done with this now */
78 if (rc != SQLITE_ROW) {
79 SQLERROR(sqlite3_errmsg(db));
80 sqlite3_finalize(ifile);
85 type = sqlite3_column_type(ifile, 0);
86 if (type == SQLITE_NULL) {
87 fprintf(stderr, "no file size\n");
88 sqlite3_finalize(ifile);
92 type = sqlite3_column_type(ifile, 1);
93 if (type == SQLITE_NULL) {
94 fprintf(stderr, "no file data\n");
95 sqlite3_finalize(ifile);
99 size = sqlite3_column_int64(ifile, 0);
100 xzdata = (void *)sqlite3_column_blob(ifile, 1);
101 blobsize = sqlite3_column_bytes(ifile, 1);
103 out = fopen(filename, "w");
105 fprintf(stderr, "can't open output file %s\n", filename);
106 sqlite3_finalize(ifile);
110 //fwrite(xzdata, blobsize, 1, stdout);
112 fprintf(stderr, "uncompressing %d bytes at %p, expect %lld\n", blobsize, xzdata, (long long int)size);
113 uncompresslzma(xzdata, blobsize, out);
116 sqlite3_finalize(ifile);