~ubuntu-branches/ubuntu/saucy/libalzabo-perl/saucy

« back to all changes in this revision

Viewing changes to lib/Alzabo/Driver/PostgreSQL.pm

  • Committer: Bazaar Package Importer
  • Author(s): Gunnar Wolf, Martín Ferrari, Gunnar Wolf
  • Date: 2007-12-23 15:19:42 UTC
  • mfrom: (3.1.1 hardy)
  • Revision ID: james.westby@ubuntu.com-20071223151942-xvtszw722lpf47xx
Tags: 0.92-2
[ Martín Ferrari ]
* Added version mangle to avoid confusion between 2 digit and 4 digit minor
  versions. (Currently only affects qareport, because CPAN's by-dist only
  shows latest release, and ours is mimicked from the ls-lR file)

[ Gunnar Wolf ]
* Updated standards-version to 3.7.3 (No changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
sub connect
27
27
{
28
28
    my $self = shift;
29
 
    my %p = @_;
30
29
 
31
30
    $self->{tran_count} = undef;
32
31
 
33
 
    return if $self->{dbh} && $self->{dbh}->ping;
34
 
 
35
32
    # This database handle is stale or nonexistent, so we need to (re)connect
36
 
    $self->disconnect;
37
 
    $self->{dbh} = $self->_make_dbh( %p, name => $self->{schema}->db_schema_name );
 
33
    $self->disconnect if $self->{dbh};
 
34
    $self->{dbh} = $self->_make_dbh( @_,
 
35
                                     name => $self->{schema}->db_schema_name
 
36
                                   );
38
37
}
39
38
 
40
39
sub supports_referential_integrity { 1 }
122
121
    my $e = $@;
123
122
 
124
123
    eval { $dbh->disconnect; };
 
124
    $e ||= $@;
125
125
 
126
126
    Alzabo::Exception::Driver->throw( error => $e ) if $e;
127
 
    Alzabo::Exception::Driver->throw( error => $@ ) if $@;
128
127
}
129
128
 
130
 
sub _make_dbh
 
129
sub _connect_params
131
130
{
132
131
    my $self = shift;
133
 
 
134
132
    my %p = @_;
135
133
 
136
134
    %p = validate( @_, { name => { type => SCALAR },
161
159
 
162
160
    my %pg_keys = map { $_ => $p{$_} } grep { /^pg_/ } keys %p;
163
161
 
164
 
    my $dbh;
165
 
    eval
166
 
    {
167
 
        $dbh = DBI->connect( $dsn,
168
 
                             $p{user},
169
 
                             $p{password},
170
 
                             { RaiseError => 1,
171
 
                               AutoCommit => 1,
172
 
                               PrintError => 0,
173
 
                               %pg_keys,
174
 
                             }
175
 
                           );
176
 
    };
177
 
 
178
 
    Alzabo::Exception::Driver->throw( error => $@ ) if $@;
179
 
    Alzabo::Exception::Driver->throw( error => "Unable to connect to database\n" ) unless $dbh;
180
 
 
181
 
    return $dbh;
 
162
    return [ $dsn, $p{user}, $p{password},
 
163
             { RaiseError => 1,
 
164
               AutoCommit => 1,
 
165
               PrintError => 0,
 
166
               %pg_keys,
 
167
             },
 
168
           ];
182
169
}
183
170
 
184
171
sub next_sequence_number
186
173
    my $self = shift;
187
174
    my $col = shift;
188
175
 
189
 
    $self->_check_dbh;
 
176
    $self->_ensure_valid_dbh;
190
177
 
191
178
    Alzabo::Exception::Params->throw
192
179
        ( error => "This column (" . $col->name . ") is not sequenced" )