2 # Module for SQLite DXSql variants
4 # Stuff like table creates and (later) alters
6 # Copyright (c) 2005 Dirk Koopman G1TLH
7 # Modifications made for Pg, Copyright (c) 2012 Wijnand Modderman-Lenstra PD0MZ
20 #my $s = q(show tables);
21 my $s = q(SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';);
22 my $sth = $self->prepare($s);
25 while (my @t = $sth->fetchrow_array) {
35 my $s = q(SELECT column_name FROM information_schema.columns WHERE table_name = 'spot');
36 my $sth = $self->prepare($s);
38 while (my @t = $sth->fetchrow_array) {
39 if ($t[0] eq 'ipaddr') {
51 my $s = q(alter table spot add column ipaddr varchar(40));
59 $s = q{create sequence spot_rowid_seq};
61 $s = q{create table spot (
62 rowid sequence primary key ,
64 spotcall varchar(14) not null,
67 spotter varchar(14) not null,
80 $s = q{alter table spot alter column rowid set default nextval('spot_rowid_seq');};
87 #dbg('adding spot index ix1');
88 #$self->do('create index spot_ix1 on spot(time desc)');
89 #dbg('adding spot index ix2');
90 #$self->do('create index spot_ix2 on spot(spotcall asc)');
100 push @$spot, undef while @$spot < 15;
101 pop @$spot while @$spot > 15;
102 eval {$sth->execute(undef, @$spot)};
104 my $s = "insert into spot values(NEXTVAL('spot_rowid_seq'),";
105 $s .= sprintf("%.1f,", $spot->[0]);
106 $s .= $self->quote($spot->[1]) . "," ;
107 $s .= $spot->[2] . ',';
108 $s .= (length $spot->[3] ? $self->quote($spot->[3]) : 'NULL') . ',';
109 $s .= $self->quote($spot->[4]) . ',';
110 $s .= $spot->[5] . ',';
111 $s .= $spot->[6] . ',';
112 $s .= (length $spot->[7] ? $self->quote($spot->[7]) : 'NULL') . ',';
113 $s .= $spot->[8] . ',';
114 $s .= $spot->[9] . ',';
115 $s .= $spot->[10] . ',';
116 $s .= $spot->[11] . ',';
117 $s .= (length $spot->[12] ? $self->quote($spot->[12]) : 'NULL') . ',';
118 $s .= (length $spot->[13] ? $self->quote($spot->[13]) : 'NULL') . ',';
119 $s .= (length $spot->[14] ? $self->quote($spot->[14]) : 'NULL') . ')';
120 eval {$self->do($s)};