Changeset 222


Ignore:
Timestamp:
Oct 29, 2006, 5:02:35 PM (13 years ago)
Author:
Dominic Hargreaves
Message:

Make everything use the modules

Location:
trunk/npemap.org.uk/cgi
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/bad-postcode.fcgi

    r215 r222  
    1212use vars qw($dbname $dbhost $dbuser $dbpass);
    1313
     14# Find our private perl libraries
     15use FindBin;
     16use lib "$FindBin::Bin/../perllib";
     17use NPEMap;
     18
    1419sub print_err;
    15 sub setup_dbh;
    16 
    17 # Read in database config
    18 my $config = 'npemap.conf';
    19 do $config or die "Can't read $config!\n";
    2020
    2121# Set up database handler to try and make sure it's ready for the first
     
    2323# No point in handling errors here since they'll get handled by the request
    2424# handler
    25 my $dbh;
    26 setup_dbh();
     25my $dbh = setup_dbh();
    2726
    2827my $returnBaseURL = '';
     
    4241
    4342    # In case the database went away, make sure we have a connection
    44     unless (setup_dbh()) {
     43    unless ($dbh = setup_dbh()) {
    4544        print_err('Error setting up database connection', $returnlink);
    4645        next REQUEST;
     
    9493    print "</body></html>\n";
    9594}
    96 
    97 sub setup_dbh {
    98     # $dbh is global
    99     my $data_source = "dbi:Pg:dbname=$dbname";
    100     $data_source .= ";host=$dbhost" if $dbhost;
    101     return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    102 }
    103 
  • trunk/npemap.org.uk/cgi/get-distant-postcodes.fcgi

    r205 r222  
    1717use vars qw($dbname $dbhost $dbuser $dbpass);
    1818
     19# Find our private perl libraries
     20use FindBin;
     21use lib "$FindBin::Bin/../perllib";
     22use NPEMap;
     23
    1924sub print_err;
    20 sub setup_dbh;
    21 
    22 # Read in database config
    23 my $config = 'npemap.conf';
    24 do $config or die "Can't read $config!\n";
    25 
    2625
    2726# Set up database handler to try and make sure it's ready for the first
     
    2928# No point in handling errors here since they'll get handled by the request
    3029# handler
    31 my $dbh;
    32 setup_dbh();
     30my $dbh = setup_dbh();
    3331
    3432
     
    3836
    3937    # In case the database went away, make sure we have a connection
    40     unless (setup_dbh()) {
     38    unless ($dbh = setup_dbh()) {
    4139        print_internal_err('Error setting up database connection');
    4240        next REQUEST;
     
    127125    print "Error: $err\n";
    128126}
    129 
    130 sub setup_dbh {
    131     # $dbh is global
    132     my $data_source = "dbi:Pg:dbname=$dbname";
    133     $data_source .= ";host=$dbhost" if $dbhost;
    134     return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    135 }
  • trunk/npemap.org.uk/cgi/get-postcodes.fcgi

    r195 r222  
    1212use vars qw($dbname $dbhost $dbuser $dbpass);
    1313
     14# Find our private perl libraries
     15use FindBin;
     16use lib "$FindBin::Bin/../perllib";
     17use NPEMap;
     18
    1419sub print_err;
    15 sub setup_dbh;
    16 
    17 # Read in database config
    18 my $config = 'npemap.conf';
    19 do $config or die "Can't read $config!\n";
    20 
    2120
    2221# Set up database handler to try and make sure it's ready for the first
     
    2423# No point in handling errors here since they'll get handled by the request
    2524# handler
    26 my $dbh;
    27 setup_dbh();
     25my $dbh = setup_dbh();
    2826
    2927
     
    3634
    3735    # In case the database went away, make sure we have a connection
    38     unless (setup_dbh()) {
     36    unless ($dbh = setup_dbh()) {
    3937        print_internal_err('Error setting up database connection');
    4038        next REQUEST;
     
    105103    print "Error: $err\n";
    106104}
    107 
    108 sub setup_dbh {
    109     # $dbh is global
    110     my $data_source = "dbi:Pg:dbname=$dbname";
    111     $data_source .= ";host=$dbhost" if $dbhost;
    112     return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    113 }
  • trunk/npemap.org.uk/cgi/interest.fcgi

    r82 r222  
    1313use vars qw($dbname $dbhost $dbuser $dbpass);
    1414
     15# Find our private perl libraries
     16use FindBin;
     17use lib "$FindBin::Bin/../perllib";
     18use NPEMap;
     19
    1520sub print_err;
    16 sub setup_dbh;
    17 
    18 # Read in database config
    19 my $config = 'npemap.conf';
    20 do $config or die "Can't read $config!\n";
    2121
    2222my $returnlink='<a href="/">Go back</a>';
     
    2626# No point in handling errors here since they'll get handled by the request
    2727# handler
    28 my $dbh;
    29 setup_dbh();
     28my $dbh = setup_dbh();
    3029
    3130my $cgi;
     
    3433
    3534    # In case the database went away, make sure we have a connection
    36     unless (setup_dbh()) {
     35    unless ($dbh = setup_dbh()) {
    3736        print_err('Error setting up database connection', $returnlink);
    3837        next REQUEST;
     
    104103    print "</body></html>\n";
    105104}
    106 
    107 sub setup_dbh {
    108     # $dbh is global
    109     my $data_source = "dbi:Pg:dbname=$dbname";
    110     $data_source .= ";host=$dbhost" if $dbhost;
    111     return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    112 }
    113 
  • trunk/npemap.org.uk/cgi/problem.fcgi

    r154 r222  
    1414use vars qw($dbname $dbhost $dbuser $dbpass);
    1515
     16# Find our private perl libraries
     17use FindBin;
     18use lib "$FindBin::Bin/../perllib";
     19use NPEMap;
     20
    1621sub print_err;
    17 sub setup_dbh;
    18 
    19 # Read in database config
    20 my $config = 'npemap.conf';
    21 do $config or die "Can't read $config!\n";
    2222
    2323# Set up database handler to try and make sure it's ready for the first
     
    2525# No point in handling errors here since they'll get handled by the request
    2626# handler
    27 my $dbh;
    28 setup_dbh();
     27my $dbh = setup_dbh();
    2928
    3029my $returnBaseURL = '';
     
    3938
    4039    # In case the database went away, make sure we have a connection
    41     unless (setup_dbh()) {
     40    unless ($dbh = setup_dbh()) {
    4241        print_err('Error setting up database connection', $returnlink);
    4342        next REQUEST;
     
    9291    print "</body></html>\n";
    9392}
    94 
    95 sub setup_dbh {
    96     # $dbh is global
    97     my $data_source = "dbi:Pg:dbname=$dbname";
    98     $data_source .= ";host=$dbhost" if $dbhost;
    99     return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    100 }
  • trunk/npemap.org.uk/cgi/submit.fcgi

    r169 r222  
    1313use vars qw($dbname $dbhost $dbuser $dbpass);
    1414
     15# Find our private perl libraries
     16use FindBin;
     17use lib "$FindBin::Bin/../perllib";
     18use NPEMap;
     19
    1520sub print_err;
    16 sub setup_dbh;
    17 
    18 # Read in database config
    19 my $config = 'npemap.conf';
    20 do $config or die "Can't read $config!\n";
    2121
    2222# Set up database handler to try and make sure it's ready for the first
     
    2424# No point in handling errors here since they'll get handled by the request
    2525# handler
    26 my $dbh;
    27 setup_dbh();
     26my $dbh = setup_dbh();
    2827
    2928my @fields = qw(easting northing postcode1 postcode2);
     
    4645
    4746    # In case the database went away, make sure we have a connection
    48     unless (setup_dbh()) {
     47    unless ($dbh = setup_dbh()) {
    4948        print_err('Error setting up database connection', $returnlink);
    5049        next REQUEST;
     
    165164    print "</body></html>\n";
    166165}
    167 
    168 sub setup_dbh {
    169     # $dbh is global
    170     my $data_source = "dbi:Pg:dbname=$dbname";
    171     $data_source .= ";host=$dbhost" if $dbhost;
    172     return $dbh = DBI->connect_cached($data_source, $dbuser, $dbpass);
    173 }
    174 
Note: See TracChangeset for help on using the changeset viewer.