pbnj (2.04-4) direct (non packaging) changes

Summary

 outputpbnj |    4 +++-
 scanpbnj   |   49 +++++++++++++++++--------------------------------
 2 files changed, 20 insertions(+), 33 deletions(-)

    
download this patch

Patch contents

--- pbnj-2.04.orig/outputpbnj
+++ pbnj-2.04/outputpbnj
@@ -949,7 +949,9 @@
     print "output not defined\n";
 }
 
-$dbh->disconnect;
+if ( $db ne 'SQLite' ) {
+    $dbh->disconnect;
+}
 
 __DATA__
 # Config.yaml
--- pbnj-2.04.orig/scanpbnj
+++ pbnj-2.04/scanpbnj
@@ -328,41 +328,26 @@
     my $os              = $href->{os};
     my $created         = $href->{created};
     my $machine_created = $href->{machine_created};
-
-    if ( $db eq "CSV" ) {
-        my $sth = $dbh->selectrow_hashref("select max('mid') from machines");
-        my $mid = $sth->{mid};
-        if ( !defined($mid) ) {
-            $mid = 1;
-        }
-        else {
-            $mid++;
-        }
-        my $insert = $dbh->prepare(
-            'INSERT INTO machines VALUES (?,?,?,?,?,?,?,?,?)');
-
-        my $success = 1;
-        $success &&= $insert->execute( $mid, $ip, $host, $localh, $os,
-            $machine_created, $created );
-
-        return $mid;
+    
+    my $sth = $dbh->selectrow_hashref("select max(mid) from machines");
+   
+    my $mid;
+    if ($db eq 'Pg') {
+    	$mid = $sth->{'max'} ;
     }
     else {
-        $dbh->do(
-            "INSERT INTO machines (ip, host, localh, os,
-                machine_created, created_on) VALUES (
-                     '$ip', '$host', '$localh', '$os',
-                     '$machine_created', '$created' ) "
-        );
+        $mid = $sth->{'max(mid)'};
     }
-    my $sth = $dbh->selectrow_hashref(
-        "SELECT mid from machines
-               WHERE ip='$ip' AND host='$host'
-                 AND localh='$localh' AND os='$os' AND
-                machine_created='$machine_created' AND created_on='$created'"
-    );
-
-    return $sth->{'mid'};
+    # new mid needs to be 1 more than the max
+    $mid++;
+    
+    my $insert = $dbh->prepare(
+       'INSERT INTO machines VALUES (?,?,?,?,?,?,?)');
+    my $success = 1;
+    $success &&= $insert->execute( $mid, $ip, $host, $localh, $os,
+        $machine_created, $created );
+    
+    return $mid;
 }
 
 ##############################################################################