}
char *zpm_findlib(struct zpm *zpm, char *soname, char *where) {
- char *select = "select pkgid, package, version, release from packagefiles_status join elflibraries on file = hash";
- char *group = "order by package, version collate vercmp desc, cast(release as integer)";
sqlite3_str *sql;
char *query, *pkgid = 0;
+char *select = "select printf('%%s-%%s-%%s',P.package,P.version,P.release) as pkgid, P.package, P.version, P.release\
+ from packagefiles PF\
+ join elflibraries EL on EL.file = PF.hash\
+ join packages P on P.package = PF.package and P.version = PF.version and P.release = PF.release";
+ char *order = "order by P.package, P.version, cast(P.release as integer)";
+
/* null pkgstr find "best" package
* best is shortest complete package if any are complete
* shortest incomplete if any are incomplete
sql = sqlite3_str_new(zpm->db);
sqlite3_str_appendall(sql, select);
- sqlite3_str_appendf(sql, " where soname = %Q", soname);
+ sqlite3_str_appendf(sql, " where P.hash is not null and EL.soname = %Q", soname);
if (where) {
sqlite3_str_appendall(sql, " and ");
}
sqlite3_str_appendall(sql, " ");
- sqlite3_str_appendall(sql, group);
+ sqlite3_str_appendall(sql, order);
sqlite3_str_appendall(sql, " limit 1;");
if (sqlite3_str_errcode(sql)) {