Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision aa1a40e9

Von Moritz Bunkus vor mehr als 11 Jahren hinzugefügt

  • ID aa1a40e9141fd718e85e6e92f78adf301f53cf1f
  • Vorgänger 89b7ddcb
  • Nachfolger a4665ffc

SL::DBUpgrade2::Base neue Funktion db_errstr() für korrekt encodierte Datenbankfehlermeldungen

Unterschiede anzeigen:

SL/DBUpgrade2/Base.pm
5 5
use parent qw(Rose::Object);
6 6

  
7 7
use Carp;
8
use Encode;
8 9
use English qw(-no_match_vars);
9 10
use File::Basename ();
10 11
use File::Copy ();
......
37 38
sub db_error {
38 39
  my ($self, $msg) = @_;
39 40

  
40
  die $::locale->text("Database update error:") . "<br>$msg<br>" . $DBI::errstr;
41
  die $::locale->text("Database update error:") . "<br>$msg<br>" . $self->db_errstr('DBI');
41 42
}
42 43

  
43 44
sub db_query {
44 45
  my ($self, $query, %params) = @_;
45 46

  
46
  return if $self->dbh->do($query, undef, @{ $params{bind} || [] });
47
  my $dbh = $params{dbh} || $self->dbh;
48

  
49
  return if $dbh->do($query, undef, @{ $params{bind} || [] });
47 50

  
48 51
  $self->db_error($query) unless $params{may_fail};
49 52

  
50
  $self->dbh->rollback;
51
  $self->dbh->begin_work;
53
  $dbh->rollback;
54
  $dbh->begin_work;
55
}
56

  
57
sub db_errstr {
58
  my ($self, $handle) = @_;
59

  
60
  my $error = $handle ? $handle->errstr : $self->dbh->errstr;
61

  
62
  return $::locale->is_utf8 ? Encode::decode('utf-8', $error) : $error;
52 63
}
53 64

  
54 65
sub check_coa {
......
221 232

  
222 233
An optional array reference containing bind parameter for the query.
223 234

  
235
=item C<dbh>
236

  
237
The database handle to use. If undefined then C<$self-E<gt>dbh> will
238
be used.
239

  
240
=back
241

  
242
=item C<db_errstr [$handle]>
243

  
244
Returns the last database from C<$handle> error message encoded in
245
Perl's internal encoding. The PostgreSQL DBD leaves the UTF-8 flag off
246
for error messages even if the C<pg_enable_utf8> attribute is set.
247

  
248
C<$handle> is optional and can be one of three things:
249

  
250
=over 2
251

  
252
=item 1. A database or statement handle. In that case
253
C<$handle-E<gt>errstr> is used.
254

  
255
=item 2. The string 'DBI'. In that case C<$DBI::errstr> is used.
256

  
257
=item 3. If it is undefined then C<$self-E<gt>dbh-E<gt>errstr> is
258
used.
259

  
224 260
=back
225 261

  
226 262
=item C<execute_script>

Auch abrufbar als: Unified diff