我正在尝试使用Ruby连接到Vertica分析数据库(从linux机器)。我已经验证了使用isql
和unixodbc
(/etc/odbc.ini
中定义的DSN,或多或少基于这个答案)连接是可能的。
$ isql VerticaDSN
+--------------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+--------------------------------------------+
我还安装了vertica
、dbi
和ruby-odbc
gems(使用ruby 1.9.2)。我无法连接所有这些,我想知道我是否做错了什么或缺少依赖项。
使用vertica宝石:
>> require 'vertica'
=> true
>> client = Vertica.connect({ :host => '10.0.0.15', :user => 'dbadmin', :password => 'pwd' })
Errno::ECONNREFUSED: Connection refused - connect(2)
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/vertica-0.8.1/lib/vertica/connection:31:in `initialize'
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/vertica-0.8.1/lib/vertica/connection:31:in `new'
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/vertica-0.8.1/lib/vertica/connection:31:in `connection'
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/vertica-0.8.1/lib/vertica/connection:24:in `initialize'
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/vertica-0.8.1/lib/vertica.rb:11:in `new'
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/vertica-0.8.1/lib/vertica.rb:11:in `connect'
使用DBI/ODBC宝石:
(使用此)
>> require 'dbi'
=> true
>> require 'odbc'
=> true
>> ODBC.datasources
=> [#<ODBC::DSN:0x0000000284c6f8 @name="VerticaDSN", @descr=""test database"">]
>> dbc = ODBC.connect('VerticaDSN')
ArgumentError: string contains null byte
from (irb):15:in `initialize'
from (irb):15:in `connect'
from (irb):15
>> dbh = DBI.connect('DBI:ODBC:VerticaDSN', 'dbadmin', 'pwd')
DBI::InterfaceError: Could not load driver (undefined method `driver_name' for ODBC:Module)
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/dbi-0.4.5/lib/dbi.rb:318:in `rescue in load_driver'
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/dbi-0.4.5/lib/dbi.rb:242:in `load_driver'
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/dbi-0.4.5/lib/dbi.rb:160:in `_get_full_driver'
from /home/sa125/.rvm/gems/ruby-1.9.2-p290/gems/dbi-0.4.5/lib/dbi.rb:145:in `connect'
我是不是遗漏了什么?谢谢
事实证明,将vertica-gem升级到--pre
版本解决了使用第一种方法的问题。通过rubygems可用的gem版本是(此时)0.8.1
,它似乎工作不太好。根据我从gem作者那里得到的反馈,我将Gemfile
改为:
gem 'vertica'
到此:
gem 'vertica', '0.9.0.beta9' # current edge