Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add support for -e as additional condition to pkg-rquery
Stefan Eßer committed 4 years ago
commit fc1d73cbc728cf0376eadec76e0071ffbce401b6
parent 7be9efa
3 files changed +10 -5
modified libpkg/pkgdb_query.c
@@ -361,7 +361,7 @@ pkgdb_repo_query_cond(struct pkgdb *db, const char *cond, const char *pattern, m

	LL_FOREACH(db->repos, cur) {
		if (repo == NULL || strcasecmp(cur->repo->name, repo) == 0) {
-
			rit = cur->repo->ops->query(cur->repo, NULL, pattern, match);
+
			rit = cur->repo->ops->query(cur->repo, cond, pattern, match);
			if (rit != NULL)
				pkgdb_it_repo_attach(it, rit);
		}
modified libpkg/repo/binary/query.c
@@ -107,13 +107,18 @@ pkg_repo_binary_query(struct pkg_repo *repo, const char *cond, const char *patte
		"prefix, desc, arch, maintainer, www, "
		"licenselogic, flatsize, pkgsize, "
		"cksum, manifestdigest, path AS repopath, '%s' AS dbname "
-
		"FROM packages AS p %s ORDER BY NAME;";
+
		"FROM packages AS p %s "
+
		"%s%s%s "
+
		"ORDER BY NAME;";

	if (match != MATCH_ALL && (pattern == NULL || pattern[0] == '\0'))
		return (NULL);

	comp = pkgdb_get_pattern_query(pattern, match);
-
	xasprintf(&sql, basesql, repo->name, comp ? comp : "");
+
	if (cond == NULL)
+
		xasprintf(&sql, basesql, repo->name, comp ? comp : "", "", "", "");
+
	else
+
		xasprintf(&sql, basesql, repo->name, comp ? comp : "", "AND (", cond + 7, ")");

	pkg_debug(4, "Pkgdb: running '%s' query for %s", sql,
	     pattern == NULL ? "all": pattern);
@@ -122,7 +127,7 @@ pkg_repo_binary_query(struct pkg_repo *repo, const char *cond, const char *patte
	if (stmt == NULL)
		return (NULL);

-
	if (match != MATCH_ALL && cond == NULL)
+
	if (match != MATCH_ALL || cond != NULL)
		sqlite3_bind_text(stmt, 1, pattern, -1, SQLITE_TRANSIENT);

	return (pkg_repo_binary_it_new(repo, stmt, PKGDB_IT_FLAG_ONCE));
modified src/rquery.c
@@ -114,6 +114,7 @@ exec_rquery(int argc, char **argv)
	int			 i;
	char			 multiline = 0;
	char			*condition = NULL;
+
	const char		*condition_sql = NULL;
	const char		*portsdir;
	xstring			*sqlcond = NULL;
	const unsigned int	 q_flags_len = NELEM(accepted_rquery_flags);
@@ -233,7 +234,6 @@ exec_rquery(int argc, char **argv)
	if (index_output)
		query_flags = PKG_LOAD_BASIC|PKG_LOAD_CATEGORIES|PKG_LOAD_DEPS;

-
	const char *condition_sql = NULL;
	if (sqlcond) {
		fflush(sqlcond->fp);
		condition_sql = sqlcond->buf;