Speichern der Historie in einer eigenen Tabelle. Auch ein Fix für Bugzilla-ID 558.
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 21 Feb 2007 07:49:28 +0000 (07:49 +0000)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 21 Feb 2007 07:49:28 +0000 (07:49 +0000)
SL/Form.pm
sql/Pg-upgrade2/history_erp.sql [new file with mode: 0644]

index b6e0d83..9193e33 100644 (file)
@@ -2248,9 +2248,12 @@ sub save_history {
                &get_employee($self, $dbh);
        }
        
-       my $query = qq|INSERT INTO status (trans_id, employee_id, addition, what_done) 
-                                  VALUES ($self->{id}, $self->{employee_id}, '$self->{addition}', '$self->{what_done}')|;
-       $dbh->do($query) || $self->dberror($query);
+       my $query =
+    qq|INSERT INTO history_erp (trans_id, employee_id, addition, what_done) | .
+    qq|VALUES (?, ?, ?, ?)|;
+  my @values = (conv_i($self->{id}), conv_i($self->{employee_id}),
+                $self->{addition}, $self->{what_done});
+  do_query($self, $dbh, $query, @values);
        
        $main::lxdebug->leave_sub();
 }
@@ -2264,27 +2267,29 @@ sub get_history {
        my $restriction = shift();
        my @tempArray;
        my $i = 0;
-       if($trans_id ne ""){
-               my $query = qq|SELECT st.employee_id, st.itime, st.addition, st.what_done, emp.name 
-                                  FROM status st 
-                                  LEFT JOIN employee emp 
-                                  ON emp.id = st.employee_id
-                                  WHERE trans_id = $trans_id|
-                                  . $restriction;
+       if ($trans_id ne "") {
+               my $query =
+      qq|SELECT h.employee_id, h.itime, h.addition, h.what_done, emp.name | .
+      qq|FROM history_erp h | .
+      qq|LEFT JOIN employee emp | .
+      qq|ON emp.id = st.employee_id | .
+      qq|WHERE trans_id = ? |
+      . $restriction;
        
                my $sth = $dbh->prepare($query) || $self->dberror($query);
        
-               $sth->execute() || $self->dberror($query);
+               $sth->execute($trans_id) || $self->dberror("$query ($trans_id)");
 
                while(my $hash_ref = $sth->fetchrow_hashref()) {
                        $hash_ref->{addition} = $main::locale->text($hash_ref->{addition});
                        $hash_ref->{what_done} = $main::locale->text($hash_ref->{what_done});
                        $tempArray[$i++] = $hash_ref; 
                }
-               return \@tempArray if ($i > 0 && $tempArray[0] ne "");
+    $main::lxdebug->leave_sub() and return \@tempArray
+      if ($i > 0 && $tempArray[0] ne "");
        }
-       return 0;
        $main::lxdebug->leave_sub();
+       return 0;
 }
 
 sub save_status {
diff --git a/sql/Pg-upgrade2/history_erp.sql b/sql/Pg-upgrade2/history_erp.sql
new file mode 100644 (file)
index 0000000..daa9c4b
--- /dev/null
@@ -0,0 +1,18 @@
+-- @tag: history_erp
+-- @description: Entfernen der Spalten in Tabelle status zum Speichern der history und daf&uuml;r eigene Tabelle f&uuml;r die history
+-- @depends: status_history
+ALTER TABLE status DROP COLUMN id;
+ALTER TABLE status DROP COLUMN employee_id;
+ALTER TABLE status DROP COLUMN addition;
+ALTER TABLE status DROP COLUMN what_done;
+
+CREATE TABLE history_erp (
+       id integer NOT NULL DEFAULT nextval('id'),
+       trans_id integer,
+       employee_id integer,
+       addition text,
+       what_done text,
+
+       PRIMARY KEY (id),
+       FOREIGN KEY (employee_id) REFERENCES employee (id)
+);