Merge branch 'master' into anyevent
[spider.git] / perl / DXSql / SQLite.pm
index d151f82e31ac314adae64d4982e13aa93e1b7084..14eb0621f96e85bbc3805daecd1200850041e168 100644 (file)
@@ -22,11 +22,36 @@ sub show_tables
        my $sth = $self->prepare($s);
        $sth->execute;
        my @out;
-       push @out, $sth->fetchrow_array;
+       while (my @t = $sth->fetchrow_array) {
+               push @out, @t;
+       }
        $sth->finish;
        return @out;
 }
 
+sub has_ipaddr
+{
+       my $self = shift;
+       my $s = q(PRAGMA table_info(spot));
+       my $sth = $self->prepare($s);
+       $sth->execute;
+       while (my @t = $sth->fetchrow_array) {
+               if ($t[0] eq 'ipaddr') {
+                       $sth->finish;
+                       return 1;
+               }
+       }
+       $sth->finish;
+       return undef;
+}
+
+sub add_ipaddr
+{
+       my $self = shift;
+       my $s = q(alter table spot add column ipaddr varchar(40));
+       $self->do($s);
+}
+
 sub spot_create_table
 {
        my $self = shift;
@@ -45,7 +70,8 @@ spotcq int,
 spotteritu int,
 spottercq int,
 spotstate text,
-spotterstate text
+spotterstate text,
+ipaddr text
 )};
        $self->do($s);
 }
@@ -53,10 +79,10 @@ spotterstate text
 sub spot_add_indexes
 {
        my $self = shift;
-       $self->do('create index spot_ix1 on spot(time desc)');
        dbg('adding spot index ix1');
-       $self->do('create index spot_ix2 on spot(spotcall asc)');
+       $self->do('create index spot_ix1 on spot(time desc)');
        dbg('adding spot index ix2');
+       $self->do('create index spot_ix2 on spot(spotcall asc)');
 }