tiny_tds 3.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +187 -74
- data/CHANGELOG.md +8 -0
- data/Gemfile +1 -1
- data/README.md +59 -50
- data/Rakefile +46 -37
- data/VERSION +1 -1
- data/ext/tiny_tds/extconf.rb +169 -70
- data/ext/tiny_tds/extconsts.rb +3 -4
- data/lib/tiny_tds/bin.rb +12 -26
- data/lib/tiny_tds/client.rb +38 -42
- data/lib/tiny_tds/error.rb +0 -2
- data/lib/tiny_tds/gem.rb +5 -9
- data/lib/tiny_tds/result.rb +0 -2
- data/lib/tiny_tds/version.rb +1 -1
- data/lib/tiny_tds.rb +28 -47
- data/tasks/native_gem.rake +11 -18
- data/tasks/package.rake +1 -3
- data/tasks/ports.rake +7 -91
- data/tasks/test.rake +3 -5
- data/test/bin/install-freetds.sh +2 -4
- data/test/bin/restore-from-native-gem.ps1 +10 -0
- data/test/client_test.rb +106 -112
- data/test/gem_test.rb +31 -107
- data/test/result_test.rb +208 -221
- data/test/schema_test.rb +177 -181
- data/test/test_helper.rb +58 -63
- data/test/thread_test.rb +22 -31
- data/tiny_tds.gemspec +28 -29
- metadata +21 -13
- data/tasks/ports/freetds.rb +0 -32
- data/tasks/ports/libiconv.rb +0 -26
- data/tasks/ports/openssl.rb +0 -62
- data/tasks/ports/recipe.rb +0 -64
- data/test/benchmark/query.rb +0 -77
- data/test/benchmark/query_odbc.rb +0 -106
- data/test/benchmark/query_tinytds.rb +0 -126
data/lib/tiny_tds.rb
CHANGED
@@ -1,61 +1,42 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'bigdecimal'
|
4
|
-
require 'rational'
|
1
|
+
require "date"
|
2
|
+
require "bigdecimal"
|
5
3
|
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
4
|
+
require "tiny_tds/version"
|
5
|
+
require "tiny_tds/error"
|
6
|
+
require "tiny_tds/client"
|
7
|
+
require "tiny_tds/result"
|
8
|
+
require "tiny_tds/gem"
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
module TinyTds
|
11
|
+
# Is this file part of a fat binary gem with bundled freetds?
|
12
|
+
# This path must be enabled by add_dll_directory on Windows.
|
13
|
+
gplat = ::Gem::Platform.local
|
14
|
+
FREETDS_LIB_PATH = Dir[File.expand_path("../ports/#{gplat.cpu}-#{gplat.os}*/lib", __dir__)].first
|
15
15
|
|
16
16
|
add_dll_path = proc do |path, &block|
|
17
|
-
|
18
|
-
require 'ruby_installer/runtime'
|
19
|
-
RubyInstaller::Runtime.add_dll_directory(path, &block)
|
20
|
-
rescue LoadError
|
21
|
-
old_path = ENV['PATH']
|
22
|
-
ENV['PATH'] = "#{path};#{old_path}"
|
17
|
+
if RUBY_PLATFORM =~ /(mswin|mingw)/i && path
|
23
18
|
begin
|
19
|
+
require "ruby_installer/runtime"
|
20
|
+
RubyInstaller::Runtime.add_dll_directory(path, &block)
|
21
|
+
rescue LoadError
|
22
|
+
old_path = ENV["PATH"]
|
23
|
+
ENV["PATH"] = "#{path};#{old_path}"
|
24
24
|
block.call
|
25
|
-
|
26
|
-
ENV['PATH'] = old_path
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
add_dll_paths = proc do |paths, &block|
|
32
|
-
if path=paths.shift
|
33
|
-
add_dll_path.call(path) do
|
34
|
-
add_dll_paths.call(paths, &block)
|
25
|
+
ENV["PATH"] = old_path
|
35
26
|
end
|
36
27
|
else
|
28
|
+
# libsybdb is found by a relative rpath in the cross compiled extension dll
|
29
|
+
# or by the system library loader
|
37
30
|
block.call
|
38
31
|
end
|
39
32
|
end
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
end
|
49
|
-
else
|
50
|
-
# Load dependent shared libraries into the process, so that they are already present,
|
51
|
-
# when tiny_tds.so is loaded. This ensures, that shared libraries are loaded even when
|
52
|
-
# the path is different between build and run time (e.g. Heroku).
|
53
|
-
ports_libs = File.join(TinyTds::Gem.ports_root_path,
|
54
|
-
"#{RbConfig::CONFIG['host']}/lib/*.so")
|
55
|
-
Dir[ports_libs].each do |lib|
|
56
|
-
require 'fiddle'
|
57
|
-
Fiddle.dlopen(lib)
|
34
|
+
add_dll_path.call(FREETDS_LIB_PATH) do
|
35
|
+
# Try the <major>.<minor> subdirectory for fat binary gems
|
36
|
+
major_minor = RUBY_VERSION[/^(\d+\.\d+)/] or
|
37
|
+
raise "Oops, can't extract the major/minor version from #{RUBY_VERSION.dump}"
|
38
|
+
require "tiny_tds/#{major_minor}/tiny_tds"
|
39
|
+
rescue LoadError
|
40
|
+
require "tiny_tds/tiny_tds"
|
58
41
|
end
|
59
|
-
|
60
|
-
require 'tiny_tds/tiny_tds'
|
61
42
|
end
|
data/tasks/native_gem.rake
CHANGED
@@ -1,23 +1,16 @@
|
|
1
|
-
|
1
|
+
CrossLibraries.each do |xlib|
|
2
|
+
platform = xlib.platform
|
2
3
|
|
3
|
-
desc
|
4
|
-
task
|
5
|
-
|
4
|
+
desc "Build fat binary gem for platform #{platform}"
|
5
|
+
task "gem:native:#{platform}" do
|
6
|
+
require "rake_compiler_dock"
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
RakeCompilerDock.sh "bundle --local && RUBY_CC_VERSION=#{meta[:ruby_versions]} rake native:#{plat} gem", platform: plat
|
8
|
+
RakeCompilerDock.sh <<-EOT, platform: platform
|
9
|
+
bundle install &&
|
10
|
+
rake native:#{platform} pkg/#{SPEC.full_name}-#{platform}.gem MAKEOPTS=-j`nproc` RUBY_CC_VERSION=#{RakeCompilerDock.set_ruby_cc_version("~> 2.7", "~> 3.0")} MAKEFLAGS="V=1"
|
11
|
+
EOT
|
12
12
|
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# assumes you are in a container provided by Rake compiler
|
16
|
-
# if not, use the task above
|
17
|
-
task 'gem:for_platform', [:gem_platform] do |_task, args|
|
18
|
-
args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
sh "RUBY_CC_VERSION=#{GEM_PLATFORM_HOSTS[args.gem_platform][:ruby_versions]} rake native:#{args.gem_platform} gem"
|
14
|
+
desc "Build the native binary gems"
|
15
|
+
multitask "gem:native" => "gem:native:#{platform}"
|
23
16
|
end
|
data/tasks/package.rake
CHANGED
data/tasks/ports.rake
CHANGED
@@ -1,108 +1,24 @@
|
|
1
|
-
|
2
|
-
require 'mini_portile2'
|
3
|
-
require 'fileutils'
|
4
|
-
require_relative 'ports/libiconv'
|
5
|
-
require_relative 'ports/openssl'
|
6
|
-
require_relative 'ports/freetds'
|
7
|
-
require_relative '../ext/tiny_tds/extconsts'
|
1
|
+
require_relative "../ext/tiny_tds/extconsts"
|
8
2
|
|
9
3
|
namespace :ports do
|
10
4
|
libraries_to_compile = {
|
11
|
-
openssl:
|
12
|
-
libiconv:
|
13
|
-
freetds:
|
5
|
+
openssl: OPENSSL_VERSION,
|
6
|
+
libiconv: ICONV_VERSION,
|
7
|
+
freetds: FREETDS_VERSION
|
14
8
|
}
|
15
9
|
|
16
|
-
directory "ports"
|
17
|
-
CLEAN.include "ports/*mingw*"
|
18
|
-
CLEAN.include "ports/*.installed"
|
19
|
-
|
20
|
-
task :openssl, [:host, :gem_platform] do |_task, args|
|
21
|
-
args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
|
22
|
-
|
23
|
-
libraries_to_compile[:openssl].files = [OPENSSL_SOURCE_URI]
|
24
|
-
libraries_to_compile[:openssl].host = args.host
|
25
|
-
libraries_to_compile[:openssl].gem_platform = args.gem_platform
|
26
|
-
|
27
|
-
libraries_to_compile[:openssl].cook
|
28
|
-
libraries_to_compile[:openssl].activate
|
29
|
-
end
|
30
|
-
|
31
|
-
task :libiconv, [:host, :gem_platform] do |_task, args|
|
32
|
-
args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
|
33
|
-
|
34
|
-
libraries_to_compile[:libiconv].files = [ICONV_SOURCE_URI]
|
35
|
-
libraries_to_compile[:libiconv].host = args.host
|
36
|
-
libraries_to_compile[:libiconv].gem_platform = args.gem_platform
|
37
|
-
libraries_to_compile[:libiconv].cook
|
38
|
-
libraries_to_compile[:libiconv].activate
|
39
|
-
end
|
40
|
-
|
41
|
-
task :freetds, [:host, :gem_platform] do |_task, args|
|
42
|
-
args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
|
43
|
-
|
44
|
-
libraries_to_compile[:freetds].files = [FREETDS_SOURCE_URI]
|
45
|
-
libraries_to_compile[:freetds].host = args.host
|
46
|
-
libraries_to_compile[:freetds].gem_platform = args.gem_platform
|
47
|
-
|
48
|
-
if libraries_to_compile[:openssl]
|
49
|
-
# freetds doesn't have an option that will provide an rpath
|
50
|
-
# so we do it manually
|
51
|
-
ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{libraries_to_compile[:openssl].path}/lib64"
|
52
|
-
# Add the pkgconfig file with MSYS2'ish path, to prefer our ports build
|
53
|
-
# over MSYS2 system OpenSSL.
|
54
|
-
ENV['PKG_CONFIG_PATH'] = "#{libraries_to_compile[:openssl].path.gsub(/^(\w):/i) { "/" + $1.downcase }}/lib64/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
|
55
|
-
libraries_to_compile[:freetds].configure_options << "--with-openssl=#{libraries_to_compile[:openssl].path}"
|
56
|
-
end
|
57
|
-
|
58
|
-
if libraries_to_compile[:libiconv]
|
59
|
-
libraries_to_compile[:freetds].configure_options << "--with-libiconv-prefix=#{libraries_to_compile[:libiconv].path}"
|
60
|
-
end
|
61
|
-
|
62
|
-
libraries_to_compile[:freetds].cook
|
63
|
-
libraries_to_compile[:freetds].activate
|
64
|
-
end
|
65
|
-
|
66
|
-
task :compile, [:host, :gem_platform] do |_task, args|
|
67
|
-
args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"])
|
68
|
-
|
69
|
-
puts "Compiling ports for #{args.host} (Ruby platform #{args.gem_platform}) ..."
|
70
|
-
|
71
|
-
libraries_to_compile.keys.each do |lib|
|
72
|
-
Rake::Task["ports:#{lib}"].invoke(args.host, args.gem_platform)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
desc 'Build the ports windows binaries via rake-compiler-dock'
|
77
|
-
task 'cross' do
|
78
|
-
require 'rake_compiler_dock'
|
79
|
-
|
80
|
-
# build the ports for all our cross compile hosts
|
81
|
-
GEM_PLATFORM_HOSTS.each do |gem_platform, meta|
|
82
|
-
# make sure to install our bundle
|
83
|
-
build = ['bundle']
|
84
|
-
build << "RUBY_CC_VERSION=#{meta[:ruby_versions]} rake ports:compile[#{meta[:host]},#{gem_platform}] MAKE='make -j`nproc`'"
|
85
|
-
RakeCompilerDock.sh build.join(' && '), platform: gem_platform
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
10
|
desc "Notes the actual versions for the compiled ports into a file"
|
90
11
|
task "version_file", [:gem_platform] do |_task, args|
|
91
12
|
args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
|
92
13
|
|
93
14
|
ports_version = {}
|
94
15
|
|
95
|
-
libraries_to_compile.each do |library,
|
96
|
-
ports_version[library] =
|
16
|
+
libraries_to_compile.each do |library, version|
|
17
|
+
ports_version[library] = version
|
97
18
|
end
|
98
19
|
|
99
20
|
ports_version[:platform] = args.gem_platform
|
100
21
|
|
101
|
-
File.
|
102
|
-
f.write ports_version
|
103
|
-
end
|
22
|
+
File.write(".ports_versions", ports_version)
|
104
23
|
end
|
105
24
|
end
|
106
|
-
|
107
|
-
desc 'Build ports and activate libraries for the current architecture.'
|
108
|
-
task :ports => ['ports:compile']
|
data/tasks/test.rake
CHANGED
@@ -1,9 +1,7 @@
|
|
1
|
-
|
2
|
-
require 'rake/testtask'
|
1
|
+
require "rake/testtask"
|
3
2
|
|
4
3
|
Rake::TestTask.new do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.test_files = FileList[
|
4
|
+
t.libs << "test"
|
5
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
7
6
|
t.verbose = true
|
8
7
|
end
|
9
|
-
|
data/test/bin/install-freetds.sh
CHANGED
@@ -10,11 +10,9 @@ fi
|
|
10
10
|
wget http://www.freetds.org/files/stable/freetds-$FREETDS_VERSION.tar.gz
|
11
11
|
tar -xzf freetds-$FREETDS_VERSION.tar.gz
|
12
12
|
cd freetds-$FREETDS_VERSION
|
13
|
-
./configure
|
14
|
-
--with-openssl=/opt/local \
|
15
|
-
--with-tdsver=7.3
|
13
|
+
./configure
|
16
14
|
make
|
17
|
-
make install
|
15
|
+
sudo make install
|
18
16
|
cd ..
|
19
17
|
rm -rf freetds-$FREETDS_VERSION
|
20
18
|
rm freetds-$FREETDS_VERSION.tar.gz
|
@@ -0,0 +1,10 @@
|
|
1
|
+
$gemVersion = (Get-Content VERSION).Trim()
|
2
|
+
$gemToUnpack = "./tiny_tds-$gemVersion-$env:RUBY_ARCHITECTURE.gem"
|
3
|
+
|
4
|
+
Write-Host "Looking to unpack $gemToUnpack"
|
5
|
+
gem unpack --target ./tmp "$gemToUnpack"
|
6
|
+
|
7
|
+
# Restore precompiled code
|
8
|
+
$source = (Resolve-Path ".\tmp\tiny_tds-$gemVersion-$env:RUBY_ARCHITECTURE\lib\tiny_tds").Path
|
9
|
+
$destination = (Resolve-Path ".\lib\tiny_tds").Path
|
10
|
+
Get-ChildItem $source -Recurse -Exclude "*.rb" | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}
|