私のコード:
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 }
警告は次のとおりです。
Issuing rollback() due to DESTROY without explicit disconnect() of DBD::Pg::db handle
171行目以降に「$dbh->commit()」を追加すると、上記のワーニングが消えました。
171 行目の後に「$dbh->commit()」を追加せずに「$hfpDbh->disconnect();」を呼び出した場合 140行目で、上記の警告も消えました。
私の質問は次 のとおりです。警告は、コミットされていないトランザクションがあることを意味しますか? そのため、警告を修正するには、明示的にコミットまたは切断する必要があります。ただし、コードには SELECT 操作しかありません。私は何が欠けていますか?
ありがとう。