tiny_tds 2.1.5 → 3.2.0

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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +590 -0
  3. data/.gitignore +2 -0
  4. data/CHANGELOG.md +32 -1
  5. data/Gemfile +1 -8
  6. data/ISSUE_TEMPLATE.md +1 -1
  7. data/README.md +75 -88
  8. data/Rakefile +44 -30
  9. data/VERSION +1 -1
  10. data/docker-compose.yml +20 -8
  11. data/ext/tiny_tds/client.c +10 -15
  12. data/ext/tiny_tds/extconf.rb +183 -66
  13. data/ext/tiny_tds/extconsts.rb +4 -11
  14. data/ext/tiny_tds/result.c +28 -35
  15. data/ext/tiny_tds/tiny_tds_ext.c +4 -1
  16. data/lib/tiny_tds/bin.rb +12 -26
  17. data/lib/tiny_tds/client.rb +38 -42
  18. data/lib/tiny_tds/error.rb +0 -2
  19. data/lib/tiny_tds/gem.rb +5 -14
  20. data/lib/tiny_tds/result.rb +0 -2
  21. data/lib/tiny_tds/version.rb +1 -1
  22. data/lib/tiny_tds.rb +28 -47
  23. data/setup_cimgruby_dev.sh +25 -0
  24. data/start_dev.sh +21 -0
  25. data/tasks/native_gem.rake +12 -10
  26. data/tasks/package.rake +1 -3
  27. data/tasks/ports.rake +14 -75
  28. data/tasks/test.rake +3 -5
  29. data/test/bin/install-freetds.sh +2 -4
  30. data/test/bin/install-mssql.ps1 +42 -0
  31. data/test/bin/install-mssqltools.sh +9 -0
  32. data/test/bin/restore-from-native-gem.ps1 +10 -0
  33. data/test/bin/setup_tinytds_db.sh +7 -0
  34. data/test/bin/setup_volume_permissions.sh +10 -0
  35. data/test/client_test.rb +111 -120
  36. data/test/gem_test.rb +32 -111
  37. data/test/result_test.rb +259 -365
  38. data/test/schema_test.rb +369 -395
  39. data/test/sql/db-create.sql +18 -0
  40. data/test/sql/db-login.sql +38 -0
  41. data/test/test_helper.rb +75 -102
  42. data/test/thread_test.rb +22 -31
  43. data/tiny_tds.gemspec +28 -27
  44. metadata +70 -57
  45. data/.travis.yml +0 -25
  46. data/appveyor.yml +0 -72
  47. data/tasks/ports/freetds.rb +0 -37
  48. data/tasks/ports/libiconv.rb +0 -43
  49. data/tasks/ports/openssl.rb +0 -62
  50. data/tasks/ports/recipe.rb +0 -52
  51. data/test/appveyor/dbsetup.ps1 +0 -27
  52. data/test/appveyor/dbsetup.sql +0 -9
  53. data/test/benchmark/query.rb +0 -77
  54. data/test/benchmark/query_odbc.rb +0 -106
  55. data/test/benchmark/query_tinytds.rb +0 -126
  56. data/test/bin/setup.sh +0 -19
  57. data/test/schema/sqlserver_2000.sql +0 -140
  58. data/test/schema/sqlserver_2005.sql +0 -140
  59. data/test/schema/sqlserver_2014.sql +0 -140
  60. data/test/schema/sqlserver_2016.sql +0 -140
  61. data/test/schema/sybase_ase.sql +0 -138
  62. /data/test/schema/{sqlserver_2008.sql → sqlserver_2017.sql} +0 -0
@@ -1,7 +1,5 @@
1
1
  module TinyTds
2
2
  class Result
3
-
4
3
  include Enumerable
5
-
6
4
  end
7
5
  end
@@ -1,3 +1,3 @@
1
1
  module TinyTds
2
- VERSION = File.read(File.expand_path('../../../VERSION', __FILE__)).chomp
2
+ VERSION = File.read(File.expand_path("../../../VERSION", __FILE__)).chomp
3
3
  end
data/lib/tiny_tds.rb CHANGED
@@ -1,61 +1,42 @@
1
- # encoding: UTF-8
2
- require 'date'
3
- require 'bigdecimal'
4
- require 'rational'
1
+ require "date"
2
+ require "bigdecimal"
5
3
 
6
- require 'tiny_tds/version'
7
- require 'tiny_tds/error'
8
- require 'tiny_tds/client'
9
- require 'tiny_tds/result'
10
- require 'tiny_tds/gem'
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
- # Support multiple ruby versions, fat binaries under Windows.
13
- if RUBY_PLATFORM =~ /mingw|mswin/ && RUBY_VERSION =~ /(\d+.\d+)/
14
- ver = Regexp.last_match(1)
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
- begin
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
- ensure
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
- # Temporary add bin directories for DLL search, so that freetds DLLs can be found.
42
- add_dll_paths.call( TinyTds::Gem.ports_bin_paths ) do
43
- begin
44
- require "tiny_tds/#{ver}/tiny_tds"
45
- rescue LoadError
46
- require 'tiny_tds/tiny_tds'
47
- end
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
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ # this should mirror the steps outlined in the circleci yml
7
+ echo "Installing mssql-tools..."
8
+ sleep 5
9
+ sudo -E ./test/bin/install-mssqltools.sh
10
+
11
+ echo "Configurating tinytds test database..."
12
+ sleep 5
13
+ ./test/bin/setup_tinytds_db.sh
14
+
15
+ echo "Building openssl library..."
16
+ sleep 5
17
+ sudo -E ./test/bin/install-openssl.sh
18
+
19
+ echo "Building freetds library..."
20
+ sleep 5
21
+ sudo -E ./test/bin/install-freetds.sh
22
+
23
+ echo "Installing gems..."
24
+ sleep 5
25
+ bundle install
data/start_dev.sh ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ # set volume read/write permissions to work both outside and inside container
7
+ sudo ./test/bin/setup_volume_permissions.sh
8
+
9
+ docker-compose up -d
10
+ echo "Waiting for containers to start..."
11
+ sleep 10
12
+
13
+ # setup circleci ruby container for development
14
+ docker exec cimg_ruby bash -c './setup_cimgruby_dev.sh'
15
+
16
+ # enter container
17
+ set +x
18
+ echo "cimg/ruby container is ready for tiny_tds development.........."
19
+ echo "To enter container run: docker exec -it cimg_ruby /bin/bash"
20
+ echo "To build solution run: docker exec cimg_ruby bash -c 'bundle exec rake build'"
21
+ echo "To test solution run: docker exec cimg_ruby bash -c 'bundle exec rake test'"
@@ -1,14 +1,16 @@
1
- # encoding: UTF-8
1
+ CrossLibraries.each do |xlib|
2
+ platform = xlib.platform
2
3
 
3
- desc 'Build the windows binary gems per rake-compiler-dock'
4
- task 'gem:windows' => ['ports:cross'] do
5
- require 'rake_compiler_dock'
4
+ desc "Build fat binary gem for platform #{platform}"
5
+ task "gem:native:#{platform}" do
6
+ require "rake_compiler_dock"
6
7
 
7
- # make sure to install our bundle
8
- build = ['bundle']
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
+ end
9
13
 
10
- # and finally build the native gem
11
- build << 'rake cross native gem RUBY_CC_VERSION=2.7.0:2.6.0:2.5.0:2.4.0 CFLAGS="-Wall" MAKE="make -j`nproc`"'
12
-
13
- RakeCompilerDock.sh build.join(' && ')
14
+ desc "Build the native binary gems"
15
+ multitask "gem:native" => "gem:native:#{platform}"
14
16
  end
data/tasks/package.rake CHANGED
@@ -1,8 +1,6 @@
1
- # encoding: UTF-8
2
- require 'rubygems/package_task'
1
+ require "rubygems/package_task"
3
2
 
4
3
  Gem::PackageTask.new(SPEC) do |pkg|
5
4
  pkg.need_tar = false
6
5
  pkg.need_zip = false
7
6
  end
8
-
data/tasks/ports.rake CHANGED
@@ -1,85 +1,24 @@
1
- # encoding: UTF-8
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
- openssl = Ports::Openssl.new(OPENSSL_VERSION)
11
- libiconv = Ports::Libiconv.new(ICONV_VERSION)
12
- freetds = Ports::Freetds.new(FREETDS_VERSION)
4
+ libraries_to_compile = {
5
+ openssl: OPENSSL_VERSION,
6
+ libiconv: ICONV_VERSION,
7
+ freetds: FREETDS_VERSION
8
+ }
13
9
 
14
- directory "ports"
15
- CLEAN.include "ports/*mingw32*"
16
- CLEAN.include "ports/*.installed"
10
+ desc "Notes the actual versions for the compiled ports into a file"
11
+ task "version_file", [:gem_platform] do |_task, args|
12
+ args.with_defaults(gem_platform: RbConfig::CONFIG["arch"])
17
13
 
18
- task :openssl, [:host] do |task, args|
19
- args.with_defaults(host: RbConfig::CONFIG['host'])
14
+ ports_version = {}
20
15
 
21
- openssl.files = [OPENSSL_SOURCE_URI]
22
- openssl.host = args.host
23
- openssl.cook
24
- openssl.activate
25
- end
26
-
27
- task :libiconv, [:host] do |task, args|
28
- args.with_defaults(host: RbConfig::CONFIG['host'])
29
-
30
- libiconv.files = [ICONV_SOURCE_URI]
31
- libiconv.host = args.host
32
- libiconv.cook
33
- libiconv.activate
34
- end
35
-
36
- task :freetds, [:host] do |task, args|
37
- args.with_defaults(host: RbConfig::CONFIG['host'])
38
-
39
- freetds.files = [FREETDS_SOURCE_URI]
40
- freetds.host = args.host
41
-
42
- if openssl
43
- # freetds doesn't have an option that will provide an rpath
44
- # so we do it manually
45
- ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{openssl.path}/lib"
46
- # Add the pkgconfig file with MSYS2'ish path, to prefer our ports build
47
- # over MSYS2 system OpenSSL.
48
- ENV['PKG_CONFIG_PATH'] = "#{openssl.path.gsub(/^(\w):/i){"/"+$1.downcase}}/lib/pkgconfig:#{ENV['PKG_CONFIG_PATH']}"
49
- freetds.configure_options << "--with-openssl=#{openssl.path}"
50
- end
51
-
52
- if libiconv
53
- freetds.configure_options << "--with-libiconv-prefix=#{libiconv.path}"
16
+ libraries_to_compile.each do |library, version|
17
+ ports_version[library] = version
54
18
  end
55
19
 
56
- freetds.cook
57
- freetds.activate
58
- end
59
-
60
- task :compile, [:host] do |task,args|
61
- args.with_defaults(host: RbConfig::CONFIG['host'])
62
-
63
- puts "Compiling ports for #{args.host}..."
20
+ ports_version[:platform] = args.gem_platform
64
21
 
65
- ['openssl','libiconv','freetds'].each do |lib|
66
- Rake::Task["ports:#{lib}"].invoke(args.host)
67
- end
68
- end
69
-
70
- desc 'Build the ports windows binaries via rake-compiler-dock'
71
- task 'cross' do
72
- require 'rake_compiler_dock'
73
-
74
- # build the ports for all our cross compile hosts
75
- GEM_PLATFORM_HOSTS.each do |gem_platform, host|
76
- # make sure to install our bundle
77
- build = ['bundle']
78
- build << "rake ports:compile[#{host}] MAKE='make -j`nproc`'"
79
- RakeCompilerDock.sh build.join(' && '), platform: gem_platform
80
- end
22
+ File.write(".ports_versions", ports_version)
81
23
  end
82
24
  end
83
-
84
- desc 'Build ports and activate libraries for the current architecture.'
85
- task :ports => ['ports:compile']
data/tasks/test.rake CHANGED
@@ -1,9 +1,7 @@
1
- # encoding: UTF-8
2
- require 'rake/testtask'
1
+ require "rake/testtask"
3
2
 
4
3
  Rake::TestTask.new do |t|
5
- t.libs << 'test'
6
- t.test_files = FileList['test/**/*_test.rb']
4
+ t.libs << "test"
5
+ t.test_files = FileList["test/**/*_test.rb"]
7
6
  t.verbose = true
8
7
  end
9
-
@@ -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 --prefix=/opt/local \
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,42 @@
1
+ param ([int] $Version)
2
+
3
+ $ProgressPreference = 'SilentlyContinue'
4
+
5
+ $DownloadLinkTable = @{
6
+ 2017 = "https://go.microsoft.com/fwlink/?linkid=829176";
7
+ 2019 = "https://download.microsoft.com/download/7/c/1/7c14e92e-bdcb-4f89-b7cf-93543e7112d1/SQLEXPR_x64_ENU.exe";
8
+ 2022 = "https://download.microsoft.com/download/3/8/d/38de7036-2433-4207-8eae-06e247e17b25/SQLEXPR_x64_ENU.exe";
9
+ }
10
+
11
+ $MajorVersionTable = @{
12
+ 2017 = 14;
13
+ 2019 = 15;
14
+ 2022 = 16;
15
+ }
16
+
17
+ if (-not(Test-path "C:\Downloads")) {
18
+ mkdir "C:\Downloads"
19
+ }
20
+
21
+ $sqlInstallationFile = "C:\Downloads\sqlexpress.exe"
22
+ if (-not(Test-path $sqlInstallationFile -PathType leaf)) {
23
+ Write-Host "Downloading SQL Express ..."
24
+ Invoke-WebRequest -Uri $DownloadLinkTable[$Version] -OutFile "C:\Downloads\sqlexpress.exe"
25
+ }
26
+
27
+ Write-Host "Installing SQL Express ..."
28
+ Start-Process -Wait -FilePath "C:\Downloads\sqlexpress.exe" -ArgumentList /qs, /x:"C:\Downloads\setup"
29
+ C:\Downloads\setup\setup.exe /q /ACTION=Install /INSTANCENAME=SQLEXPRESS /FEATURES=SQLEngine /UPDATEENABLED=0 /SQLSVCACCOUNT='NT AUTHORITY\System' /SQLSYSADMINACCOUNTS='BUILTIN\ADMINISTRATORS' /TCPENABLED=1 /NPENABLED=0 /IACCEPTSQLSERVERLICENSETERMS
30
+
31
+ Write-Host "Configuring SQL Express ..."
32
+ stop-service MSSQL`$SQLEXPRESS
33
+ set-itemproperty -path "HKLM:\software\microsoft\microsoft sql server\mssql$($MajorVersionTable[$Version]).SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall" -name tcpdynamicports -value ''
34
+ set-itemproperty -path "HKLM:\software\microsoft\microsoft sql server\mssql$($MajorVersionTable[$Version]).SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall" -name tcpport -value 1433
35
+ set-itemproperty -path "HKLM:\software\microsoft\microsoft sql server\mssql$($MajorVersionTable[$Version]).SQLEXPRESS\mssqlserver\" -name LoginMode -value 2
36
+
37
+ Write-Host "Starting SQL Express ..."
38
+ start-service MSSQL`$SQLEXPRESS
39
+
40
+ Write-Host "Configuring MSSQL for TinyTDS ..."
41
+ & sqlcmd -i './test/sql/db-create.sql'
42
+ & sqlcmd -i './test/sql/db-login.sql'
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
7
+ curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
8
+ sudo apt-get update
9
+ sudo ACCEPT_EULA=Y apt-get -y install mssql-tools unixodbc-dev
@@ -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)}
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i ./test/sql/db-create.sql
7
+ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P $SA_PASSWORD -i ./test/sql/db-login.sql
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+
5
+ sudo groupadd -g 3434 circleci_tinytds
6
+ sudo usermod -a -G circleci_tinytds $USER
7
+ sudo useradd circleci_tinytds -u 3434 -g 3434
8
+ sudo usermod -a -G circleci_tinytds circleci_tinytds
9
+ sudo chgrp -R circleci_tinytds .
10
+ sudo chmod -R g+rwx .