1
運用教程中,我創建了需要從表單信息,並檢查什麼是數據庫中可用的輸入數據的方法的信息:Perl的舞者:傳遞的數據庫信息行模板
post '/identry' => sub {
#to cut short the long code the following are the steps
#getting the last time the data has been entered into the database
# to match with the ids entered through the form , I have to display what is available
in the database for the same position
my $sql2 = "SELECT a.ID FROM db_test a, db_check b WHERE
a.POSITION=b.RACK||'/'||b.POS AND DOE =TO_TIMESTAMP('$last_entry','dd-mm-yyyy hh24:mi:ss:ff') ORDER BY SUBSTR(a.POSITION,9,3)";
my $sth2= $dbh->prepare($sql2) or die $dbh->errstr;
$sth2->execute() or die "$dbh->errstr \n";
template 'checkid.tt', {
'checkid_url' => uri_for('/checkid'),
'entries' => $sth2->fetchall_hashref('ID'),
};
};
我收到錯誤
Warning caught during route execution: DBD::Oracle::st fetchall_hashref failed: ERROR no statement executing (perhaps you need to call execute first) [for Statement "SELECT a.ID FROM db_test a,db_check b WHERE a.POSITION=b.RACK||'/'||b.POS AND DOE =TO_TIMESTAMP('02-12-2014 12:00:33:000000','dd-mm-yyyy hh24:mi:ss:ff') ORDER BY SUBSTR(a.POSITION,9,3)"]
的模板如下
<% IF entries.size %>
<% FOREACH ID IN entries %>
<p><input type="text" name=id1 id="id1" value="<% entries.$ID.0 %>" size =8>
<input type="text" name=id2 id="id2" value="<% entries.$ID.1 %>" size =8>
</p>
<% END %>
<% ELSE %>
<em> No data available in Database </em>
<% END %>
可以在' - > execute'之後記錄$ sth2 - > {Executed}嗎?還要注意,方法不是用雙引號插入('「$ dbh-> errstr」')。 – choroba 2014-12-02 13:01:47
在fetchall_hashref'my $ entries = $ sth2-> fetchall_hashref('ID')上執行之後,我使用data :: Dumper完成了結果。 print STDERR Dumper($ entries);'並得到如下結果:$ VAR1 = {001A => {'ID'=>'001A'},'002b => {'ID'=>'002b'}} ;' – user2838042 2014-12-02 13:26:24
嗯......你能否將'entries => $ entries'傳遞給模板? – choroba 2014-12-02 13:38:39