My code:
122 # 123 my $hfpDbh = undef; 124 unless ( 125 $hfpDbh = DBI->connect("dbi:Pg:host=....")#removed something 128 ) { 129 Log( ERROR, "" ); 130 Exit( 1 ) 131 } 132 $hfpDbh->{RaiseError} = 1; 133 $hfpDbh->{AutoCommit} = 0; 134 135 ( my $mydata, $msg ) = load_data( $hfpDbh, $DatFile ); 136 unless ( defined($mydata) ) 137 { 138 Log(INFO, "Calling exit...2"); 139 } 140 #$hfpDbh->disconnect(); 141 Exit( 0 ); 142 Log(INFO, "Calling exit...4"); 143 144 145 sub load_data 146 { 147 my ( $dbh, $DatFile ) = @_; 148 my $msg = ''; 149 unless ( $dbh ) { 150 $msg = 'cannot load data, no DB handle'; 151 Log( ERROR, $msg ); 152 } 153 Log(INFO, "Call load_data..."); 154 my $q = "SELECT ip as ip FROM rules WHERE active = 'true' AND isGood = 'true';"; 155 my $stmt = undef; 156 unless ( $stmt = $dbh->prepare( $q ) ) { 157 $msg = "unable to prepare SQL query: $q"; 158 Log( ERROR, $msg ); 159 } 160 161 eval { $stmt->execute() }; 162 if ( $@ ) { 163 $msg = "failed to execute SQL query: $@"; 164 Log( ERROR, $msg ); 165 } 166 167 my $data = {}; 168 while ( my $row = $stmt->fetchrow_hashref() ) { 169 #Log(INFO, "testing row"); 170 } 171 $stmt->finish(); 172 return $data, $msg; 173 }
The warning is:
Issuing rollback() due to DESTROY without explicit disconnect() of DBD::Pg::db handle
If I add "$dbh->commit()" after Line 171, the above warn disappeared.
If I did not add "$dbh->commit()" after Line 171 but called "$hfpDbh->disconnect();" in Line 140, the above warn disappeared too.
My question is: The warning means that there are uncommitted transactions? That is why I need to commit or disconnect explicitly to fix the warning. But there is only SELECT operation in the code. What I am missing?
Thanks.