Skip to content

Commit

Permalink
synch with recent sqlports
Browse files Browse the repository at this point in the history
  • Loading branch information
marcespie committed Jul 14, 2019
1 parent 796deee commit c499e64
Showing 1 changed file with 87 additions and 84 deletions.
171 changes: 87 additions & 84 deletions lib/SqlPorts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,151 +18,154 @@ use Dancer ':syntax';
use strict;
use warnings;

my $db = DBI->connect("dbi:SQLite:dbname=".config->{database}, '', '', {});
my $db = DBI->connect("dbi:SQLite:dbname=".config->{database}, '', '',
{ReadOnly => 1});

my $category;
my $list_req = $db->prepare(
q{select
distinct(categorykeys.value)
from categorykeys
order by categorykeys.value
distinct(_categorykeys.value)
from _categorykeys
order by _categorykeys.value
});
$list_req->bind_columns(\($category));
$list_req->execute;

my $list_cat_req = $db->prepare(
q{select paths.fullpkgpath,
q{select min(_paths.fullpkgpath),
fullpkgname
from paths
join Ports on paths.id=Ports.fullpkgpath
join categories on categories.fullpkgpath=paths.id
join categorykeys on categorykeys.keyref=categories.value
where categorykeys.value=?
from _paths
join _Ports on _paths.id=_Ports.fullpkgpath
and _paths.id=_paths.canonical
join _categories on _categories.fullpkgpath=_paths.id
join _categorykeys on _categorykeys.keyref=_categories.value
where _categorykeys.value=?
group by fullpkgname
order by fullpkgname
});
my ($fullpkgpath, $fullpkgname);
$list_cat_req->bind_columns(\($fullpkgpath, $fullpkgname));

my $info_req = $db->prepare(
q{select
paths.id,
paths.fullpkgpath,
_paths.id,
_paths.fullpkgpath,
p2.fullpkgpath,
ports.comment,
ports.homepage,
descr.value,
_ports.comment,
_ports.homepage,
_descr.value,
fullpkgname,
permit_cd.value,
permit_ftp.value,
email.value
from paths
join paths p2 on p2.id=paths.pkgpath
join Ports on paths.id=Ports.fullpkgpath
left join Descr on paths.id=Descr.fullpkgpath
join keywords2 permit_cd
on ports.permit_package_cdrom=permit_cd.keyref
join keywords2 permit_ftp
on ports.permit_package_ftp=permit_ftp.keyref
join email on ports.maintainer=email.keyref
where paths.fullpkgpath=?});
_email.value
from _paths
join _paths p2 on p2.id=_paths.pkgpath
join _Ports on _paths.id=_Ports.fullpkgpath
left join _Descr on _paths.id=_Descr.fullpkgpath
join _keywords2 permit_cd
on _ports.permit_package_cdrom=permit_cd.keyref
join _keywords2 permit_ftp
on _ports.permit_package_ftp=permit_ftp.keyref
join _email on _ports.maintainer=_email.keyref
where _paths.fullpkgpath=?});
my ($id, $path, $simplepath, $comment, $homepage, $descr, $permit_cd, $permit_ftp, $maintainer);
$info_req->bind_columns(\($id, $path, $simplepath, $comment, $homepage, $descr, $fullpkgname, $permit_cd, $permit_ftp, $maintainer));

my $dep_req = $db->prepare(
q{select
depends.type,
depends.fulldepends,
_depends.type,
_depends.fulldepends,
t2.fullpkgpath
from depends
join paths on depends.dependspath=paths.id
join paths t2 on paths.canonical=t2.id
where depends.fullpkgpath=?
order by depends.fulldepends
from _depends
join _paths on _depends.dependspath=_paths.id
join _paths t2 on _paths.canonical=t2.id
where _depends.fullpkgpath=?
order by _depends.fulldepends
});
my ($type, $fulldepends, $dependspath);
$dep_req->bind_columns(\($type, $fulldepends, $dependspath));

my $revdep_req = $db->prepare(
q{select
distinct(paths.fullpkgpath)
from paths
join paths t3 on t3.canonical = paths.id
join paths t2 on t2.pkgpath=t3.id
join depends on depends.fullpkgpath=t2.id
where depends.dependspath in
(select id from paths where canonical=?)
order by paths.fullpkgpath});
distinct(_paths.fullpkgpath)
from _paths
join _paths t3 on t3.canonical = _paths.id
join _paths t2 on t2.pkgpath=t3.id
join _depends on _depends.fullpkgpath=t2.id
where _depends.dependspath in
(select id from _paths where canonical=?)
order by _paths.fullpkgpath});

my $revpath;
$revdep_req->bind_columns(\$revpath);

my $multi_req = $db->prepare(
q{select
ports.fullpkgname,
_ports.fullpkgname,
t2.fullpkgpath
from multi
join paths on multi.subpkgpath=paths.id
join paths t2 on paths.canonical=t2.id
join ports on paths.canonical=ports.fullpkgpath
where multi.fullpkgpath=?
from _multi
join _paths on _multi.subpkgpath=_paths.id
join _paths t2 on _paths.canonical=t2.id
join _ports on _paths.canonical=_ports.fullpkgpath
where _multi.fullpkgpath=?
});
my ($multi, $subpath);
$multi_req->bind_columns(\($multi, $subpath));
my $only_for = $db->prepare(
q{select
Arch.value
from OnlyForArch
join Arch on arch.keyref=OnlyForArch.value
where OnlyForArch.fullpkgpath=?
order by Arch.value
_Arch.value
from _OnlyForArch
join _Arch on _arch.keyref=_OnlyForArch.value
where _OnlyForArch.fullpkgpath=?
order by _Arch.value
});
my $arch;
$only_for->bind_columns(\($arch));
my $not_for = $db->prepare(
q{select
Arch.value
from NotforArch
join Arch on arch.keyref=NotForArch.value
where NotForArch.fullpkgpath=?
order by Arch.value
_Arch.value
from _NotforArch
join _Arch on _arch.keyref=_NotForArch.value
where _NotForArch.fullpkgpath=?
order by _Arch.value
});
$not_for->bind_columns(\($arch));
my $cat_req = $db->prepare(
q{select
categorykeys.value
from categories
join categorykeys on categorykeys.keyref=categories.value
where categories.fullpkgpath=?
order by categorykeys.value
_categorykeys.value
from _categories
join _categorykeys on _categorykeys.keyref=_categories.value
where _categories.fullpkgpath=?
order by _categorykeys.value
});
$cat_req->bind_columns(\($category));

my $broken_req = $db->prepare(
q{select
arch.value,
broken.value
from broken
left join arch on arch.keyref=broken.arch
_arch.value,
_broken.value
from _broken
left join _arch on _arch.keyref=_broken.arch
where fullpkgpath=?
order by arch.value});
order by _arch.value});

my $broken;
$broken_req->bind_columns(\($arch, $broken));

my $readme_req = $db->prepare(
q{select
readme.value
from readme
value
from _readme
where fullpkgpath=?});

my $readme;
$readme_req->bind_columns(\$readme);

my $canonical_req = $db->prepare(
q{select
paths.fullpkgpath
from paths
join paths t2 on t2.canonical=paths.id
_paths.fullpkgpath
from _paths
join _paths t2 on t2.canonical=_paths.id
where t2.fullpkgpath=?});

my $canonical;
Expand Down Expand Up @@ -311,45 +314,45 @@ sub search
}
}
close $fh;
push(@where, "paths.fullpkgpath in (".join(', ', map {$db->quote($_)} keys %h).")");
push(@where, "_paths.fullpkgpath in (".join(', ', map {$db->quote($_)} keys %h).")");
}
}

if ($search->{descr}) {
my $d = "%$search->{descr}%";
push(@params, $d, $d);
$s .= q{left join Descr on paths.id=Descr.fullpkgpath};
push(@where, q{(descr.value like ? or ports.comment like ?)});
$s .= q{left join _Descr on _paths.id=_Descr.fullpkgpath};
push(@where, q{(_descr.value like ? or _ports.comment like ?)});
}
if ($search->{maintainer}) {
push(@params, "%$search->{maintainer}%");
$s .= q{
join email on ports.maintainer=email.keyref
join _email on _ports.maintainer=_email.keyref
};
push(@where, q{email.value like ?});
push(@where, q{_email.value like ?});
}
if ($search->{category}) {
push(@params, $search->{category});
$s .= q{
join categories on categories.fullpkgpath=paths.id
join categorykeys on categorykeys.keyref=categories.value};
push(@where, q{categorykeys.value like ?});
join _categories on _categories.fullpkgpath=_paths.id
join _categorykeys on _categorykeys.keyref=_categories.value};
push(@where, q{_categorykeys.value like ?});
}
if ($search->{pkgname}) {
push(@params, "%$search->{pkgname}%");
push(@where, q{fullpkgname like ?});
}
if ($search->{path}) {
push(@params, "%$search->{path}%");
push(@where, q{paths.fullpkgpath like ?});
push(@where, q{_paths.fullpkgpath like ?});
}
if (@where > 0) {
$s.= " where ".join(" and ", @where);
}
$s = qq{select
paths.fullpkgpath, fullpkgname
from paths
join Ports on paths.id=Ports.fullpkgpath
_paths.fullpkgpath, fullpkgname
from _paths
join _Ports on _paths.id=_Ports.fullpkgpath
$s
order by fullpkgname
};
Expand Down

0 comments on commit c499e64

Please sign in to comment.