Skip to content

Commit

Permalink
Add categories/license/options to search
Browse files Browse the repository at this point in the history
  • Loading branch information
bapt committed Aug 11, 2011
1 parent 5805557 commit 0088f93
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 21 deletions.
66 changes: 46 additions & 20 deletions libpkg/pkgdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,8 @@ pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, int flags)

populate_pkg(it->stmt, pkg);

/* load only for PKG_INSTALLED */
if (it->type != PKG_INSTALLED)
/* load only for PKG_INSTALLED and PKG_REMOTE */
if (it->type != PKG_INSTALLED && it->type != PKG_REMOTE)
return (EPKG_OK);

if (flags & PKG_LOAD_DEPS)
Expand Down Expand Up @@ -938,25 +938,45 @@ pkgdb_loaddirs(struct pkgdb *db, struct pkg *pkg)
int
pkgdb_loadlicense(struct pkgdb *db, struct pkg *pkg)
{
const char sql[] = ""
"SELECT name "
"FROM pkg_licenses, licenses "
"WHERE package_id = ?1 "
"AND license_id = licenses.id "
"ORDER by name DESC";
const char *sql;
if (pkg->type != PKG_REMOTE) {
sql = ""
"SELECT name "
"FROM main.pkg_licenses, main.licenses AS l "
"WHERE package_id = ?1 "
"AND license_id = l.id "
"ORDER by name DESC";
} else {
sql = ""
"SELECT name "
"FROM remote.pkg_licenses, remote.licenses AS l "
"WHERE package_id = ?1 "
"AND license_id = l.id "
"ORDER by name DESC";
}

return (loadval(db->sqlite, pkg, sql, PKG_LOAD_LICENSES, pkg_addlicense, pkg_freelicenses));
}

int
pkgdb_loadcategory(struct pkgdb *db, struct pkg *pkg)
{
const char sql[] = ""
"SELECT categories.name "
"FROM pkg_categories, categories "
"WHERE package_id = ?1 "
"AND category_id = categories.id "
"ORDER by name DESC";
const char *sql;
if (pkg->type != PKG_REMOTE) {
sql = ""
"SELECT name "
"FROM main.pkg_categories, main.categories AS c "
"WHERE package_id = ?1 "
"AND category_id = c.id "
"ORDER by name DESC";
} else {
sql = ""
"SELECT name "
"FROM remote.pkg_categories, remote.categories AS c "
"WHERE package_id = ?1 "
"AND category_id = c.id "
"ORDER by name DESC";
}

return (loadval(db->sqlite, pkg, sql, PKG_LOAD_CATEGORIES, pkg_addcategory, pkg_freecategories));
}
Expand Down Expand Up @@ -1042,12 +1062,18 @@ pkgdb_loadoptions(struct pkgdb *db, struct pkg *pkg)
{
sqlite3_stmt *stmt;
int ret;
const char sql[] = ""
const char *sql;
if (pkg->type != PKG_REMOTE) {
sql = ""
"SELECT option, value "
"FROM options "
"FROM main.options "
"WHERE package_id = ?1";

assert(pkg->type == PKG_INSTALLED);
} else {
sql = ""
"SELECT option, value "
"FROM remote.options "
"WHERE package_id = ?1";
}

if (pkg->flags & PKG_LOAD_OPTIONS)
return (EPKG_OK);
Expand Down Expand Up @@ -1789,8 +1815,8 @@ pkgdb_rquery(struct pkgdb *db, const char *pattern, match_t match, pkgdb_field f
return (NULL);
}

sbuf_cat(sql, "SELECT origin, name, version, comment, "
"desc, arch, arch, osversion, maintainer, www, "
sbuf_cat(sql, "SELECT id AS rowid, origin, name, version, comment, prefix, "
"desc, arch, arch, osversion, maintainer, www, licenselogic, "
"flatsize AS newflatsize, pkgsize, cksum, path AS repopath FROM remote.packages");

switch (match) {
Expand Down
1 change: 1 addition & 0 deletions pkg/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ print_info(struct pkg * const pkg, unsigned int opt)
printf("Name: %s\n", pkg_get(pkg, PKG_NAME));
printf("Version: %s\n", pkg_get(pkg, PKG_VERSION));
printf("Origin: %s\n", pkg_get(pkg, PKG_ORIGIN));
printf("Prefix: %s\n", pkg_get(pkg, PKG_PREFIX));
printf("Categories:");
while (pkg_categories(pkg, &cat) == EPKG_OK)
printf(" %s", pkg_category_name(cat));
Expand Down
22 changes: 21 additions & 1 deletion pkg/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ exec_search(int argc, char **argv)
struct pkgdb *db = NULL;
struct pkgdb_it *it = NULL;
struct pkg *pkg = NULL;
struct pkg_category *cat = NULL;
struct pkg_license *lic = NULL;
struct pkg_option *opt = NULL;

while ((ch = getopt(argc, argv, "gxXcd")) != -1) {
switch (ch) {
Expand Down Expand Up @@ -71,13 +74,30 @@ exec_search(int argc, char **argv)
goto cleanup;
}

while (( retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
while (( retcode = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC|PKG_LOAD_CATEGORIES|PKG_LOAD_LICENSES|PKG_LOAD_OPTIONS)) == EPKG_OK) {
printf("Name: %s\n", pkg_get(pkg, PKG_NAME));
printf("Version: %s\n", pkg_get(pkg, PKG_VERSION));
printf("Origin: %s\n", pkg_get(pkg, PKG_ORIGIN));
printf("Prefix: %s\n", pkg_get(pkg, PKG_PREFIX));
printf("Categories:");
while (pkg_categories(pkg, &cat) == EPKG_OK)
printf(" %s", pkg_category_name(cat));
printf("\n");
printf("Licenses: ");
while (pkg_licenses(pkg, &lic) == EPKG_OK) {
printf(" %s", pkg_license_name(lic));
if (pkg_licenselogic(pkg) != 1)
printf(" %c", pkg_licenselogic(pkg));
else
printf(" ");
}
printf("\b \n");
printf("Maintainer: %s\n", pkg_get(pkg, PKG_MAINTAINER));
printf("WWW: %s\n", pkg_get(pkg, PKG_WWW));
printf("Comment: %s\n", pkg_get(pkg, PKG_COMMENT));
printf("Options: \n");
while (pkg_options(pkg, &opt) == EPKG_OK)
printf("\t%s: %s\n", pkg_option_opt(opt), pkg_option_value(opt));
humanize_number(size, sizeof(size), pkg_new_flatsize(pkg), "B", HN_AUTOSCALE, 0);
printf("Flat size: %s\n", size);
humanize_number(size, sizeof(size), pkg_new_pkgsize(pkg), "B", HN_AUTOSCALE, 0);
Expand Down

0 comments on commit 0088f93

Please sign in to comment.