tiny_tds 2.1.6-x64-mingw-ucrt

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +407 -0
  3. data/.codeclimate.yml +20 -0
  4. data/.gitattributes +1 -0
  5. data/.gitignore +22 -0
  6. data/.rubocop.yml +31 -0
  7. data/CHANGELOG.md +280 -0
  8. data/CODE_OF_CONDUCT.md +31 -0
  9. data/Gemfile +2 -0
  10. data/ISSUE_TEMPLATE.md +38 -0
  11. data/MIT-LICENSE +23 -0
  12. data/README.md +504 -0
  13. data/Rakefile +62 -0
  14. data/VERSION +1 -0
  15. data/bin/defncopy-ttds +3 -0
  16. data/bin/tsql-ttds +3 -0
  17. data/docker-compose.yml +34 -0
  18. data/exe/.keep +0 -0
  19. data/ext/tiny_tds/client.c +499 -0
  20. data/ext/tiny_tds/client.h +53 -0
  21. data/ext/tiny_tds/extconf.rb +92 -0
  22. data/ext/tiny_tds/extconsts.rb +15 -0
  23. data/ext/tiny_tds/result.c +634 -0
  24. data/ext/tiny_tds/result.h +32 -0
  25. data/ext/tiny_tds/tiny_tds_ext.c +12 -0
  26. data/ext/tiny_tds/tiny_tds_ext.h +17 -0
  27. data/lib/tiny_tds/3.1/tiny_tds.so +0 -0
  28. data/lib/tiny_tds/3.2/tiny_tds.so +0 -0
  29. data/lib/tiny_tds/bin.rb +104 -0
  30. data/lib/tiny_tds/client.rb +136 -0
  31. data/lib/tiny_tds/error.rb +14 -0
  32. data/lib/tiny_tds/gem.rb +27 -0
  33. data/lib/tiny_tds/result.rb +7 -0
  34. data/lib/tiny_tds/version.rb +3 -0
  35. data/lib/tiny_tds.rb +61 -0
  36. data/patches/freetds/1.00.27/0001-mingw_missing_inet_pton.diff +34 -0
  37. data/patches/freetds/1.00.27/0002-Don-t-use-MSYS2-file-libws2_32.diff +28 -0
  38. data/patches/libiconv/1.14/1-avoid-gets-error.patch +17 -0
  39. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/bsqldb.exe +0 -0
  40. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/datacopy.exe +0 -0
  41. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/defncopy.exe +0 -0
  42. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/freebcp.exe +0 -0
  43. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/libct-4.dll +0 -0
  44. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/libsybdb-5.dll +0 -0
  45. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/osql +388 -0
  46. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/tdspool.exe +0 -0
  47. data/ports/x64-mingw-ucrt/freetds/1.1.24/bin/tsql.exe +0 -0
  48. data/ports/x64-mingw-ucrt/freetds/1.1.24/lib/libct.dll.a +0 -0
  49. data/ports/x64-mingw-ucrt/freetds/1.1.24/lib/libct.la +41 -0
  50. data/ports/x64-mingw-ucrt/freetds/1.1.24/lib/libsybdb.dll.a +0 -0
  51. data/ports/x64-mingw-ucrt/freetds/1.1.24/lib/libsybdb.la +41 -0
  52. data/ports/x64-mingw-ucrt/libiconv/1.15/bin/iconv.exe +0 -0
  53. data/ports/x64-mingw-ucrt/libiconv/1.15/bin/libcharset-1.dll +0 -0
  54. data/ports/x64-mingw-ucrt/libiconv/1.15/bin/libiconv-2.dll +0 -0
  55. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/charset.alias +4 -0
  56. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/libcharset.dll.a +0 -0
  57. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/libcharset.la +41 -0
  58. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/libiconv.dll.a +0 -0
  59. data/ports/x64-mingw-ucrt/libiconv/1.15/lib/libiconv.la +41 -0
  60. data/ports/x64-mingw-ucrt/openssl/1.1.1s/bin/c_rehash +251 -0
  61. data/ports/x64-mingw-ucrt/openssl/1.1.1s/bin/libcrypto-1_1-x64.dll +0 -0
  62. data/ports/x64-mingw-ucrt/openssl/1.1.1s/bin/libssl-1_1-x64.dll +0 -0
  63. data/ports/x64-mingw-ucrt/openssl/1.1.1s/bin/openssl.exe +0 -0
  64. data/ports/x64-mingw-ucrt/openssl/1.1.1s/lib/libcrypto.a +0 -0
  65. data/ports/x64-mingw-ucrt/openssl/1.1.1s/lib/libcrypto.dll.a +0 -0
  66. data/ports/x64-mingw-ucrt/openssl/1.1.1s/lib/libssl.a +0 -0
  67. data/ports/x64-mingw-ucrt/openssl/1.1.1s/lib/libssl.dll.a +0 -0
  68. data/setup_cimgruby_dev.sh +25 -0
  69. data/start_dev.sh +21 -0
  70. data/tasks/native_gem.rake +23 -0
  71. data/tasks/package.rake +8 -0
  72. data/tasks/ports/freetds.rb +37 -0
  73. data/tasks/ports/libiconv.rb +26 -0
  74. data/tasks/ports/openssl.rb +62 -0
  75. data/tasks/ports/recipe.rb +64 -0
  76. data/tasks/ports.rake +108 -0
  77. data/tasks/test.rake +9 -0
  78. data/test/benchmark/query.rb +77 -0
  79. data/test/benchmark/query_odbc.rb +106 -0
  80. data/test/benchmark/query_tinytds.rb +126 -0
  81. data/test/bin/install-freetds.sh +20 -0
  82. data/test/bin/install-mssql.ps1 +31 -0
  83. data/test/bin/install-mssqltools.sh +9 -0
  84. data/test/bin/install-openssl.sh +18 -0
  85. data/test/bin/setup_tinytds_db.sh +7 -0
  86. data/test/bin/setup_volume_permissions.sh +10 -0
  87. data/test/client_test.rb +275 -0
  88. data/test/gem_test.rb +177 -0
  89. data/test/result_test.rb +814 -0
  90. data/test/schema/1px.gif +0 -0
  91. data/test/schema/sqlserver_2000.sql +140 -0
  92. data/test/schema/sqlserver_2005.sql +140 -0
  93. data/test/schema/sqlserver_2008.sql +140 -0
  94. data/test/schema/sqlserver_2014.sql +140 -0
  95. data/test/schema/sqlserver_2016.sql +140 -0
  96. data/test/schema/sqlserver_azure.sql +140 -0
  97. data/test/schema/sybase_ase.sql +138 -0
  98. data/test/schema_test.rb +443 -0
  99. data/test/sql/db-create.sql +18 -0
  100. data/test/sql/db-login.sql +38 -0
  101. data/test/test_helper.rb +280 -0
  102. data/test/thread_test.rb +98 -0
  103. data/tiny_tds.gemspec +31 -0
  104. metadata +267 -0
@@ -0,0 +1,77 @@
1
+ $:.unshift File.expand_path('../../../lib',__FILE__)
2
+ require 'rubygems'
3
+ require 'bench_press'
4
+ require 'tiny_tds'
5
+ require 'odbc'
6
+ require 'odbc_utf8'
7
+
8
+ extend BenchPress
9
+
10
+ author 'Ken Collins'
11
+ summary 'Query everything.'
12
+
13
+ reps 1_000
14
+
15
+ @odbc = ODBC.connect ENV['TINYTDS_UNIT_DATASERVER'], 'tinytds', ''
16
+ @odbc.use_time = true
17
+
18
+ @odbc_utf8 = ODBC_UTF8.connect ENV['TINYTDS_UNIT_DATASERVER'], 'tinytds', ''
19
+ @odbc_utf8.use_time = true
20
+
21
+ @tinytds = TinyTds::Client.new(
22
+ :dataserver => ENV['TINYTDS_UNIT_DATASERVER'],
23
+ :username => 'tinytds',
24
+ :password => '',
25
+ :database => 'tinytdstest',
26
+ :appname => 'TinyTds Dev',
27
+ :login_timeout => 5,
28
+ :timeout => 5 )
29
+
30
+ @query_all = "SELECT * FROM [datatypes]"
31
+
32
+
33
+ measure "ODBC (ascii-8bit)" do
34
+ h = @odbc.run(@query_all)
35
+ h.fetch_all
36
+ h.drop
37
+ end
38
+
39
+ # measure "ODBC (utf8)" do
40
+ # h = @odbc_utf8.run(@query_all)
41
+ # h.fetch_all
42
+ # h.drop
43
+ # end
44
+
45
+ measure "TinyTDS (row caching)" do
46
+ @tinytds.execute(@query_all).each
47
+ end
48
+
49
+ measure "TinyTDS (no caching)" do
50
+ @tinytds.execute(@query_all).each(:cache_rows => false)
51
+ end
52
+
53
+
54
+
55
+ =begin
56
+
57
+ Author: Ken Collins
58
+ Date: January 22, 2011
59
+ Summary: Query everything.
60
+
61
+ System Information
62
+ ------------------
63
+ Operating System: Mac OS X 10.6.6 (10J567)
64
+ CPU: Intel Core 2 Duo 1.6 GHz
65
+ Processor Count: 2
66
+ Memory: 4 GB
67
+ ruby 1.8.7 (2010-04-19 patchlevel 253) [i686-darwin10.4.3], MBARI 0x6770, Ruby Enterprise Edition 2010.02
68
+
69
+ "TinyTDS (row caching)" is up to 79% faster over 1,000 repetitions
70
+ ------------------------------------------------------------------
71
+
72
+ TinyTDS (row caching) 4.90862512588501 secs Fastest
73
+ TinyTDS (no caching) 4.91626906394958 secs 0% Slower
74
+ ODBC (ascii-8bit) 23.959536075592 secs 79% Slower
75
+
76
+ =end
77
+
@@ -0,0 +1,106 @@
1
+ require 'rubygems'
2
+ require 'bench_press'
3
+ begin gem 'odbc', '0.99992' ; rescue Gem::LoadError ; end
4
+ require 'odbc'
5
+
6
+ extend BenchPress
7
+
8
+ author 'Ken Collins'
9
+ summary 'Benchmarking ODBC Querys'
10
+
11
+ reps 1_000
12
+
13
+ @client = ODBC.connect ENV['TINYTDS_UNIT_DATASERVER'], 'tinytds', ''
14
+ @client.use_time = true
15
+
16
+ @query_nothing = "SELECT NULL AS [null]"
17
+ @query_ints = "SELECT [int], [bigint], [smallint], [tinyint] FROM [datatypes]"
18
+ @query_binaries = "SELECT [binary_50], [image], [varbinary_50] FROM [datatypes]"
19
+ @query_bits = "SELECT [bit] FROM [datatypes]"
20
+ @query_chars = "SELECT [char_10], [nchar_10], [ntext], [nvarchar_50], [text], [varchar_50] FROM [datatypes]"
21
+ @query_dates = "SELECT [datetime], [smalldatetime] FROM [datatypes]"
22
+ @query_decimals = "SELECT [decimal_9_2], [decimal_16_4], [numeric_18_0], [numeric_36_2] FROM [datatypes]"
23
+ @query_floats = "SELECT [float], [real] FROM [datatypes]"
24
+ @query_moneys = "SELECT [money], [smallmoney] FROM [datatypes]"
25
+ @query_guids = "SELECT [uniqueidentifier] FROM [datatypes]"
26
+ @query_all = "SELECT * FROM [datatypes]"
27
+
28
+ def select_all(query)
29
+ h = @client.run(query)
30
+ h.fetch_all
31
+ h.drop
32
+ end
33
+
34
+
35
+ measure "Nothing" do
36
+ select_all @query_nothing
37
+ end
38
+
39
+ measure "Integers" do
40
+ select_all @query_ints
41
+ end
42
+
43
+ measure "Binaries" do
44
+ select_all @query_binaries
45
+ end
46
+
47
+ measure "Bits" do
48
+ select_all @query_bits
49
+ end
50
+
51
+ measure "Chars" do
52
+ select_all @query_chars
53
+ end
54
+
55
+ measure "Dates" do
56
+ select_all @query_dates
57
+ end
58
+
59
+ measure "Decimals" do
60
+ select_all @query_decimals
61
+ end
62
+
63
+ measure "Floats" do
64
+ select_all @query_floats
65
+ end
66
+
67
+ measure "Moneys" do
68
+ select_all @query_moneys
69
+ end
70
+
71
+ measure "Guids" do
72
+ select_all @query_guids
73
+ end
74
+
75
+ measure "All" do
76
+ select_all @query_all
77
+ end
78
+
79
+
80
+ =begin
81
+
82
+ System Information
83
+ ------------------
84
+ Operating System: Mac OS X 10.6.4 (10F569)
85
+ CPU: Intel Core 2 Duo 2.4 GHz
86
+ Processor Count: 2
87
+ Memory: 4 GB
88
+ ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10.4.0]
89
+
90
+ "Nothing" is up to 98% faster over 1,000 repetitions
91
+ ----------------------------------------------------
92
+
93
+ Nothing 0.297961950302124 secs Fastest
94
+ Bits 0.377611875534058 secs 21% Slower
95
+ Guids 0.381000995635986 secs 21% Slower
96
+ Moneys 0.405518054962158 secs 26% Slower
97
+ Floats 0.409428119659424 secs 27% Slower
98
+ Integers 0.448167085647583 secs 33% Slower
99
+ Decimals 0.471596956253052 secs 36% Slower
100
+ Dates 0.52501106262207 secs 43% Slower
101
+ Binaries 3.66349482536316 secs 91% Slower
102
+ Chars 6.82928085327148 secs 95% Slower
103
+ All 28.4982612133026 secs 98% Slower
104
+
105
+ =end
106
+
@@ -0,0 +1,126 @@
1
+ require 'rubygems'
2
+ require 'bench_press'
3
+ $:.unshift File.expand_path('../../../lib',__FILE__)
4
+ require 'tiny_tds'
5
+
6
+ extend BenchPress
7
+
8
+ author 'Ken Collins'
9
+ summary 'Benchmark TinyTds Querys'
10
+
11
+ reps 1_000
12
+
13
+ @client = TinyTds::Client.new({
14
+ :dataserver => ENV['TINYTDS_UNIT_DATASERVER'],
15
+ :username => 'tinytds',
16
+ :password => '',
17
+ :database => 'tinytdstest',
18
+ :appname => 'TinyTds Dev',
19
+ :login_timeout => 5,
20
+ :timeout => 5
21
+ })
22
+
23
+ @query_nothing = "SELECT NULL AS [null]"
24
+ @query_ints = "SELECT [int], [bigint], [smallint], [tinyint] FROM [datatypes]"
25
+ @query_binaries = "SELECT [binary_50], [image], [varbinary_50] FROM [datatypes]"
26
+ @query_bits = "SELECT [bit] FROM [datatypes]"
27
+ @query_chars = "SELECT [char_10], [nchar_10], [ntext], [nvarchar_50], [text], [varchar_50] FROM [datatypes]"
28
+ @query_dates = "SELECT [datetime], [smalldatetime] FROM [datatypes]"
29
+ @query_decimals = "SELECT [decimal_9_2], [decimal_16_4], [numeric_18_0], [numeric_36_2] FROM [datatypes]"
30
+ @query_floats = "SELECT [float], [real] FROM [datatypes]"
31
+ @query_moneys = "SELECT [money], [smallmoney] FROM [datatypes]"
32
+ @query_guids = "SELECT [uniqueidentifier] FROM [datatypes]"
33
+ @query_all = "SELECT * FROM [datatypes]"
34
+
35
+ def select_all(query)
36
+ @client.execute(query).each
37
+ end
38
+
39
+
40
+ measure "Nothing" do
41
+ select_all @query_nothing
42
+ end
43
+
44
+ measure "Integers" do
45
+ select_all @query_ints
46
+ end
47
+
48
+ measure "Binaries" do
49
+ select_all @query_binaries
50
+ end
51
+
52
+ measure "Bits" do
53
+ select_all @query_bits
54
+ end
55
+
56
+ measure "Chars" do
57
+ select_all @query_chars
58
+ end
59
+
60
+ measure "Dates" do
61
+ select_all @query_dates
62
+ end
63
+
64
+ measure "Decimals" do
65
+ select_all @query_decimals
66
+ end
67
+
68
+ measure "Floats" do
69
+ select_all @query_floats
70
+ end
71
+
72
+ measure "Moneys" do
73
+ select_all @query_moneys
74
+ end
75
+
76
+ measure "Guids" do
77
+ select_all @query_guids
78
+ end
79
+
80
+ measure "All" do
81
+ select_all @query_all
82
+ end
83
+
84
+
85
+ =begin
86
+
87
+ Query Tinytds
88
+ =============
89
+ Author: Ken Collins
90
+ Date: September 11, 2011
91
+ Summary: Benchmark TinyTds Querys
92
+
93
+ System Information
94
+ ------------------
95
+ Operating System: Mac OS X 10.7.1 (11B26)
96
+ CPU: Quad-Core Intel Xeon 2.66 GHz
97
+ Processor Count: 4
98
+ Memory: 24 GB
99
+ ruby 1.8.7 (2011-02-18 patchlevel 334) [i686-darwin11.1.0], MBARI 0x6770, Ruby Enterprise Edition 2011.03
100
+
101
+ ----------------------------------------------------
102
+ (before 64bit times) (after 64bit times)
103
+ Nothing 0.287657022476196 secs Nothing 0.289273977279663 secs
104
+ Bits 0.406533002853394 secs Bits 0.424988031387329 secs
105
+ Guids 0.419962882995605 secs Guids 0.427381992340088 secs
106
+ Floats 0.452103137969971 secs Floats 0.455377101898193 secs
107
+ Moneys 0.481696844100952 secs Moneys 0.485175132751465 secs
108
+ Integers 0.496185064315796 secs Integers 0.525003910064697 secs
109
+ Binaries 0.538873195648193 secs Decimals 0.541536808013916 secs
110
+ Decimals 0.540570974349976 secs Binaries 0.542865991592407 secs
111
+ Dates 0.761389970779419 secs Dates 1.51440119743347 secs
112
+ Chars 0.793163061141968 secs Chars 0.666505098342896 secs
113
+ All 4.4630811214447 secs All 5.17242312431335 secs
114
+
115
+ =end
116
+
117
+
118
+
119
+
120
+
121
+
122
+
123
+
124
+
125
+
126
+
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ if [ -z "$FREETDS_VERSION" ]; then
7
+ FREETDS_VERSION=$(ruby -r "./ext/tiny_tds/extconsts.rb" -e "puts FREETDS_VERSION")
8
+ fi
9
+
10
+ wget http://www.freetds.org/files/stable/freetds-$FREETDS_VERSION.tar.gz
11
+ tar -xzf freetds-$FREETDS_VERSION.tar.gz
12
+ cd freetds-$FREETDS_VERSION
13
+ ./configure --prefix=/opt/local \
14
+ --with-openssl=/opt/local \
15
+ --with-tdsver=7.3
16
+ make
17
+ make install
18
+ cd ..
19
+ rm -rf freetds-$FREETDS_VERSION
20
+ rm freetds-$FREETDS_VERSION.tar.gz
@@ -0,0 +1,31 @@
1
+ $ProgressPreference = 'SilentlyContinue'
2
+
3
+ if (-not(Test-path "C:\Downloads"))
4
+ {
5
+ mkdir "C:\Downloads"
6
+ }
7
+
8
+ $sqlInstallationFile = "C:\Downloads\sqlexpress.exe"
9
+ if (-not(Test-path $sqlInstallationFile -PathType leaf))
10
+ {
11
+ Write-Host "Downloading SQL Express ..."
12
+ Invoke-WebRequest -Uri "https://go.microsoft.com/fwlink/?linkid=829176" -OutFile "C:\Downloads\sqlexpress.exe"
13
+ }
14
+
15
+ Write-Host "Installing SQL Express ..."
16
+ Start-Process -Wait -FilePath "C:\Downloads\sqlexpress.exe" -ArgumentList /qs, /x:"C:\Downloads\setup"
17
+ 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
18
+
19
+ Write-Host "Configuring SQL Express ..."
20
+ stop-service MSSQL`$SQLEXPRESS
21
+ set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpdynamicports -value ''
22
+ set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\supersocketnetlib\tcp\ipall' -name tcpport -value 1433
23
+ set-itemproperty -path 'HKLM:\software\microsoft\microsoft sql server\mssql14.SQLEXPRESS\mssqlserver\' -name LoginMode -value 2
24
+
25
+ Write-Host "Starting SQL Express ..."
26
+ start-service MSSQL`$SQLEXPRESS
27
+
28
+ Write-Host "Configuring MSSQL for TinyTDS ..."
29
+ & sqlcmd -Q "CREATE DATABASE [tinytdstest];"
30
+ & sqlcmd -Q "CREATE LOGIN [tinytds] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [tinytdstest];"
31
+ & sqlcmd -Q "USE [tinytdstest]; CREATE USER [tinytds] FOR LOGIN [tinytds]; EXEC sp_addrolemember N'db_owner', N'tinytds';"
@@ -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,18 @@
1
+ #!/usr/bin/env bash
2
+
3
+ set -x
4
+ set -e
5
+
6
+ if [ -z "$OPENSSL_VERSION" ]; then
7
+ OPENSSL_VERSION=$(ruby -r "./ext/tiny_tds/extconsts.rb" -e "puts OPENSSL_VERSION")
8
+ fi
9
+
10
+ wget https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz
11
+ tar -xzf openssl-$OPENSSL_VERSION.tar.gz
12
+ cd openssl-$OPENSSL_VERSION
13
+ ./config --prefix=/opt/local --openssldir=/opt/local
14
+ make
15
+ make install_sw install_ssldirs
16
+ cd ..
17
+ rm -rf openssl-$OPENSSL_VERSION
18
+ rm openssl-$OPENSSL_VERSION.tar.gz
@@ -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 .
@@ -0,0 +1,275 @@
1
+ # encoding: utf-8
2
+ require 'test_helper'
3
+
4
+ class ClientTest < TinyTds::TestCase
5
+ describe 'with valid credentials' do
6
+ before do
7
+ @client = new_connection
8
+ end
9
+
10
+ it 'must not be closed' do
11
+ assert !@client.closed?
12
+ assert @client.active?
13
+ end
14
+
15
+ it 'allows client connection to be closed' do
16
+ assert @client.close
17
+ assert @client.closed?
18
+ assert !@client.active?
19
+ assert @client.dead?
20
+ action = lambda { @client.execute('SELECT 1 as [one]').each }
21
+ assert_raise_tinytds_error(action) do |e|
22
+ assert_match %r{closed connection}i, e.message, 'ignore if non-english test run'
23
+ end
24
+ end
25
+
26
+ it 'has getters for the tds version information (brittle since conf takes precedence)' do
27
+ if sybase_ase?
28
+ assert_equal 7, @client.tds_version
29
+ assert_equal 'DBTDS_5_0 - 5.0 SQL Server', @client.tds_version_info
30
+ elsif @client.tds_73?
31
+ assert_equal 11, @client.tds_version
32
+ assert_equal 'DBTDS_7_3 - Microsoft SQL Server 2008', @client.tds_version_info
33
+ else
34
+ assert_equal 9, @client.tds_version
35
+ assert_equal 'DBTDS_7_1/DBTDS_8_0 - Microsoft SQL Server 2000', @client.tds_version_info
36
+ end
37
+ end
38
+
39
+ it 'uses UTF-8 client charset/encoding by default' do
40
+ assert_equal 'UTF-8', @client.charset
41
+ assert_equal Encoding.find('UTF-8'), @client.encoding
42
+ end
43
+
44
+ it 'has a #escape method used for quote strings' do
45
+ assert_equal "''hello''", @client.escape("'hello'")
46
+ end
47
+
48
+ ['CP850', 'CP1252', 'ISO-8859-1'].each do |encoding|
49
+ it "allows valid iconv character set - #{encoding}" do
50
+ begin
51
+ client = new_connection(:encoding => encoding)
52
+ assert_equal encoding, client.charset
53
+ assert_equal Encoding.find(encoding), client.encoding
54
+ ensure
55
+ client.close if client
56
+ end
57
+ end
58
+ end
59
+
60
+ it 'must be able to use :host/:port connection' do
61
+ host = ENV['TINYTDS_UNIT_HOST_TEST'] || ENV['TINYTDS_UNIT_HOST'] || 'localhost'
62
+ port = ENV['TINYTDS_UNIT_PORT_TEST'] || ENV['TINYTDS_UNIT_PORT'] || 1433
63
+ begin
64
+ client = new_connection dataserver: nil, host: host, port: port
65
+ ensure
66
+ client.close if client
67
+ end
68
+ end unless sqlserver_azure?
69
+ end
70
+
71
+ describe 'With in-valid options' do
72
+ before(:all) do
73
+ init_toxiproxy
74
+ end
75
+
76
+ it 'raises an argument error when no :host given and :dataserver is blank' do
77
+ assert_raises(ArgumentError) { new_connection :dataserver => nil, :host => nil }
78
+ end
79
+
80
+ it 'raises an argument error when no :username is supplied' do
81
+ assert_raises(ArgumentError) { TinyTds::Client.new :username => nil }
82
+ end
83
+
84
+ it 'raises TinyTds exception with undefined :dataserver' do
85
+ options = connection_options :login_timeout => 1, :dataserver => 'DOESNOTEXIST'
86
+ action = lambda { new_connection(options) }
87
+ assert_raise_tinytds_error(action) do |e|
88
+ # Not sure why tese are different.
89
+ if ruby_darwin?
90
+ assert_equal 20009, e.db_error_number
91
+ assert_equal 9, e.severity
92
+ assert_match %r{is unavailable or does not exist}i, e.message, 'ignore if non-english test run'
93
+ else
94
+ assert_equal 20012, e.db_error_number
95
+ assert_equal 2, e.severity
96
+ assert_match %r{server name not found in configuration files}i, e.message, 'ignore if non-english test run'
97
+ end
98
+ end
99
+ assert_new_connections_work
100
+ end
101
+
102
+ it 'raises TinyTds exception with long query past :timeout option' do
103
+ client = new_connection :timeout => 1
104
+ action = lambda { client.execute("WaitFor Delay '00:00:02'").do }
105
+ assert_raise_tinytds_error(action) do |e|
106
+ assert_equal 20003, e.db_error_number
107
+ assert_equal 6, e.severity
108
+ assert_match %r{timed out}i, e.message, 'ignore if non-english test run'
109
+ end
110
+ assert_client_works(client)
111
+ close_client(client)
112
+ assert_new_connections_work
113
+ end
114
+
115
+ it 'must not timeout per sql batch when not under transaction' do
116
+ client = new_connection :timeout => 2
117
+ client.execute("WaitFor Delay '00:00:01'").do
118
+ client.execute("WaitFor Delay '00:00:01'").do
119
+ client.execute("WaitFor Delay '00:00:01'").do
120
+ close_client(client)
121
+ end
122
+
123
+ it 'must not timeout per sql batch when under transaction' do
124
+ client = new_connection :timeout => 2
125
+ begin
126
+ client.execute("BEGIN TRANSACTION").do
127
+ client.execute("WaitFor Delay '00:00:01'").do
128
+ client.execute("WaitFor Delay '00:00:01'").do
129
+ client.execute("WaitFor Delay '00:00:01'").do
130
+ ensure
131
+ client.execute("COMMIT TRANSACTION").do
132
+ close_client(client)
133
+ end
134
+ end
135
+
136
+ it 'raises TinyTds exception with tcp socket network failure' do
137
+ begin
138
+ client = new_connection timeout: 2, port: 1234, host: ENV['TOXIPROXY_HOST']
139
+ assert_client_works(client)
140
+ action = lambda { client.execute("waitfor delay '00:00:05'").do }
141
+
142
+ # Use toxiproxy to close the TCP socket after 1 second.
143
+ # We want TinyTds to execute the statement, hit the timeout configured above, and then not be able to use the network to cancel
144
+ # the network connection needs to close after the sql batch is sent and before the timeout above is hit
145
+ Toxiproxy[:sqlserver_test].toxic(:slow_close, delay: 1000).apply do
146
+ assert_raise_tinytds_error(action) do |e|
147
+ assert_equal 20003, e.db_error_number
148
+ assert_equal 6, e.severity
149
+ assert_match %r{timed out}i, e.message, 'ignore if non-english test run'
150
+ end
151
+ end
152
+ ensure
153
+ assert_new_connections_work
154
+ end
155
+ end
156
+
157
+ it 'raises TinyTds exception with dead connection network failure' do
158
+ skip if ruby_windows?
159
+
160
+ begin
161
+ client = new_connection timeout: 2, port: 1234, host: ENV['TOXIPROXY_HOST']
162
+ assert_client_works(client)
163
+ action = lambda { client.execute("waitfor delay '00:00:05'").do }
164
+
165
+ # Use toxiproxy to close the network connection after 1 second.
166
+ # We want TinyTds to execute the statement, hit the timeout configured above, and then not be able to use the network to cancel
167
+ # the network connection needs to close after the sql batch is sent and before the timeout above is hit
168
+ Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 1000).apply do
169
+ assert_raise_tinytds_error(action) do |e|
170
+ assert_equal 20047, e.db_error_number
171
+ assert_includes [1,9], e.severity
172
+ assert_match %r{dead or not enabled}i, e.message, 'ignore if non-english test run'
173
+ end
174
+ end
175
+ ensure
176
+ assert_new_connections_work
177
+ end
178
+ end
179
+
180
+ it 'raises TinyTds exception with login timeout' do
181
+ begin
182
+ action = lambda do
183
+ Toxiproxy[:sqlserver_test].toxic(:timeout, timeout: 0).apply do
184
+ new_connection login_timeout: 1, port: 1234, host: ENV['TOXIPROXY_HOST']
185
+ end
186
+ end
187
+ assert_raise_tinytds_error(action) do |e|
188
+ assert_equal 20003, e.db_error_number
189
+ assert_equal 6, e.severity
190
+ assert_match %r{timed out}i, e.message, 'ignore if non-english test run'
191
+ end
192
+ ensure
193
+ assert_new_connections_work
194
+ end
195
+ end
196
+
197
+ it 'raises TinyTds exception with wrong :username' do
198
+ skip if ENV['CI'] && sqlserver_azure? # Some issue with db_error_number.
199
+ options = connection_options :username => 'willnotwork'
200
+ action = lambda { new_connection(options) }
201
+ assert_raise_tinytds_error(action) do |e|
202
+ assert_equal sybase_ase? ? 4002 : 18456, e.db_error_number
203
+ assert_equal 14, e.severity
204
+ assert_match %r{login failed}i, e.message, 'ignore if non-english test run'
205
+ end
206
+ assert_new_connections_work
207
+ end
208
+
209
+ end
210
+
211
+ describe '#parse_username' do
212
+ let(:client) { @client = new_connection }
213
+
214
+ it 'returns username if azure is not true' do
215
+ _(
216
+ client.send(:parse_username, username: 'user@abc123.database.windows.net')
217
+ ).must_equal 'user@abc123.database.windows.net'
218
+ end
219
+
220
+ it 'returns short username if azure is true' do
221
+ _(
222
+ client.send(
223
+ :parse_username,
224
+ username: 'user@abc123.database.windows.net',
225
+ host: 'abc123.database.windows.net',
226
+ azure: true
227
+ )
228
+ ).must_equal 'user@abc123'
229
+ end
230
+
231
+ it 'returns full username if azure is false' do
232
+ _(
233
+ client.send(
234
+ :parse_username,
235
+ username: 'user@abc123.database.windows.net',
236
+ host: 'abc123.database.windows.net',
237
+ azure: false
238
+ )
239
+ ).must_equal 'user@abc123.database.windows.net'
240
+ end
241
+
242
+ it 'returns short username if passed and azure is true' do
243
+ _(
244
+ client.send(
245
+ :parse_username,
246
+ username: 'user@abc123',
247
+ host: 'abc123.database.windows.net',
248
+ azure: true
249
+ )
250
+ ).must_equal 'user@abc123'
251
+ end
252
+
253
+ it 'returns username with servername if passed and azure is true' do
254
+ _(
255
+ client.send(
256
+ :parse_username,
257
+ username: 'user',
258
+ host: 'abc123.database.windows.net',
259
+ azure: true
260
+ )
261
+ ).must_equal 'user@abc123'
262
+ end
263
+
264
+ it 'returns username with servername if passed and azure is false' do
265
+ _(
266
+ client.send(
267
+ :parse_username,
268
+ username: 'user',
269
+ host: 'abc123.database.windows.net',
270
+ azure: false
271
+ )
272
+ ).must_equal 'user'
273
+ end
274
+ end
275
+ end