dee586f76168c07504287a9365cddbff110db213
[spider.git] / perl / DXSql / mysql.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::mysql;
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(show tables);
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(describe spot);
36         my $sth = $self->prepare($s);
37         $sth->execute;
38         while (my @t = $sth->fetchrow_array) {
39                 if ($t[0] 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 varchar(40));
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 auto_increment primary key ,
60 freq real not null,
61 spotcall varchar(14) not null,
62 time int not null,
63 comment varchar(255),
64 spotter varchar(14) not null,
65 spotdxcc smallint,
66 spotterdxcc smallint,
67 origin varchar(14),
68 spotitu tinyint,
69 spotcq tinyint,
70 spotteritu tinyint,
71 spottercq tinyint,
72 spotstate char(2),
73 spotterstate char(2),
74 ipaddr varchar(40)
75 )};
76         $self->do($s);
77 }
78
79 sub spot_add_indexes
80 {
81         my $self = shift;
82         $self->do('create index spot_ix1 on spot(time desc)');
83         dbg('adding spot index ix1');
84         $self->do('create index spot_ix2 on spot(spotcall asc)');
85         dbg('adding spot index ix2');
86 }
87
88
89 1;