本文主要是介绍Hp Vertica数据库Perl编程,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Hp Vertica数据库Perl编程
Perl语言有Database Interface module,叫做DBI。
DBI执行特定的数据库的任务,依赖Database Driver modules (DBDs)
DBI:和数据库的交互,具有持续性。
Perl操控HP Vertica方式:
DBI模块的DBD::ODBC和HP Vertica's ODBC driver交互
See the CPAN pages for Perl's DBI http://search.cpan.org/dist/DBI/DBI.pm and DBD::ODBC http://search.cpan.org/~mjevans/DBD-ODBC-1.43/ODBC.pm |
Perl Client编程先决条件:
【1】The HP Vertica ODBC drivers安装和配置
注: Installing the HP Vertica Client Drivers 1.Client Driver标准: ODBC drivers符合 ODBC 3.5.1标准; JDBC drivers 符合 JDK5标准 ADO.NET drivers符合framework 3.0标准 2.windows客户端下载32-bit or 64-bit client installer 3.java应用,要加载vertica_jdk_5.jar,例如 java -classpath /opt/vertica/java/lib/vertica_jdk_5.jar myapplication.class |
【2】Windows安装Perl
ActivePerl http://www.activestate.com/activeperl/ Strawberry Perl http://strawberryperl.com/ |
【3】Perl Driver Modules (DBI 和DBD::ODBC)
HP Vertica支持的perl module
DBI version 1.609 (DBI-1.609.tar.gz) DBD::ODBC version 1.22 (DBD-ODBC-1.22.tar.gz) |
测试DBI是否安装
C:\Windows\System32>perl -e "use DBI;" C:\Windows\System32> |
测试DBD::ODBC是否安装
C:\Windows\System32>perl -e "use DBD::ODBC;" C:\Windows\System32> |
或者用脚本来同时验证
#!/usr/bin/perl use strict; # Attempt to load the DBI module in an eval using require. Prevents # script from erroring out if DBI is not installed. eval { require DBI; DBI->import(); }; if ($@) { # The eval failed, so DBI must not be installed print "DBI module is not installed\n"; } else { # Eval was successful, so DBI is installed print "DBI Module is installed\n"; # List the drivers that DBI knows about. my @drivers = DBI->available_drivers; print "Available Drivers: \n"; foreach my $driver (@drivers) { print "\t$driver\n"; } # See if DBD::ODBC is installed by searching driver array. if (grep {/ODBC/i} @drivers) { print "\nDBD::ODBC is installed.\n"; # List the ODBC data sources (DSNs) defined on the system print "Defined ODBC Data Sources:\n"; my @dsns = DBI->data_sources('ODBC'); foreach my $dsn (@dsns) { print "\t$dsn\n"; } } else { print "DBD::ODBC is not installed\n"; } } |
输出结果为
DBI Module is installed Available Drivers: CSV DBM ExampleP File Gofer ODBC Oracle Pg Proxy SQLite Sponge DBD::ODBC is installed. Defined ODBC Data Sources: dbi:ODBC:dBASE Files dbi:ODBC:Excel Files dbi:ODBC:MS Access Database |
【4】安装缺少的Perl Modules
缺少dbi:ODBC:VerticaDSN
对于ActiveState Perl for Windows, 使用Perl Package Manager (PPM) |
使用Perl连接HP Vertica
使用Perl的DBI模块的connect函数连接vertica数据库, connect函数需要数据源字符串参数和用户名,密码,连接属性等。数据源字符串以“dbi:ODBC”开头,告诉
这篇关于Hp Vertica数据库Perl编程的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!