]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DBUpgrade2/Base.pm
Nicht mehr benötigte MetaSetups löschen: DptTrans, TranslationPaymentTerm
[mfinanz.git] / SL / DBUpgrade2 / Base.pm
index 9978b207e40637e2a634dbec0e5600f80d12dd71..6f0bb829c6d54833ebbd40aab6754da379d3475d 100644 (file)
@@ -59,7 +59,7 @@ sub db_errstr {
 
   my $error = $handle ? $handle->errstr : $self->dbh->errstr;
 
-  return $::locale->is_utf8 ? Encode::decode('utf-8', $error) : $error;
+  return Encode::decode('utf-8', $error);
 }
 
 sub check_coa {
@@ -119,6 +119,24 @@ sub add_print_templates {
   return 1;
 }
 
+sub drop_constraints {
+  my ($self, %params) = @_;
+
+  croak "Missing parameter 'table'" unless $params{table};
+  $params{type}   ||= 'FOREIGN KEY';
+  $params{schema} ||= 'public';
+
+  my $constraints = $self->dbh->selectall_arrayref(<<SQL, undef, $params{type}, $params{schema}, $params{table});
+    SELECT constraint_name
+    FROM information_schema.table_constraints
+    WHERE (constraint_type = ?)
+      AND (table_schema    = ?)
+      AND (table_name      = ?)
+SQL
+
+  $self->db_query(qq|ALTER TABLE auth."$params{table}" DROP CONSTRAINT "${_}"|) for map { $_->[0] } @{ $constraints };
+}
+
 1;
 __END__
 
@@ -259,6 +277,21 @@ used.
 
 =back
 
+=item C<drop_constraints %params>
+
+Drops all constraints of a type (e.g. foreign keys) on a table. One
+parameter is mandatory: C<table>. Optional parameters include:
+
+=over 2
+
+=item * C<schema> -- if missing defaults to C<public>
+
+=item * C<type> -- if missing defaults to C<FOREIGN KEY>. Must be one of
+the values contained in the C<information_schema.table_constraints>
+view in the C<constraint_type> column.
+
+=back
+
 =item C<execute_script>
 
 Executes a named database upgrade script. This function is not