forked from localytics/odbc_adapter
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
require 'odbc_adapter/adapters/postgresql_odbc_adapter' | ||
|
||
module ODBCAdapter | ||
module Adapters | ||
# Overrides specific to Snowflake. Mostly taken from | ||
# https://eng.localytics.com/connecting-to-snowflake-with-ruby-on-rails/ | ||
class SnowflakeODBCAdapter < PostgreSQLODBCAdapter | ||
# Explicitly turning off prepared statements as they are not yet working with | ||
# snowflake + the ODBC ActiveRecord adapter | ||
def prepared_statements | ||
false | ||
end | ||
|
||
# Quoting needs to be changed for snowflake | ||
def quote_column_name(name) | ||
name.to_s | ||
end | ||
|
||
private | ||
|
||
# Override dbms_type_cast to get the values encoded in UTF-8 | ||
def dbms_type_cast(columns, values) | ||
int_column = {} | ||
columns.each_with_index do |c, i| | ||
int_column[i] = c.type == 3 && c.scale.zero? | ||
end | ||
|
||
float_column = {} | ||
columns.each_with_index do |c, i| | ||
float_column[i] = c.type == 3 && !c.scale.zero? | ||
end | ||
|
||
values.each do |row| | ||
row.each_index do |idx| | ||
val = row[idx] | ||
if val | ||
if int_column[idx] | ||
row[idx] = val.to_i | ||
elsif float_column[idx] | ||
row[idx] = val.to_f | ||
elsif val.is_a?(String) | ||
row[idx] = val.force_encoding('UTF-8') | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters