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 /* this is really just read env */
82 zpm_readopts(&pkg, ac, av);
84 /* given a package name, get the packages */
85 /* no package name, get all */
87 if (zpm_open(&pkg, av[1])) {
89 // char where[1024] = "";
91 /* TODO allow more args to nail down version and release */
97 parse_package(av[2], package, version, &release);
100 sprintf(sql, "%s where package = '%s' and version = "
101 "'%s' and release = %d %s;", select,
102 package, version, release, group);
103 } else if (*version != 0) {
104 sprintf(sql, "%s where package = '%s' and version = "
106 package, version, group);
110 sprintf(sql, "%s where package = '%s' %s;",
111 select, av[2], group);
114 sprintf(sql, "%s %s;", select, group);
117 /* install a collation function */
119 /* sqlite seems to need the columns in the result to
120 * do the sort right */
121 // 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);
122 // fprintf(stdout, "\n");
124 zpm_exec(&pkg, sql, prow, stdout, &errmsg);