Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 在Perl脚本中执行SQLite DB时出现问题_Linux_Perl_Sqlite - Fatal编程技术网

Linux 在Perl脚本中执行SQLite DB时出现问题

Linux 在Perl脚本中执行SQLite DB时出现问题,linux,perl,sqlite,Linux,Perl,Sqlite,所以我是Perl新手,也是SQLite新手。我有SQL方面的经验,但这种新的Perl语法让我有些困惑 因此,我遇到了一个问题,我试图使用Perl脚本从IPtable日志创建一个DB来解析表中的数据,并向人们发送通知。脚本还向用户发送通知,但我认为这与此问题无关 这就是我收到的错误 DBD::SQLite::db prepare失败:没有这样的表:syslog\u decom\u notif位于./send\u notification\u syslog.pl第251行。 无法在./send\u

所以我是Perl新手,也是SQLite新手。我有SQL方面的经验,但这种新的Perl语法让我有些困惑

因此,我遇到了一个问题,我试图使用Perl脚本从IPtable日志创建一个DB来解析表中的数据,并向人们发送通知。脚本还向用户发送通知,但我认为这与此问题无关

这就是我收到的错误

DBD::SQLite::db prepare失败:没有这样的表:syslog\u decom\u notif位于./send\u notification\u syslog.pl第251行。 无法在./send\u notification\u 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 }
2子选择\u联系人{
233我的@contact_信息;
234 my$dbh=DBI->connect(装饰通知数据库“,”);
235
236 my($where_子句,@exec_参数)=构建where_子句();
237
238 my$SQL=execute(@exec_params);
253如果($debug_模式){
254 my@cols=@{$sth->{NAME};
255个打印联接“|”、@cols;
256打印“\n”;
257         }
258 while(my@res=$sth->fetchrow){
259 for(my$i=0;$ifinish();
265返回@contact_info;
266 }
我四处搜索,似乎找不到任何真正有助于解决这个问题的东西

我欣赏所有的想法


最好的问候

简单的事实是,正如它所说的,DBI在您打开的数据库中找不到名为syslog\u decom\u notif的表。在准备失败后,其他一切都将无法工作

我想您的表名是正确的,所以我想知道
DECOM\u NOTIFICATION\u DB
的值。这是从哪里来的?它可能是用
use constant
定义的字符串吗

在SQLite的
connect
调用中,DBI需要一个类似于
DBI:SQLite:dbname=my_db_file
的DSN。如果该文件不存在,它将被创建,因此可能您的设置错误,并且您使用的是空数据库


更新

要查看您连接到的数据库中的内容,请在
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;

my$tables=$dbh->selectcol\u arrayref(它说
没有这样的表:syslog\u decom\u notif
。有这样的表吗?尝试执行查询(
$SQL
,您已经在输出它了)在命令行db客户端中。它还表示您正在创建一个表并存储数据,但您的代码只显示一个
SELECT
语句。这有点奇怪。;-)谢谢你的输入!我编辑了我的帖子,我的意思是说数据在数据库中被解析,然后通过电子邮件发送通知。我不是说数据被解析然后存储。:-)DECOM_NOTIFICATION_DB在脚本的早期被设置为一个use常量。至于您所说的连接,我仍在研究,但我会给您回复。我在回答中添加了一些代码,以显示将列出您连接到的SQLite数据库中的表的代码。我发现了错误。在某个地方使用常量是一个r当一个软件包被插入到代码中时,我非常感谢你的帮助!