简体   繁体   English

如何使用perl dbi和mysql压缩数据

[英]how to compress data using perl dbi with mysql

I am using perl dbi connection to pull data remotely. 我正在使用perl dbi连接来远程提取数据。 I am looking to compress the data if possible. 我希望尽可能压缩数据。 Is there a way to do a file compression over the net with perl dbi for mysql? 有没有办法用perl dbi对网络进行文件压缩?

Here is my snippet for getting data: 这是我获取数据的代码段:

     my $sth = $dbh->prepare("SELECT UUID(), '$node', 1, 2, 3, 4, vts FROM $tblist");
     $sth->execute();
     while (my($uid, $hostnm,$1,$2,$3,$upd,$vts) = $sth->fetchrow_array() ) { 
       print $gzip_fh "rec^A$uid^Ehost^A$hostnm^E1^A$1^E2^A$2^E3^A$3^E4^A$upd^Evts^A$vts^D";
     }
     $sth->finish;

Best option will be to use prepared statements ; 最好的选择是使用准备好的陈述 ; with this, once you have compiled the statement once you just have to send the arguments over the wire each time you need to run the queries. 有了这个,一旦你编译了语句,只需要在每次需要运行查询时通过线路发送参数。

The example here shows how to perform a simple prepare, if you are going to utilize the same query over and over again you should keep your $sth which you can continue to call $sth->execute() on with new variables. 这里的示例显示了如何执行简单的准备,如果要反复使用相同的查询,则应保留$sth ,您可以继续使用新变量调用$sth->execute() The reason this cuts down on your network traversal is because you're not sending the query each time you run $sth->execute($var) , instead you're just passing an ID for the prepared statement and the variables that go into the ? 减少网络遍历的原因是因为每次运行$sth->execute($var)时都不会发送查询,而只是传递准备好的语句的ID和进入的变量的? placeholders. 占位符。

$sth = $dbh->prepare("select * from table where column=?");
$sth->execute($var);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM