fix sh/dx <call> with sql spot logging
[spider.git] / perl / DXSql / SQLite.pm
1 #
2 # Module for SQLite DXSql variants
3 #
4 # Stuff like table creates and (later) alters
5 #
6 #
7 #
8 # Copyright (c) 2005 Dirk Koopman G1TLH
9 #
10
11 package DXSql::SQLite;
12
13 use DXDebug;
14
15 use vars qw(@ISA);
16 @ISA = qw{DXSql};
17
18 sub show_tables
19 {
20         my $self = shift;
21         my $s = q(SELECT name FROM sqlite_master WHERE type='table' ORDER BY name);
22         my $sth = $self->prepare($s);
23         $sth->execute;
24         my @out;
25         while (my @t = $sth->fetchrow_array) {
26                 push @out, @t;
27         }
28         $sth->finish;
29         return @out;
30 }
31
32 sub has_ipaddr
33 {
34         my $self = shift;
35         my $s = q(PRAGMA table_info(spot));
36         my $sth = $self->prepare($s);
37         $sth->execute;
38         while (my @t = $sth->fetchrow_array) {
39                 if ($t[1] eq 'ipaddr') {
40                         $sth->finish;
41                         return 1;
42                 }
43         }
44         $sth->finish;
45         return undef;
46 }
47
48 sub add_ipaddr
49 {
50         my $self = shift;
51         my $s = q(alter table spot add column ipaddr text);
52         $self->do($s);
53 }
54
55 sub spot_create_table
56 {
57         my $self = shift;
58         my $s = q{create table spot (
59 rowid integer primary key,
60 freq real not null,
61 spotcall text not null,
62 time int not null,
63 comment text,
64 spotter text not null,
65 spotdxcc int,
66 spotterdxcc int,
67 origin text,
68 spotitu int,
69 spotcq int,
70 spotteritu int,
71 spottercq int,
72 spotstate text,
73 spotterstate text,
74 ipaddr text
75 )};
76         $self->do($s);
77 }
78
79 sub spot_add_indexes
80 {
81         my $self = shift;
82         dbg('adding spot index ix1');
83         $self->do('create index spot_ix1 on spot(time desc)');
84         dbg('adding spot index ix2');
85         $self->do('create index spot_ix2 on spot(spotcall asc)');
86 }
87
88
89 1;