Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add pkgdb_it_count()
Bryan Drewery committed 11 years ago
commit 0f6bca2b1d7f0bdcb4c10431713882435f070a1e
parent ab1b61a
3 files changed +40 -0
modified libpkg/libpkg.ver
@@ -206,6 +206,7 @@ global:
	pkgdb_downgrade_lock;
	pkgdb_dump;
	pkgdb_file_set_cksum;
+
	pkgdb_it_count;
	pkgdb_it_free;
	pkgdb_it_next;
	pkgdb_it_reset;
modified libpkg/pkg.h.in
@@ -1120,6 +1120,12 @@ int pkgdb_it_next(struct pkgdb_it *, struct pkg **pkg, unsigned flags);
void pkgdb_it_reset(struct pkgdb_it *);

/**
+
 * Return the number of rows found.
+
 * @return -1 on error
+
 */
+
int pkgdb_it_count(struct pkgdb_it *);
+

+
/**
 * Free a struct pkgdb_it.
 */
void pkgdb_it_free(struct pkgdb_it *);
modified libpkg/pkgdb_iterator.c
@@ -914,6 +914,39 @@ pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, unsigned flags)
	return (EPKG_FATAL);
}

+
int
+
pkgdb_it_count(struct pkgdb_it *it)
+
{
+
	int		 	i;
+
	int		 	ret;
+
	struct pkgdb_sqlite_it *sit;
+

+
	assert(it != NULL);
+

+
	i = 0;
+
	sit = &it->un.local;
+

+
	if (sit == NULL)
+
		return (0);
+

+
	while ((ret = sqlite3_step(sit->stmt))) {
+
		switch (ret) {
+
		case SQLITE_ROW:
+
			++i;
+
			break;
+
		case SQLITE_DONE:
+
			goto done;
+
		default:
+
			ERROR_SQLITE(sit->sqlite, "iterator");
+
			return (-1);
+
		}
+
	}
+

+
done:
+
	pkgdb_it_reset(it);
+
	return (i);
+
}
+

void
pkgdb_it_reset(struct pkgdb_it *it)
{