tiny_tds 1.0.4 → 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 (64) hide show
  1. checksums.yaml +5 -5
  2. data/.codeclimate.yml +20 -0
  3. data/.gitattributes +1 -0
  4. data/.github/workflows/ci.yml +590 -0
  5. data/.gitignore +2 -0
  6. data/.rubocop.yml +31 -0
  7. data/{CHANGELOG → CHANGELOG.md} +133 -26
  8. data/Gemfile +1 -5
  9. data/ISSUE_TEMPLATE.md +36 -3
  10. data/README.md +147 -85
  11. data/Rakefile +51 -94
  12. data/VERSION +1 -1
  13. data/docker-compose.yml +34 -0
  14. data/ext/tiny_tds/client.c +149 -67
  15. data/ext/tiny_tds/client.h +11 -5
  16. data/ext/tiny_tds/extconf.rb +144 -283
  17. data/ext/tiny_tds/extconsts.rb +4 -11
  18. data/ext/tiny_tds/result.c +68 -50
  19. data/ext/tiny_tds/tiny_tds_ext.c +4 -1
  20. data/lib/tiny_tds/bin.rb +44 -40
  21. data/lib/tiny_tds/client.rb +63 -55
  22. data/lib/tiny_tds/error.rb +0 -3
  23. data/lib/tiny_tds/gem.rb +23 -0
  24. data/lib/tiny_tds/result.rb +0 -3
  25. data/lib/tiny_tds.rb +37 -32
  26. data/{ports/patches/freetds/1.00 → patches/freetds/1.00.27}/0001-mingw_missing_inet_pton.diff +4 -4
  27. data/patches/freetds/1.00.27/0002-Don-t-use-MSYS2-file-libws2_32.diff +28 -0
  28. data/patches/libiconv/1.14/1-avoid-gets-error.patch +17 -0
  29. data/setup_cimgruby_dev.sh +25 -0
  30. data/start_dev.sh +21 -0
  31. data/tasks/native_gem.rake +16 -0
  32. data/tasks/package.rake +6 -0
  33. data/tasks/ports.rake +24 -0
  34. data/tasks/test.rake +7 -0
  35. data/test/bin/install-freetds.sh +18 -0
  36. data/test/bin/install-mssql.ps1 +42 -0
  37. data/test/bin/install-mssqltools.sh +9 -0
  38. data/test/bin/install-openssl.sh +18 -0
  39. data/test/bin/restore-from-native-gem.ps1 +10 -0
  40. data/test/bin/setup_tinytds_db.sh +7 -0
  41. data/test/bin/setup_volume_permissions.sh +10 -0
  42. data/test/client_test.rb +161 -112
  43. data/test/gem_test.rb +100 -0
  44. data/test/result_test.rb +293 -313
  45. data/test/schema_test.rb +369 -395
  46. data/test/sql/db-create.sql +18 -0
  47. data/test/sql/db-login.sql +38 -0
  48. data/test/test_helper.rb +116 -85
  49. data/test/thread_test.rb +22 -31
  50. data/tiny_tds.gemspec +27 -24
  51. metadata +109 -56
  52. data/appveyor.yml +0 -51
  53. data/test/appveyor/dbsetup.ps1 +0 -27
  54. data/test/appveyor/dbsetup.sql +0 -9
  55. data/test/benchmark/query.rb +0 -77
  56. data/test/benchmark/query_odbc.rb +0 -106
  57. data/test/benchmark/query_tinytds.rb +0 -126
  58. data/test/schema/sqlserver_2000.sql +0 -140
  59. data/test/schema/sqlserver_2005.sql +0 -140
  60. data/test/schema/sqlserver_2014.sql +0 -140
  61. data/test/schema/sybase_ase.sql +0 -138
  62. /data/bin/{defncopy → defncopy-ttds} +0 -0
  63. /data/bin/{tsql → tsql-ttds} +0 -0
  64. /data/test/schema/{sqlserver_2008.sql → sqlserver_2017.sql} +0 -0
data/README.md CHANGED
@@ -1,10 +1,13 @@
1
1
  # TinyTDS - Simple and fast FreeTDS bindings for Ruby using DB-Library.
2
2
 
3
- [![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) [![Gem Version](https://img.shields.io/gem/v/tiny_tds.svg)](https://rubygems.org/gems/tiny_tds) [![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)
3
+ * [![Gem Version](https://img.shields.io/gem/v/tiny_tds.svg)](https://rubygems.org/gems/tiny_tds) - Gem Version
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
4
5
 
5
- 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.
6
+ ## About TinyTDS
6
7
 
7
- 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.
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.
9
+
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.
8
11
 
9
12
  The API is simple and consists of these classes:
10
13
 
@@ -15,54 +18,71 @@ The API is simple and consists of these classes:
15
18
 
16
19
  ## Install
17
20
 
18
- Installing with rubygems should just work. TinyTDS is currently tested on Ruby version 2.0.0 and upward.
21
+ tiny_tds is tested with Ruby v2.7 and upwards.
19
22
 
20
- ```
21
- $ gem install tiny_tds
23
+ ### Windows and Linux (64-bit)
24
+
25
+ We precompile tiny_tds with FreeTDS and supporting libraries, which are dynamically linked at runtime. Therefore, you can run:
26
+
27
+ ```shell
28
+ gem install tiny_tds
22
29
  ```
23
30
 
24
- If you use Windows, we pre-compile TinyTDS with static versions of FreeTDS, libiconv, and OpenSSL. On all other platforms, we will find these dependencies. If none exist, our native extension will use MiniPortile to install any missing dependencies listed above for your specific platform. These dependencies will be built and linked within the installed TinyTDS gem. 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.
25
32
 
33
+ You can also avoid getting the platform-specific gem if you want to compile FreeTDS and supporting libraries yourself:
34
+
35
+ ```shell
36
+ gem install tiny_tds --platform ruby
26
37
  ```
27
- --enable-system-freetds / --disable-system-freetds
28
- --enable-system-iconv / --disable-system-iconv
29
- --enable-system-openssl / --disable-system-openssl
30
- Force use of system or builtin freetds/iconv/openssl library.
31
- Default is to prefer system libraries and fallback to builtin.
32
38
 
33
- --with-freetds-dir=DIR
34
- Use the freetds library placed under DIR.
39
+ ### Mac
35
40
 
36
- --enable-lookup
37
- Search for freetds through all paths in the PATH environment variable.
41
+ Install FreeTDS via Homebrew:
38
42
 
39
- --enable-cross-build
40
- Do cross-build.
43
+ ```shell
44
+ brew install openssl@3 libiconv
45
+ brew install freetds
41
46
  ```
42
47
 
48
+ Then you can install tiny_tds:
43
49
 
44
- ## FreeTDS Compatibility & Configuration
50
+ ```shell
51
+ gem install tiny_tds
52
+ ```
45
53
 
46
- 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
47
55
 
48
- **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.
49
57
 
50
- * **Do I need to install FreeTDS?** Yes! Somehow, someway, you are going to need FreeTDS for TinyTDS to compile against. You can avoid installing FreeTDS on your system by using our projects usage of rake-compiler and mini_portile to compile and package a native gem just for you. See the "Using MiniPortile" section below.
58
+ ```shell
59
+ $ apt-get install wget
60
+ $ apt-get install build-essential
61
+ $ apt-get install libc6-dev
51
62
 
52
- * **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
+ ```
53
70
 
54
- * **Do I need to configure `--with-tdsver` equal to anything?** Most likely! Technically you should not have too. 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.
55
72
 
56
- * **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
+ ```
57
76
 
58
- * **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
59
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.
60
80
 
61
81
  ## Data Types
62
82
 
63
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.
64
84
 
65
- 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.
66
86
 
67
87
  * [date]
68
88
  * [datetime2]
@@ -89,9 +109,22 @@ Creating a new client takes a hash of options. For valid iconv encoding options,
89
109
  * :appname - Short string seen in SQL Servers process/activity window.
90
110
  * :tds_version - TDS version. Defaults to "7.3".
91
111
  * :login_timeout - Seconds to wait for login. Default to 60 seconds.
92
- * :timeout - Seconds to wait for a response to a SQL command. Default 5 seconds.
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).
93
113
  * :encoding - Any valid iconv value like CP1251 or ISO-8859-1. Default UTF-8.
94
114
  * :azure - Pass true to signal that you are connecting to azure.
115
+ * :contained - Pass true to signal that you are connecting with a contained database user.
116
+ * :use_utf16 - Instead of using UCS-2 for database wide character encoding use UTF-16. Newer Windows versions use this encoding instead of UCS-2. Default true.
117
+ * :message_handler - Pass in a `call`-able object such as a `Proc` or a method to receive info messages from the database. It should have a single parameter, which will be a `TinyTds::Error` object representing the message. For example:
118
+
119
+ ```ruby
120
+ opts = ... # host, username, password, etc
121
+ opts[:message_handler] = Proc.new { |m| puts m.message }
122
+ client = TinyTds::Client.new opts
123
+ # => Changed database context to 'master'.
124
+ # => Changed language setting to us_english.
125
+ client.execute("print 'hello world!'").do
126
+ # => hello world!
127
+ ```
95
128
 
96
129
  Use the `#active?` method to determine if a connection is good. The implementation of this method may change but it should always guarantee that a connection is good. Current it checks for either a closed or dead connection.
97
130
 
@@ -288,9 +321,13 @@ By default row caching is turned on because the SQL Server adapter for ActiveRec
288
321
  TinyTDS takes an opinionated stance on how we handle encoding errors. First, we treat errors differently on reads vs. writes. Our opinion is that if you are reading bad data due to your client's encoding option, you would rather just find `?` marks in your strings vs being blocked with exceptions. This is how things wold work via ODBC or SMS. On the other hand, writes will raise an exception. In this case we raise the SYBEICONVO/2402 error message which has a description of `Error converting characters into server's character set. Some character(s) could not be converted.`. Even though the severity of this message is only a `4` and TinyTDS will automatically strip/ignore unknown characters, we feel you should know that you are inserting bad encodings. In this way, a transaction can be rolled back, etc. Remember, any database write that has bad characters due to the client encoding will still be written to the database, but it is up to you rollback said write if needed. Most ORMs like ActiveRecord handle this scenario just fine.
289
322
 
290
323
 
324
+ ## Timeout Error Handling
325
+
326
+ TinyTDS will raise a `TinyTDS::Error` when a timeout is reached based on the options supplied to the client. Depending on the reason for the timeout, the connection could be dead or alive. When db processing is the cause for the timeout, the connection should still be usable after the error is raised. When network failure is the cause of the timeout, the connection will be dead. If you attempt to execute another command batch on a dead connection you will see a `DBPROCESS is dead or not enabled` error. Therefore, it is recommended to check for a `dead?` connection before trying to execute another command batch.
327
+
291
328
  ## Binstubs
292
329
 
293
- The TinyTDS gem uses binstub wrappers which mirror compiled [FreeTDS Utilities](http://www.freetds.org/userguide/usefreetds.htm) binaries. These native executables are usually installed at the system level when installing FreeTDS. However, when using MiniPortile to install TinyTDS as we do with Windows binaries, these binstubs will find and prefer local gem `exe` directory executables. These are the following binstubs we wrap.
330
+ The TinyTDS gem uses binstub wrappers which mirror compiled [FreeTDS Utilities](https://www.freetds.org/userguide/usefreetds.html) binaries. These native executables are usually installed at the system level when installing FreeTDS. However, when using MiniPortile to install TinyTDS as we do with Windows binaries, these binstubs will find and prefer local gem `exe` directory executables. These are the following binstubs we wrap.
294
331
 
295
332
  * tsql - Used to test connections and debug compile time settings.
296
333
  * defncopy - Used to dump schema structures.
@@ -309,104 +346,131 @@ TinyTDS is fully tested with the Azure platform. You must set the `azure: true`
309
346
 
310
347
  **IMPORTANT**: Do not use `username@server.database.windows.net` for the username connection option! You must use the shorter `username@server` instead!
311
348
 
312
- We recommend the following settings when using TinyTDS with Azure. These are the same settings used in the ActiveRecord SQL Server adapter.
349
+ Also, please read the [Azure SQL Database General Guidelines and Limitations](https://msdn.microsoft.com/en-us/library/ee336245.aspx) MSDN article to understand the differences. Specifically, the connection constraints section!
350
+
351
+ ## Connection Settings
352
+
353
+ A DBLIB connection does not have the same default SET options for a standard SMS SQL Server connection. Hence, we recommend the following options post establishing your connection.
354
+
355
+ #### SQL Server
313
356
 
314
357
  ```sql
315
- SET ANSI_NULLS ON
358
+ SET ANSI_DEFAULTS ON
359
+
360
+ SET QUOTED_IDENTIFIER ON
316
361
  SET CURSOR_CLOSE_ON_COMMIT OFF
317
- SET ANSI_NULL_DFLT_ON ON
318
362
  SET IMPLICIT_TRANSACTIONS OFF
319
- SET ANSI_PADDING ON
320
- SET QUOTED_IDENTIFIER ON
321
- SET ANSI_WARNINGS ON
363
+ SET TEXTSIZE 2147483647
364
+ SET CONCAT_NULL_YIELDS_NULL ON
322
365
  ```
323
366
 
324
- Also, please read the [Azure SQL Database General Guidelines and Limitations](https://msdn.microsoft.com/en-us/library/ee336245.aspx) MSDN article to understand the differences. Specifically, the connection constraints section!
325
-
367
+ #### Azure
326
368
 
327
- ## Emoji Support 😍
328
-
329
- This is possible using FreeTDS version 0.95 or higher. You must 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`.
369
+ ```sql
370
+ SET ANSI_NULLS ON
371
+ SET ANSI_NULL_DFLT_ON ON
372
+ SET ANSI_PADDING ON
373
+ SET ANSI_WARNINGS ON
330
374
 
331
- ```ini
332
- [global]
333
- use utf-16 = true
375
+ SET QUOTED_IDENTIFIER ON
376
+ SET CURSOR_CLOSE_ON_COMMIT OFF
377
+ SET IMPLICIT_TRANSACTIONS OFF
378
+ SET TEXTSIZE 2147483647
379
+ SET CONCAT_NULL_YIELDS_NULL ON
334
380
  ```
335
381
 
336
- Good news! If you are using FreeTDS v1.0 or later, then `use utf-16` is set true by default!
337
382
 
383
+ ## Thread Safety
338
384
 
339
- ## Using MiniPortile
385
+ TinyTDS must be used with a connection pool for thread safety. If you use ActiveRecord or the [Sequel](https://github.com/jeremyevans/sequel) gem this is done for you. However, if you are using TinyTDS on your own, we recommend using the ConnectionPool gem when using threads:
340
386
 
341
- MiniPortile is a minimalistic implementation of a port/recipe system. <https://github.com/luislavena/mini_portile>
387
+ * ConnectionPool Gem - https://github.com/mperham/connection_pool
342
388
 
343
- The TinyTDS project uses MiniPortile so that we can easily install a local version of FreeTDS and supporting libraries to link against when building a test version of TinyTDS. This same system is also used when installing TinyTDS with Rubygems and building native extensions. It is possible to build TinyTDS with a specific version of FreeTDS using the `TINYTDS_FREETDS_VERSION` environment variable. Here are some exampbles of possible values.
389
+ Please read our [thread_test.rb](https://github.com/rails-sqlserver/tiny_tds/blob/master/test/thread_test.rb) file for details on how we test its usage.
344
390
 
345
- ```
346
- $ rake TDSVER='7.1' TINYTDS_FREETDS_VERSION='0.95' -- --disable-system-freetds --disable-system-iconv
347
- ```
348
-
349
- To find out more about the FreeTDS release system [visit this thread](http://lists.ibiblio.org/pipermail/freetds/2012q1/027756.html) on their mailing list. You can also browse thier FTP server [ftp://ftp.astron.com/pub/freetds/](ftp://ftp.astron.com/pub/freetds/) for version number strings.
350
391
 
392
+ ## Emoji Support 😍
351
393
 
352
- ## Compiling Gems for Windows
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.
353
395
 
354
- For the convenience of Windows users, TinyTDS ships pre-compiled gems for Ruby 2.0, 2.1 and 2.2 on Windows. In order to generate these gems, [rake-compiler-dock](https://github.com/rake-compiler/rake-compiler-dock) is used. This project provides a [Docker image](https://registry.hub.docker.com/u/larskanis/rake-compiler-dock/) with rvm, cross-compilers and a number of different target versions of Ruby.
396
+ ## Development & Testing
355
397
 
356
- 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:
398
+ First, clone the repo using the command line or your Git GUI of choice.
357
399
 
358
- ```
359
- $ rake gem:windows
400
+ ```shell
401
+ $ git clone git@github.com:rails-sqlserver/tiny_tds.git
360
402
  ```
361
403
 
362
- The compiled gems will exist in `./pkg` directory.
404
+ After that, the quickest way to get setup for development is to use [Docker](https://www.docker.com/). Assuming you have [downloaded docker](https://www.docker.com/products/docker) for your platform, you can use [docker-compose](https://docs.docker.com/compose/install/) to run the necessary containers for testing.
363
405
 
406
+ ```shell
407
+ $ docker-compose up -d
408
+ ```
364
409
 
365
- ## Development & Testing
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:
366
411
 
367
- First make sure your local database has a `[tinytdstest]` database with a owner login named `[tinytds]` having no password. The following SQL run via the `sa` account should set that up for you.
412
+ ```shell
413
+ $ docker network create main-network
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
416
+ $ docker pull shopify/toxiproxy
417
+ $ docker run -p 8474:8474 -p 1234:1234 -d --name toxiproxy --network main-network shopify/toxiproxy
418
+ ```
419
+
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).
368
421
 
369
- ```bash
370
- $ tsql -H <host> -p 1433 -U sa -P <pass>
371
- $ sqsh -H <host> -p 1433 -U sa -P <pass>
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
372
425
  ```
373
426
 
374
- ```sql
375
- CREATE DATABASE [tinytdstest];
376
- GO
377
- CREATE LOGIN [tinytds] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [tinytdstest];
378
- GO
379
- USE [tinytdstest];
380
- CREATE USER [tinytds] FOR LOGIN [tinytds];
381
- GO
382
- EXEC sp_addrolemember N'db_owner', N'tinytds';
383
- GO
427
+ From here you can build and run tests against an installed version of FreeTDS.
428
+
429
+ ```shell
430
+ $ bundle install
431
+ $ bundle exec rake
384
432
  ```
385
433
 
386
- We use bundler for development. Simply run `bundle install` then `rake` to build the gem and run the unit tests. Before running the test rake task, you may need to define a pair of environment variables that help the client connect to your specific FreeTDS database server name and which schema (2000, 2005, 2008, 2014, Azure or Sybase ASE) to use. For example:
434
+ Examples us using enviornment variables to customize the test task.
387
435
 
388
436
  ```
389
437
  $ rake TINYTDS_UNIT_DATASERVER=mydbserver
390
- or
391
- $ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2008
392
- or
438
+ $ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2017
393
439
  $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure
394
- or
395
- $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_UNIT_PORT=5000 TINYTDS_SCHEMA=sybase_ase
396
440
  ```
397
441
 
398
- If you do not want to use MiniPortile to compile a local project version of FreeTDS and instead use your local system version, use the `TINYTDS_SKIP_PORTS` environment variable. This will ignore any port tasks and will instead build and link to your system's FreeTDS installation as a normal gem install would.
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.
399
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
400
457
  ```
401
- $ rake TINYTDS_SKIP_PORTS=1
458
+
459
+ The compiled gems will exist in `./pkg` directory.
460
+
461
+ If you only need a specific gem for one platform and architecture, run this command:
462
+
463
+ ```shell
464
+ bundle exec rake gem:native:x64-mingw-ucrt
402
465
  ```
403
466
 
467
+ All the supported architectures and platforms are listed in the `Rakefile` in the `CrossLibraries` constant.
404
468
 
405
469
  ## Help & Support
406
470
 
407
471
  * Github Source: http://github.com/rails-sqlserver/tiny_tds
408
472
  * Github Issues: http://github.com/rails-sqlserver/tiny_tds/issues
409
- * Google Group: http://groups.google.com/group/rails-sqlserver-adapter
473
+ * Gitter Chat: https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter
410
474
  * IRC Room: #rails-sqlserver on irc.freenode.net
411
475
 
412
476
 
@@ -426,6 +490,4 @@ My name is Ken Collins and I currently maintain the SQL Server adapter for Activ
426
490
 
427
491
  ## License
428
492
 
429
- 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>
430
-
431
-
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,110 +1,67 @@
1
- # encoding: UTF-8
2
- require 'rake'
3
- require 'rake/clean'
4
- require 'rbconfig'
5
- require 'rake/testtask'
6
- require 'rake/extensiontask'
7
- require 'rubygems/package_task'
8
- require_relative './ext/tiny_tds/extconsts'
1
+ require "rbconfig"
2
+ require "rake"
3
+ require "rake/clean"
4
+ require "rake/extensiontask"
9
5
 
10
- def test_libs
11
- ['lib','test']
12
- end
13
-
14
- def test_files
15
- if ENV['TEST_FILES']
16
- ENV['TEST_FILES'].split(',').map{ |f| f.strip }.sort
17
- else
18
- Dir.glob("test/**/*_test.rb").sort
19
- end
20
- end
21
-
22
- def add_file_to_gem(spec, relative_path)
23
- target_path = File.join gem_build_path(spec), relative_path
24
- target_dir = File.dirname(target_path)
25
- mkdir_p target_dir
26
- rm_f target_path
27
- safe_ln relative_path, target_path
28
- spec.files += [relative_path]
29
- end
30
-
31
- def gem_build_path(spec)
32
- File.join 'pkg', spec.full_name
33
- end
34
-
35
- gemspec = Gem::Specification::load(File.expand_path('../tiny_tds.gemspec', __FILE__))
36
-
37
- Rake::TestTask.new do |t|
38
- t.libs = test_libs
39
- t.test_files = test_files
40
- t.verbose = true
41
- end
6
+ SPEC = Gem::Specification.load(File.expand_path("../tiny_tds.gemspec", __FILE__))
42
7
 
43
- Gem::PackageTask.new(gemspec) do |pkg|
44
- pkg.need_tar = false
45
- pkg.need_zip = false
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
46
18
  end
47
19
 
48
- task :compile
20
+ # Add our project specific files to clean for a rebuild
21
+ CLEAN.include FileList["{ext,lib}/**/*.{so,#{RbConfig::CONFIG["DLEXT"]},o}"],
22
+ FileList["exe/*"]
49
23
 
50
- task :build => [:clean, :compile]
51
- task(:build_quietly) { capture_stds { Rake::Task[:build].invoke } }
52
-
53
- task :default => [:build, :test]
24
+ # Clobber all our temp files and ports files including .install files
25
+ # and archives
26
+ CLOBBER.include FileList["tmp/**/*"],
27
+ FileList["ports/**/*"].exclude(%r{^ports/archives})
54
28
 
55
29
  Dir["tasks/*.rake"].sort.each { |f| load f }
56
30
 
57
- Rake::ExtensionTask.new('tiny_tds', gemspec) do |ext|
58
- ext.lib_dir = 'lib/tiny_tds'
31
+ Rake::ExtensionTask.new("tiny_tds", SPEC) do |ext|
32
+ ext.lib_dir = "lib/tiny_tds"
59
33
  ext.cross_compile = true
60
- ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
61
- ext.cross_config_options += %w[ --disable-lookup --enable-cross-build ]
34
+ ext.cross_platform = CrossLibraries.map(&:platform)
35
+
62
36
  # Add dependent DLLs to the cross gems
63
37
  ext.cross_compiling do |spec|
64
- platform_host_map = {
65
- 'x86-mingw32' => 'i686-w64-mingw32',
66
- 'x64-mingw32' => 'x86_64-w64-mingw32'
67
- }
68
- gemplat = spec.platform.to_s
69
- host = platform_host_map[gemplat]
70
- dlls = [
71
- "libeay32-1.0.2g-#{host}.dll",
72
- "ssleay32-1.0.2g-#{host}.dll",
73
- "libiconv-2.dll",
74
- "libsybdb-5.dll",
75
- ]
76
- # We don't need the sources in a fat binary gem
77
- spec.files = spec.files.reject { |f| f=~/^ports\/archives/ }
78
- spec.files += dlls.map { |dll| "ports/#{host}/bin/#{File.basename(dll)}" }
79
- spec.files += Dir.glob('exe/*')
80
- dlls.each do |dll|
81
- file "ports/#{host}/bin/#{dll}" do |t|
82
- sh "x86_64-w64-mingw32-strip", t.name
83
- end
38
+ # The fat binary gem doesn't depend on the freetds package, since it bundles the library.
39
+ spec.metadata.delete("msys2_mingw_dependencies")
40
+
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
+ ]
84
53
  end
85
54
  end
86
- end
87
55
 
88
- # Bundle the freetds sources to avoid download while gem install.
89
- task gem_build_path(gemspec) do
90
- add_file_to_gem gemspec, "ports/archives/freetds-#{FREETDS_VERSION}.tar.bz2"
91
- end
92
-
93
- desc "Build the windows binary gems per rake-compiler-dock"
94
- task 'gem:windows' do
95
- require 'rake_compiler_dock'
96
- RakeCompilerDock.sh <<-EOT
97
- bundle && rake cross native gem RUBY_CC_VERSION=2.0.0:2.1.6:2.2.2:2.3.0 CFLAGS="-Wall"
98
- EOT
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
+ }
63
+ end
99
64
  end
100
65
 
101
- def capture_stds
102
- pstdout, $stdout = $stdout, StringIO.new
103
- pstderr, $stderr = $stderr, StringIO.new
104
- yield
105
- $stdout.string
106
- $stderr.string
107
- ensure
108
- $stdout = pstdout
109
- $stderr = pstderr
110
- end
66
+ task build: [:clean, :compile]
67
+ task default: [:build, :test]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.4
1
+ 3.2.0
@@ -0,0 +1,34 @@
1
+ version: '3'
2
+
3
+ networks:
4
+ main-network:
5
+
6
+ services:
7
+ mssql:
8
+ image: mcr.microsoft.com/mssql/server:${MSSQL_VERSION:-2017}-latest
9
+ container_name: sqlserver
10
+ environment:
11
+ ACCEPT_EULA: Y
12
+ MSSQL_SA_PASSWORD: super01S3cUr3
13
+ ports:
14
+ - "1433:1433"
15
+ network_mode: "host"
16
+
17
+ toxiproxy:
18
+ image: shopify/toxiproxy
19
+ container_name: toxiproxy
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"