odbc_adapter 4.2.0 → 4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 791ccc95087c9361555daf8c3f464da82ac3b003
4
- data.tar.gz: cc8210e283ac73556cd90c89b7fc6902a7611cd2
3
+ metadata.gz: 0b346729dc34997485619663c87b6649b2454c2b
4
+ data.tar.gz: 5cf390727ae990ec1267e26d24ba9304a0b04cd4
5
5
  SHA512:
6
- metadata.gz: 3aab9df767fd6f5079549eb4c075d4a769d27d53d7d2ec769ddde3ca1c063fa78446d025cae91ca8bc815e35871a5370ba178fb36248be61d2b964d63882b3a7
7
- data.tar.gz: 22c3bbef81248cc70ee6bc1e69c16d1bec90ddc7795cb5a6a4db54ff969cfd6e8769591c370222042dc1431b7447a34d9de4888496cec5b8bf2334dbf68890e7
6
+ metadata.gz: 9649d34b588a48502e6792ad71f37c05c2fb742160f24d95935f5c56984fc41c8641a28f999a9af44891f16d7553683021acc50f52b7945d389176c93c66e96d
7
+ data.tar.gz: 015a240fe4c71e01cbe710410c61cc24b98b470b7cb55fbb07621a73d334f643a161bd99dafc3ffb8274c6c25ce3ed5503de70ce099712397db4b30ee4a30317
data/bin/console CHANGED
@@ -2,6 +2,60 @@
2
2
 
3
3
  require 'bundler/setup'
4
4
  require 'odbc_adapter'
5
+ require 'pry'
5
6
 
6
- require 'irb'
7
- IRB.start
7
+ require 'odbc_adapter/adapters/postgresql_odbc_adapter'
8
+ ODBCAdapter.register(/snowflake/, ODBCAdapter::Adapters::PostgreSQLODBCAdapter) do
9
+ # Here until we upgrade the ODBC driver
10
+ class DecimalCaster
11
+ attr_reader :column
12
+
13
+ def initialize(column)
14
+ @column = column
15
+ end
16
+
17
+ def cast(value)
18
+ return if value.nil?
19
+ column.scale.zero? ? value.to_i : value.to_f
20
+ end
21
+ end
22
+
23
+ # Handles strings that aren't utf-8 encoded
24
+ class StringEncodingCaster
25
+ def cast(value)
26
+ value.is_a?(String) ? value.force_encoding('UTF-8') : value
27
+ end
28
+ end
29
+
30
+ def quote_column_name(name)
31
+ name.to_s
32
+ end
33
+
34
+ private
35
+
36
+ # Monkey-patch the type casting for SQL_DECIMAL columns until we upgrade the ODBC driver
37
+ def dbms_type_cast(columns, values)
38
+ casters = Hash.new { |h, k| h[k] = [StringEncodingCaster.new] }
39
+
40
+ columns.each_with_index do |column, idx|
41
+ casters[idx] << DecimalCaster.new(column) if column.type == ODBC::SQL_DECIMAL
42
+ end
43
+
44
+ values.each do |row|
45
+ row.each_index do |idx|
46
+ casters[idx].each { |caster| row[idx] = caster.cast(row[idx]) }
47
+ end
48
+ end
49
+
50
+ values
51
+ end
52
+ end
53
+
54
+ ActiveRecord::Base.establish_connection(adapter: 'odbc', dsn: 'LocalyticsProductionSnowflake')
55
+
56
+ binding.pry
57
+
58
+ # class FactSession < ActiveRecord::Base
59
+ # end
60
+ #
61
+ # puts FactSession.where(device_new: true).to_sql
@@ -74,6 +74,7 @@ module ActiveRecord
74
74
  include ::ODBCAdapter::SchemaStatements
75
75
 
76
76
  ADAPTER_NAME = 'ODBC'.freeze
77
+ BOOLEAN_TYPE = 'BOOLEAN'.freeze
77
78
  ERR_DUPLICATE_KEY_VALUE = 23505
78
79
 
79
80
  attr_reader :dbms
@@ -40,6 +40,22 @@ module ODBCAdapter
40
40
  string.gsub(/\\/, '\&\&').gsub(/'/, "''")
41
41
  end
42
42
 
43
+ def quoted_true
44
+ '1'
45
+ end
46
+
47
+ def unquoted_true
48
+ 1
49
+ end
50
+
51
+ def quoted_false
52
+ '0'
53
+ end
54
+
55
+ def unquoted_false
56
+ 0
57
+ end
58
+
43
59
  def disable_referential_integrity(&block) #:nodoc:
44
60
  old = select_value("SELECT @@FOREIGN_KEY_CHECKS")
45
61
 
@@ -62,7 +62,7 @@ module ODBCAdapter
62
62
 
63
63
  case value
64
64
  when String
65
- return super unless 'bytea' == column.sql_type
65
+ return super unless 'bytea' == column.native_type
66
66
  { value: value, format: 1 }
67
67
  else
68
68
  super
@@ -75,14 +75,6 @@ module ODBCAdapter
75
75
  string.gsub(/\\/, '\&\&').gsub(/'/, "''")
76
76
  end
77
77
 
78
- def quoted_true
79
- "'t'"
80
- end
81
-
82
- def quoted_false
83
- "'f'"
84
- end
85
-
86
78
  def disable_referential_integrity #:nodoc:
87
79
  execute(tables.map { |name| "ALTER TABLE #{quote_table_name(name)} DISABLE TRIGGER ALL" }.join(';'))
88
80
  yield
@@ -25,10 +25,6 @@ module ODBCAdapter
25
25
  "#{quote_char.chr}#{name}#{quote_char.chr}"
26
26
  end
27
27
 
28
- def quoted_true
29
- '1'
30
- end
31
-
32
28
  # Ideally, we'd return an ODBC date or timestamp literal escape
33
29
  # sequence, but not all ODBC drivers support them.
34
30
  def quoted_date(value)
@@ -48,7 +48,12 @@ module ODBCAdapter
48
48
  # SQLColumns: IS_NULLABLE, SQLColumns: NULLABLE
49
49
  col_nullable = nullability(col_name, col[17], col[10])
50
50
 
51
- cast_type = lookup_cast_type(col_sql_type)
51
+ cast_type =
52
+ if col_native_type == self.class::BOOLEAN_TYPE
53
+ ActiveRecord::Type::Boolean.new
54
+ else
55
+ lookup_cast_type(col_sql_type)
56
+ end
52
57
  cols << new_column(format_case(col_name), col_default, cast_type, col_sql_type, col_nullable, col_native_type, col_scale, col_limit)
53
58
  end
54
59
  end
@@ -1,3 +1,3 @@
1
1
  module ODBCAdapter
2
- VERSION = '4.2.0'
2
+ VERSION = '4.2.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: odbc_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Localytics
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-23 00:00:00.000000000 Z
11
+ date: 2017-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-odbc