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
data/README.md CHANGED
@@ -1,16 +1,13 @@
1
1
  # TinyTDS - Simple and fast FreeTDS bindings for Ruby using DB-Library.
2
2
 
3
- * [![TravisCI](https://travis-ci.org/rails-sqlserver/tiny_tds.svg?branch=master)](https://travis-ci.org/rails-sqlserver/tiny_tds) - TravisCI
4
- * [![Build Status](https://ci.appveyor.com/api/projects/status/g2bhhbsdkx0mal55/branch/master?svg=true)](https://ci.appveyor.com/project/rails-sqlserver/tiny-tds/branch/master) - Appveyor
5
3
  * [![Gem Version](https://img.shields.io/gem/v/tiny_tds.svg)](https://rubygems.org/gems/tiny_tds) - Gem Version
6
4
  * [![Gitter chat](https://img.shields.io/badge/%E2%8A%AA%20GITTER%20-JOIN%20CHAT%20%E2%86%92-brightgreen.svg?style=flat)](https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter) - Community
7
5
 
8
-
9
6
  ## About TinyTDS
10
7
 
11
- The TinyTDS gem is meant to serve the extremely common use-case of connecting, querying and iterating over results to Microsoft SQL Server or Sybase databases from Ruby using the FreeTDS's DB-Library API.
8
+ The TinyTDS gem is meant to serve the extremely common use-case of connecting, querying and iterating over results to Microsoft SQL Server from Ruby using the FreeTDS's DB-Library API.
12
9
 
13
- TinyTDS offers automatic casting to Ruby primitives along with proper encoding support. It converts all SQL Server datatypes to native Ruby primitives while supporting :utc or :local time zones for time-like types. To date it is the only Ruby client library that allows client encoding options, defaulting to UTF-8, while connecting to SQL Server. It also properly encodes all string and binary data. The motivation for TinyTDS is to become the de-facto low level connection mode for the SQL Server Adapter for ActiveRecord.
10
+ TinyTDS offers automatic casting to Ruby primitives along with proper encoding support. It converts all SQL Server datatypes to native Ruby primitives while supporting :utc or :local time zones for time-like types. To date it is the only Ruby client library that allows client encoding options, defaulting to UTF-8, while connecting to SQL Server. It also properly encodes all string and binary data.
14
11
 
15
12
  The API is simple and consists of these classes:
16
13
 
@@ -21,69 +18,71 @@ The API is simple and consists of these classes:
21
18
 
22
19
  ## Install
23
20
 
24
- Installing with rubygems should just work. TinyTDS is currently tested on Ruby version 2.0.0 and upward.
25
-
26
- ```
27
- $ gem install tiny_tds
28
- ```
21
+ tiny_tds is tested with Ruby v2.7 and upwards.
29
22
 
30
- If you use Windows, we pre-compile TinyTDS with static versions of FreeTDS and supporting libraries.
31
- If you're using RubyInstaller the binary gem will require that devkit is installed and in your path to operate properly.
23
+ ### Windows and Linux (64-bit)
32
24
 
33
- On all other platforms, we will find these dependencies. It is recommended that you install the latest FreeTDS via your method of choice. For example, here is how to install FreeTDS on Ubuntu. You might also need the `build-essential` and possibly the `libc6-dev` packages.
25
+ We precompile tiny_tds with FreeTDS and supporting libraries, which are dynamically linked at runtime. Therefore, you can run:
34
26
 
35
27
  ```shell
36
- $ apt-get install wget
37
- $ apt-get install build-essential
38
- $ apt-get install libc6-dev
39
-
40
- $ wget http://www.freetds.org/files/stable/freetds-1.1.24.tar.gz
41
- $ tar -xzf freetds-1.1.24.tar.gz
42
- $ cd freetds-1.1.24
43
- $ ./configure --prefix=/usr/local --with-tdsver=7.3
44
- $ make
45
- $ make install
28
+ gem install tiny_tds
46
29
  ```
47
30
 
48
- Please read the MiniPortile and/or Windows sections at the end of this file for advanced configuration options past the following:
31
+ It should find the platform-specific gem.
49
32
 
50
- ```
51
- --with-freetds-dir=DIR
52
- Use the freetds library placed under DIR.
53
- ```
33
+ You can also avoid getting the platform-specific gem if you want to compile FreeTDS and supporting libraries yourself:
54
34
 
35
+ ```shell
36
+ gem install tiny_tds --platform ruby
37
+ ```
55
38
 
56
- ## Getting Started
39
+ ### Mac
57
40
 
58
- Optionally, Microsoft has done a great job writing some articles on how to get started with SQL Server and Ruby using TinyTDS. Please checkout one of the following posts that match your platform.
41
+ Install FreeTDS via Homebrew:
59
42
 
60
- * [SQL Server on a Mac](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/mac)
61
- * [SQL Server on RHEL](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/rhel)
62
- * [SQL Server on Ubuntu](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/ubuntu)
43
+ ```shell
44
+ brew install openssl@3 libiconv
45
+ brew install freetds
46
+ ```
63
47
 
48
+ Then you can install tiny_tds:
64
49
 
65
- ## FreeTDS Compatibility & Configuration
50
+ ```shell
51
+ gem install tiny_tds
52
+ ```
66
53
 
67
- TinyTDS is developed against FreeTDS 0.95, 0.99, and 1.0 current. Our default and recommended is 1.0. We also test with SQL Server 2008, 2014, and Azure. However, usage of TinyTDS with SQL Server 2000 or 2005 should be just fine. Below are a few QA style notes about installing FreeTDS.
54
+ ### Everybody else
68
55
 
69
- **NOTE:** Windows users of our pre-compiled native gems need not worry about installing FreeTDS and its dependencies.
56
+ `tiny_tds` will find FreeTDS and other libraries based on your compiler paths. Below you can see an example on how to install FreeTDS on a Debian system.
70
57
 
71
- * **Do I need to install FreeTDS?** Yes! Somehow, someway, you are going to need FreeTDS for TinyTDS to compile against.
58
+ ```shell
59
+ $ apt-get install wget
60
+ $ apt-get install build-essential
61
+ $ apt-get install libc6-dev
72
62
 
73
- * **OK, I am installing FreeTDS, how do I configure it?** Contrary to what most people think, you do not need to specially configure FreeTDS in any way for client libraries like TinyTDS to use it. About the only requirement is that you compile it with libiconv for proper encoding support. FreeTDS must also be compiled with OpenSSL (or the like) to use it with Azure. See the "Using TinyTDS with Azure" section below for more info.
63
+ $ wget http://www.freetds.org/files/stable/freetds-1.4.23.tar.gz
64
+ $ tar -xzf freetds-1.4.23.tar.gz
65
+ $ cd freetds-1.4.23
66
+ $ ./configure --prefix=/usr/local --with-tdsver=7.4 --disable-odbc
67
+ $ make
68
+ $ make install
69
+ ```
74
70
 
75
- * **Do I need to configure `--with-tdsver` equal to anything?** Most likely! Technically you should not have to. This is only a default for clients/configs that do not specify what TDS version they want to use. We are currently having issues with passing down a TDS version with the login bit. Till we get that fixed, if you are not using a freetds.conf or a TDSVER environment variable, then make sure to use 7.1.
71
+ You can also tell `tiny_tds` where to find your FreeTDS installation.
76
72
 
77
- * **But I want to use TDS version 7.2 for SQL Server 2005 and up!** TinyTDS uses TDS version 7.1 (previously named 8.0) and fully supports all the data types supported by FreeTDS, this includes `varchar(max)` and `nvarchar(max)`. Technically compiling and using TDS version 7.2 with FreeTDS is not supported. But this does not mean those data types will not work. I know, it's confusing If you want to learn more, read this thread. http://lists.ibiblio.org/pipermail/freetds/2011q3/027306.html
73
+ ```shell
74
+ gem install tiny_tds -- --with-freetds-dir=/opt/freetds
75
+ ```
78
76
 
79
- * **I want to configure FreeTDS using `--enable-msdblib` and/or `--enable-sybase-compat` so it works for my database. Cool?** It's a waste of time and totally moot! Client libraries like TinyTDS define their own C structure names where they diverge from Sybase to SQL Server. Technically we use the MSDBLIB structures which does not mean we only work with that database vs Sybase. These configs are just a low level default for C libraries that do not define what they want. So I repeat, you do not NEED to use any of these, nor will they hurt anything since we control what C structure names we use internally!
77
+ ## Getting Started
80
78
 
79
+ Optionally, Microsoft has done a great job writing [an article](https://learn.microsoft.com/en-us/sql/connect/ruby/ruby-driver-for-sql-server?view=sql-server-ver16) on how to get started with SQL Server and Ruby using TinyTDS, however, the articles are using outdated versions.
81
80
 
82
81
  ## Data Types
83
82
 
84
83
  Our goal is to support every SQL Server data type and covert it to a logical Ruby object. When dates or times are returned, they are instantiated to either `:utc` or `:local` time depending on the query options. Only [datetimeoffset] types are excluded. All strings are associated the to the connection's encoding and all binary data types are associated to Ruby's `ASCII-8BIT/BINARY` encoding.
85
84
 
86
- Below is a list of the data types we support when using the 7.3 TDS protocol version. Using a lower protocol version will result in these types being returned as strings.
85
+ Below is a list of the data types we support when using the 7.4 TDS protocol version. Using a lower protocol version will result in these types being returned as strings.
87
86
 
88
87
  * [date]
89
88
  * [datetime2]
@@ -110,7 +109,7 @@ Creating a new client takes a hash of options. For valid iconv encoding options,
110
109
  * :appname - Short string seen in SQL Servers process/activity window.
111
110
  * :tds_version - TDS version. Defaults to "7.3".
112
111
  * :login_timeout - Seconds to wait for login. Default to 60 seconds.
113
- * :timeout - Seconds to wait for a response to a SQL command. Default 5 seconds. Prior to 1.0rc5, FreeTDS was unable to set the timeout on a per-client basis, permitting only a global timeout value. This means that if you're using an older version, the timeout values for all clients will be overwritten each time you instantiate a new `TinyTds::Client` object. If you are using 1.0rc5 or later, all clients will have an independent timeout setting as you'd expect. Timeouts caused by network failure will raise a timeout error 1 second after the configured timeout limit is hit (see [#481](https://github.com/rails-sqlserver/tiny_tds/pull/481) for details).
112
+ * :timeout - Seconds to wait for a response to a SQL command. Default 5 seconds. Timeouts caused by network failure will raise a timeout error 1 second after the configured timeout limit is hit (see [#481](https://github.com/rails-sqlserver/tiny_tds/pull/481) for details).
114
113
  * :encoding - Any valid iconv value like CP1251 or ISO-8859-1. Default UTF-8.
115
114
  * :azure - Pass true to signal that you are connecting to azure.
116
115
  * :contained - Pass true to signal that you are connecting with a contained database user.
@@ -392,28 +391,7 @@ Please read our [thread_test.rb](https://github.com/rails-sqlserver/tiny_tds/blo
392
391
 
393
392
  ## Emoji Support 😍
394
393
 
395
- This is possible using FreeTDS version 0.95 or higher. You must use the `use_utf16` login option or add the following config to your `freetds.conf` in either the global section or a specfic dataserver. If you are on Windows, the default location for your conf file will be in `C:\Sites`.
396
-
397
- ```ini
398
- [global]
399
- use utf-16 = true
400
- ```
401
-
402
- The default is true and since FreeTDS v1.0 would do this as well.
403
-
404
-
405
- ## Compiling Gems for Windows
406
-
407
- For the convenience of Windows users, TinyTDS ships pre-compiled gems for supported versions of Ruby on Windows. In order to generate these gems, [rake-compiler-dock](https://github.com/rake-compiler/rake-compiler-dock) is used. This project provides several [Docker images](https://registry.hub.docker.com/u/larskanis/) with rvm, cross-compilers and a number of different target versions of Ruby.
408
-
409
- Run the following rake task to compile the gems for Windows. This will check the availability of [Docker](https://www.docker.com/) (and boot2docker on Windows or OS-X) and will give some advice for download and installation. When docker is running, it will download the docker image (once-only) and start the build:
410
-
411
- ```
412
- $ rake gem:windows
413
- ```
414
-
415
- The compiled gems will exist in `./pkg` directory.
416
-
394
+ This is possible. Since FreeTDS v1.0, utf-16 is enabled by default and supported by tiny_tds. You can toggle it by using `use_utf16` when establishing the connection.
417
395
 
418
396
  ## Development & Testing
419
397
 
@@ -429,27 +407,21 @@ After that, the quickest way to get setup for development is to use [Docker](htt
429
407
  $ docker-compose up -d
430
408
  ```
431
409
 
432
- This will download our SQL Server for Linux Docker image based from [microsoft/mssql-server-linux/](https://hub.docker.com/r/microsoft/mssql-server-linux/). Our image already has the `[tinytdstest]` DB and `tinytds` users created. This will also download a [toxiproxy](https://github.com/shopify/toxiproxy) Docker image which we can use to simulate network failures for tests. Basically, it does the following.
410
+ This will download the official SQL Server for Linux Docker image from [Microsoft](https://hub.docker.com/r/microsoft/mssql-server-linux/). This will also download a [toxiproxy](https://github.com/shopify/toxiproxy) Docker image which we can use to simulate network failures for tests. Basically, it does the following:
433
411
 
434
412
  ```shell
435
413
  $ docker network create main-network
436
- $ docker pull metaskills/mssql-server-linux-tinytds
437
- $ docker run -p 1433:1433 -d --name sqlserver --network main-network metaskills/mssql-server-linux-tinytds
414
+ $ docker pull mcr.microsoft.com/mssql/server:2017-latest
415
+ $ docker run -p 1433:1433 -d --name sqlserver --network main-network mcr.microsoft.com/mssql/server:2017-latest
438
416
  $ docker pull shopify/toxiproxy
439
417
  $ docker run -p 8474:8474 -p 1234:1234 -d --name toxiproxy --network main-network shopify/toxiproxy
440
418
  ```
441
419
 
442
- If you are using your own database. Make sure to run these SQL commands as SA to get the test database and user installed.
443
-
444
- ```sql
445
- CREATE DATABASE [tinytdstest];
446
- ```
420
+ Make sure to run these SQL scripts as SA to get the test database and user installed. If needed, install [sqlcmd as described by Microsoft for your platform](https://learn.microsoft.com/en-us/sql/tools/sqlcmd/sqlcmd-utility?view=sql-server-ver16&tabs=go%2Clinux&pivots=cs1-bash).
447
421
 
448
- ```sql
449
- CREATE LOGIN [tinytds] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [tinytdstest];
450
- USE [tinytdstest];
451
- CREATE USER [tinytds] FOR LOGIN [tinytds];
452
- EXEC sp_addrolemember N'db_owner', N'tinytds';
422
+ ```shell
423
+ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P super01S3cUr3 -i ./test/sql/db-create.sql
424
+ /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P super01S3cUr3 -i ./test/sql/db-login.sql
453
425
  ```
454
426
 
455
427
  From here you can build and run tests against an installed version of FreeTDS.
@@ -463,21 +435,36 @@ Examples us using enviornment variables to customize the test task.
463
435
 
464
436
  ```
465
437
  $ rake TINYTDS_UNIT_DATASERVER=mydbserver
466
- $ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2008
438
+ $ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2017
467
439
  $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
468
- $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_UNIT_PORT=5000 TINYTDS_SCHEMA=sybase_ase
469
440
  ```
470
441
 
471
- ## Docker Builds
442
+ ### Code formatting
443
+
444
+ We are using `standardrb` to format our code. Just run `bundle exec standardrb --fix` to format all Ruby files.
445
+
446
+ ### Compiling Gems for Windows and Linux
447
+
448
+ > [!WARNING]
449
+ > Compiling the Gems on native Windows currently does not work.
450
+
451
+ For the convenience, TinyTDS ships pre-compiled gems for supported versions of Ruby on Windows and Linux. In order to generate these gems, [rake-compiler-dock](https://github.com/rake-compiler/rake-compiler-dock) is used.
452
+
453
+ Run the following rake task to compile the gems. This will check the availability of [Docker](https://www.docker.com/) and will give some advice for download and installation. When docker is running, it will download the docker image (once-only) and start the build:
454
+
455
+ ```shell
456
+ bundle exec rake gem:native
457
+ ```
458
+
459
+ The compiled gems will exist in `./pkg` directory.
472
460
 
473
- If you use a [multi stage](https://docs.docker.com/develop/develop-images/multistage-build/) Docker build to assemble your gems in one phase and then copy your app and gems
474
- into another, lighter, container without build tools you will need to make sure you tell the OS how to find dependencies for TinyTDS.
461
+ If you only need a specific gem for one platform and architecture, run this command:
475
462
 
476
- After you have built and installed FreeTDS it will normally place library files in `/usr/local/lib`. When TinyTDS builds native extensions,
477
- it [already knows to look here](https://github.com/rails-sqlserver/tiny_tds/blob/master/ext/tiny_tds/extconf.rb#L31) but if you copy your app to a new container that link will be broken.
463
+ ```shell
464
+ bundle exec rake gem:native:x64-mingw-ucrt
465
+ ```
478
466
 
479
- Set the LD_LIBRARY_PATH environment variable `export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}` and run `ldconfig`. If you run `ldd tiny_tds.so` you should not see any broken links. Make
480
- sure you also copied in the library dependencies from your build container with a command like `COPY --from=builder /usr/local/lib /usr/local/lib`.
467
+ All the supported architectures and platforms are listed in the `Rakefile` in the `CrossLibraries` constant.
481
468
 
482
469
  ## Help & Support
483
470
 
@@ -503,4 +490,4 @@ My name is Ken Collins and I currently maintain the SQL Server adapter for Activ
503
490
 
504
491
  ## License
505
492
 
506
- TinyTDS is Copyright (c) 2010-2015 Ken Collins, <ken@metaskills.net> and Will Bond (Veracross LLC) <wbond@breuer.com>. It is distributed under the MIT license. Windows binaries contain pre-compiled versions of FreeTDS <http://www.freetds.org/> which is licensed under the GNU LGPL license at <http://www.gnu.org/licenses/lgpl-2.0.html>
493
+ TinyTDS is Copyright (c) 2010-2015 Ken Collins, <ken@metaskills.net> and Will Bond (Veracross LLC) <wbond@breuer.com>. It is distributed under the MIT license. Windows and Linux binaries contain pre-compiled versions of FreeTDS <http://www.freetds.org/> and `libconv` which is licensed under the GNU LGPL license at <http://www.gnu.org/licenses/lgpl-2.0.html>. They also contain OpenSSL, which is licensed under the OpenSSL license at <https://openssl-library.org/source/license/index.html>.
data/Rakefile CHANGED
@@ -1,18 +1,24 @@
1
- # encoding: UTF-8
2
- require 'rbconfig'
3
- require 'rake'
4
- require 'rake/clean'
5
- require 'rake/extensiontask'
6
- require_relative './ext/tiny_tds/extconsts'
7
-
8
- SPEC = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__))
9
- GEM_PLATFORM_HOSTS = {
10
- 'x86-mingw32' => 'i686-w64-mingw32',
11
- 'x64-mingw32' => 'x86_64-w64-mingw32'
12
- }
1
+ require "rbconfig"
2
+ require "rake"
3
+ require "rake/clean"
4
+ require "rake/extensiontask"
5
+
6
+ SPEC = Gem::Specification.load(File.expand_path("../tiny_tds.gemspec", __FILE__))
7
+
8
+ CrossLibrary = Struct.new :platform, :openssl_config
9
+ CrossLibraries = [
10
+ ["x64-mingw-ucrt", "mingw64"],
11
+ ["x64-mingw32", "mingw64"],
12
+ ["x86_64-linux-gnu", "linux-x86_64"],
13
+ ["x86_64-linux-musl", "linux-x86_64"],
14
+ ["aarch64-linux-gnu", "linux-aarch64"],
15
+ ["aarch64-linux-musl", "linux-aarch64"]
16
+ ].map do |platform, openssl_config|
17
+ CrossLibrary.new platform, openssl_config
18
+ end
13
19
 
14
20
  # Add our project specific files to clean for a rebuild
15
- CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG['DLEXT']},o}"],
21
+ CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG["DLEXT"]},o}"],
16
22
  FileList["exe/*"]
17
23
 
18
24
  # Clobber all our temp files and ports files including .install files
@@ -20,34 +26,42 @@ CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG['DLEXT']},o}"],
20
26
  CLOBBER.include FileList["tmp/**/*"],
21
27
  FileList["ports/**/*"].exclude(%r{^ports/archives})
22
28
 
23
- Dir['tasks/*.rake'].sort.each { |f| load f }
29
+ Dir["tasks/*.rake"].sort.each { |f| load f }
24
30
 
25
- Rake::ExtensionTask.new('tiny_tds', SPEC) do |ext|
26
- ext.lib_dir = 'lib/tiny_tds'
31
+ Rake::ExtensionTask.new("tiny_tds", SPEC) do |ext|
32
+ ext.lib_dir = "lib/tiny_tds"
27
33
  ext.cross_compile = true
28
- ext.cross_platform = GEM_PLATFORM_HOSTS.keys
34
+ ext.cross_platform = CrossLibraries.map(&:platform)
29
35
 
30
36
  # Add dependent DLLs to the cross gems
31
37
  ext.cross_compiling do |spec|
32
38
  # The fat binary gem doesn't depend on the freetds package, since it bundles the library.
33
- spec.metadata.delete('msys2_mingw_dependencies')
34
-
35
- platform_host_map = GEM_PLATFORM_HOSTS
36
- gemplat = spec.platform.to_s
37
- host = platform_host_map[gemplat]
39
+ spec.metadata.delete("msys2_mingw_dependencies")
38
40
 
39
- # We don't need the sources in a fat binary gem
40
- spec.files = spec.files.reject { |f| f =~ %r{^ports\/archives/} }
41
-
42
- # Make sure to include the ports binaries and libraries
43
- spec.files += FileList["ports/#{host}/**/**/{bin,lib}/*"].exclude do |f|
44
- File.directory? f
41
+ if /mingw/.match?(spec.platform.to_s)
42
+ spec.files += [
43
+ "ports/#{spec.platform}/bin/libsybdb-5.dll",
44
+ "ports/#{spec.platform}/bin/defncopy.exe",
45
+ "ports/#{spec.platform}/bin/tsql.exe"
46
+ ]
47
+ elsif /linux/.match?(spec.platform.to_s)
48
+ spec.files += [
49
+ "ports/#{spec.platform}/lib/libsybdb.so.5",
50
+ "ports/#{spec.platform}/bin/defncopy",
51
+ "ports/#{spec.platform}/bin/tsql"
52
+ ]
45
53
  end
54
+ end
46
55
 
47
- spec.files += Dir.glob('exe/*')
56
+ ext.cross_config_options += CrossLibraries.map do |xlib|
57
+ {
58
+ xlib.platform => [
59
+ "--with-cross-build=#{xlib.platform}",
60
+ "--with-openssl-platform=#{xlib.openssl_config}"
61
+ ]
62
+ }
48
63
  end
49
64
  end
50
65
 
51
66
  task build: [:clean, :compile]
52
67
  task default: [:build, :test]
53
-
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.5
1
+ 3.2.0
data/docker-compose.yml CHANGED
@@ -5,18 +5,30 @@ networks:
5
5
 
6
6
  services:
7
7
  mssql:
8
- image: metaskills/mssql-server-linux-tinytds:2017-GA
8
+ image: mcr.microsoft.com/mssql/server:${MSSQL_VERSION:-2017}-latest
9
9
  container_name: sqlserver
10
+ environment:
11
+ ACCEPT_EULA: Y
12
+ MSSQL_SA_PASSWORD: super01S3cUr3
10
13
  ports:
11
14
  - "1433:1433"
12
- networks:
13
- - main-network
15
+ network_mode: "host"
14
16
 
15
17
  toxiproxy:
16
18
  image: shopify/toxiproxy
17
19
  container_name: toxiproxy
18
- ports:
19
- - "8474:8474"
20
- - "1234:1234"
21
- networks:
22
- - main-network
20
+ command: '/toxiproxy -host=127.0.0.1'
21
+ network_mode: "host"
22
+
23
+ cimgruby:
24
+ image: "cimg/ruby:${RUBY_VERSION:-2.7}"
25
+ container_name: cimg_ruby
26
+ environment:
27
+ TESTOPTS: '-v'
28
+ TINYTDS_UNIT_HOST: '127.0.0.1'
29
+ SA_PASSWORD: super01S3cUr3
30
+ TOXIPROXY_HOST: '127.0.0.1'
31
+ command: tail -F anything
32
+ volumes:
33
+ - .:/home/circleci/project
34
+ network_mode: "host"
@@ -232,6 +232,7 @@ static void rb_tinytds_client_free(void *ptr) {
232
232
  dbloginfree(cwrap->login);
233
233
  if (cwrap->client && !cwrap->closed) {
234
234
  dbclose(cwrap->client);
235
+ cwrap->client = NULL;
235
236
  cwrap->closed = 1;
236
237
  cwrap->userdata->closed = 1;
237
238
  }
@@ -263,6 +264,7 @@ static VALUE rb_tinytds_close(VALUE self) {
263
264
  GET_CLIENT_WRAPPER(self);
264
265
  if (cwrap->client && !cwrap->closed) {
265
266
  dbclose(cwrap->client);
267
+ cwrap->client = NULL;
266
268
  cwrap->closed = 1;
267
269
  cwrap->userdata->closed = 1;
268
270
  }
@@ -297,8 +299,7 @@ static VALUE rb_tinytds_execute(VALUE self, VALUE sql) {
297
299
  REQUIRE_OPEN_CLIENT(cwrap);
298
300
  dbcmd(cwrap->client, StringValueCStr(sql));
299
301
  if (dbsqlsend(cwrap->client) == FAIL) {
300
- rb_warn("TinyTds: dbsqlsend() returned FAIL.\n");
301
- return Qfalse;
302
+ rb_raise(cTinyTdsError, "failed dbsqlsend() function");
302
303
  }
303
304
  cwrap->userdata->dbsql_sent = 1;
304
305
  result = rb_tinytds_new_result_obj(cwrap);
@@ -402,17 +403,15 @@ static VALUE rb_tinytds_connect(VALUE self, VALUE opts) {
402
403
  #endif
403
404
  }
404
405
  }
405
- #ifdef DBSETUTF16
406
- if (use_utf16 == Qtrue) { DBSETLUTF16(cwrap->login, 1); }
407
- if (use_utf16 == Qfalse) { DBSETLUTF16(cwrap->login, 0); }
408
- #else
409
- if (use_utf16 == Qtrue || use_utf16 == Qfalse) {
410
- rb_warning("TinyTds: Please consider upgrading to FreeTDS 0.99 or higher for better unicode support.\n");
411
- }
412
- #endif
406
+ if (use_utf16 == Qtrue) { DBSETLUTF16(cwrap->login, 1); }
407
+ if (use_utf16 == Qfalse) { DBSETLUTF16(cwrap->login, 0); }
413
408
 
414
409
  cwrap->client = dbopen(cwrap->login, StringValueCStr(dataserver));
415
410
  if (cwrap->client) {
411
+ if (dbtds(cwrap->client) < 11) {
412
+ rb_raise(cTinyTdsError, "connecting with a TDS version older than 7.3!");
413
+ }
414
+
416
415
  VALUE transposed_encoding, timeout_string;
417
416
 
418
417
  cwrap->closed = 0;
@@ -433,11 +432,7 @@ static VALUE rb_tinytds_connect(VALUE self, VALUE opts) {
433
432
  }
434
433
  transposed_encoding = rb_funcall(cTinyTdsClient, intern_transpose_iconv_encoding, 1, charset);
435
434
  cwrap->encoding = rb_enc_find(StringValueCStr(transposed_encoding));
436
- if (dbtds(cwrap->client) <= 7) {
437
- cwrap->identity_insert_sql = "SELECT CAST(@@IDENTITY AS bigint) AS Ident";
438
- } else {
439
- cwrap->identity_insert_sql = "SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident";
440
- }
435
+ cwrap->identity_insert_sql = "SELECT CAST(SCOPE_IDENTITY() AS bigint) AS Ident";
441
436
  }
442
437
  return self;
443
438
  }