commit cfa8bcc1ed13ff75d334145671cee27905afc705 from: Izzy Blacklock date: Thu Jul 06 00:35:04 2023 UTC Added checks for data to insert before calling dbInsertRecord() commit - 23393a00219da04c2f0c1ab63b2084a84f011dbe commit + cfa8bcc1ed13ff75d334145671cee27905afc705 blob - 754a6137c0cf1d7f66a5fda6f10e009c403ba693 blob + c10ca2ba504f623dbbcd8010296a6a913869bac3 --- lib/IRCNOW/Database.pm +++ lib/IRCNOW/Database.pm @@ -5,6 +5,9 @@ use DBI; use DBD::SQLite; use IRCNOW::IO qw(:DEBUG); +use Data::Dumper; + + sub new { my ($class, @arguments) = @_; my $self = { @arguments }; @@ -94,15 +97,20 @@ sub dbInsertRecord { my $stmt = qq{ INSERT INTO $table ($fieldStr) VALUES ($valStr) }; + + debug(INFO,"IRCNOW::Database::dbInsertRecord() SQL Stmt: ". $stmt); if (ref $data->[0] eq "ARRAY") { # We have multiple records to insert my $sth = $dbh->prepare($stmt); for (@$data) { $sth->execute(@$_) or die $dbh->errstr; } - } else { - debug(INFO,"INSERTING:". $stmt,$data); + } elsif (scalar @$data == scalar @$fields) { # make sure we have data to insert $dbh->do($stmt, undef, $data); + } else { + debug(ERROR,"Mismatch on number of fileds to insert.\n" + . Dumper($data) + ); } } blob - 5845d73610bef4f59ad64b8af2cfa4d9bea8407d blob + c2ff41ca00091ba6e7448ef49c870e987802735f --- parseznc.pl +++ parseznc.pl @@ -22,9 +22,13 @@ use Data::Dumper; my $lastRecord=$znclog->dbLastRecord() || []; my $data = $znclog->parseLog($lastRecord->[1],$lastRecord->[3],$lastRecord->[4]); -#debug (WARNINGS, Dumper($data)); +debug (WARNINGS, "znclog: New entries to insert: \n" . Dumper($data)); -#$znclog->dbInsertRecord($data); +if (@$data) { + $znclog->dbInsertRecord($data); +} + + #print Dumper($znclog->parseLog($lastRecord->[1],$lastRecord->[3],$lastRecord->[4])); #$znclog->createTable();