- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我想从一个fifo管道中插入数据到一个mysql表中
我的脚本如下:
#!/usr/bin/perl
#Script to read data out of a named pipe and write to MySQL database.
$| = 1;
use strict;
use DBI();
my $filename;
my $inputline;
my $linenumber;
my @arr;
$filename = "./SEC_fifo";
open(FIFO, "+< $filename") or die "FIFO error on $filename $!";
my $dbh = DBI->connect("DBI:mysql:database=ecdb;host=localhost",
"user", "[pwd]",
{'RaiseError' => 1});
while (<FIFO>)
{
$inputline = $_;
@arr = split(/,/,$inputline);
# Quit read loop when requested.
last if($inputline =~ /quit/i);
chop $inputline;
$linenumber++;
print "Got: [$inputline], ";
my $sql="";
my $sth="";
my @row;
print "output.\n".$arr[0],$arr[1],$arr[2],$arr[3],$arr[4],$arr[5],$arr[6],$arr[7],$arr[8],$arr[9],$arr[10],$arr[11],$arr[12],$arr[13]."\n";
# perl trim function - remove leading and trailing whitespace
my $str = $arr[6] ;
$str =~ s/^\s+//;
$str =~ s/\s+$//;
if($str ne 'Normal')
{
print "arr[6]=".$arr[6]."\n";
$sql = "select Hid from Devices where hostname = '$arr[2]'";
print $sql."\n";
$sth = $dbh->prepare($sql);
$sth->execute || die "Could not execute SQL statement ... maybe invalid? \n\n $sql
\n";
@row=$sth->fetchrow_array;
my $hid1=@row[0];
$sql = "select Hid from Devices where hostname = '$arr[3]'";
$sth = $dbh->prepare($sql);
$sth->execute || die "Could not execute SQL statement ... maybe invalid? \n\n $sql \n";
@row=$sth->fetchrow_array;
my $hid2=@row[0];
$sql = "select Eid from Event where Eventname = '$arr[8]' and severity = '$arr[9]' and Trapoid='$arr[10]'";
print "sql=".$sql."\n";
$sth = $dbh->prepare($sql);
$sth->execute || die "Could not execute SQL statement ... maybe invalid? \n\n $sql \n";
@row=$sth->fetchrow_array;
my $eid1=@row[0];
#print "eid1=".@row[0]."\n";
$sql = "select Eid from Event where Eventname = '$arr[11]' and severity = '$arr[12]' and Trapoid='$arr[13]'";
#print "sql=".$sql."\n";
$sth = $dbh->prepare($sql);
$sth->execute || die "Could not execute SQL statement ... maybe invalid? \n\n $sql \n";
@row=$sth->fetchrow_array;
my $eid2=@row[0];
print "eid1=".$eid1."\n";
print "eid2=".@row[0]."\n";
$sql = "insert into secresult (Hid_1,Hid_2,interface_1,interface_2,ifindex_1,ifindex_2,Eid_1,Eid_2,start_time_1,start_time_2,effect_range,description) values ($hid1,$hid2,'$arr[4]','$arr[5]',$arr[6],$arr[7],$eid1,$eid2,'$arr[0]','$arr[1]','$arr[14]','$arr[15]')";
print $sql."\n";
$dbh->do($sql);
print "inserted it.\n";
}
else
{
$sql = "select Hid from Devices where hostname = '$arr[1]'";
$sth = $dbh->prepare($sql);
$sth->execute || die "Could not execute SQL statement ... maybe invalid? \n\n $sql \n";
@row=$sth->fetchrow_array;
my $hid=@row[0];
$sql = "select Eid from Event where trapoid = '$arr[0]' and severity != 'Normal'";
#print "sql=".$sql."\n";
$sth = $dbh->prepare($sql);
$sth->execute || die "Could not execute SQL statement ... maybe invalid? \n\n $sql \n";
@row=$sth->fetchrow_array;
my $eid=@row[0];
$sql = "select id from (SELECT * FROM secresult WHERE end_time_1 ='' and Hid_1=$hid and interface_1 ='$arr[4]' and ifindex_1=$arr[5] ORDER BY start_time_1 DESC LIMIT 1) result where result.eid_1 = $eid";
print "sql=".$sql."\n";
$sth = $dbh->prepare($sql);
$sth->execute || die "Could not execute SQL statement ... maybe invalid? \n\n $sql \n";
@row=$sth->fetchrow_array;
my $id=@row[0];
if($id !="")
{
$sql = "update secresult set end_time_1 = '$arr[2]' where id = '$id'";
print $sql."\n";
$dbh->do($sql);
print "updated it.\n";
}
else
{
$sql = "select id from (SELECT * FROM secresult WHERE end_time_2 ='' and Hid_1=$hid and interface_2 ='$arr[4]' and ifindex_2=$arr[5] ORDER BY start_time_2 DESC LIMIT 1) result where result.eid_2 = $eid";
print "sql=".$sql."\n";
$sth = $dbh->prepare($sql);
$sth->execute || die "Could not execute SQL statement ... maybe invalid? \n\n $sql \n";
@row=$sth->fetchrow_array;
$id=@row[0];
$sql = "update secresult set end_time_2 = '$arr[2]' where id = '$id'";
print $sql."\n";
$dbh->do($sql);
print "updated it.\n";
}
}
}
my $sth = $dbh->prepare("SELECT * FROM secresult"); $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'id'}, line = $ref->{'textline'}\n"; }
$sth->finish();
$dbh->disconnect();
exit;
我可以通过脚本插入到数据库中,但是当我执行脚本进行监听时,几分钟后从 fifo 获取数据,脚本将显示错误消息“DBD::mysql::st execute failed: MySQL服务器已经离开 ./Db_code.pl 第 66 行,第 5 行”
第 66 行是“$sth->execute || die”Could not execute SQL statement ... maybe invalid?\n\n $sql\n";"
最佳答案
在任何数据库操作和重新连接(或克隆)之前确保 dbh 仍然连接(ping)
while (<FIFO>)
{
if ( ! $dbh->ping ) {
$dbh = $dbh->clone() or die "cannot connect to db";
}
...
} #end FIFO
关于mysql - DBD::mysql::st 执行失败:MySQL 服务器已离开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23866132/
var newRight; if(either.isRight()) { newRight = either.getOrElse(() => throw UnimplementedError())
我正在做一个登录字段。它由 UITextfields 和一个弹出选择器 Controller 的按钮组成。单击按钮以显示按钮弹出时,我想删除/保留/取消编辑文本字段。 我试过: [发件人resignF
我试图在用户关闭选项卡或转到另一个选项卡(如 facebook、gmail、GoDaddy 和其他选项卡)之前显示确认弹窗。 我的代码适用于 Firefox,但不适用于 chrome、safari 等
我无法退出代码中的 While 循环和方法。用户可以选择输入 1 或 2 和 0 来取消(离开菜单和方法)。但是就像现在的代码一样,我猜 Switch 中的默认选项会阻止它离开 While 循环!?我
所以我目前正在学习这个关于 PHP 表单的教程,并且我把它放到了这个页面的底部,它说到目前为止要测试表单,http://www.webreference.com/programming/php/sea
我正在开发一个可以让用户登录 2 个 xmpprooms 的应用程序,但同时只能登录 2 个,所以如果他想连接到另一个,我必须断开他与前一个的连接并连接到下一个。使用此代码: 这是我离开房间的方式:
我目前正在 React 应用程序中使用我的网络摄像头拍照。然而,当我离开组件时,绿灯继续亮着,我似乎无法关闭我的网络摄像头。这是我用来使用网络摄像头的代码。 navigator.webkitGet
实际到达很简单,标签进入接收器天线范围,但是偏离是造成问题的原因。 首先,我们了解一些有关设置的信息。 标签: 它们以433Mhz的速度工作,每1.5秒钟发送一次“心跳”,移动时进入传输突发模式,这种
这是我的第二个问题(已经回答):Creating SharedPreferences object inside Fragment . 在弄清楚如何在静态 Fragment 类中创建 SharedPr
我需要离开 Firebase 中的一个项目,但我没有选择离开该项目,因为我没有该项目的所有权。我是该项目的成员,需要离开该项目,因为该项目的开发已在几个月前停止 有什么选择可以做到这一点吗?我还需要从
我希望在以下情况下触发我的 javascript: 当打开多个 IE 选项卡时,当前 IE 选项卡将被切换。 当前 IE 选项卡关闭时。 我不希望我的 JS 代码被页内弹出对话框触发。 当整个 IE
我在 socket.io wiki 上查看如何使用房间,但加入和离开不起作用,我想知道他们是否可能更改了一些内容但没有机会更新 wiki? socket.join("room-"+data.meid)
在此 Activity 中我使用振动,因此由用户选择按照振动节奏移动的球,但是当我想向后返回屏幕时,即返回到MainActivity,应用程序继续振动而不停止。这是我的代码,我已经尝试了所有方法,但无
我正在构建一个用于学习 SwiftUI 的小型待办事项应用程序,我可以在 CoreData 中创建一个任务列表并将它们标记为完成,这会将 isComplete 设置为 true 并将图像从空圆圈更改为
我在 if 语句中有一个 if 语句。 如果第二个if语句中的条件返回false,我要转到第一个else因为它会自动设置我的验证控件。 希望你明白 if (page.isvalid() ) {
我正在尝试找到一种方法,让我的变量在应用程序的整个生命周期中保持不变。我设计该应用程序的方式是用户单击类(class)并提交成绩。我想要的是应用程序在 Activity 结束后存储成绩。当用户退出屏幕
首先你应该知道,允许玩家玩的区域是一个正方形,即320x320,位于屏幕中央。这个 320x320 的正方形是一个 5x5 的网格 [每个图 block 64x64],并且玩家始终位于网格图 bloc
我的应用程序在离开 UIViewController 时崩溃并出现以下错误。 [FeedSingleViewCell retain]: message sent to deallocated inst
使用此代码允许媒体播放器在全屏时横向旋转(应用程序不支持): // handle orientation for the device func application (_ application:
好的。查看了可能的答案,但我在这里没有看到我的问题。 我有一个相当标准的 GCD 重复计时器: class RepeatingGCDTimer { /// This holds our cur
我是一名优秀的程序员,十分优秀!