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.
- checksums.yaml +5 -5
- data/.codeclimate.yml +20 -0
- data/.gitattributes +1 -0
- data/.github/workflows/ci.yml +590 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +31 -0
- data/{CHANGELOG → CHANGELOG.md} +133 -26
- data/Gemfile +1 -5
- data/ISSUE_TEMPLATE.md +36 -3
- data/README.md +147 -85
- data/Rakefile +51 -94
- data/VERSION +1 -1
- data/docker-compose.yml +34 -0
- data/ext/tiny_tds/client.c +149 -67
- data/ext/tiny_tds/client.h +11 -5
- data/ext/tiny_tds/extconf.rb +144 -283
- data/ext/tiny_tds/extconsts.rb +4 -11
- data/ext/tiny_tds/result.c +68 -50
- data/ext/tiny_tds/tiny_tds_ext.c +4 -1
- data/lib/tiny_tds/bin.rb +44 -40
- data/lib/tiny_tds/client.rb +63 -55
- data/lib/tiny_tds/error.rb +0 -3
- data/lib/tiny_tds/gem.rb +23 -0
- data/lib/tiny_tds/result.rb +0 -3
- data/lib/tiny_tds.rb +37 -32
- data/{ports/patches/freetds/1.00 → patches/freetds/1.00.27}/0001-mingw_missing_inet_pton.diff +4 -4
- data/patches/freetds/1.00.27/0002-Don-t-use-MSYS2-file-libws2_32.diff +28 -0
- data/patches/libiconv/1.14/1-avoid-gets-error.patch +17 -0
- data/setup_cimgruby_dev.sh +25 -0
- data/start_dev.sh +21 -0
- data/tasks/native_gem.rake +16 -0
- data/tasks/package.rake +6 -0
- data/tasks/ports.rake +24 -0
- data/tasks/test.rake +7 -0
- data/test/bin/install-freetds.sh +18 -0
- data/test/bin/install-mssql.ps1 +42 -0
- data/test/bin/install-mssqltools.sh +9 -0
- data/test/bin/install-openssl.sh +18 -0
- data/test/bin/restore-from-native-gem.ps1 +10 -0
- data/test/bin/setup_tinytds_db.sh +7 -0
- data/test/bin/setup_volume_permissions.sh +10 -0
- data/test/client_test.rb +161 -112
- data/test/gem_test.rb +100 -0
- data/test/result_test.rb +293 -313
- data/test/schema_test.rb +369 -395
- data/test/sql/db-create.sql +18 -0
- data/test/sql/db-login.sql +38 -0
- data/test/test_helper.rb +116 -85
- data/test/thread_test.rb +22 -31
- data/tiny_tds.gemspec +27 -24
- metadata +109 -56
- data/appveyor.yml +0 -51
- data/test/appveyor/dbsetup.ps1 +0 -27
- data/test/appveyor/dbsetup.sql +0 -9
- data/test/benchmark/query.rb +0 -77
- data/test/benchmark/query_odbc.rb +0 -106
- data/test/benchmark/query_tinytds.rb +0 -126
- data/test/schema/sqlserver_2000.sql +0 -140
- data/test/schema/sqlserver_2005.sql +0 -140
- data/test/schema/sqlserver_2014.sql +0 -140
- data/test/schema/sybase_ase.sql +0 -138
- /data/bin/{defncopy → defncopy-ttds} +0 -0
- /data/bin/{tsql → tsql-ttds} +0 -0
- /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
|
-
|
3
|
+
* [](https://rubygems.org/gems/tiny_tds) - Gem Version
|
4
|
+
* [](https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter) - Community
|
4
5
|
|
5
|
-
|
6
|
+
## About TinyTDS
|
6
7
|
|
7
|
-
TinyTDS
|
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
|
-
|
21
|
+
tiny_tds is tested with Ruby v2.7 and upwards.
|
19
22
|
|
20
|
-
|
21
|
-
|
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
|
-
|
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
|
-
|
34
|
-
Use the freetds library placed under DIR.
|
39
|
+
### Mac
|
35
40
|
|
36
|
-
|
37
|
-
Search for freetds through all paths in the PATH environment variable.
|
41
|
+
Install FreeTDS via Homebrew:
|
38
42
|
|
39
|
-
|
40
|
-
|
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
|
-
|
50
|
+
```shell
|
51
|
+
gem install tiny_tds
|
52
|
+
```
|
45
53
|
|
46
|
-
|
54
|
+
### Everybody else
|
47
55
|
|
48
|
-
|
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
|
-
|
58
|
+
```shell
|
59
|
+
$ apt-get install wget
|
60
|
+
$ apt-get install build-essential
|
61
|
+
$ apt-get install libc6-dev
|
51
62
|
|
52
|
-
|
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
|
-
|
71
|
+
You can also tell `tiny_tds` where to find your FreeTDS installation.
|
55
72
|
|
56
|
-
|
73
|
+
```shell
|
74
|
+
gem install tiny_tds -- --with-freetds-dir=/opt/freetds
|
75
|
+
```
|
57
76
|
|
58
|
-
|
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.
|
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](
|
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
|
-
|
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
|
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
|
320
|
-
SET
|
321
|
-
SET ANSI_WARNINGS ON
|
363
|
+
SET TEXTSIZE 2147483647
|
364
|
+
SET CONCAT_NULL_YIELDS_NULL ON
|
322
365
|
```
|
323
366
|
|
324
|
-
|
325
|
-
|
367
|
+
#### Azure
|
326
368
|
|
327
|
-
|
328
|
-
|
329
|
-
|
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
|
-
|
332
|
-
|
333
|
-
|
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
|
-
|
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
|
-
|
387
|
+
* ConnectionPool Gem - https://github.com/mperham/connection_pool
|
342
388
|
|
343
|
-
|
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
|
-
|
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
|
-
|
396
|
+
## Development & Testing
|
355
397
|
|
356
|
-
|
398
|
+
First, clone the repo using the command line or your Git GUI of choice.
|
357
399
|
|
358
|
-
```
|
359
|
-
$
|
400
|
+
```shell
|
401
|
+
$ git clone git@github.com:rails-sqlserver/tiny_tds.git
|
360
402
|
```
|
361
403
|
|
362
|
-
|
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
|
-
|
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
|
-
|
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
|
-
```
|
370
|
-
|
371
|
-
|
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
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
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
|
-
|
434
|
+
Examples us using enviornment variables to customize the test task.
|
387
435
|
|
388
436
|
```
|
389
437
|
$ rake TINYTDS_UNIT_DATASERVER=mydbserver
|
390
|
-
|
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
|
-
|
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
|
-
|
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
|
-
*
|
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
|
-
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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
|
-
|
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
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
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(
|
58
|
-
ext.lib_dir =
|
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 =
|
61
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
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
|
-
|
102
|
-
|
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
|
+
3.2.0
|
data/docker-compose.yml
ADDED
@@ -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"
|