IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 29282


Ignore:
Timestamp:
Sep 30, 2010, 1:47:22 PM (16 years ago)
Author:
rhenders
Message:

Mirroring changes from czartool version: need to share a common class in future

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippToPsps/perl/ippToPsps/MySQLDb.pm

    r28757 r29282  
    6565}                                                                               
    6666
    67 
    6867###########################################################################
    6968#
    70 # Returns 'now' as a timestamp
     69# Adds the provided interval to the provided time
    7170#
    7271###########################################################################
    73 sub getIntervalInPast {
    74     my ($self, $interval) = @_;
     72sub addInterval {
     73    my ($self, $time, $interval) = @_;
    7574
    7675      my $query = $self->{_db}->prepare(<<SQL);
    77           SELECT now() - INTERVAL $interval;
     76          SELECT '$time' + INTERVAL $interval;
    7877SQL
    7978    $query->execute;
     
    8281}
    8382
     83###########################################################################
     84#
     85# Subtracts the provided interval from the provided time
     86#
     87###########################################################################
     88sub subtractInterval {
     89    my ($self, $time, $interval) = @_;
     90
     91      my $query = $self->{_db}->prepare(<<SQL);
     92          SELECT '$time' - INTERVAL $interval;
     93SQL
     94    $query->execute;
     95
     96return scalar $query->fetchrow_array();
     97}
     98
     99###########################################################################
     100#
     101# Returns whether time1 is before time2
     102#
     103###########################################################################
     104sub isBefore {
     105    my ($self, $time1, $time2) = @_;
     106
     107      my $query = $self->{_db}->prepare(<<SQL);
     108          SELECT '$time1' < '$time2';
     109SQL
     110    $query->execute;
     111
     112return scalar $query->fetchrow_array();
     113}
    84114
    85115###########################################################################
     
    97127
    98128return scalar $query->fetchrow_array();
     129}
     130
     131#######################################################################################
     132#
     133# Optimizes a table
     134#
     135#######################################################################################
     136sub optimizeTable {
     137    my ($self, $table) = @_;
     138
     139    my $query = $self->{_db}->prepare(<<SQL);
     140    OPTIMIZE TABLE $table;
     141SQL
     142
     143    my $success = $query->execute;
     144
     145    print "* ";
     146    if (!$success) {print "UN";}
     147    print "successfully optimized '$table' table\n";
     148
     149    return $success;
    99150}
    100151
Note: See TracChangeset for help on using the changeset viewer.