db2_query 0.2.0 → 0.3.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 +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +208 -45
- data/Rakefile +3 -2
- data/lib/db2_query.rb +10 -11
- data/lib/db2_query/base.rb +3 -6
- data/lib/db2_query/config.rb +20 -21
- data/lib/db2_query/connection.rb +125 -0
- data/lib/db2_query/core.rb +105 -33
- data/lib/db2_query/error.rb +16 -0
- data/lib/db2_query/formatter.rb +2 -2
- data/lib/db2_query/logger.rb +42 -0
- data/lib/db2_query/railtie.rb +4 -9
- data/lib/db2_query/result.rb +18 -4
- data/lib/db2_query/tasks/database.rake +20 -37
- data/lib/db2_query/tasks/init.rake +1 -1
- data/lib/db2_query/tasks/initializer.rake +18 -11
- data/lib/db2_query/version.rb +2 -2
- metadata +27 -65
- data/lib/active_record/connection_adapters/db2_query_adapter.rb +0 -203
- data/lib/db2_query/connection_handling.rb +0 -33
- data/lib/db2_query/database_statements.rb +0 -88
- data/lib/db2_query/odbc_connector.rb +0 -38
|
@@ -1,52 +1,35 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "db2_query"
|
|
4
|
+
|
|
3
5
|
DB2_QUERY_DATABASE_TEMPLATE ||= <<-EOF
|
|
4
6
|
# frozen_string_literal: true
|
|
5
|
-
|
|
7
|
+
|
|
6
8
|
development:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
secondary:
|
|
13
|
-
adapter: db2_query
|
|
14
|
-
conn_string:
|
|
15
|
-
driver: DB2
|
|
16
|
-
database: ARUNIT2
|
|
17
|
-
dbalias: ARUNIT2
|
|
18
|
-
hostname: LOCALHOST
|
|
19
|
-
currentschema: LIBTEST
|
|
20
|
-
port: "0"
|
|
21
|
-
protocol: IPC
|
|
22
|
-
uid: <%= ENV["DB2EC_UID"] %>
|
|
23
|
-
pwd: <%= ENV["DB2EC_PWD"] %>
|
|
9
|
+
dsn: TODO
|
|
10
|
+
idle: 5
|
|
11
|
+
pool: 5
|
|
12
|
+
timeout: 5
|
|
13
|
+
|
|
24
14
|
test:
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
dbalias: ARUNIT2
|
|
36
|
-
hostname: LOCALHOST
|
|
37
|
-
currentschema: LIBTEST
|
|
38
|
-
port: "0"
|
|
39
|
-
protocol: IPC
|
|
40
|
-
uid: <%= ENV["DB2EC_UID"] %>
|
|
41
|
-
pwd: <%= ENV["DB2EC_PWD"] %>
|
|
15
|
+
dsn: TODO
|
|
16
|
+
idle: 5
|
|
17
|
+
pool: 5
|
|
18
|
+
timeout: 5
|
|
19
|
+
|
|
20
|
+
production:
|
|
21
|
+
dsn: TODO
|
|
22
|
+
idle: 5
|
|
23
|
+
pool: 5
|
|
24
|
+
timeout: 5
|
|
42
25
|
EOF
|
|
43
26
|
|
|
44
27
|
namespace :db2query do
|
|
45
28
|
desc "Create Database configuration file"
|
|
46
29
|
task :database do
|
|
47
|
-
database_path = "#{Rails.root}/config/
|
|
30
|
+
database_path = "#{Rails.root}/config/db2query.yml"
|
|
48
31
|
if File.exist?(database_path)
|
|
49
|
-
raise
|
|
32
|
+
raise Db2Query::Error, "Db2Query database config file exists, please check first"
|
|
50
33
|
else
|
|
51
34
|
puts " Creating database config file ..."
|
|
52
35
|
File.open(database_path, "w") do |file|
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "db2_query"
|
|
4
|
+
|
|
3
5
|
DB2_QUERY_INITIALIZER_TEMPLATE ||= <<-EOF
|
|
4
6
|
# frozen_string_literal: true
|
|
5
|
-
|
|
6
|
-
# Example
|
|
7
|
+
require "db2_query"
|
|
7
8
|
require "db2_query/formatter"
|
|
8
|
-
class FirstNameFormatter < Db2Query::AbstractFormatter
|
|
9
|
-
def format(value)
|
|
10
|
-
"Dr." + value
|
|
11
|
-
end
|
|
12
|
-
end
|
|
13
9
|
|
|
14
|
-
Db2Query::
|
|
15
|
-
|
|
10
|
+
Db2Query::Base.initiation do |base|
|
|
11
|
+
base.establish_connection
|
|
16
12
|
end
|
|
13
|
+
|
|
14
|
+
# Example
|
|
15
|
+
#class FirstNameFormatter < Db2Query::AbstractFormatter
|
|
16
|
+
# def format(value)
|
|
17
|
+
# "Dr." + value
|
|
18
|
+
# end
|
|
19
|
+
#end
|
|
20
|
+
|
|
21
|
+
#Db2Query::Formatter.registration do |format|
|
|
22
|
+
# format.register(:first_name_formatter, FirstNameFormatter)
|
|
23
|
+
#end
|
|
17
24
|
EOF
|
|
18
25
|
|
|
19
26
|
namespace :db2query do
|
|
@@ -22,7 +29,7 @@ namespace :db2query do
|
|
|
22
29
|
# Create initializer file
|
|
23
30
|
initializer_path = "#{Rails.root}/config/initializers/db2query.rb"
|
|
24
31
|
if File.exist?(initializer_path)
|
|
25
|
-
raise
|
|
32
|
+
raise Db2Query::Error, "Db2Query initializer file exists, please check first"
|
|
26
33
|
else
|
|
27
34
|
puts " Creating initializer file ..."
|
|
28
35
|
File.open(initializer_path, "w") do |file|
|
|
@@ -31,4 +38,4 @@ namespace :db2query do
|
|
|
31
38
|
puts " File '#{initializer_path}' created."
|
|
32
39
|
end
|
|
33
40
|
end
|
|
34
|
-
end
|
|
41
|
+
end
|
data/lib/db2_query/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,71 +1,31 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: db2_query
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- yohanes_l
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2021-07-06 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - "~>"
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0.99999'
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - "~>"
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0.99999'
|
|
27
|
-
- !ruby/object:Gem::Dependency
|
|
28
|
-
name: activesupport
|
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
|
30
|
-
requirements:
|
|
31
|
-
- - "~>"
|
|
32
|
-
- !ruby/object:Gem::Version
|
|
33
|
-
version: 6.0.3
|
|
34
|
-
- - ">="
|
|
35
|
-
- !ruby/object:Gem::Version
|
|
36
|
-
version: 6.0.3.1
|
|
37
|
-
type: :runtime
|
|
38
|
-
prerelease: false
|
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
40
|
-
requirements:
|
|
41
|
-
- - "~>"
|
|
42
|
-
- !ruby/object:Gem::Version
|
|
43
|
-
version: 6.0.3
|
|
44
|
-
- - ">="
|
|
45
|
-
- !ruby/object:Gem::Version
|
|
46
|
-
version: 6.0.3.1
|
|
47
|
-
- !ruby/object:Gem::Dependency
|
|
48
|
-
name: activerecord
|
|
14
|
+
name: rubocop
|
|
49
15
|
requirement: !ruby/object:Gem::Requirement
|
|
50
16
|
requirements:
|
|
51
|
-
- - "~>"
|
|
52
|
-
- !ruby/object:Gem::Version
|
|
53
|
-
version: 6.0.3
|
|
54
17
|
- - ">="
|
|
55
18
|
- !ruby/object:Gem::Version
|
|
56
|
-
version:
|
|
57
|
-
type: :
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
58
21
|
prerelease: false
|
|
59
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
60
23
|
requirements:
|
|
61
|
-
- - "~>"
|
|
62
|
-
- !ruby/object:Gem::Version
|
|
63
|
-
version: 6.0.3
|
|
64
24
|
- - ">="
|
|
65
25
|
- !ruby/object:Gem::Version
|
|
66
|
-
version:
|
|
26
|
+
version: '0'
|
|
67
27
|
- !ruby/object:Gem::Dependency
|
|
68
|
-
name: rubocop
|
|
28
|
+
name: rubocop-performance
|
|
69
29
|
requirement: !ruby/object:Gem::Requirement
|
|
70
30
|
requirements:
|
|
71
31
|
- - ">="
|
|
@@ -79,7 +39,7 @@ dependencies:
|
|
|
79
39
|
- !ruby/object:Gem::Version
|
|
80
40
|
version: '0'
|
|
81
41
|
- !ruby/object:Gem::Dependency
|
|
82
|
-
name: rubocop-
|
|
42
|
+
name: rubocop-rails
|
|
83
43
|
requirement: !ruby/object:Gem::Requirement
|
|
84
44
|
requirements:
|
|
85
45
|
- - ">="
|
|
@@ -93,7 +53,7 @@ dependencies:
|
|
|
93
53
|
- !ruby/object:Gem::Version
|
|
94
54
|
version: '0'
|
|
95
55
|
- !ruby/object:Gem::Dependency
|
|
96
|
-
name:
|
|
56
|
+
name: faker
|
|
97
57
|
requirement: !ruby/object:Gem::Requirement
|
|
98
58
|
requirements:
|
|
99
59
|
- - ">="
|
|
@@ -107,7 +67,7 @@ dependencies:
|
|
|
107
67
|
- !ruby/object:Gem::Version
|
|
108
68
|
version: '0'
|
|
109
69
|
- !ruby/object:Gem::Dependency
|
|
110
|
-
name:
|
|
70
|
+
name: byebug
|
|
111
71
|
requirement: !ruby/object:Gem::Requirement
|
|
112
72
|
requirements:
|
|
113
73
|
- - ">="
|
|
@@ -121,7 +81,7 @@ dependencies:
|
|
|
121
81
|
- !ruby/object:Gem::Version
|
|
122
82
|
version: '0'
|
|
123
83
|
- !ruby/object:Gem::Dependency
|
|
124
|
-
name:
|
|
84
|
+
name: rails
|
|
125
85
|
requirement: !ruby/object:Gem::Requirement
|
|
126
86
|
requirements:
|
|
127
87
|
- - ">="
|
|
@@ -135,13 +95,13 @@ dependencies:
|
|
|
135
95
|
- !ruby/object:Gem::Version
|
|
136
96
|
version: '0'
|
|
137
97
|
- !ruby/object:Gem::Dependency
|
|
138
|
-
name:
|
|
98
|
+
name: connection_pool
|
|
139
99
|
requirement: !ruby/object:Gem::Requirement
|
|
140
100
|
requirements:
|
|
141
101
|
- - ">="
|
|
142
102
|
- !ruby/object:Gem::Version
|
|
143
103
|
version: '0'
|
|
144
|
-
type: :
|
|
104
|
+
type: :runtime
|
|
145
105
|
prerelease: false
|
|
146
106
|
version_requirements: !ruby/object:Gem::Requirement
|
|
147
107
|
requirements:
|
|
@@ -149,22 +109,23 @@ dependencies:
|
|
|
149
109
|
- !ruby/object:Gem::Version
|
|
150
110
|
version: '0'
|
|
151
111
|
- !ruby/object:Gem::Dependency
|
|
152
|
-
name:
|
|
112
|
+
name: ruby-odbc
|
|
153
113
|
requirement: !ruby/object:Gem::Requirement
|
|
154
114
|
requirements:
|
|
155
115
|
- - ">="
|
|
156
116
|
- !ruby/object:Gem::Version
|
|
157
117
|
version: '0'
|
|
158
|
-
type: :
|
|
118
|
+
type: :runtime
|
|
159
119
|
prerelease: false
|
|
160
120
|
version_requirements: !ruby/object:Gem::Requirement
|
|
161
121
|
requirements:
|
|
162
122
|
- - ">="
|
|
163
123
|
- !ruby/object:Gem::Version
|
|
164
124
|
version: '0'
|
|
165
|
-
description: A Rails
|
|
125
|
+
description: A Rails 5 & Rails 6 plugin for handling Db2 SQL SIUD statement (SELECT,
|
|
126
|
+
INSERT, UPDATE, DELETE) by using ODBC connection.
|
|
166
127
|
email:
|
|
167
|
-
- yohanes.lumentut@
|
|
128
|
+
- yohanes.lumentut@gmail.com
|
|
168
129
|
executables: []
|
|
169
130
|
extensions: []
|
|
170
131
|
extra_rdoc_files: []
|
|
@@ -172,26 +133,27 @@ files:
|
|
|
172
133
|
- MIT-LICENSE
|
|
173
134
|
- README.md
|
|
174
135
|
- Rakefile
|
|
175
|
-
- lib/active_record/connection_adapters/db2_query_adapter.rb
|
|
176
136
|
- lib/db2_query.rb
|
|
177
137
|
- lib/db2_query/base.rb
|
|
178
138
|
- lib/db2_query/config.rb
|
|
179
|
-
- lib/db2_query/
|
|
139
|
+
- lib/db2_query/connection.rb
|
|
180
140
|
- lib/db2_query/core.rb
|
|
181
|
-
- lib/db2_query/
|
|
141
|
+
- lib/db2_query/error.rb
|
|
182
142
|
- lib/db2_query/formatter.rb
|
|
183
|
-
- lib/db2_query/
|
|
143
|
+
- lib/db2_query/logger.rb
|
|
184
144
|
- lib/db2_query/railtie.rb
|
|
185
145
|
- lib/db2_query/result.rb
|
|
186
146
|
- lib/db2_query/tasks/database.rake
|
|
187
147
|
- lib/db2_query/tasks/init.rake
|
|
188
148
|
- lib/db2_query/tasks/initializer.rake
|
|
189
149
|
- lib/db2_query/version.rb
|
|
190
|
-
homepage: https://github.com/yohaneslumentut
|
|
150
|
+
homepage: https://github.com/yohaneslumentut
|
|
191
151
|
licenses:
|
|
192
152
|
- MIT
|
|
193
153
|
metadata:
|
|
194
|
-
|
|
154
|
+
homepage_uri: https://github.com/yohaneslumentut
|
|
155
|
+
source_code_uri: https://github.com/yohaneslumentut/db2_query
|
|
156
|
+
changelog_uri: https://github.com/yohaneslumentut/db2_query
|
|
195
157
|
post_install_message:
|
|
196
158
|
rdoc_options: []
|
|
197
159
|
require_paths:
|
|
@@ -207,8 +169,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
207
169
|
- !ruby/object:Gem::Version
|
|
208
170
|
version: '0'
|
|
209
171
|
requirements: []
|
|
210
|
-
rubygems_version: 3.
|
|
172
|
+
rubygems_version: 3.0.3
|
|
211
173
|
signing_key:
|
|
212
174
|
specification_version: 4
|
|
213
|
-
summary:
|
|
175
|
+
summary: Rails Db2 ODBC plugin
|
|
214
176
|
test_files: []
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "odbc_utf8"
|
|
4
|
-
require "db2_query/odbc_connector"
|
|
5
|
-
require "db2_query/database_statements"
|
|
6
|
-
|
|
7
|
-
module ActiveRecord
|
|
8
|
-
module ConnectionHandling
|
|
9
|
-
def db2_query_connection(config)
|
|
10
|
-
conn_type = (config.keys & DB2Query::CONNECTION_TYPES).first
|
|
11
|
-
if conn_type.nil?
|
|
12
|
-
raise ArgumentError, "No data source name (:dsn) or connection string (:conn_str) provided."
|
|
13
|
-
end
|
|
14
|
-
connector = DB2Query::ODBCConnector.new(conn_type, config)
|
|
15
|
-
ConnectionAdapters::DB2QueryConnection.new(connector, config)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
module ConnectionAdapters
|
|
20
|
-
class DB2QueryConnection
|
|
21
|
-
include DB2Query::DatabaseStatements
|
|
22
|
-
include ActiveSupport::Callbacks
|
|
23
|
-
define_callbacks :checkout, :checkin
|
|
24
|
-
|
|
25
|
-
set_callback :checkin, :after, :enable_lazy_transactions!
|
|
26
|
-
|
|
27
|
-
attr_accessor :pool
|
|
28
|
-
attr_reader :owner, :connector, :lock
|
|
29
|
-
alias :in_use? :owner
|
|
30
|
-
|
|
31
|
-
def initialize(connector, config)
|
|
32
|
-
@connector = connector
|
|
33
|
-
@instrumenter = ActiveSupport::Notifications.instrumenter
|
|
34
|
-
@config = config
|
|
35
|
-
@pool = ActiveRecord::ConnectionAdapters::NullPool.new
|
|
36
|
-
@lock = ActiveSupport::Concurrency::LoadInterlockAwareMonitor.new
|
|
37
|
-
connect
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def connect
|
|
41
|
-
@connection = connector.connect
|
|
42
|
-
@connection.use_time = true
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
def active?
|
|
46
|
-
@connection.connected?
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def reconnect!
|
|
50
|
-
disconnect!
|
|
51
|
-
connect
|
|
52
|
-
end
|
|
53
|
-
alias reset! reconnect!
|
|
54
|
-
|
|
55
|
-
def disconnect!
|
|
56
|
-
if @connection.connected?
|
|
57
|
-
@connection.commit
|
|
58
|
-
@connection.disconnect
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def check_version
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def enable_lazy_transactions!
|
|
66
|
-
@lazy_transactions_enabled = true
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def lease
|
|
70
|
-
if in_use?
|
|
71
|
-
msg = +"Cannot lease connection, "
|
|
72
|
-
if @owner == Thread.current
|
|
73
|
-
msg << "it is already leased by the current thread."
|
|
74
|
-
else
|
|
75
|
-
msg << "it is already in use by a different thread: #{@owner}. " \
|
|
76
|
-
"Current thread: #{Thread.current}."
|
|
77
|
-
end
|
|
78
|
-
raise ActiveRecordError, msg
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
@owner = Thread.current
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def verify!
|
|
85
|
-
reconnect! unless active?
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def translate_exception_class(e, sql, binds)
|
|
89
|
-
message = "#{e.class.name}: #{e.message}"
|
|
90
|
-
|
|
91
|
-
exception = translate_exception(
|
|
92
|
-
e, message: message, sql: sql, binds: binds
|
|
93
|
-
)
|
|
94
|
-
exception.set_backtrace e.backtrace
|
|
95
|
-
exception
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil) # :doc:
|
|
99
|
-
@instrumenter.instrument(
|
|
100
|
-
"sql.active_record",
|
|
101
|
-
sql: sql,
|
|
102
|
-
name: name,
|
|
103
|
-
binds: binds,
|
|
104
|
-
type_casted_binds: type_casted_binds,
|
|
105
|
-
statement_name: statement_name,
|
|
106
|
-
connection_id: object_id,
|
|
107
|
-
connection: self) do
|
|
108
|
-
@lock.synchronize do
|
|
109
|
-
yield
|
|
110
|
-
end
|
|
111
|
-
rescue => e
|
|
112
|
-
raise translate_exception_class(e, sql, binds)
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
def translate_exception(exception, message:, sql:, binds:)
|
|
117
|
-
case exception
|
|
118
|
-
when RuntimeError
|
|
119
|
-
exception
|
|
120
|
-
else
|
|
121
|
-
ActiveRecord::StatementInvalid.new(message, sql: sql, binds: binds)
|
|
122
|
-
end
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def expire
|
|
126
|
-
if in_use?
|
|
127
|
-
if @owner != Thread.current
|
|
128
|
-
raise ActiveRecordError, "Cannot expire connection, " \
|
|
129
|
-
"it is owned by a different thread: #{@owner}. " \
|
|
130
|
-
"Current thread: #{Thread.current}."
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
@idle_since = Concurrent.monotonic_time
|
|
134
|
-
@owner = nil
|
|
135
|
-
else
|
|
136
|
-
raise ActiveRecordError, "Cannot expire connection, it is not currently leased."
|
|
137
|
-
end
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def steal!
|
|
141
|
-
if in_use?
|
|
142
|
-
if @owner != Thread.current
|
|
143
|
-
pool.send :remove_connection_from_thread_cache, self, @owner
|
|
144
|
-
|
|
145
|
-
@owner = Thread.current
|
|
146
|
-
end
|
|
147
|
-
else
|
|
148
|
-
raise ActiveRecordError, "Cannot steal connection, it is not currently leased."
|
|
149
|
-
end
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
def seconds_idle # :nodoc:
|
|
153
|
-
return 0 if in_use?
|
|
154
|
-
Concurrent.monotonic_time - @idle_since
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
private
|
|
158
|
-
def type_map
|
|
159
|
-
@type_map ||= Type::TypeMap.new.tap do |mapping|
|
|
160
|
-
initialize_type_map(mapping)
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
def alias_type(map, new_type, old_type)
|
|
165
|
-
map.register_type(new_type) do |_, *args|
|
|
166
|
-
map.lookup(old_type, *args)
|
|
167
|
-
end
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
def initialize_type_map(map)
|
|
171
|
-
map.register_type "boolean", Type::Boolean.new
|
|
172
|
-
map.register_type ODBC::SQL_CHAR, Type::String.new
|
|
173
|
-
map.register_type ODBC::SQL_LONGVARCHAR, Type::Text.new
|
|
174
|
-
map.register_type ODBC::SQL_TINYINT, Type::Integer.new(limit: 4)
|
|
175
|
-
map.register_type ODBC::SQL_SMALLINT, Type::Integer.new(limit: 8)
|
|
176
|
-
map.register_type ODBC::SQL_INTEGER, Type::Integer.new(limit: 16)
|
|
177
|
-
map.register_type ODBC::SQL_BIGINT, Type::BigInteger.new(limit: 32)
|
|
178
|
-
map.register_type ODBC::SQL_REAL, Type::Float.new(limit: 24)
|
|
179
|
-
map.register_type ODBC::SQL_FLOAT, Type::Float.new
|
|
180
|
-
map.register_type ODBC::SQL_DOUBLE, Type::Float.new(limit: 53)
|
|
181
|
-
map.register_type ODBC::SQL_DECIMAL, Type::Float.new
|
|
182
|
-
map.register_type ODBC::SQL_NUMERIC, Type::Integer.new
|
|
183
|
-
map.register_type ODBC::SQL_BINARY, Type::Binary.new
|
|
184
|
-
map.register_type ODBC::SQL_DATE, Type::Date.new
|
|
185
|
-
map.register_type ODBC::SQL_DATETIME, Type::DateTime.new
|
|
186
|
-
map.register_type ODBC::SQL_TIME, Type::Time.new
|
|
187
|
-
map.register_type ODBC::SQL_TIMESTAMP, Type::DateTime.new
|
|
188
|
-
map.register_type ODBC::SQL_GUID, Type::String.new
|
|
189
|
-
|
|
190
|
-
alias_type map, ODBC::SQL_BIT, "boolean"
|
|
191
|
-
alias_type map, ODBC::SQL_VARCHAR, ODBC::SQL_CHAR
|
|
192
|
-
alias_type map, ODBC::SQL_WCHAR, ODBC::SQL_CHAR
|
|
193
|
-
alias_type map, ODBC::SQL_WVARCHAR, ODBC::SQL_CHAR
|
|
194
|
-
alias_type map, ODBC::SQL_WLONGVARCHAR, ODBC::SQL_LONGVARCHAR
|
|
195
|
-
alias_type map, ODBC::SQL_VARBINARY, ODBC::SQL_BINARY
|
|
196
|
-
alias_type map, ODBC::SQL_LONGVARBINARY, ODBC::SQL_BINARY
|
|
197
|
-
alias_type map, ODBC::SQL_TYPE_DATE, ODBC::SQL_DATE
|
|
198
|
-
alias_type map, ODBC::SQL_TYPE_TIME, ODBC::SQL_TIME
|
|
199
|
-
alias_type map, ODBC::SQL_TYPE_TIMESTAMP, ODBC::SQL_TIMESTAMP
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
end
|