7 static int prow(void *f, int ncols, char **vals, char **cols) {
12 fprintf(stderr, "sqlite can't get column names\n");
14 for (i=3;i<ncols;i++) {
15 if (i>3) fprintf(out, "\t");
16 fprintf(out, "%s", vals[i]);
22 void parse_package(char *pstr, char *name, char *ver, int *rel) {
27 /* string - ver - rel */
28 /* rel is all digits */
30 * ^(.+)-([0-9][^-]*)-([\d+])$
33 * The main problem in parsing is that the package name itself
34 * can contain a '-', so you can't just split on '-'
35 * Also, the version can be just digits.
38 /* everything up to the first '-' is in the name */
40 if (*pstr == '-' && isdigit(*(pstr+1))) {
52 while (*pstr && *pstr != '-') {
67 int main(int ac, char **av){
69 char *select = "select package, version, release, package||'-'||version||'-'||release as pkgid from packages";
70 char *group = "group by package having max( version||'-'||release collate vercmp) order by length(package), package, version||'-'||release collate vercmp";
72 // char *select = "select package, version, release, package||'-'||version||'-'||release as pkgid from packages";
73 // char *order = "order by package, version collate vercmp, cast(release as integer)";
77 fprintf(stderr, "usage: db path\n");
81 /* given a package name, get the packages */
82 /* no package name, get all */
84 if (zpm_open(&pkg, av[1])) {
86 // char where[1024] = "";
88 /* TODO allow more args to nail down version and release */
94 parse_package(av[2], package, version, &release);
97 sprintf(sql, "%s where package = '%s' and version = "
98 "'%s' and release = %d %s;", select,
99 package, version, release, group);
100 } else if (*version != 0) {
101 sprintf(sql, "%s where package = '%s' and version = "
103 package, version, group);
107 sprintf(sql, "%s where package = '%s' %s;",
108 select, av[2], group);
111 sprintf(sql, "%s %s;", select, group);
114 /* install a collation function */
116 /* sqlite seems to need the columns in the result to
117 * do the sort right */
118 // zpm_exec(&pkg, "select package, version, release, package||'-'||version||'-'||release as pkgid from packages order by package, version collate vercmp, cast(release as integer)", prow, stdout, &errmsg);
119 // fprintf(stdout, "\n");
121 zpm_exec(&pkg, sql, prow, stdout, &errmsg);