Changeset 1870 in ProjectBuilder


Ignore:
Timestamp:
Apr 10, 2014, 10:50:27 AM (10 years ago)
Author:
Bruno Cornec
Message:
  • Fix #129 by creating a new function pb_connect_db managing onnection to the announces DB and creating it appropriately in all cases (webssh as well)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • devel/pb/bin/pb

    r1861 r1870  
    40164016
    40174017    # Store it in DB for external usage (Web pages generation)
    4018     my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
    4019 
    4020     my $precmd = "";
    4021     if (! -f $db) {
    4022         $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
    4023     }
    4024 
    4025     my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
    4026                         { RaiseError => 1, AutoCommit => 1 })
    4027                         || die "Unable to connect to $db";
    4028 
    4029     if ($precmd ne "") {
    4030         my $sth = $dbh->prepare(qq{$precmd})
    4031                     || die "Unable to create table into $db";
    4032         $sth->execute();
    4033     }
     4018    my $dbh = pb_connect_db();
    40344019
    40354020    # To read whole file
     
    40414026    pb_log(2,"INSERT INTO announces VALUES (NULL, $pbdate, $announce)");
    40424027    my $sth = $dbh->prepare(qq{INSERT INTO announces VALUES (NULL,?,?)})
    4043                     || die "Unable to insert into $db";
     4028                    || die "Unable to insert into db";
    40444029    $sth->execute($pbdate, $announce);
    40454030    $sth->finish();
     
    41154100    my ($pkgv, $pkgt) = pb_conf_get_if("pkgver","pkgtag");
    41164101
    4117     # DB of announces for external usage (Web pages generation)
    4118     my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
    4119 
    4120     my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
    4121                         { RaiseError => 1, AutoCommit => 1 })
    4122                         || die "Unable to connect to $db";
     4102
     4103    my $dbh = pb_connect_db();
    41234104    # For date handling
    41244105    $ENV{LANGUAGE}="C";
     
    41534134}
    41544135
     4136sub pb_connect_db {
     4137
     4138    # Store in DB for external usage (Web pages generation)
     4139    my $db = "$ENV{'PBCONFDIR'}/announces3.sql";
     4140
     4141    my $precmd = "";
     4142    if (! -f $db) {
     4143        $precmd = "CREATE TABLE announces (id INTEGER PRIMARY KEY AUTOINCREMENT, date DATE, announce VARCHAR[65535])";
     4144    }
     4145
     4146    my $dbh = DBI->connect("dbi:SQLite:dbname=$db","","",
     4147                        { RaiseError => 1, AutoCommit => 1 })
     4148                        || die "Unable to connect to $db";
     4149
     4150    if ($precmd ne "") {
     4151        my $sth = $dbh->prepare(qq{$precmd})
     4152                    || die "Unable to create table into $db";
     4153        $sth->execute();
     4154    }
     4155
     4156    return($dbh);
     4157}
     4158
    41554159
    41564160# Return the SSH key file to use
Note: See TracChangeset for help on using the changeset viewer.