Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions ext/ruby_snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var rbSnowflakeModule C.VALUE
var DB_IDENTIFIER = C.rb_intern(C.CString("db"))
var RESULT_IDENTIFIER = C.rb_intern(C.CString("rows"))
var RESULT_DURATION = C.rb_intern(C.CString("@query_duration"))
var RESULT_ERROR = C.rb_intern(C.CString("@error"))
var ERROR_IDENT = C.rb_intern(C.CString("@error"))

var objects = make(map[interface{}]bool)

Expand All @@ -68,12 +68,14 @@ func Connect(self C.VALUE, account C.VALUE, warehouse C.VALUE, database C.VALUE,

dsn, err := sf.DSN(cfg)
if err != nil {
rb_raise(C.rb_eArgError, "Snowflake Config Creation Error: '%s'", err)
errStr := fmt.Sprintf("Snowflake Config Creation Error: '%s'", err.Error())
C.rb_ivar_set(self, ERROR_IDENT, RbString(errStr))
}

db, err := sql.Open("snowflake", dsn)
if err != nil {
rb_raise(C.rb_eArgError, "Connection Error: '%s'", err)
errStr := fmt.Sprintf("Connection Error: '%s'", err.Error())
C.rb_ivar_set(self, ERROR_IDENT, RbString(errStr))
}
rs := SnowflakeClient{db}
ptr := gopointer.Save(&rs)
Expand All @@ -95,7 +97,7 @@ func (x SnowflakeClient) Fetch(statement C.VALUE) C.VALUE {
if err != nil {
result := C.rb_class_new_instance(0, &empty, rbSnowflakeResultClass)
errStr := fmt.Sprintf("Query error: '%s'", err.Error())
C.rb_ivar_set(result, RESULT_ERROR, RbString(errStr))
C.rb_ivar_set(result, ERROR_IDENT, RbString(errStr))
return result
}

Expand All @@ -106,7 +108,7 @@ func (x SnowflakeClient) Fetch(statement C.VALUE) C.VALUE {
if err != nil {
result := C.rb_class_new_instance(0, &empty, rbSnowflakeResultClass)
errStr := fmt.Sprintf("Query error: '%s'", err.Error())
C.rb_ivar_set(result, RESULT_ERROR, RbString(errStr))
C.rb_ivar_set(result, ERROR_IDENT, RbString(errStr))
return result
}

Expand Down
4 changes: 4 additions & 0 deletions lib/ruby_snowflake_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ module Snowflake
require "ruby_snowflake_client_ext" # build bundle of the go files

class Client
attr_reader :error
# Wrap the private _connect method, as sending kwargs to Go would require
# wrapping the function in C as the current CGO has a limitation on
# accepting variadic arguments for functions.
def connect(account:"", warehouse:"", database:"", schema: "", user: "", password: "", role: "")
_connect(account, warehouse, database, schema, user, password, role)
if error != nil
raise(error)
end
true
end

Expand Down
2 changes: 1 addition & 1 deletion spec/snowflake/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
context "when the account is empty" do
it "will return an error" do
expect { client.connect }.to raise_error(
ArgumentError, "Snowflake Config Creation Error: '260000: account is empty'"
"Snowflake Config Creation Error: '260000: account is empty'"
)
end
end
Expand Down