pass inserter thru so it's much easier to change table schemes

This commit is contained in:
espie 2018-11-27 10:36:17 +00:00
parent e8967feb1d
commit f6522ba714
4 changed files with 35 additions and 32 deletions

View File

@ -1,7 +1,7 @@
# $OpenBSD: Makefile,v 1.87 2018/11/27 08:28:34 espie Exp $
# $OpenBSD: Makefile,v 1.88 2018/11/27 10:36:17 espie Exp $
CATEGORIES = databases
V = 6.20
V = 6.21
DISTNAME = sqlports-$V
DISTFILES =
COMMENT = sqlite database of ports

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl
# $OpenBSD: Column.pm,v 1.11 2018/11/27 08:28:34 espie Exp $
# $OpenBSD: Column.pm,v 1.12 2018/11/27 10:36:17 espie Exp $
#
# Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org>
#
@ -51,7 +51,7 @@ sub normal_schema
sub view_schema
{
my ($self, $t) = @_;
my ($self, $t, $inserter) = @_;
return $self->realname($t)." AS ".$self->name;
}
@ -124,8 +124,9 @@ sub realname
sub view_schema
{
my ($self, $t) = @_;
return ($self->table."."."Id AS PathId", $self->SUPER::view_schema($t));
my ($self, $t, $inserter) = @_;
return ($self->table."."."Id AS PathId",
$self->SUPER::view_schema($t, $inserter));
}
sub normal_schema
@ -136,8 +137,8 @@ sub normal_schema
sub join_schema
{
my ($self, $table) = @_;
return "JOIN Paths ".$self->{table}." ON ".$self->table.".ID=$table.".$self->name;
my ($self, $table, $inserter) = @_;
return "JOIN ".$inserter->table_name("Paths")." ".$self->{table}." ON ".$self->table.".ID=$table.".$self->name;
}
package ValueColumn;
@ -172,9 +173,9 @@ sub realname
sub join_schema
{
my ($self, $table) = @_;
my ($self, $table, $inserter) = @_;
if (defined $self->k) {
return "JOIN ".$self->k." ".$self->table." ON ".$self->table.".KEYREF=$table.".$self->name;
return "JOIN ".$inserter->table_name($self->k)." ".$self->table." ON ".$self->table.".KEYREF=$table.".$self->name;
}
}
@ -189,8 +190,8 @@ sub normal_schema
sub join_schema
{
my ($self, $table) = @_;
return "LEFT ".$self->SUPER::join_schema($table);
my ($self, $table, $inserter) = @_;
return "LEFT ".$self->SUPER::join_schema($table, $inserter);
}
1;

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl
# $OpenBSD: Inserter.pm,v 1.20 2018/11/27 08:28:34 espie Exp $
# $OpenBSD: Inserter.pm,v 1.21 2018/11/27 10:36:17 espie Exp $
#
# Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org>
#
@ -170,7 +170,7 @@ sub make_table
sub subselect
{
my ($self, $class) = @_;
return $class->subselect;
return $class->subselect($self);
}
sub make_ordered_view
@ -322,12 +322,13 @@ sub create_canonical_depends
my ($self, $class) = @_;
my $t = $class->table;
my $id = $self->id;
my $p = $self->table_name("Paths");
$self->new_object('VIEW', "canonical_depends",
qq{as select
p1.canonical as fullpkgpath,
p2.canonical as dependspath, $t.type from $t
join paths p1 on p1.$id=$t.fullpkgpath
join paths p2 on p2.$id=$t.dependspath});
join $p p1 on p1.$id=$t.fullpkgpath
join $p p2 on p2.$id=$t.dependspath});
}
sub commit_to_db
@ -361,7 +362,7 @@ sub view_name
sub subselect
{
my ($self, $class) = @_;
return $class->subselect_compact;
return $class->subselect_compact($self);
}
sub convert_depends
@ -413,11 +414,12 @@ sub create_view
my ($self, $table, @columns) = @_;
unshift(@columns, PathColumn->new);
my @l = $self->map_columns('view', \@columns, $table);
my @j = $self->map_columns('join', \@columns, $table);
my $t = $self->table_name($table);
my @l = $self->map_columns('view', \@columns, $t, $self);
my @j = $self->map_columns('join', \@columns, $t, $self);
$self->new_object('VIEW', $table,
"AS SELECT ".join(", ", @l). " FROM ".
$self->table_name($table).' '.join(' ', @j));
$t.' '.join(' ', @j));
}
sub make_table

View File

@ -1,4 +1,4 @@
# $OpenBSD: Var.pm,v 1.36 2018/11/25 17:08:48 espie Exp $
# $OpenBSD: Var.pm,v 1.37 2018/11/27 10:36:17 espie Exp $
#
# Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org>
#
@ -115,15 +115,15 @@ sub normal_insert
sub subselect
{
my $self = shift;
my $t = $self->table;
my ($self, $inserter) = @_;
my $t = $inserter->table_name($self->table);
return "select fullpkgpath, value from $t order by n";
}
sub subselect_compact
{
my $self = shift;
return $self->subselect;
my ($self, $inserter) = @_;
return $self->subselect($inserter);
}
sub group_by
@ -366,8 +366,8 @@ sub group_by
sub subselect
{
my $self = shift;
my $t = $self->table;
my ($self, $inserter) = @_;
my $t = $inserter->table_name($self->table);
return "select fullpkgpath, fulldepends as value, type from $t order by n";
}
@ -539,9 +539,9 @@ sub add
sub subselect_compact
{
my $self = shift;
my $t = $self->table;
my $k = $self->keyword_table;
my ($self, $inserter) = @_;
my $t = $inserter->table_name($self->table);
my $k = $inserter->table_name($self->keyword_table);
return "select fullpkgpath, $k.value from $t join $k on $k.keyref=$t.value order by n";
}
@ -592,8 +592,8 @@ sub columns
sub subselect
{
my $self = shift;
my $t = $self->table;
my ($self, $inserter) = @_;
my $t = $inserter->table_name($self->table);
return qq{
select fullpkgpath,
case quotetype