Skip to content

Commit bd74c62

Browse files
authored
Merge pull request #150 from praveen-db2/master
Download clidriver issue fixed
2 parents fdf82ae + f1e202f commit bd74c62

4 files changed

Lines changed: 47 additions & 32 deletions

File tree

IBM_DB_Adapter/ibm_db/CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Change Log
22
==============
3+
2023/03/29 (IBM_DB adapter 5.4.1, driver 3.1.0)
4+
- Download clidriver issue fixed and replaced http links with https.
5+
6+
2023/01/06 (IBM_DB adapter 5.4.0, driver 3.1.0)
7+
- Support for Ruby 3.1 and Rails 7.0
38

49
2022/10/06 (IBM_DB adapter 5.3.2, driver 3.0.6)
510
- Allowed all rails versions < 6.2 in gemspec, replaced limit clause with FETCH FIRST n ROWS

IBM_DB_Adapter/ibm_db/IBM_DB.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require 'pathname'
1010
Gem::Specification.new do |spec|
1111
# Required spec
1212
spec.name = 'ibm_db'
13-
spec.version = '5.4.0'
13+
spec.version = '5.4.1'
1414
spec.summary = 'Rails Driver and Adapter for IBM Data Servers: {DB2 on Linux/Unix/Windows, DB2 on zOS, DB2 on i5/OS, Informix (IDS)}'
1515

1616
# Optional spec
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
1919
spec.homepage = 'https://github.com/ibmdb/ruby-ibmdb'
2020
spec.required_ruby_version = '>= 2.5.0'
2121
spec.add_dependency('zip')
22+
spec.add_dependency('down')
2223
spec.add_dependency('activerecord', '<7.1')
2324
spec.requirements << 'ActiveRecord, at least 7.0'
2425

IBM_DB_Adapter/ibm_db/ext/extconf.rb

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
require 'zlib'
66
require 'zip'
77
require 'fileutils'
8-
8+
require 'down'
99

1010
# +----------------------------------------------------------------------+
1111
# | Licensed Materials - Property of IBM |
@@ -114,24 +114,13 @@ def downloadCLIPackage(destination, link = nil)
114114
downloadLink = link
115115
end
116116

117-
uri = URI.parse(downloadLink)
118117
if ZIP
119118
filename = "#{destination}/clidriver.zip"
120119
else
121120
filename = "#{destination}/clidriver.tar.gz"
122121
end
123-
124-
headers = {
125-
'Accept-Encoding' => 'identity',
126-
}
127-
128-
request = Net::HTTP::Get.new(uri.request_uri, headers)
129-
http = Net::HTTP.new(uri.host, uri.port)
130-
response = http.request(request)
131-
132-
f = open(filename, 'wb')
133-
f.write(response.body)
134-
f.close()
122+
123+
Down.download(downloadLink, destination: filename)
135124

136125
filename
137126
end

IBM_DB_Driver/extconf.rb

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
require 'open-uri'
44
require 'rubygems/package'
55
require 'zlib'
6+
require 'zip'
67
require 'fileutils'
7-
8+
require 'down'
89

910
# +----------------------------------------------------------------------+
1011
# | Licensed Materials - Property of IBM |
@@ -42,6 +43,7 @@ def suppress_warnings
4243
end
4344

4445
DOWNLOADLINK = ''
46+
ZIP = false
4547

4648
if(RUBY_PLATFORM =~ /aix/i)
4749
#AIX
@@ -94,6 +96,15 @@ def suppress_warnings
9496
else
9597
puts "Mac OS 32 bit not supported. Please use an x64 architecture."
9698
end
99+
elsif (RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/)
100+
ZIP = true
101+
if(is64Bit)
102+
puts "Detected platform - windows 64"
103+
DOWNLOADLINK= "https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/ntx64_odbc_cli.zip"
104+
else
105+
puts "Detected platform - windows 32"
106+
DOWNLOADLINK= "https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/nt32_odbc_cli.zip"
107+
end
97108
end
98109

99110
def downloadCLIPackage(destination, link = nil)
@@ -103,22 +114,27 @@ def downloadCLIPackage(destination, link = nil)
103114
downloadLink = link
104115
end
105116

106-
uri = URI.parse(downloadLink)
107-
filename = "#{destination}/clidriver.tar.gz"
108-
109-
headers = {
110-
'Accept-Encoding' => 'identity',
111-
}
117+
if ZIP
118+
filename = "#{destination}/clidriver.zip"
119+
else
120+
filename = "#{destination}/clidriver.tar.gz"
121+
end
122+
123+
Down.download(downloadLink, destination: filename)
112124

113-
request = Net::HTTP::Get.new(uri.request_uri, headers)
114-
http = Net::HTTP.new(uri.host, uri.port)
115-
response = http.request(request)
125+
filename
126+
end
116127

117-
f = open(filename, 'wb')
118-
f.write(response.body)
119-
f.close()
128+
def extract_zip(file, destination)
129+
FileUtils.mkdir_p(destination)
120130

121-
filename
131+
Zip::File.open(file) do |zip_file|
132+
zip_file.each do |f|
133+
fpath = File.join(destination, f.name)
134+
FileUtils.mkdir_p(File.dirname(fpath))
135+
zip_file.extract(f, fpath) unless File.exist?(fpath)
136+
end
137+
end
122138
end
123139

124140
def untarCLIPackage(archive,destination)
@@ -157,8 +173,12 @@ def untarCLIPackage(archive,destination)
157173
puts "Environment variable IBM_DB_HOME is not set. Downloading and setting up the DB2 client driver\n"
158174
destination = "#{File.expand_path(File.dirname(File.dirname(__FILE__)))}/../lib"
159175

160-
archive = downloadCLIPackage(destination)
161-
untarCLIPackage(archive,destination)
176+
archive = downloadCLIPackage(destination)
177+
if (ZIP)
178+
extract_zip(archive, destination)
179+
else
180+
untarCLIPackage(archive,destination)
181+
end
162182

163183
IBM_DB_HOME="#{destination}/clidriver"
164184

@@ -262,7 +282,7 @@ def libpathflag(libpath)
262282
end
263283
end
264284
else
265-
if(RUBY_VERSION =~ /2./ || RUBY_VERSION =~ /3./)
285+
if(RUBY_VERSION =~ /2./ || RUBY_VERSION =~ /3./)
266286
ldflags = case RbConfig::CONFIG["arch"]
267287
when /solaris2/
268288
libpath[0..-2].map {|path| " -R#{path}"}.join

0 commit comments

Comments
 (0)