Skip to content

Commit

Permalink
working with the connection more
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Ferguson committed Oct 5, 2010
1 parent 2fea5b0 commit ef452cc
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ ext/Makefile
ext/mkmf.log
ext/*.o
ext/*.so
spec/configuration.rb
15 changes: 6 additions & 9 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
require 'rubygems'
require 'rake/gempackagetask'
require 'rake/rdoctask'
require 'rake/testtask'
require 'spec/rake/spectask'

load 'vertica.gemspec'

Rake::GemPackageTask.new(VERTICA_SPEC) do |pkg|
pkg.need_tar = true
pkg.need_tar = true
end

task :default => "test"
Expand All @@ -16,15 +16,12 @@ task :clean do
include FileUtils
rm_rf 'pkg'
end

desc "Run tests"
Rake::TestTask.new("test") do |t|
t.libs << ["test", "ext"]
t.pattern = 'test/*_test.rb'
t.verbose = true

Spec::Rake::SpecTask.new do |t|
t.warning = true
t.rcov = false
end

task :doc => [:rdoc]
namespace :doc do
Rake::RDocTask.new do |rdoc|
Expand Down
2 changes: 1 addition & 1 deletion lib/vertica/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Column
:timestamp_tz,
:interval,
:time_tz,
:numberic,
:numeric,
:bytea,
:rle_tuple
]
Expand Down
6 changes: 1 addition & 5 deletions lib/vertica/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

module Vertica
class Connection
attr_accessor :conn
attr_accessor :host
attr_accessor :port
attr_accessor :database
Expand Down Expand Up @@ -247,10 +248,5 @@ def convert_transaction_status_to_sym(status)
nil
end
end

def conn
@conn
end

end
end
13 changes: 12 additions & 1 deletion lib/vertica/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ def initialize(field_descriptions, field_values)
end

def columns
@columns ||= @field_descriptions.map { |fd| Column.new(fd[:type_modifier], fd[:format_code], fd[:table_oid], fd[:name], fd[:attribute_number], fd[:data_type_oid], fd[:data_type_size]) }
@columns ||= @field_descriptions.map do |fd|
Column.new(fd[:type_modifier], fd[:format_code], fd[:table_oid],
fd[:name], fd[:attribute_number], fd[:data_type_oid], fd[:data_type_size])
end
end

def rows
Expand Down Expand Up @@ -42,5 +45,13 @@ def each
yield row if block_given?
end
end

# Some compatibility with the pg gem

def getvalue(row, column)
rows[row][column]
end


end
end
14 changes: 14 additions & 0 deletions spec/configuration.template.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Configuration

class << self
def host; ''; end
def port; 5433; end
def database; ''; end
def username; 'dbadmin'; end
def password; ''; end

def [](key)
send(key)
end
end
end
24 changes: 24 additions & 0 deletions spec/pg_compatibility_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
require File.join(File.dirname(__FILE__), "spec_helper")

describe Vertica::Connection do
before(:each) do
@connection = Vertica::Connection.new(
Configuration[:host], Configuration[:port],
Configuration[:database], Configuration[:username],
Configuration[:password], false, false
)
end

it "should" do
r = c.query("SELECT * FROM test_table")
assert_equal 1, r.row_count
assert_equal 2, r.columns.length
assert_equal :in, r.columns[0].data_type
assert_equal 'id', r.columns[0].name
assert_equal :varchar, r.columns[1].data_type
assert_equal 'name', r.columns[1].name
assert_equal [[1, 'matt']], r.rows
c.close

end
end
2 changes: 2 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require File.join(File.dirname(__FILE__), 'configuration')
require File.join(File.dirname(__FILE__), '..', 'lib', 'vertica')
6 changes: 3 additions & 3 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
class Test::Unit::TestCase

TEST_CONNECTION_USER = 'dbadmin'
TEST_CONNECTION_PASSWORD = 'cl3v3rcstore'
TEST_CONNECTION_HOST = 'ec2-174-129-157-242.compute-1.amazonaws.com'
TEST_CONNECTION_PASSWORD = 'yamittome'
TEST_CONNECTION_HOST = 'edb-001'
TEST_CONNECTION_PORT = 5433
TEST_CONNECTION_DATABASE = 'db'
TEST_CONNECTION_DATABASE = 'yamhouse'

TEST_CONNECTION_HASH = {
:user => TEST_CONNECTION_USER,
Expand Down

0 comments on commit ef452cc

Please sign in to comment.