所以我是Perl的新手,也是SQLite的新手.我有SQL经验,但这个新的Perl语法让我有点沮丧.
所以我有一个问题,我正在尝试使用Perl脚本从IPtable日志创建数据库来解析表所具有的数据并向人们发送通知.该脚本还向用户发送通知,但我不认为这与此问题有任何关系.
这是我收到的错误.
DBD :: SQLite :: db prepare failed:没有这样的表:syslog_decom_notif at ./send_notification_syslog.pl第251行.无法在./send_notification_syslog.pl第252行的未定义值上调用方法"execute".
下面是我收到错误的代码:
2 sub select_contacts {
233 my @contact_info;
234 my $dbh = DBI->connect( DECOM_NOTIFICATION_DB ,"","");
235
236 my ( $where_clause, @exec_params ) = build_where_clause();
237
238 my $SQL = <<SQL;
239 select
240 contact
241 , status
242 , contact_mngr
243 , hostname
244 , contact_type
245 , syslog_server
246 from
247 syslog_decom_notif
248 $where_clause
249 SQL
250 debug ( __LINE__ . " Excuting SQL = \n[ $SQL ]\n" );
251 my $sth = $dbh->prepare( $SQL );
252 $sth->execute( @exec_params );
253 if ( $debug_mode ) {
254 my @cols = @{$sth->{NAME}};
255 print join '|', @cols;
256 print "\n";
257 }
258 while (my @res = $sth->fetchrow) {
259 for ( my $i=0; $i<@res; $i++ ) { $res[$i] = 'Null' if ! defined $res[$i]; }
260 my $row = join '|', @res;
261 debug "$row\n";
262 push @contact_info, $row;
263 }
264 $sth->finish();
265 return @contact_info;
266 }
Run Code Online (Sandbox Code Playgroud)
我四处搜寻,似乎无法找到任何可以帮助解决这个问题的东西.
我很欣赏任何想法.
最好的祝福
嗯,简单的事实是,正如它所说,DBI找不到syslog_decom_notif你打开的数据库中调用的表.之后,prepare已经没有别的没去上班.
我认为你的表名是正确的,所以我想知道它的价值DECOM_NOTIFICATION_DB.这来自哪里?它可能是一个字符串定义use constant?
在connect对SQLite 的调用中,DBI期望DSN看起来像dbi:SQLite:dbname=my_db_file.如果该文件不存在,它将被创建,所以也许您错误地设置了这个并且您正在使用空数据库?
更新
要查看已连接的数据库中的内容,请在DBI->connect调用后立即添加.它将在连接的数据库中打印一个表列表.确保END终结符出现在行的开头,并且在它之前或之后没有空格.
my $tables = $dbh->selectcol_arrayref(<<END);
SELECT name FROM sqlite_master
WHERE type='table'
ORDER BY name
END
print "$_\n" for @$tables;
Run Code Online (Sandbox Code Playgroud)