From 13f9c93af3e02bad04821281232dd57637d4fff5 Mon Sep 17 00:00:00 2001 From: Andy Pfister Date: Thu, 28 Mar 2024 20:43:33 +0100 Subject: [PATCH] Remove code no longer relevant when dropping support for SQL Server < 2017 --- README.md | 44 +- ext/tiny_tds/client.c | 10 +- ext/tiny_tds/result.c | 54 +-- tasks/ports/freetds.rb | 7 +- test/client_test.rb | 7 +- test/result_test.rb | 291 +++++-------- test/schema/sqlserver_2000.sql | 140 ------ test/schema/sqlserver_2005.sql | 140 ------ test/schema/sqlserver_2008.sql | 140 ------ test/schema/sqlserver_2014.sql | 140 ------ test/schema/sybase_ase.sql | 138 ------ test/schema_test.rb | 754 ++++++++++++++++----------------- test/test_helper.rb | 40 +- 13 files changed, 514 insertions(+), 1391 deletions(-) delete mode 100644 test/schema/sqlserver_2000.sql delete mode 100644 test/schema/sqlserver_2005.sql delete mode 100644 test/schema/sqlserver_2008.sql delete mode 100644 test/schema/sqlserver_2014.sql delete mode 100644 test/schema/sybase_ase.sql diff --git a/README.md b/README.md index 69e7b943..00e59335 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,9 @@ ## About TinyTDS -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. +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. -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. +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 API is simple and consists of these classes: @@ -19,14 +19,14 @@ The API is simple and consists of these classes: ## Install -Installing with rubygems should just work. TinyTDS is currently tested on Ruby version 2.0.0 and upward. +Installing with rubygems should just work. TinyTDS is currently tested on Ruby version 2.7.0 and upward. ``` $ gem install tiny_tds ``` If you use Windows, we pre-compile TinyTDS with static versions of FreeTDS and supporting libraries. -If you're using RubyInstaller the binary gem will require that devkit is installed and in your path to operate properly. +If you're using RubyInstaller, the binary gem will require that devkit is installed and in your path to operate properly. 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. @@ -35,10 +35,10 @@ $ apt-get install wget $ apt-get install build-essential $ apt-get install libc6-dev -$ wget http://www.freetds.org/files/stable/freetds-1.1.24.tar.gz -$ tar -xzf freetds-1.1.24.tar.gz -$ cd freetds-1.1.24 -$ ./configure --prefix=/usr/local --with-tdsver=7.3 +$ wget http://www.freetds.org/files/stable/freetds-1.4.10.tar.gz +$ tar -xzf freetds-1.4.10.tar.gz +$ cd freetds-1.4.10 +$ ./configure --prefix=/usr/local --with-tdsver=7.4 $ make $ make install ``` @@ -53,26 +53,22 @@ Please read the MiniPortile and/or Windows sections at the end of this file for ## Getting Started -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. - -* [SQL Server on a Mac](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/mac) -* [SQL Server on RHEL](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/rhel) -* [SQL Server on Ubuntu](https://www.microsoft.com/en-us/sql-server/developer-get-started/ruby/ubuntu) +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. ## FreeTDS Compatibility & Configuration -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. +TinyTDS is developed against FreeTDs 1.1+. We also test with SQL Server 2017, 2019, 2022 and Azure. Older version of SQL Server or FreeTDS could work, but are not supported. -**NOTE:** Windows users of our pre-compiled native gems need not worry about installing FreeTDS and its dependencies. +> [!IMPORTANT] +> +> Windows users of our pre-compiled native gems need not worry about installing FreeTDS and its dependencies. * **Do I need to install FreeTDS?** Yes! Somehow, someway, you are going to need FreeTDS for TinyTDS to compile against. * **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. -* **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. - -* **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 +* **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.4. * **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! @@ -81,7 +77,7 @@ TinyTDS is developed against FreeTDS 0.95, 0.99, and 1.0 current. Our default an 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. -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. +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. * [date] * [datetime2] @@ -108,7 +104,7 @@ Creating a new client takes a hash of options. For valid iconv encoding options, * :appname - Short string seen in SQL Servers process/activity window. * :tds_version - TDS version. Defaults to "7.3". * :login_timeout - Seconds to wait for login. Default to 60 seconds. -* :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). +* :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). * :encoding - Any valid iconv value like CP1251 or ISO-8859-1. Default UTF-8. * :azure - Pass true to signal that you are connecting to azure. * :contained - Pass true to signal that you are connecting with a contained database user. @@ -390,16 +386,13 @@ Please read our [thread_test.rb](https://github.com/rails-sqlserver/tiny_tds/blo ## Emoji Support 😍 -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`. +This is possible. 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`. ```ini [global] use utf-16 = true ``` -The default is true and since FreeTDS v1.0 would do this as well. - - ## Compiling Gems for Windows 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. @@ -461,9 +454,8 @@ Examples us using enviornment variables to customize the test task. ``` $ rake TINYTDS_UNIT_DATASERVER=mydbserver -$ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2008 +$ rake TINYTDS_UNIT_DATASERVER=mydbserver TINYTDS_SCHEMA=sqlserver_2016 $ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_SCHEMA=sqlserver_azure -$ rake TINYTDS_UNIT_HOST=mydb.host.net TINYTDS_UNIT_PORT=5000 TINYTDS_SCHEMA=sybase_ase ``` ## Docker Builds diff --git a/ext/tiny_tds/client.c b/ext/tiny_tds/client.c index ea01d144..a76ec327 100644 --- a/ext/tiny_tds/client.c +++ b/ext/tiny_tds/client.c @@ -404,14 +404,8 @@ static VALUE rb_tinytds_connect(VALUE self, VALUE opts) { #endif } } - #ifdef DBSETUTF16 - if (use_utf16 == Qtrue) { DBSETLUTF16(cwrap->login, 1); } - if (use_utf16 == Qfalse) { DBSETLUTF16(cwrap->login, 0); } - #else - if (use_utf16 == Qtrue || use_utf16 == Qfalse) { - rb_warning("TinyTds: Please consider upgrading to FreeTDS 0.99 or higher for better unicode support.\n"); - } - #endif + if (use_utf16 == Qtrue) { DBSETLUTF16(cwrap->login, 1); } + if (use_utf16 == Qfalse) { DBSETLUTF16(cwrap->login, 0); } cwrap->client = dbopen(cwrap->login, StringValueCStr(dataserver)); if (cwrap->client) { diff --git a/ext/tiny_tds/result.c b/ext/tiny_tds/result.c index 52d32230..3bc8845c 100644 --- a/ext/tiny_tds/result.c +++ b/ext/tiny_tds/result.c @@ -302,38 +302,30 @@ static VALUE rb_tinytds_result_fetch_row(VALUE self, ID timezone, int symbolize_ case 41: // SYBMSTIME case 42: // SYBMSDATETIME2 case 43: { // SYBMSDATETIMEOFFSET - #ifdef DBVERSION_73 - if (dbtds(rwrap->client) >= DBTDS_7_3) { - DBDATEREC2 dr2; - dbanydatecrack(rwrap->client, &dr2, coltype, data); - switch(coltype) { - case 40: { // SYBMSDATE - val = rb_funcall(cDate, intern_new, 3, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day)); - break; - } - case 41: { // SYBMSTIME - VALUE rational_nsec = rb_Rational(INT2NUM(dr2.nanosecond), opt_onek); - val = rb_funcall(rb_cTime, timezone, 7, INT2NUM(1900), INT2NUM(1), INT2NUM(1), INT2NUM(dr2.hour), INT2NUM(dr2.minute), INT2NUM(dr2.second), rational_nsec); - break; - } - case 42: { // SYBMSDATETIME2 - VALUE rational_nsec = rb_Rational(INT2NUM(dr2.nanosecond), opt_onek); - val = rb_funcall(rb_cTime, timezone, 7, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day), INT2NUM(dr2.hour), INT2NUM(dr2.minute), INT2NUM(dr2.second), rational_nsec); - break; - } - case 43: { // SYBMSDATETIMEOFFSET - long long numerator = ((long)dr2.second * (long long)1000000000) + (long long)dr2.nanosecond; - VALUE rational_sec = rb_Rational(LL2NUM(numerator), opt_onebil); - val = rb_funcall(rb_cTime, intern_new, 7, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day), INT2NUM(dr2.hour), INT2NUM(dr2.minute), rational_sec, INT2NUM(dr2.tzone*60)); - break; - } - } - } else { - val = ENCODED_STR_NEW(data, data_len); + DBDATEREC2 dr2; + dbanydatecrack(rwrap->client, &dr2, coltype, data); + switch(coltype) { + case 40: { // SYBMSDATE + val = rb_funcall(cDate, intern_new, 3, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day)); + break; } - #else - val = ENCODED_STR_NEW(data, data_len); - #endif + case 41: { // SYBMSTIME + VALUE rational_nsec = rb_Rational(INT2NUM(dr2.nanosecond), opt_onek); + val = rb_funcall(rb_cTime, timezone, 7, INT2NUM(1900), INT2NUM(1), INT2NUM(1), INT2NUM(dr2.hour), INT2NUM(dr2.minute), INT2NUM(dr2.second), rational_nsec); + break; + } + case 42: { // SYBMSDATETIME2 + VALUE rational_nsec = rb_Rational(INT2NUM(dr2.nanosecond), opt_onek); + val = rb_funcall(rb_cTime, timezone, 7, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day), INT2NUM(dr2.hour), INT2NUM(dr2.minute), INT2NUM(dr2.second), rational_nsec); + break; + } + case 43: { // SYBMSDATETIMEOFFSET + long long numerator = ((long)dr2.second * (long long)1000000000) + (long long)dr2.nanosecond; + VALUE rational_sec = rb_Rational(LL2NUM(numerator), opt_onebil); + val = rb_funcall(rb_cTime, intern_new, 7, INT2NUM(dr2.year), INT2NUM(dr2.month), INT2NUM(dr2.day), INT2NUM(dr2.hour), INT2NUM(dr2.minute), rational_sec, INT2NUM(dr2.tzone*60)); + break; + } + } break; } case SYBCHAR: diff --git a/tasks/ports/freetds.rb b/tasks/ports/freetds.rb index baf4f1f6..d0f4166c 100644 --- a/tasks/ports/freetds.rb +++ b/tasks/ports/freetds.rb @@ -15,12 +15,7 @@ def configure_defaults opts << '--with-pic' opts << '--disable-odbc' - - if version =~ /0\.91/ - opts << '--with-tdsver=7.1' - else - opts << '--with-tdsver=7.3' - end + opts << '--with-tdsver=7.3' if windows? opts << '--sysconfdir=C:/Sites' diff --git a/test/client_test.rb b/test/client_test.rb index d095db71..fff406f6 100644 --- a/test/client_test.rb +++ b/test/client_test.rb @@ -24,10 +24,7 @@ class ClientTest < TinyTds::TestCase end it 'has getters for the tds version information (brittle since conf takes precedence)' do - if sybase_ase? - assert_equal 7, @client.tds_version - assert_equal 'DBTDS_5_0 - 5.0 SQL Server', @client.tds_version_info - elsif @client.tds_73? + if @client.tds_73? assert_equal 11, @client.tds_version assert_equal 'DBTDS_7_3 - Microsoft SQL Server 2008', @client.tds_version_info else @@ -199,7 +196,7 @@ class ClientTest < TinyTds::TestCase options = connection_options :username => 'willnotwork' action = lambda { new_connection(options) } assert_raise_tinytds_error(action) do |e| - assert_equal sybase_ase? ? 4002 : 18456, e.db_error_number + assert_equal 18456, e.db_error_number assert_equal 14, e.severity assert_match %r{login failed}i, e.message, 'ignore if non-english test run' end diff --git a/test/result_test.rb b/test/result_test.rb index e40217f4..1d054f92 100644 --- a/test/result_test.rb +++ b/test/result_test.rb @@ -154,7 +154,7 @@ class ResultTest < TinyTds::TestCase inserted_rows = @client.execute("INSERT INTO [datatypes] ([varchar_50]) VALUES ('#{text}')").do assert_equal 1, inserted_rows, 'should have inserted row for one above' updated_rows = @client.execute("UPDATE [datatypes] SET [varchar_50] = NULL WHERE [varchar_50] = '#{text}'").do - assert_equal 1, updated_rows, 'should have updated row for one above' unless sqlserver_2000? # Will report -1 + assert_equal 1, updated_rows, 'should have updated row for one above' end end @@ -166,7 +166,7 @@ class ResultTest < TinyTds::TestCase inserted_rows = @client.execute("INSERT INTO [datatypes] ([varchar_50]) VALUES ('#{text}')").do assert_equal 1, inserted_rows, 'should have inserted row for one above' updated_rows = @client.execute("UPDATE [datatypes] SET [varchar_50] = NULL WHERE [varchar_50] = '#{text}'").do - assert_equal 1, updated_rows, 'should have updated row for one above' unless sqlserver_2000? # Will report -1 + assert_equal 1, updated_rows, 'should have updated row for one above' end end @@ -177,19 +177,18 @@ class ResultTest < TinyTds::TestCase @client.execute("INSERT INTO [datatypes] ([varchar_50]) VALUES ('#{text}')").do sql_identity = @client.execute(@client.identity_sql).each.first['Ident'] native_identity = @client.execute("INSERT INTO [datatypes] ([varchar_50]) VALUES ('#{text}')").insert - assert_equal sql_identity+1, native_identity + assert_equal sql_identity + 1, native_identity end end it 'returns bigint for #insert when needed' do return if sqlserver_azure? # We can not alter clustered index like this test does. - return if sybase_ase? # On Sybase, sp_helpindex cannot be used inside a transaction since it does a - # 'CREATE TABLE' command is not allowed within a multi-statement transaction - # and and sp_helpindex creates a temporary table #spindtab. + # 'CREATE TABLE' command is not allowed within a multi-statement transaction + # and and sp_helpindex creates a temporary table #spindtab. rollback_transaction(@client) do seed = 9223372036854775805 @client.execute("DELETE FROM [datatypes]").do - id_constraint_name = @client.execute("EXEC sp_helpindex [datatypes]").detect{ |row| row['index_keys'] == 'id' }['index_name'] + id_constraint_name = @client.execute("EXEC sp_helpindex [datatypes]").detect { |row| row['index_keys'] == 'id' }['index_name'] @client.execute("ALTER TABLE [datatypes] DROP CONSTRAINT [#{id_constraint_name}]").do @client.execute("ALTER TABLE [datatypes] DROP COLUMN [id]").do @client.execute("ALTER TABLE [datatypes] ADD [id] [bigint] NOT NULL IDENTITY(1,1) PRIMARY KEY").do @@ -236,13 +235,13 @@ class ResultTest < TinyTds::TestCase no_results_query = "SELECT [id], [varchar_50] FROM [datatypes] WHERE [varchar_50] = 'NOTFOUND'" # Fields before each. result = @client.execute(no_results_query) - _(result.fields).must_equal ['id','varchar_50'] + _(result.fields).must_equal ['id', 'varchar_50'] result.each - _(result.fields).must_equal ['id','varchar_50'] + _(result.fields).must_equal ['id', 'varchar_50'] # Each then fields result = @client.execute(no_results_query) result.each - _(result.fields).must_equal ['id','varchar_50'] + _(result.fields).must_equal ['id', 'varchar_50'] end it 'allows the result to be canceled before reading' do @@ -307,7 +306,7 @@ class ResultTest < TinyTds::TestCase it 'use same string object for hash keys' do data = @client.execute("SELECT [id], [bigint] FROM [datatypes]").each - assert_equal data.first.keys.map{ |r| r.object_id }, data.last.keys.map{ |r| r.object_id } + assert_equal data.first.keys.map { |r| r.object_id }, data.last.keys.map { |r| r.object_id } end it 'has properly encoded column names with symbol keys' do @@ -326,7 +325,7 @@ class ResultTest < TinyTds::TestCase it 'allows #return_code to work with stored procedures and reset per sql batch' do assert_nil @client.return_code result = @client.execute("EXEC tinytds_TestReturnCodes") - assert_equal [{"one"=>1}], result.each + assert_equal [{ "one" => 1 }], result.each assert_equal 420, @client.return_code assert_equal 420, result.return_code result = @client.execute('SELECT 1 as [one]') @@ -343,7 +342,7 @@ class ResultTest < TinyTds::TestCase describe 'with multiple result sets' do before do - @empty_select = "SELECT 1 AS [rs1] WHERE 1 = 0" + @empty_select = "SELECT 1 AS [rs1] WHERE 1 = 0" @double_select = "SELECT 1 AS [rs1] SELECT 2 AS [rs2]" @triple_select_1st_empty = "SELECT 1 AS [rs1] WHERE 1 = 0 @@ -361,8 +360,8 @@ class ResultTest < TinyTds::TestCase result = @client.execute(@double_select) result_sets = result.each assert_equal 2, result_sets.size - assert_equal [{'rs1' => 1}], result_sets.first - assert_equal [{'rs2' => 2}], result_sets.last + assert_equal [{ 'rs1' => 1 }], result_sets.first + assert_equal [{ 'rs2' => 2 }], result_sets.last assert_equal [['rs1'], ['rs2']], result.fields assert_equal result.each.object_id, result.each.object_id, 'same cached rows' # As array @@ -383,20 +382,12 @@ class ResultTest < TinyTds::TestCase end it 'works from a stored procedure' do - if sqlserver? - results1, results2 = @client.execute("EXEC sp_helpconstraint '[datatypes]'").each - assert_equal [{"Object Name"=>"[datatypes]"}], results1 - constraint_info = results2.first - assert constraint_info.key?("constraint_keys") - assert constraint_info.key?("constraint_type") - assert constraint_info.key?("constraint_name") - elsif sybase_ase? - results1, results2 = @client.execute("EXEC sp_helpconstraint 'datatypes'").each - assert results1['name'] =~ /^datatypes_bit/ - assert results1['defintion'] == 'DEFAULT 0' - assert results2['name'] =~ /^datatypes_id/ - assert results2['defintion'] =~ /^PRIMARY KEY/ - end + results1, results2 = @client.execute("EXEC sp_helpconstraint '[datatypes]'").each + assert_equal [{ "Object Name" => "[datatypes]" }], results1 + constraint_info = results2.first + assert constraint_info.key?("constraint_keys") + assert constraint_info.key?("constraint_type") + assert constraint_info.key?("constraint_name") end describe 'using :empty_sets TRUE' do @@ -423,8 +414,8 @@ class ResultTest < TinyTds::TestCase result_sets = result.each assert_equal 3, result_sets.size assert_equal [], result_sets[0] - assert_equal [{'rs2' => 2}], result_sets[1] - assert_equal [{'rs3' => 3}], result_sets[2] + assert_equal [{ 'rs2' => 2 }], result_sets[1] + assert_equal [{ 'rs3' => 3 }], result_sets[2] assert_equal [['rs1'], ['rs2'], ['rs3']], result.fields assert_equal result.each.object_id, result.each.object_id, 'same cached rows' # As array @@ -442,9 +433,9 @@ class ResultTest < TinyTds::TestCase result = @client.execute(@triple_select_2nd_empty) result_sets = result.each assert_equal 3, result_sets.size - assert_equal [{'rs1' => 1}], result_sets[0] + assert_equal [{ 'rs1' => 1 }], result_sets[0] assert_equal [], result_sets[1] - assert_equal [{'rs3' => 3}], result_sets[2] + assert_equal [{ 'rs3' => 3 }], result_sets[2] assert_equal [['rs1'], ['rs2'], ['rs3']], result.fields assert_equal result.each.object_id, result.each.object_id, 'same cached rows' # As array @@ -462,8 +453,8 @@ class ResultTest < TinyTds::TestCase result = @client.execute(@triple_select_3rd_empty) result_sets = result.each assert_equal 3, result_sets.size - assert_equal [{'rs1' => 1}], result_sets[0] - assert_equal [{'rs2' => 2}], result_sets[1] + assert_equal [{ 'rs1' => 1 }], result_sets[0] + assert_equal [{ 'rs2' => 2 }], result_sets[1] assert_equal [], result_sets[2] assert_equal [['rs1'], ['rs2'], ['rs3']], result.fields assert_equal result.each.object_id, result.each.object_id, 'same cached rows' @@ -503,8 +494,8 @@ class ResultTest < TinyTds::TestCase result = @client.execute(@triple_select_1st_empty) result_sets = result.each assert_equal 2, result_sets.size - assert_equal [{'rs2' => 2}], result_sets[0] - assert_equal [{'rs3' => 3}], result_sets[1] + assert_equal [{ 'rs2' => 2 }], result_sets[0] + assert_equal [{ 'rs3' => 3 }], result_sets[1] assert_equal [['rs2'], ['rs3']], result.fields assert_equal result.each.object_id, result.each.object_id, 'same cached rows' # As array @@ -521,8 +512,8 @@ class ResultTest < TinyTds::TestCase result = @client.execute(@triple_select_2nd_empty) result_sets = result.each assert_equal 2, result_sets.size - assert_equal [{'rs1' => 1}], result_sets[0] - assert_equal [{'rs3' => 3}], result_sets[1] + assert_equal [{ 'rs1' => 1 }], result_sets[0] + assert_equal [{ 'rs3' => 3 }], result_sets[1] assert_equal [['rs1'], ['rs3']], result.fields assert_equal result.each.object_id, result.each.object_id, 'same cached rows' # As array @@ -539,8 +530,8 @@ class ResultTest < TinyTds::TestCase result = @client.execute(@triple_select_3rd_empty) result_sets = result.each assert_equal 2, result_sets.size - assert_equal [{'rs1' => 1}], result_sets[0] - assert_equal [{'rs2' => 2}], result_sets[1] + assert_equal [{ 'rs1' => 1 }], result_sets[0] + assert_equal [{ 'rs2' => 2 }], result_sets[1] assert_equal [['rs1'], ['rs2']], result.fields assert_equal result.each.object_id, result.each.object_id, 'same cached rows' # As array @@ -590,7 +581,7 @@ class ResultTest < TinyTds::TestCase before do @big_text = 'x' * 2_000_000 @old_textsize = @client.execute("SELECT @@TEXTSIZE AS [textsize]").each.first['textsize'].inspect - @client.execute("SET TEXTSIZE #{(@big_text.length*2)+1}").do + @client.execute("SET TEXTSIZE #{(@big_text.length * 2) + 1}").do end it 'must insert and select large varchar_max' do @@ -601,7 +592,7 @@ class ResultTest < TinyTds::TestCase insert_and_select_datatype :nvarchar_max end - end unless sqlserver_2000? || sybase_ase? + end end @@ -612,189 +603,105 @@ class ResultTest < TinyTds::TestCase assert_equal [], @client.execute('').each end - if sqlserver? + describe 'using :message_handler option' do + let(:messages) { Array.new } - describe 'using :message_handler option' do - let(:messages) { Array.new } - - before do - close_client - @client = new_connection message_handler: Proc.new { |m| messages << m } - end - - after do - messages.clear - end + before do + close_client + @client = new_connection message_handler: Proc.new { |m| messages << m } + end - it 'has a message handler that responds to call' do - assert @client.message_handler.respond_to?(:call) - end + after do + messages.clear + end - it 'calls the provided message handler when severity is 10 or less' do - (1..10).to_a.each do |severity| - messages.clear - msg = "Test #{severity} severity" - state = rand(1..255) - @client.execute("RAISERROR(N'#{msg}', #{severity}, #{state})").do - m = messages.first - assert_equal 1, messages.length, 'there should be one message after one raiserror' - assert_equal msg, m.message, 'message text' - assert_equal severity, m.severity, 'message severity' unless severity == 10 && m.severity.to_i == 0 - assert_equal state, m.os_error_number, 'message state' - end - end + it 'has a message handler that responds to call' do + assert @client.message_handler.respond_to?(:call) + end - it 'calls the provided message handler for `print` messages' do + it 'calls the provided message handler when severity is 10 or less' do + (1..10).to_a.each do |severity| messages.clear - msg = 'hello' - @client.execute("PRINT '#{msg}'").do + msg = "Test #{severity} severity" + state = rand(1..255) + @client.execute("RAISERROR(N'#{msg}', #{severity}, #{state})").do m = messages.first - assert_equal 1, messages.length, 'there should be one message after one print statement' + assert_equal 1, messages.length, 'there should be one message after one raiserror' assert_equal msg, m.message, 'message text' - end - - it 'must raise an error preceded by a `print` message' do - messages.clear - action = lambda { @client.execute("EXEC tinytds_TestPrintWithError").do } - assert_raise_tinytds_error(action) do |e| - assert_equal 'hello', messages.first.message, 'message text' - - assert_equal "Error following print", e.message - assert_equal 16, e.severity - assert_equal 50000, e.db_error_number - end - end - - it 'calls the provided message handler for each of a series of `print` messages' do - messages.clear - @client.execute("EXEC tinytds_TestSeveralPrints").do - assert_equal ['hello 1', 'hello 2', 'hello 3'], messages.map { |e| e.message }, 'message list' - end - - it 'should flush info messages before raising error in cases of timeout' do - @client = new_connection timeout: 1, message_handler: Proc.new { |m| messages << m } - action = lambda { @client.execute("print 'hello'; waitfor delay '00:00:02'").do } - messages.clear - assert_raise_tinytds_error(action) do |e| - assert_match %r{timed out}i, e.message, 'ignore if non-english test run' - assert_equal 6, e.severity - assert_equal 20003, e.db_error_number - assert_equal 'hello', messages.first&.message, 'message text' - end - end - - it 'should print info messages before raising error in cases of timeout' do - @client = new_connection timeout: 1, message_handler: Proc.new { |m| messages << m } - action = lambda { @client.execute("raiserror('hello', 1, 1) with nowait; waitfor delay '00:00:02'").do } - messages.clear - assert_raise_tinytds_error(action) do |e| - assert_match %r{timed out}i, e.message, 'ignore if non-english test run' - assert_equal 6, e.severity - assert_equal 20003, e.db_error_number - assert_equal 'hello', messages.first&.message, 'message text' - end + assert_equal severity, m.severity, 'message severity' unless severity == 10 && m.severity.to_i == 0 + assert_equal state, m.os_error_number, 'message state' end end - it 'must not raise an error when severity is 10 or less' do - (1..10).to_a.each do |severity| - @client.execute("RAISERROR(N'Test #{severity} severity', #{severity}, 1)").do - end + it 'calls the provided message handler for `print` messages' do + messages.clear + msg = 'hello' + @client.execute("PRINT '#{msg}'").do + m = messages.first + assert_equal 1, messages.length, 'there should be one message after one print statement' + assert_equal msg, m.message, 'message text' end - it 'raises an error when severity is greater than 10' do - action = lambda { @client.execute("RAISERROR(N'Test 11 severity', 11, 1)").do } + it 'must raise an error preceded by a `print` message' do + messages.clear + action = lambda { @client.execute("EXEC tinytds_TestPrintWithError").do } assert_raise_tinytds_error(action) do |e| - assert_equal "Test 11 severity", e.message - assert_equal 11, e.severity + assert_equal 'hello', messages.first.message, 'message text' + + assert_equal "Error following print", e.message + assert_equal 16, e.severity assert_equal 50000, e.db_error_number end end - else + it 'calls the provided message handler for each of a series of `print` messages' do + messages.clear + @client.execute("EXEC tinytds_TestSeveralPrints").do + assert_equal ['hello 1', 'hello 2', 'hello 3'], messages.map { |e| e.message }, 'message list' + end - it 'raises an error' do - action = lambda { @client.execute("RAISERROR 50000 N'Hello World'").do } + it 'should flush info messages before raising error in cases of timeout' do + @client = new_connection timeout: 1, message_handler: Proc.new { |m| messages << m } + action = lambda { @client.execute("print 'hello'; waitfor delay '00:00:02'").do } + messages.clear assert_raise_tinytds_error(action) do |e| - assert_equal "Hello World", e.message - assert_equal 16, e.severity # predefined on ASE - assert_equal 50000, e.db_error_number + assert_match %r{timed out}i, e.message, 'ignore if non-english test run' + assert_equal 6, e.severity + assert_equal 20003, e.db_error_number + assert_equal 'hello', messages.first&.message, 'message text' end - assert_followup_query end - end - - it 'throws an error when you execute another query with other results pending' do - @client.execute(@query1) - action = lambda { @client.execute(@query1) } - assert_raise_tinytds_error(action) do |e| - assert_match %r|with results pending|i, e.message - assert_equal 7, e.severity - assert_equal 20019, e.db_error_number + it 'should print info messages before raising error in cases of timeout' do + @client = new_connection timeout: 1, message_handler: Proc.new { |m| messages << m } + action = lambda { @client.execute("raiserror('hello', 1, 1) with nowait; waitfor delay '00:00:02'").do } + messages.clear + assert_raise_tinytds_error(action) do |e| + assert_match %r{timed out}i, e.message, 'ignore if non-english test run' + assert_equal 6, e.severity + assert_equal 20003, e.db_error_number + assert_equal 'hello', messages.first&.message, 'message text' + end end end - it 'must error gracefully with bad table name' do - action = lambda { @client.execute('SELECT * FROM [foobar]').each } - assert_raise_tinytds_error(action) do |e| - pattern = sybase_ase? ? /foobar not found/ : %r|invalid object name.*foobar|i - assert_match pattern, e.message - assert_equal 16, e.severity - assert_equal 208, e.db_error_number + it 'must not raise an error when severity is 10 or less' do + (1..10).to_a.each do |severity| + @client.execute("RAISERROR(N'Test #{severity} severity', #{severity}, 1)").do end - assert_followup_query end - it 'must error gracefully with incorrect syntax' do - action = lambda { @client.execute('this will not work').each } + it 'raises an error when severity is greater than 10' do + action = lambda { @client.execute("RAISERROR(N'Test 11 severity', 11, 1)").do } assert_raise_tinytds_error(action) do |e| - assert_match %r|incorrect syntax|i, e.message - assert_equal 15, e.severity - assert_equal 156, e.db_error_number + assert_equal "Test 11 severity", e.message + assert_equal 11, e.severity + assert_equal 50000, e.db_error_number end - assert_followup_query end - - it 'must not error at all from reading non-convertable charcters and just use ? marks' do - close_client - @client = new_connection :encoding => 'ASCII' - _(@client.charset).must_equal 'ASCII' - _(find_value(202, :nvarchar_50)).must_equal 'test nvarchar_50 ??' - end - - it 'must error gracefully from writing non-convertable characters' do - close_client - @client = new_connection :encoding => 'ASCII' - _(@client.charset).must_equal 'ASCII' - rollback_transaction(@client) do - text = 'Test ✓' - @client.execute("DELETE FROM [datatypes] WHERE [nvarchar_50] IS NOT NULL").do - action = lambda { @client.execute("INSERT INTO [datatypes] ([nvarchar_50]) VALUES ('#{text}')").do } - assert_raise_tinytds_error(action) do |e| - _(e.message).must_match %r{Unclosed quotation mark}i - _(e.severity).must_equal 15 - _(e.db_error_number).must_equal 105 - end - assert_followup_query - end - end - - it 'errors gracefully with incorrect syntax in sp_executesql' do - action = lambda { @client.execute("EXEC sp_executesql N'this will not work'").each } - assert_raise_tinytds_error(action) do |e| - assert_match %r|incorrect syntax|i, e.message - assert_equal 15, e.severity - assert_equal 156, e.db_error_number - end - assert_followup_query - end unless sybase_ase? - end - end - protected def assert_followup_query diff --git a/test/schema/sqlserver_2000.sql b/test/schema/sqlserver_2000.sql deleted file mode 100644 index f62b7612..00000000 --- a/test/schema/sqlserver_2000.sql +++ /dev/null @@ -1,140 +0,0 @@ - -/* - - * Binary Data - Our test binary data is a 1 pixel gif. The basic (raw) data is below. Quoting this data - would involve this (encode) method and be (encoded) with the 0x prefix for raw SQL. In other clients the - (raw_db) value without the 0x prefix would need to be (packed) again yield the original (raw) value. - - (raw) - "GIF89a\001\000\001\000\221\000\000\377\377\377\377\377\377\376\001\002\000\000\000!\371\004\004\024\000\377\000,\000\000\000\000\001\000\001\000\000\002\002D\001\000;" - (encode) - "0x#{raw.unpack("H*")[0]}" - (encoded) - "0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (raw_db) - "47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (packed) - [raw_db].pack('H*') - -*/ - -CREATE TABLE [dbo].[datatypes] ( - [id] [int] NOT NULL IDENTITY(1,1) PRIMARY KEY, - [bigint] [bigint] NULL, - [binary_50] [binary](50) NULL, - [bit] [bit] NULL, - [char_10] [char](10) NULL, - -- [date] [date] NULL, - [datetime] [datetime] NULL, - -- [datetime2_7] [datetime2](7) NULL, - -- [datetime2_2] [datetime2](2) NULL, - -- [datetimeoffset_2] [datetimeoffset](2) NULL, - -- [datetimeoffset_7] [datetimeoffset](7) NULL, - [decimal_9_2] [decimal](9, 2) NULL, - [decimal_16_4] [decimal](16, 4) NULL, - [float] [float] NULL, - -- [geography] [geography] NULL, - -- [geometry] [geometry] NULL, - -- [hierarchyid] [hierarchyid] NULL, - [image] [image] NULL, - [int] [int] NULL, - [money] [money] NULL, - [nchar_10] [nchar](10) NULL, - [ntext] [ntext] NULL, - [numeric_18_0] [numeric](18, 0) NULL, - [numeric_36_2] [numeric](36, 2) NULL, - [nvarchar_50] [nvarchar](50) NULL, - -- [nvarchar_max] [nvarchar](max) NULL, - [real] [real] NULL, - [smalldatetime] [smalldatetime] NULL, - [smallint] [smallint] NULL, - [smallmoney] [smallmoney] NULL, - [text] [text] NULL, - -- [time_2] [time](2) NULL, - -- [time_7] [time](7) NULL, - [timestamp] [timestamp] NULL, - [tinyint] [tinyint] NULL, - [uniqueidentifier] [uniqueidentifier] NULL, - [varbinary_50] [varbinary](50) NULL, - -- [varbinary_max] [varbinary](max) NULL, - [varchar_50] [varchar](50) NULL - -- [varchar_max] [varchar](max) NULL, - -- [xml] [xml] NULL -) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] - -SET IDENTITY_INSERT [datatypes] ON - -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 11, -9223372036854775807 ) -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 12, 9223372036854775806 ) -INSERT INTO [datatypes] ([id], [binary_50]) VALUES ( 21, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 31, 1 ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 32, 0 ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 41, '1234567890' ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 42, '12345678' ) --- INSERT INTO [datatypes] ([id], [date]) VALUES ( 51, '0001-01-01' ) --- INSERT INTO [datatypes] ([id], [date]) VALUES ( 52, '9999-12-31' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 61, '1753-01-01T00:00:00.000' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 62, '9999-12-31T23:59:59.997' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 63, '2010-01-01T12:34:56.123' ) --- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 71, '0001-01-01 00:00:00.0000000' ) --- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 72, '1984-01-24 04:20:00.0000000' ) --- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 73, '9999-12-31 23:59:59.9999999' ) --- INSERT INTO [datatypes] ([id], [datetime2_2]) VALUES ( 74, '9999-12-31 23:59:59.123456789' ) --- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 81, '1984-01-24T04:20:00.1234567-08:00' ) -- 1984-01-24 04:20:00.00 -08:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 82, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.00 +00:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 83, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.99 +00:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 84, '1984-01-24T04:20:59.1234567-08:00' ) -- 1984-01-24 04:20:59.1234567 -08:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 85, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.0000000 +00:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 86, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.9999999 +00:00 -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 91, 12345.01 ) -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 92, 1234567.89 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 93, 0.0 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 94, 123456789012.3456 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 101, 123.00000001 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 102, 0.0 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 103, 123.45 ) --- INSERT INTO [datatypes] ([id], [geography]) VALUES ( 111, geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326) ) -- 0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0 --- INSERT INTO [datatypes] ([id], [geometry]) VALUES ( 121, geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 0) ) -- 0x0000000001040300000000000000000059400000000000005940000000000000344000000000008066400000000000806640000000000080664001000000010000000001000000FFFFFFFF0000000002 --- INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 131, CAST('/1/' AS hierarchyid) ) -- 0x58 --- INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 132, CAST('/2/' AS hierarchyid) ) -- 0x68 -INSERT INTO [datatypes] ([id], [image]) VALUES ( 141, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 151, -2147483647 ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 152, 2147483646 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 161, 4.20 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 162, -922337203685477.5807 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 163, 922337203685477.5806 ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 171, N'1234567890' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 172, N'123456åå' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 173, N'abc123' ) -INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 181, N'test ntext' ) -INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 182, N'test ntext åå' ) -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 191, 191 ) -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 192, 123456789012345678 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 193, 12345678901234567890.01 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 194, 123.46 ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 201, N'test nvarchar_50' ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 202, N'test nvarchar_50 åå' ) --- INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 211, N'test nvarchar_max' ) --- INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 212, N'test nvarchar_max åå' ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 221, 123.45 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 222, 0.0 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 223, 0.00001 ) -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 231, '1901-01-01T15:45:00.000' ) -- 1901-01-01 15:45:00 -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 232, '2078-06-05T04:20:00.000' ) -- 2078-06-05 04:20:00 -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 241, -32767 ) -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 242, 32766 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 251, 4.20 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 252, -214748.3647 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 253, 214748.3646 ) -INSERT INTO [datatypes] ([id], [text]) VALUES ( 271, 'test text' ) --- INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 281, '15:45:00.709714966' ) -- 15:45:00.71 --- INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 282, '04:20:00.288321545' ) -- 04:20:00.29 --- INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 283, '15:45:00.709714966' ) -- 15:45:00.709714900 --- INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 284, '04:20:00.288321545' ) -- 04:20:00.288321500 -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 301, 0 ) -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 302, 255 ) -INSERT INTO [datatypes] ([id], [uniqueidentifier]) VALUES ( 311, NEWID() ) -INSERT INTO [datatypes] ([id], [varbinary_50]) VALUES ( 321, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) --- INSERT INTO [datatypes] ([id], [varbinary_max]) VALUES ( 331, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [varchar_50]) VALUES ( 341, 'test varchar_50' ) --- INSERT INTO [datatypes] ([id], [varchar_max]) VALUES ( 351, 'test varchar_max' ) --- INSERT INTO [datatypes] ([id], [xml]) VALUES ( 361, 'batz' ) - -SET IDENTITY_INSERT [datatypes] OFF - - diff --git a/test/schema/sqlserver_2005.sql b/test/schema/sqlserver_2005.sql deleted file mode 100644 index 2fd86e97..00000000 --- a/test/schema/sqlserver_2005.sql +++ /dev/null @@ -1,140 +0,0 @@ - -/* - - * Binary Data - Our test binary data is a 1 pixel gif. The basic (raw) data is below. Quoting this data - would involve this (encode) method and be (encoded) with the 0x prefix for raw SQL. In other clients the - (raw_db) value without the 0x prefix would need to be (packed) again yield the original (raw) value. - - (raw) - "GIF89a\001\000\001\000\221\000\000\377\377\377\377\377\377\376\001\002\000\000\000!\371\004\004\024\000\377\000,\000\000\000\000\001\000\001\000\000\002\002D\001\000;" - (encode) - "0x#{raw.unpack("H*")[0]}" - (encoded) - "0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (raw_db) - "47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (packed) - [raw_db].pack('H*') - -*/ - -CREATE TABLE [dbo].[datatypes] ( - [id] [int] NOT NULL IDENTITY(1,1) PRIMARY KEY, - [bigint] [bigint] NULL, - [binary_50] [binary](50) NULL, - [bit] [bit] NULL, - [char_10] [char](10) NULL, - -- [date] [date] NULL, - [datetime] [datetime] NULL, - -- [datetime2_7] [datetime2](7) NULL, - -- [datetime2_2] [datetime2](2) NULL, - -- [datetimeoffset_2] [datetimeoffset](2) NULL, - -- [datetimeoffset_7] [datetimeoffset](7) NULL, - [decimal_9_2] [decimal](9, 2) NULL, - [decimal_16_4] [decimal](16, 4) NULL, - [float] [float] NULL, - -- [geography] [geography] NULL, - -- [geometry] [geometry] NULL, - -- [hierarchyid] [hierarchyid] NULL, - [image] [image] NULL, - [int] [int] NULL, - [money] [money] NULL, - [nchar_10] [nchar](10) NULL, - [ntext] [ntext] NULL, - [numeric_18_0] [numeric](18, 0) NULL, - [numeric_36_2] [numeric](36, 2) NULL, - [nvarchar_50] [nvarchar](50) NULL, - [nvarchar_max] [nvarchar](max) NULL, - [real] [real] NULL, - [smalldatetime] [smalldatetime] NULL, - [smallint] [smallint] NULL, - [smallmoney] [smallmoney] NULL, - [text] [text] NULL, - -- [time_2] [time](2) NULL, - -- [time_7] [time](7) NULL, - [timestamp] [timestamp] NULL, - [tinyint] [tinyint] NULL, - [uniqueidentifier] [uniqueidentifier] NULL, - [varbinary_50] [varbinary](50) NULL, - [varbinary_max] [varbinary](max) NULL, - [varchar_50] [varchar](50) NULL, - [varchar_max] [varchar](max) NULL, - [xml] [xml] NULL -) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] - -SET IDENTITY_INSERT [datatypes] ON - -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 11, -9223372036854775807 ) -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 12, 9223372036854775806 ) -INSERT INTO [datatypes] ([id], [binary_50]) VALUES ( 21, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 31, 1 ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 32, 0 ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 41, '1234567890' ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 42, '12345678' ) --- INSERT INTO [datatypes] ([id], [date]) VALUES ( 51, '0001-01-01' ) --- INSERT INTO [datatypes] ([id], [date]) VALUES ( 52, '9999-12-31' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 61, '1753-01-01T00:00:00.000' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 62, '9999-12-31T23:59:59.997' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 63, '2010-01-01T12:34:56.123' ) --- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 71, '0001-01-01 00:00:00.0000000' ) --- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 72, '1984-01-24 04:20:00.0000000' ) --- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 73, '9999-12-31 23:59:59.9999999' ) --- INSERT INTO [datatypes] ([id], [datetime2_2]) VALUES ( 74, '9999-12-31 23:59:59.123456789' ) --- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 81, '1984-01-24T04:20:00.1234567-08:00' ) -- 1984-01-24 04:20:00.00 -08:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 82, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.00 +00:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 83, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.99 +00:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 84, '1984-01-24T04:20:59.1234567-08:00' ) -- 1984-01-24 04:20:59.1234567 -08:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 85, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.0000000 +00:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 86, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.9999999 +00:00 -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 91, 12345.01 ) -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 92, 1234567.89 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 93, 0.0 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 94, 123456789012.3456 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 101, 123.00000001 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 102, 0.0 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 103, 123.45 ) --- INSERT INTO [datatypes] ([id], [geography]) VALUES ( 111, geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326) ) -- 0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0 --- INSERT INTO [datatypes] ([id], [geometry]) VALUES ( 121, geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 0) ) -- 0x0000000001040300000000000000000059400000000000005940000000000000344000000000008066400000000000806640000000000080664001000000010000000001000000FFFFFFFF0000000002 --- INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 131, CAST('/1/' AS hierarchyid) ) -- 0x58 --- INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 132, CAST('/2/' AS hierarchyid) ) -- 0x68 -INSERT INTO [datatypes] ([id], [image]) VALUES ( 141, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 151, -2147483647 ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 152, 2147483646 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 161, 4.20 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 162, -922337203685477.5807 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 163, 922337203685477.5806 ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 171, N'1234567890' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 172, N'123456åå' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 173, N'abc123' ) -INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 181, N'test ntext' ) -INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 182, N'test ntext åå' ) -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 191, 191 ) -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 192, 123456789012345678 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 193, 12345678901234567890.01 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 194, 123.46 ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 201, N'test nvarchar_50' ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 202, N'test nvarchar_50 åå' ) -INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 211, N'test nvarchar_max' ) -INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 212, N'test nvarchar_max åå' ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 221, 123.45 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 222, 0.0 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 223, 0.00001 ) -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 231, '1901-01-01T15:45:00.000Z' ) -- 1901-01-01 15:45:00 -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 232, '2078-06-05T04:20:00.000Z' ) -- 2078-06-05 04:20:00 -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 241, -32767 ) -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 242, 32766 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 251, 4.20 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 252, -214748.3647 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 253, 214748.3646 ) -INSERT INTO [datatypes] ([id], [text]) VALUES ( 271, 'test text' ) --- INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 281, '15:45:00.709714966' ) -- 15:45:00.71 --- INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 282, '04:20:00.288321545' ) -- 04:20:00.29 --- INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 283, '15:45:00.709714966' ) -- 15:45:00.709714900 --- INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 284, '04:20:00.288321545' ) -- 04:20:00.288321500 -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 301, 0 ) -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 302, 255 ) -INSERT INTO [datatypes] ([id], [uniqueidentifier]) VALUES ( 311, NEWID() ) -INSERT INTO [datatypes] ([id], [varbinary_50]) VALUES ( 321, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [varbinary_max]) VALUES ( 331, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [varchar_50]) VALUES ( 341, 'test varchar_50' ) -INSERT INTO [datatypes] ([id], [varchar_max]) VALUES ( 351, 'test varchar_max' ) -INSERT INTO [datatypes] ([id], [xml]) VALUES ( 361, 'batz' ) - -SET IDENTITY_INSERT [datatypes] OFF - - diff --git a/test/schema/sqlserver_2008.sql b/test/schema/sqlserver_2008.sql deleted file mode 100644 index 09a17a4b..00000000 --- a/test/schema/sqlserver_2008.sql +++ /dev/null @@ -1,140 +0,0 @@ - -/* - - * Binary Data - Our test binary data is a 1 pixel gif. The basic (raw) data is below. Quoting this data - would involve this (encode) method and be (encoded) with the 0x prefix for raw SQL. In other clients the - (raw_db) value without the 0x prefix would need to be (packed) again yield the original (raw) value. - - (raw) - "GIF89a\001\000\001\000\221\000\000\377\377\377\377\377\377\376\001\002\000\000\000!\371\004\004\024\000\377\000,\000\000\000\000\001\000\001\000\000\002\002D\001\000;" - (encode) - "0x#{raw.unpack("H*")[0]}" - (encoded) - "0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (raw_db) - "47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (packed) - [raw_db].pack('H*') - -*/ - -CREATE TABLE [dbo].[datatypes] ( - [id] [int] NOT NULL IDENTITY(1,1) PRIMARY KEY, - [bigint] [bigint] NULL, - [binary_50] [binary](50) NULL, - [bit] [bit] NULL, - [char_10] [char](10) NULL, - [date] [date] NULL, - [datetime] [datetime] NULL, - [datetime2_7] [datetime2](7) NULL, - [datetime2_2] [datetime2](2) NULL, - [datetimeoffset_2] [datetimeoffset](2) NULL, - [datetimeoffset_7] [datetimeoffset](7) NULL, - [decimal_9_2] [decimal](9, 2) NULL, - [decimal_16_4] [decimal](16, 4) NULL, - [float] [float] NULL, - [geography] [geography] NULL, - [geometry] [geometry] NULL, - [hierarchyid] [hierarchyid] NULL, - [image] [image] NULL, - [int] [int] NULL, - [money] [money] NULL, - [nchar_10] [nchar](10) NULL, - [ntext] [ntext] NULL, - [numeric_18_0] [numeric](18, 0) NULL, - [numeric_36_2] [numeric](36, 2) NULL, - [nvarchar_50] [nvarchar](50) NULL, - [nvarchar_max] [nvarchar](max) NULL, - [real] [real] NULL, - [smalldatetime] [smalldatetime] NULL, - [smallint] [smallint] NULL, - [smallmoney] [smallmoney] NULL, - [text] [text] NULL, - [time_2] [time](2) NULL, - [time_7] [time](7) NULL, - [timestamp] [timestamp] NULL, - [tinyint] [tinyint] NULL, - [uniqueidentifier] [uniqueidentifier] NULL, - [varbinary_50] [varbinary](50) NULL, - [varbinary_max] [varbinary](max) NULL, - [varchar_50] [varchar](50) NULL, - [varchar_max] [varchar](max) NULL, - [xml] [xml] NULL -) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] - -SET IDENTITY_INSERT [datatypes] ON - -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 11, -9223372036854775807 ) -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 12, 9223372036854775806 ) -INSERT INTO [datatypes] ([id], [binary_50]) VALUES ( 21, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 31, 1 ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 32, 0 ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 41, '1234567890' ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 42, '12345678' ) -INSERT INTO [datatypes] ([id], [date]) VALUES ( 51, '0001-01-01' ) -INSERT INTO [datatypes] ([id], [date]) VALUES ( 52, '9999-12-31' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 61, '1753-01-01T00:00:00.000' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 62, '9999-12-31T23:59:59.997' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 63, '2010-01-01T12:34:56.123' ) -INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 71, '0001-01-01 00:00:00.0000000' ) -INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 72, '1984-01-24 04:20:00.0000000' ) -INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 73, '9999-12-31 23:59:59.9999999' ) -INSERT INTO [datatypes] ([id], [datetime2_2]) VALUES ( 74, '9999-12-31 23:59:59.123456789' ) -INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 81, '1984-01-24T04:20:00.1234567-08:00' ) -- 1984-01-24 04:20:00.00 -08:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 82, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.00 +00:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 83, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.99 +00:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 84, '1984-01-24T04:20:59.1234567-08:00' ) -- 1984-01-24 04:20:59.1234567 -08:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 85, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.0000000 +00:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 86, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.9999999 +00:00 -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 91, 12345.01 ) -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 92, 1234567.89 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 93, 0.0 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 94, 123456789012.3456 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 101, 123.00000001 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 102, 0.0 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 103, 123.45 ) -INSERT INTO [datatypes] ([id], [geography]) VALUES ( 111, geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326) ) -- 0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0 -INSERT INTO [datatypes] ([id], [geometry]) VALUES ( 121, geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 0) ) -- 0x0000000001040300000000000000000059400000000000005940000000000000344000000000008066400000000000806640000000000080664001000000010000000001000000FFFFFFFF0000000002 -INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 131, CAST('/1/' AS hierarchyid) ) -- 0x58 -INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 132, CAST('/2/' AS hierarchyid) ) -- 0x68 -INSERT INTO [datatypes] ([id], [image]) VALUES ( 141, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 151, -2147483647 ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 152, 2147483646 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 161, 4.20 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 162, -922337203685477.5807 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 163, 922337203685477.5806 ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 171, N'1234567890' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 172, N'123456åå' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 173, N'abc123' ) -INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 181, N'test ntext' ) -INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 182, N'test ntext åå' ) -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 191, 191 ) -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 192, 123456789012345678 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 193, 12345678901234567890.01 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 194, 123.46 ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 201, N'test nvarchar_50' ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 202, N'test nvarchar_50 åå' ) -INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 211, N'test nvarchar_max' ) -INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 212, N'test nvarchar_max åå' ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 221, 123.45 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 222, 0.0 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 223, 0.00001 ) -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 231, '1901-01-01T15:45:00.000Z' ) -- 1901-01-01 15:45:00 -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 232, '2078-06-05T04:20:00.000Z' ) -- 2078-06-05 04:20:00 -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 241, -32767 ) -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 242, 32766 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 251, 4.20 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 252, -214748.3647 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 253, 214748.3646 ) -INSERT INTO [datatypes] ([id], [text]) VALUES ( 271, 'test text' ) -INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 281, '15:45:00.709714966' ) -- 15:45:00.71 -INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 282, '04:20:00.288321545' ) -- 04:20:00.29 -INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 283, '15:45:00.709714966' ) -- 15:45:00.709714900 -INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 284, '04:20:00.288321545' ) -- 04:20:00.288321500 -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 301, 0 ) -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 302, 255 ) -INSERT INTO [datatypes] ([id], [uniqueidentifier]) VALUES ( 311, NEWID() ) -INSERT INTO [datatypes] ([id], [varbinary_50]) VALUES ( 321, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [varbinary_max]) VALUES ( 331, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [varchar_50]) VALUES ( 341, 'test varchar_50' ) -INSERT INTO [datatypes] ([id], [varchar_max]) VALUES ( 351, 'test varchar_max' ) -INSERT INTO [datatypes] ([id], [xml]) VALUES ( 361, 'batz' ) - -SET IDENTITY_INSERT [datatypes] OFF - - diff --git a/test/schema/sqlserver_2014.sql b/test/schema/sqlserver_2014.sql deleted file mode 100644 index 09a17a4b..00000000 --- a/test/schema/sqlserver_2014.sql +++ /dev/null @@ -1,140 +0,0 @@ - -/* - - * Binary Data - Our test binary data is a 1 pixel gif. The basic (raw) data is below. Quoting this data - would involve this (encode) method and be (encoded) with the 0x prefix for raw SQL. In other clients the - (raw_db) value without the 0x prefix would need to be (packed) again yield the original (raw) value. - - (raw) - "GIF89a\001\000\001\000\221\000\000\377\377\377\377\377\377\376\001\002\000\000\000!\371\004\004\024\000\377\000,\000\000\000\000\001\000\001\000\000\002\002D\001\000;" - (encode) - "0x#{raw.unpack("H*")[0]}" - (encoded) - "0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (raw_db) - "47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (packed) - [raw_db].pack('H*') - -*/ - -CREATE TABLE [dbo].[datatypes] ( - [id] [int] NOT NULL IDENTITY(1,1) PRIMARY KEY, - [bigint] [bigint] NULL, - [binary_50] [binary](50) NULL, - [bit] [bit] NULL, - [char_10] [char](10) NULL, - [date] [date] NULL, - [datetime] [datetime] NULL, - [datetime2_7] [datetime2](7) NULL, - [datetime2_2] [datetime2](2) NULL, - [datetimeoffset_2] [datetimeoffset](2) NULL, - [datetimeoffset_7] [datetimeoffset](7) NULL, - [decimal_9_2] [decimal](9, 2) NULL, - [decimal_16_4] [decimal](16, 4) NULL, - [float] [float] NULL, - [geography] [geography] NULL, - [geometry] [geometry] NULL, - [hierarchyid] [hierarchyid] NULL, - [image] [image] NULL, - [int] [int] NULL, - [money] [money] NULL, - [nchar_10] [nchar](10) NULL, - [ntext] [ntext] NULL, - [numeric_18_0] [numeric](18, 0) NULL, - [numeric_36_2] [numeric](36, 2) NULL, - [nvarchar_50] [nvarchar](50) NULL, - [nvarchar_max] [nvarchar](max) NULL, - [real] [real] NULL, - [smalldatetime] [smalldatetime] NULL, - [smallint] [smallint] NULL, - [smallmoney] [smallmoney] NULL, - [text] [text] NULL, - [time_2] [time](2) NULL, - [time_7] [time](7) NULL, - [timestamp] [timestamp] NULL, - [tinyint] [tinyint] NULL, - [uniqueidentifier] [uniqueidentifier] NULL, - [varbinary_50] [varbinary](50) NULL, - [varbinary_max] [varbinary](max) NULL, - [varchar_50] [varchar](50) NULL, - [varchar_max] [varchar](max) NULL, - [xml] [xml] NULL -) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] - -SET IDENTITY_INSERT [datatypes] ON - -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 11, -9223372036854775807 ) -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 12, 9223372036854775806 ) -INSERT INTO [datatypes] ([id], [binary_50]) VALUES ( 21, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 31, 1 ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 32, 0 ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 41, '1234567890' ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 42, '12345678' ) -INSERT INTO [datatypes] ([id], [date]) VALUES ( 51, '0001-01-01' ) -INSERT INTO [datatypes] ([id], [date]) VALUES ( 52, '9999-12-31' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 61, '1753-01-01T00:00:00.000' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 62, '9999-12-31T23:59:59.997' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 63, '2010-01-01T12:34:56.123' ) -INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 71, '0001-01-01 00:00:00.0000000' ) -INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 72, '1984-01-24 04:20:00.0000000' ) -INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 73, '9999-12-31 23:59:59.9999999' ) -INSERT INTO [datatypes] ([id], [datetime2_2]) VALUES ( 74, '9999-12-31 23:59:59.123456789' ) -INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 81, '1984-01-24T04:20:00.1234567-08:00' ) -- 1984-01-24 04:20:00.00 -08:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 82, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.00 +00:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 83, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.99 +00:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 84, '1984-01-24T04:20:59.1234567-08:00' ) -- 1984-01-24 04:20:59.1234567 -08:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 85, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.0000000 +00:00 -INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 86, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.9999999 +00:00 -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 91, 12345.01 ) -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 92, 1234567.89 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 93, 0.0 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 94, 123456789012.3456 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 101, 123.00000001 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 102, 0.0 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 103, 123.45 ) -INSERT INTO [datatypes] ([id], [geography]) VALUES ( 111, geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326) ) -- 0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0 -INSERT INTO [datatypes] ([id], [geometry]) VALUES ( 121, geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 0) ) -- 0x0000000001040300000000000000000059400000000000005940000000000000344000000000008066400000000000806640000000000080664001000000010000000001000000FFFFFFFF0000000002 -INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 131, CAST('/1/' AS hierarchyid) ) -- 0x58 -INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 132, CAST('/2/' AS hierarchyid) ) -- 0x68 -INSERT INTO [datatypes] ([id], [image]) VALUES ( 141, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 151, -2147483647 ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 152, 2147483646 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 161, 4.20 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 162, -922337203685477.5807 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 163, 922337203685477.5806 ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 171, N'1234567890' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 172, N'123456åå' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 173, N'abc123' ) -INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 181, N'test ntext' ) -INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 182, N'test ntext åå' ) -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 191, 191 ) -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 192, 123456789012345678 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 193, 12345678901234567890.01 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 194, 123.46 ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 201, N'test nvarchar_50' ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 202, N'test nvarchar_50 åå' ) -INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 211, N'test nvarchar_max' ) -INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 212, N'test nvarchar_max åå' ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 221, 123.45 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 222, 0.0 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 223, 0.00001 ) -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 231, '1901-01-01T15:45:00.000Z' ) -- 1901-01-01 15:45:00 -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 232, '2078-06-05T04:20:00.000Z' ) -- 2078-06-05 04:20:00 -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 241, -32767 ) -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 242, 32766 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 251, 4.20 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 252, -214748.3647 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 253, 214748.3646 ) -INSERT INTO [datatypes] ([id], [text]) VALUES ( 271, 'test text' ) -INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 281, '15:45:00.709714966' ) -- 15:45:00.71 -INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 282, '04:20:00.288321545' ) -- 04:20:00.29 -INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 283, '15:45:00.709714966' ) -- 15:45:00.709714900 -INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 284, '04:20:00.288321545' ) -- 04:20:00.288321500 -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 301, 0 ) -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 302, 255 ) -INSERT INTO [datatypes] ([id], [uniqueidentifier]) VALUES ( 311, NEWID() ) -INSERT INTO [datatypes] ([id], [varbinary_50]) VALUES ( 321, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [varbinary_max]) VALUES ( 331, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [varchar_50]) VALUES ( 341, 'test varchar_50' ) -INSERT INTO [datatypes] ([id], [varchar_max]) VALUES ( 351, 'test varchar_max' ) -INSERT INTO [datatypes] ([id], [xml]) VALUES ( 361, 'batz' ) - -SET IDENTITY_INSERT [datatypes] OFF - - diff --git a/test/schema/sybase_ase.sql b/test/schema/sybase_ase.sql deleted file mode 100644 index dd700895..00000000 --- a/test/schema/sybase_ase.sql +++ /dev/null @@ -1,138 +0,0 @@ - -/* - - * Binary Data - Our test binary data is a 1 pixel gif. The basic (raw) data is below. Quoting this data - would involve this (encode) method and be (encoded) with the 0x prefix for raw SQL. In other clients the - (raw_db) value without the 0x prefix would need to be (packed) again yield the original (raw) value. - - (raw) - "GIF89a\001\000\001\000\221\000\000\377\377\377\377\377\377\376\001\002\000\000\000!\371\004\004\024\000\377\000,\000\000\000\000\001\000\001\000\000\002\002D\001\000;" - (encode) - "0x#{raw.unpack("H*")[0]}" - (encoded) - "0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (raw_db) - "47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b" - (packed) - [raw_db].pack('H*') - -*/ - -CREATE TABLE [datatypes] ( - [id] [int] IDENTITY NOT NULL PRIMARY KEY, - [bigint] [bigint] NULL, - [binary_50] [binary](50) NULL, - [bit] [bit] DEFAULT 0, - [char_10] [char](10) NULL, - [date] [date] NULL, - [datetime] [datetime] NULL, - -- [datetime2_7] [datetime2](7) NULL, - -- [datetimeoffset_2] [datetimeoffset](2) NULL, - -- [datetimeoffset_7] [datetimeoffset](7) NULL, - [decimal_9_2] [decimal](9, 2) NULL, - [decimal_16_4] [decimal](16, 4) NULL, - [float] [float] NULL, - -- [geography] [geography] NULL, - -- [geometry] [geometry] NULL, - -- [hierarchyid] [hierarchyid] NULL, - [image] [image] NULL, - [int] [int] NULL, - [money] [money] NULL, - [nchar_10] [nchar](10) NULL, - -- [ntext] [ntext] NULL, - [numeric_18_0] [numeric](18, 0) NULL, - [numeric_36_2] [numeric](36, 2) NULL, - [nvarchar_50] [nvarchar](50) NULL, - -- [nvarchar_max] [nvarchar](max) NULL, - [real] [real] NULL, - [smalldatetime] [smalldatetime] NULL, - [smallint] [smallint] NULL, - [smallmoney] [smallmoney] NULL, - [text] [text] NULL, - -- [time_2] [time](2) NULL, - -- [time_7] [time](7) NULL, - [timestamp] [timestamp] NULL, - [tinyint] [tinyint] NULL, - -- [uniqueidentifier] [uniqueidentifier] NULL, - [varbinary_50] [varbinary](50) NULL, - -- [varbinary_max] [varbinary](max) NULL, - [varchar_50] [varchar](50) NULL - -- [varchar_max] [varchar](max) NULL, - -- [xml] [xml] NULL -) - -SET IDENTITY_INSERT [datatypes] ON - -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 11, -9223372036854775807 ) -INSERT INTO [datatypes] ([id], [bigint]) VALUES ( 12, 9223372036854775806 ) -INSERT INTO [datatypes] ([id], [binary_50]) VALUES ( 21, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 31, 1 ) -INSERT INTO [datatypes] ([id], [bit]) VALUES ( 32, 0 ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 41, '1234567890' ) -INSERT INTO [datatypes] ([id], [char_10]) VALUES ( 42, '12345678' ) -INSERT INTO [datatypes] ([id], [date]) VALUES ( 51, '0001-01-01' ) -INSERT INTO [datatypes] ([id], [date]) VALUES ( 52, '9999-12-31' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 61, '1753-01-01T00:00:00.000' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 62, '9999-12-31T23:59:59.997' ) -INSERT INTO [datatypes] ([id], [datetime]) VALUES ( 63, '2010-01-01T12:34:56.123' ) --- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 71, '0001-01-01T00:00:00.0000000Z' ) --- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 72, '1984-01-24T04:20:00.1234567-08:00' ) --- INSERT INTO [datatypes] ([id], [datetime2_7]) VALUES ( 73, '9999-12-31T23:59:59.9999999Z' ) --- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 81, '1984-01-24T04:20:00.1234567-08:00' ) -- 1984-01-24 04:20:00.00 -08:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 82, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.00 +00:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_2]) VALUES ( 83, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.99 +00:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 84, '1984-01-24T04:20:00.1234567-08:00' ) -- 1984-01-24 04:20:00.1234567 -08:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 85, '1984-01-24T04:20:00.0000000Z' ) -- 1984-01-24 04:20:00.0000000 +00:00 --- INSERT INTO [datatypes] ([id], [datetimeoffset_7]) VALUES ( 86, '9999-12-31T23:59:59.9999999Z' ) -- 9999-12-31 23:59:59.9999999 +00:00 -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 91, 12345.01 ) -INSERT INTO [datatypes] ([id], [decimal_9_2]) VALUES ( 92, 1234567.89 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 93, 0.0 ) -INSERT INTO [datatypes] ([id], [decimal_16_4]) VALUES ( 94, 123456789012.3456 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 101, 123.00000001 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 102, 0.0 ) -INSERT INTO [datatypes] ([id], [float]) VALUES ( 103, 123.45 ) --- INSERT INTO [datatypes] ([id], [geography]) VALUES ( 111, geography::STGeomFromText('LINESTRING(-122.360 47.656, -122.343 47.656)', 4326) ) -- 0xE610000001148716D9CEF7D34740D7A3703D0A975EC08716D9CEF7D34740CBA145B6F3955EC0 --- INSERT INTO [datatypes] ([id], [geometry]) VALUES ( 121, geometry::STGeomFromText('LINESTRING (100 100, 20 180, 180 180)', 0) ) -- 0x0000000001040300000000000000000059400000000000005940000000000000344000000000008066400000000000806640000000000080664001000000010000000001000000FFFFFFFF0000000002 --- INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 131, CAST('/1/' AS hierarchyid) ) -- 0x58 --- INSERT INTO [datatypes] ([id], [hierarchyid]) VALUES ( 132, CAST('/2/' AS hierarchyid) ) -- 0x68 -INSERT INTO [datatypes] ([id], [image]) VALUES ( 141, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 151, -2147483647 ) -INSERT INTO [datatypes] ([id], [int]) VALUES ( 152, 2147483646 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 161, 4.20 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 162, -922337203685477.5807 ) -INSERT INTO [datatypes] ([id], [money]) VALUES ( 163, 922337203685477.5806 ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 171, N'1234567890' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 172, N'123456åå' ) -INSERT INTO [datatypes] ([id], [nchar_10]) VALUES ( 173, N'abc123' ) --- INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 181, N'test ntext' ) --- INSERT INTO [datatypes] ([id], [ntext]) VALUES ( 182, N'test ntext' ) -- Removed UTF-8 chars. They make sybase choke in comments. -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 191, 191 ) -INSERT INTO [datatypes] ([id], [numeric_18_0]) VALUES ( 192, 123456789012345678 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 193, 12345678901234567890.01 ) -INSERT INTO [datatypes] ([id], [numeric_36_2]) VALUES ( 194, 123.46 ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 201, N'test nvarchar_50' ) -INSERT INTO [datatypes] ([id], [nvarchar_50]) VALUES ( 202, N'test nvarchar_50 åå' ) --- INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 211, N'test nvarchar_max' ) --- INSERT INTO [datatypes] ([id], [nvarchar_max]) VALUES ( 212, N'test nvarchar_max' ) -- Removed UTF-8 chars. They make sybase choke in comments. -INSERT INTO [datatypes] ([id], [real]) VALUES ( 221, 123.45 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 222, 0.0 ) -INSERT INTO [datatypes] ([id], [real]) VALUES ( 223, 0.00001 ) -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 231, '1901-01-01T15:45:00.000' ) -- 1901-01-01 15:45:00 -INSERT INTO [datatypes] ([id], [smalldatetime]) VALUES ( 232, '2078-06-05T04:20:00.000' ) -- 2078-06-05 04:20:00 -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 241, -32767 ) -INSERT INTO [datatypes] ([id], [smallint]) VALUES ( 242, 32766 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 251, 4.20 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 252, -214748.3647 ) -INSERT INTO [datatypes] ([id], [smallmoney]) VALUES ( 253, 214748.3646 ) -INSERT INTO [datatypes] ([id], [text]) VALUES ( 271, 'test text' ) --- INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 281, '1901-01-01T15:45:00.0100001Z' ) -- 15:45:00.01 --- INSERT INTO [datatypes] ([id], [time_2]) VALUES ( 282, '1984-01-24T04:20:00.0000001-08:00' ) -- 04:20:00.00 --- INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 283, '1901-01-01T15:45:00.0100001Z' ) -- 15:45:00.0100001 --- INSERT INTO [datatypes] ([id], [time_7]) VALUES ( 284, '1984-01-24T04:20:00.0000001-08:00' ) -- 04:20:00.0000001 -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 301, 0 ) -INSERT INTO [datatypes] ([id], [tinyint]) VALUES ( 302, 255 ) --- INSERT INTO [datatypes] ([id], [uniqueidentifier]) VALUES ( 311, NEWID() ) -INSERT INTO [datatypes] ([id], [varbinary_50]) VALUES ( 321, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) --- INSERT INTO [datatypes] ([id], [varbinary_max]) VALUES ( 331, 0x47494638396101000100910000fffffffffffffe010200000021f904041400ff002c00000000010001000002024401003b ) -INSERT INTO [datatypes] ([id], [varchar_50]) VALUES ( 341, 'test varchar_50' ) --- INSERT INTO [datatypes] ([id], [varchar_max]) VALUES ( 351, 'test varchar_max' ) --- INSERT INTO [datatypes] ([id], [xml]) VALUES ( 361, 'batz' ) - -SET IDENTITY_INSERT [datatypes] OFF - - diff --git a/test/schema_test.rb b/test/schema_test.rb index afffc616..a1128d7b 100644 --- a/test/schema_test.rb +++ b/test/schema_test.rb @@ -8,436 +8,414 @@ class SchemaTest < TinyTds::TestCase before do @@current_schema_loaded ||= load_current_schema @client = new_connection - @gif1px = File.read('test/schema/1px.gif',:mode=>"rb:BINARY") + @gif1px = File.read('test/schema/1px.gif', :mode => "rb:BINARY") end - describe 'for shared types' do + it 'casts bigint' do + assert_equal (-9223372036854775807), find_value(11, :bigint) + assert_equal 9223372036854775806, find_value(12, :bigint) + end - it 'casts bigint' do - assert_equal (-9223372036854775807), find_value(11, :bigint) - assert_equal 9223372036854775806, find_value(12, :bigint) - end + it 'casts binary' do + value = find_value(21, :binary_50) + assert_equal @gif1px + "\000", value + assert_binary_encoding(value) + end - it 'casts binary' do - value = find_value(21, :binary_50) - assert_equal @gif1px + "\000", value - assert_binary_encoding(value) - end + it 'casts bit' do + assert_equal true, find_value(31, :bit) + assert_equal false, find_value(32, :bit) + assert_nil find_value(21, :bit) + end - it 'casts bit' do - assert_equal true, find_value(31, :bit) - assert_equal false, find_value(32, :bit) - assert_nil find_value(21, :bit) - end + it 'casts char' do + partial_char = '12345678 ' + assert_equal '1234567890', find_value(41, :char_10) + assert_equal partial_char, find_value(42, :char_10) + assert_utf8_encoding find_value(42, :char_10) + end - it 'casts char' do - partial_char = '12345678 ' - assert_equal '1234567890', find_value(41, :char_10) - assert_equal partial_char, find_value(42, :char_10) - assert_utf8_encoding find_value(42, :char_10) - end + it 'casts datetime' do + # 1753-01-01T00:00:00.000 + v = find_value 61, :datetime + assert_instance_of Time, v, 'not in range of Time class' + assert_equal 1753, v.year + assert_equal 01, v.month + assert_equal 01, v.day + assert_equal 0, v.hour + assert_equal 0, v.min + assert_equal 0, v.sec + assert_equal 0, v.usec + # 9999-12-31T23:59:59.997 + v = find_value 62, :datetime + assert_instance_of Time, v, 'not in range of Time class' + assert_equal 9999, v.year + assert_equal 12, v.month + assert_equal 31, v.day + assert_equal 23, v.hour + assert_equal 59, v.min + assert_equal 59, v.sec + assert_equal 997000, v.usec + assert_equal utc_offset, find_value(62, :datetime, :timezone => :local).utc_offset + assert_equal 0, find_value(62, :datetime, :timezone => :utc).utc_offset + # 2010-01-01T12:34:56.123 + v = find_value 63, :datetime + assert_instance_of Time, v, 'in range of Time class' + assert_equal 2010, v.year + assert_equal 01, v.month + assert_equal 01, v.day + assert_equal 12, v.hour + assert_equal 34, v.min + assert_equal 56, v.sec + assert_equal 123000, v.usec + assert_equal utc_offset, find_value(63, :datetime, :timezone => :local).utc_offset + assert_equal 0, find_value(63, :datetime, :timezone => :utc).utc_offset + end - it 'casts datetime' do - # 1753-01-01T00:00:00.000 - v = find_value 61, :datetime - assert_instance_of Time, v, 'not in range of Time class' - assert_equal 1753, v.year - assert_equal 01, v.month - assert_equal 01, v.day - assert_equal 0, v.hour - assert_equal 0, v.min - assert_equal 0, v.sec - assert_equal 0, v.usec - # 9999-12-31T23:59:59.997 - v = find_value 62, :datetime - assert_instance_of Time, v, 'not in range of Time class' - assert_equal 9999, v.year - assert_equal 12, v.month - assert_equal 31, v.day - assert_equal 23, v.hour - assert_equal 59, v.min - assert_equal 59, v.sec - assert_equal 997000, v.usec - assert_equal utc_offset, find_value(62, :datetime, :timezone => :local).utc_offset - assert_equal 0, find_value(62, :datetime, :timezone => :utc).utc_offset - # 2010-01-01T12:34:56.123 - v = find_value 63, :datetime - assert_instance_of Time, v, 'in range of Time class' - assert_equal 2010, v.year - assert_equal 01, v.month - assert_equal 01, v.day - assert_equal 12, v.hour - assert_equal 34, v.min - assert_equal 56, v.sec - assert_equal 123000, v.usec - assert_equal utc_offset, find_value(63, :datetime, :timezone => :local).utc_offset - assert_equal 0, find_value(63, :datetime, :timezone => :utc).utc_offset - end + it 'casts decimal' do + assert_instance_of BigDecimal, find_value(91, :decimal_9_2) + assert_equal BigDecimal('12345.01'), find_value(91, :decimal_9_2) + assert_equal BigDecimal('1234567.89'), find_value(92, :decimal_9_2) + assert_equal BigDecimal('0.0'), find_value(93, :decimal_16_4) + assert_equal BigDecimal('123456789012.3456'), find_value(94, :decimal_16_4) + end - it 'casts decimal' do - assert_instance_of BigDecimal, find_value(91, :decimal_9_2) - assert_equal BigDecimal('12345.01'), find_value(91, :decimal_9_2) - assert_equal BigDecimal('1234567.89'), find_value(92, :decimal_9_2) - assert_equal BigDecimal('0.0'), find_value(93, :decimal_16_4) - assert_equal BigDecimal('123456789012.3456'), find_value(94, :decimal_16_4) - end + it 'casts float' do + assert_equal 123.00000001, find_value(101, :float) + assert_equal 0.0, find_value(102, :float) + assert_equal find_value(102, :float).object_id, find_value(102, :float).object_id, 'use global zero float' + assert_equal 123.45, find_value(103, :float) + end - it 'casts float' do - assert_equal 123.00000001, find_value(101,:float) - assert_equal 0.0, find_value(102,:float) - assert_equal find_value(102,:float).object_id, find_value(102,:float).object_id, 'use global zero float' - assert_equal 123.45, find_value(103,:float) - end + it 'casts image' do + value = find_value(141, :image) + assert_equal @gif1px, value + assert_binary_encoding(value) + end - it 'casts image' do - value = find_value(141,:image) - assert_equal @gif1px, value - assert_binary_encoding(value) - end + it 'casts int' do + assert_equal (-2147483647), find_value(151, :int) + assert_equal 2147483646, find_value(152, :int) + end - it 'casts int' do - assert_equal (-2147483647), find_value(151, :int) - assert_equal 2147483646, find_value(152, :int) - end + it 'casts money' do + assert_instance_of BigDecimal, find_value(161, :money) + assert_equal BigDecimal('4.20'), find_value(161, :money) + assert_equal BigDecimal('922337203685477.5806'), find_value(163, :money) + assert_equal BigDecimal('-922337203685477.5807'), find_value(162, :money) + end - it 'casts money' do - assert_instance_of BigDecimal, find_value(161, :money) - assert_equal BigDecimal('4.20'), find_value(161, :money) - assert_equal BigDecimal('922337203685477.5806'), find_value(163 ,:money) - assert_equal BigDecimal('-922337203685477.5807'), find_value(162 ,:money) - end + it 'casts nchar' do + assert_equal '1234567890', find_value(171, :nchar_10) + assert_equal '123456åå ', find_value(172, :nchar_10) + assert_equal 'abc123 ', find_value(173, :nchar_10) + end - it 'casts nchar' do - assert_equal '1234567890', find_value(171, :nchar_10) - assert_equal '123456åå ', find_value(172, :nchar_10) - assert_equal 'abc123 ', find_value(173, :nchar_10) - end + it 'casts ntext' do + assert_equal 'test ntext', find_value(181, :ntext) + assert_equal 'test ntext åå', find_value(182, :ntext) + assert_utf8_encoding find_value(182, :ntext) + # If this test fails, try setting the "text size" in your freetds.conf. See: http://www.freetds.org/faq.html#textdata + large_value = "x" * 5000 + large_value_id = @client.execute("INSERT INTO [datatypes] ([ntext]) VALUES (N'#{large_value}')").insert + assert_equal large_value, find_value(large_value_id, :ntext) + end - it 'casts ntext' do - assert_equal 'test ntext', find_value(181, :ntext) - assert_equal 'test ntext åå', find_value(182, :ntext) - assert_utf8_encoding find_value(182, :ntext) - # If this test fails, try setting the "text size" in your freetds.conf. See: http://www.freetds.org/faq.html#textdata - large_value = "x" * 5000 - large_value_id = @client.execute("INSERT INTO [datatypes] ([ntext]) VALUES (N'#{large_value}')").insert - assert_equal large_value, find_value(large_value_id, :ntext) - end unless sybase_ase? - - it 'casts numeric' do - assert_instance_of BigDecimal, find_value(191, :numeric_18_0) - assert_equal BigDecimal('191'), find_value(191, :numeric_18_0) - assert_equal BigDecimal('123456789012345678'), find_value(192, :numeric_18_0) - assert_equal BigDecimal('12345678901234567890.01'), find_value(193, :numeric_36_2) - assert_equal BigDecimal('123.46'), find_value(194, :numeric_36_2) - end + it 'casts numeric' do + assert_instance_of BigDecimal, find_value(191, :numeric_18_0) + assert_equal BigDecimal('191'), find_value(191, :numeric_18_0) + assert_equal BigDecimal('123456789012345678'), find_value(192, :numeric_18_0) + assert_equal BigDecimal('12345678901234567890.01'), find_value(193, :numeric_36_2) + assert_equal BigDecimal('123.46'), find_value(194, :numeric_36_2) + end - it 'casts nvarchar' do - assert_equal 'test nvarchar_50', find_value(201, :nvarchar_50) - assert_equal 'test nvarchar_50 åå', find_value(202, :nvarchar_50) - assert_utf8_encoding find_value(202, :nvarchar_50) - end + it 'casts nvarchar' do + assert_equal 'test nvarchar_50', find_value(201, :nvarchar_50) + assert_equal 'test nvarchar_50 åå', find_value(202, :nvarchar_50) + assert_utf8_encoding find_value(202, :nvarchar_50) + end - it 'casts real' do - assert_in_delta 123.45, find_value(221, :real), 0.01 - assert_equal 0.0, find_value(222, :real) - assert_equal find_value(222, :real).object_id, find_value(222, :real).object_id, 'use global zero float' - assert_in_delta 0.00001, find_value(223, :real), 0.000001 - end + it 'casts real' do + assert_in_delta 123.45, find_value(221, :real), 0.01 + assert_equal 0.0, find_value(222, :real) + assert_equal find_value(222, :real).object_id, find_value(222, :real).object_id, 'use global zero float' + assert_in_delta 0.00001, find_value(223, :real), 0.000001 + end - it 'casts smalldatetime' do - # 1901-01-01 15:45:00 - v = find_value 231, :smalldatetime - assert_instance_of Time, v - assert_equal 1901, v.year - assert_equal 01, v.month - assert_equal 01, v.day - assert_equal 15, v.hour - assert_equal 45, v.min - assert_equal 00, v.sec - assert_equal Time.local(1901).utc_offset, find_value(231, :smalldatetime, :timezone => :local).utc_offset - assert_equal 0, find_value(231, :smalldatetime, :timezone => :utc).utc_offset - # 2078-06-05 04:20:00 - v = find_value 232, :smalldatetime - assert_instance_of Time, v - assert_equal 2078, v.year - assert_equal 06, v.month - assert_equal 05, v.day - assert_equal 04, v.hour - assert_equal 20, v.min - assert_equal 00, v.sec - assert_equal Time.local(2078,6).utc_offset, find_value(232, :smalldatetime, :timezone => :local).utc_offset - assert_equal 0, find_value(232, :smalldatetime, :timezone => :utc).utc_offset - end + it 'casts smalldatetime' do + # 1901-01-01 15:45:00 + v = find_value 231, :smalldatetime + assert_instance_of Time, v + assert_equal 1901, v.year + assert_equal 01, v.month + assert_equal 01, v.day + assert_equal 15, v.hour + assert_equal 45, v.min + assert_equal 00, v.sec + assert_equal Time.local(1901).utc_offset, find_value(231, :smalldatetime, :timezone => :local).utc_offset + assert_equal 0, find_value(231, :smalldatetime, :timezone => :utc).utc_offset + # 2078-06-05 04:20:00 + v = find_value 232, :smalldatetime + assert_instance_of Time, v + assert_equal 2078, v.year + assert_equal 06, v.month + assert_equal 05, v.day + assert_equal 04, v.hour + assert_equal 20, v.min + assert_equal 00, v.sec + assert_equal Time.local(2078, 6).utc_offset, find_value(232, :smalldatetime, :timezone => :local).utc_offset + assert_equal 0, find_value(232, :smalldatetime, :timezone => :utc).utc_offset + end - it 'casts smallint' do - assert_equal (-32767), find_value(241, :smallint) - assert_equal 32766, find_value(242, :smallint) - end + it 'casts smallint' do + assert_equal (-32767), find_value(241, :smallint) + assert_equal 32766, find_value(242, :smallint) + end - it 'casts smallmoney' do - assert_instance_of BigDecimal, find_value(251, :smallmoney) - assert_equal BigDecimal("4.20"), find_value(251, :smallmoney) - assert_equal BigDecimal("-214748.3647"), find_value(252, :smallmoney) - assert_equal BigDecimal("214748.3646"), find_value(253, :smallmoney) - end + it 'casts smallmoney' do + assert_instance_of BigDecimal, find_value(251, :smallmoney) + assert_equal BigDecimal("4.20"), find_value(251, :smallmoney) + assert_equal BigDecimal("-214748.3647"), find_value(252, :smallmoney) + assert_equal BigDecimal("214748.3646"), find_value(253, :smallmoney) + end - it 'casts text' do - assert_equal 'test text', find_value(271, :text) - assert_utf8_encoding find_value(271, :text) - end + it 'casts text' do + assert_equal 'test text', find_value(271, :text) + assert_utf8_encoding find_value(271, :text) + end - it 'casts tinyint' do - assert_equal 0, find_value(301, :tinyint) - assert_equal 255, find_value(302, :tinyint) - end + it 'casts tinyint' do + assert_equal 0, find_value(301, :tinyint) + assert_equal 255, find_value(302, :tinyint) + end - it 'casts uniqueidentifier' do - assert_match %r|\w{8}-\w{4}-\w{4}-\w{4}-\w{12}|, find_value(311, :uniqueidentifier) - assert_utf8_encoding find_value(311, :uniqueidentifier) - end unless sybase_ase? + it 'casts uniqueidentifier' do + assert_match %r|\w{8}-\w{4}-\w{4}-\w{4}-\w{12}|, find_value(311, :uniqueidentifier) + assert_utf8_encoding find_value(311, :uniqueidentifier) + end - it 'casts varbinary' do - value = find_value(321, :varbinary_50) - assert_equal @gif1px, value - assert_binary_encoding(value) - end + it 'casts varbinary' do + value = find_value(321, :varbinary_50) + assert_equal @gif1px, value + assert_binary_encoding(value) + end - it 'casts varchar' do - assert_equal 'test varchar_50', find_value(341, :varchar_50) - assert_utf8_encoding find_value(341, :varchar_50) - end + it 'casts varchar' do + assert_equal 'test varchar_50', find_value(341, :varchar_50) + assert_utf8_encoding find_value(341, :varchar_50) + end + it 'casts nvarchar(max)' do + assert_equal 'test nvarchar_max', find_value(211, :nvarchar_max) + assert_equal 'test nvarchar_max åå', find_value(212, :nvarchar_max) + assert_utf8_encoding find_value(212, :nvarchar_max) end + it 'casts varbinary(max)' do + value = find_value(331, :varbinary_max) + assert_equal @gif1px, value + assert_binary_encoding(value) + end - describe 'for 2005 and up' do + it 'casts varchar(max)' do + value = find_value(351, :varchar_max) + assert_equal 'test varchar_max', value + assert_utf8_encoding(value) + end - it 'casts nvarchar(max)' do - assert_equal 'test nvarchar_max', find_value(211, :nvarchar_max) - assert_equal 'test nvarchar_max åå', find_value(212, :nvarchar_max) - assert_utf8_encoding find_value(212, :nvarchar_max) - end + it 'casts xml' do + value = find_value(361, :xml) + assert_equal 'batz', value + assert_utf8_encoding(value) + end - it 'casts varbinary(max)' do - value = find_value(331, :varbinary_max) - assert_equal @gif1px, value - assert_binary_encoding(value) + it 'casts date' do + # 0001-01-01 + v = find_value 51, :date + if @client.tds_73? + assert_instance_of Date, v + assert_equal 1, v.year, 'Year' + assert_equal 1, v.month, 'Month' + assert_equal 1, v.day, 'Day' + else + assert_equal '0001-01-01', v end - - it 'casts varchar(max)' do - value = find_value(351, :varchar_max) - assert_equal 'test varchar_max', value - assert_utf8_encoding(value) + # 9999-12-31 + v = find_value 52, :date + if @client.tds_73? + assert_instance_of Date, v + assert_equal 9999, v.year, 'Year' + assert_equal 12, v.month, 'Month' + assert_equal 31, v.day, 'Day' + else + assert_equal '9999-12-31', v end + end - it 'casts xml' do - value = find_value(361, :xml) - assert_equal 'batz', value - assert_utf8_encoding(value) + it 'casts time' do + # 15:45:00.709714966 + v = find_value 281, :time_2 + if @client.tds_73? + assert_instance_of Time, v + assert_equal 1900, v.year, 'Year' + assert_equal 1, v.month, 'Month' + assert_equal 1, v.day, 'Day' + assert_equal 15, v.hour, 'Hour' + assert_equal 45, v.min, 'Minute' + assert_equal 0, v.sec, 'Second' + assert_equal 710000, v.usec, 'Microseconds' + assert_equal 710000000, v.nsec, 'Nanoseconds' + else + assert_equal '15:45:00.71', v end - - end if sqlserver_2005? || sqlserver_2008? || sqlserver_2014? || sqlserver_azure? - - - describe 'for 2008 and up' do - - it 'casts date' do - # 0001-01-01 - v = find_value 51, :date - if @client.tds_73? - assert_instance_of Date, v - assert_equal 1, v.year, 'Year' - assert_equal 1, v.month, 'Month' - assert_equal 1, v.day, 'Day' - else - assert_equal '0001-01-01', v - end - # 9999-12-31 - v = find_value 52, :date - if @client.tds_73? - assert_instance_of Date, v - assert_equal 9999, v.year, 'Year' - assert_equal 12, v.month, 'Month' - assert_equal 31, v.day, 'Day' - else - assert_equal '9999-12-31', v - end + # 04:20:00.288321545 + v = find_value 282, :time_2 + if @client.tds_73? + assert_instance_of Time, v + assert_equal 1900, v.year, 'Year' + assert_equal 1, v.month, 'Month' + assert_equal 1, v.day, 'Day' + assert_equal 4, v.hour, 'Hour' + assert_equal 20, v.min, 'Minute' + assert_equal 0, v.sec, 'Second' + assert_equal 290000, v.usec, 'Microseconds' + assert_equal 290000000, v.nsec, 'Nanoseconds' + else + assert_equal '04:20:00.29', v + end + # 15:45:00.709714966 + v = find_value 283, :time_7 + if @client.tds_73? + assert_instance_of Time, v + assert_equal 1900, v.year, 'Year' + assert_equal 1, v.month, 'Month' + assert_equal 1, v.day, 'Day' + assert_equal 15, v.hour, 'Hour' + assert_equal 45, v.min, 'Minute' + assert_equal 0, v.sec, 'Second' + assert_equal 709715, v.usec, 'Microseconds' + assert_equal 709715000, v.nsec, 'Nanoseconds' + else + assert_equal '15:45:00.7097150', v + end + # 04:20:00.288321545 + v = find_value 284, :time_7 + if @client.tds_73? + assert_instance_of Time, v + assert_equal 1900, v.year, 'Year' + assert_equal 1, v.month, 'Month' + assert_equal 1, v.day, 'Day' + assert_equal 4, v.hour, 'Hour' + assert_equal 20, v.min, 'Minute' + assert_equal 0, v.sec, 'Second' + assert_equal 288321, v.usec, 'Microseconds' + assert_equal 288321500, v.nsec, 'Nanoseconds' + else + assert_equal '04:20:00.2883215', v end + end - it 'casts time' do - # 15:45:00.709714966 - v = find_value 281, :time_2 - if @client.tds_73? - assert_instance_of Time, v - assert_equal 1900, v.year, 'Year' - assert_equal 1, v.month, 'Month' - assert_equal 1, v.day, 'Day' - assert_equal 15, v.hour, 'Hour' - assert_equal 45, v.min, 'Minute' - assert_equal 0, v.sec, 'Second' - assert_equal 710000, v.usec, 'Microseconds' - assert_equal 710000000, v.nsec, 'Nanoseconds' - else - assert_equal '15:45:00.71', v - end - # 04:20:00.288321545 - v = find_value 282, :time_2 - if @client.tds_73? - assert_instance_of Time, v - assert_equal 1900, v.year, 'Year' - assert_equal 1, v.month, 'Month' - assert_equal 1, v.day, 'Day' - assert_equal 4, v.hour, 'Hour' - assert_equal 20, v.min, 'Minute' - assert_equal 0, v.sec, 'Second' - assert_equal 290000, v.usec, 'Microseconds' - assert_equal 290000000, v.nsec, 'Nanoseconds' - else - assert_equal '04:20:00.29', v - end - # 15:45:00.709714966 - v = find_value 283, :time_7 - if @client.tds_73? - assert_instance_of Time, v - assert_equal 1900, v.year, 'Year' - assert_equal 1, v.month, 'Month' - assert_equal 1, v.day, 'Day' - assert_equal 15, v.hour, 'Hour' - assert_equal 45, v.min, 'Minute' - assert_equal 0, v.sec, 'Second' - assert_equal 709715, v.usec, 'Microseconds' - assert_equal 709715000, v.nsec, 'Nanoseconds' - else - assert_equal '15:45:00.7097150', v - end - # 04:20:00.288321545 - v = find_value 284, :time_7 - if @client.tds_73? - assert_instance_of Time, v - assert_equal 1900, v.year, 'Year' - assert_equal 1, v.month, 'Month' - assert_equal 1, v.day, 'Day' - assert_equal 4, v.hour, 'Hour' - assert_equal 20, v.min, 'Minute' - assert_equal 0, v.sec, 'Second' - assert_equal 288321, v.usec, 'Microseconds' - assert_equal 288321500, v.nsec, 'Nanoseconds' - else - assert_equal '04:20:00.2883215', v - end + it 'casts datetime2' do + # 0001-01-01 00:00:00.0000000 + v = find_value 71, :datetime2_7 + if @client.tds_73? + assert_instance_of Time, v + assert_equal 1, v.year, 'Year' + assert_equal 1, v.month, 'Month' + assert_equal 1, v.day, 'Day' + assert_equal 0, v.hour, 'Hour' + assert_equal 0, v.min, 'Minute' + assert_equal 0, v.sec, 'Second' + assert_equal 0, v.usec, 'Microseconds' + assert_equal 0, v.nsec, 'Nanoseconds' + else + assert_equal '0001-01-01 00:00:00.0000000', v + end + # 1984-01-24 04:20:00.0000000 + v = find_value 72, :datetime2_7 + if @client.tds_73? + assert_instance_of Time, v + assert_equal 1984, v.year, 'Year' + assert_equal 1, v.month, 'Month' + assert_equal 24, v.day, 'Day' + assert_equal 4, v.hour, 'Hour' + assert_equal 20, v.min, 'Minute' + assert_equal 0, v.sec, 'Second' + assert_equal 0, v.usec, 'Microseconds' + assert_equal 0, v.nsec, 'Nanoseconds' + else + assert_equal '1984-01-24 04:20:00.0000000', v end + # 9999-12-31 23:59:59.9999999 + v = find_value 73, :datetime2_7 + if @client.tds_73? + assert_instance_of Time, v + assert_equal 9999, v.year, 'Year' + assert_equal 12, v.month, 'Month' + assert_equal 31, v.day, 'Day' + assert_equal 23, v.hour, 'Hour' + assert_equal 59, v.min, 'Minute' + assert_equal 59, v.sec, 'Second' + assert_equal 999999, v.usec, 'Microseconds' + assert_equal 999999900, v.nsec, 'Nanoseconds' + else + assert_equal '9999-12-31 23:59:59.9999999', v + end + # 9999-12-31 23:59:59.123456789 + v = find_value 74, :datetime2_2 + if @client.tds_73? + assert_instance_of Time, v + assert_equal 9999, v.year, 'Year' + assert_equal 12, v.month, 'Month' + assert_equal 31, v.day, 'Day' + assert_equal 23, v.hour, 'Hour' + assert_equal 59, v.min, 'Minute' + assert_equal 59, v.sec, 'Second' + assert_equal 120000, v.usec, 'Microseconds' + assert_equal 120000000, v.nsec, 'Nanoseconds' + else + assert_equal '9999-12-31 23:59:59.12', v + end + end - it 'casts datetime2' do - # 0001-01-01 00:00:00.0000000 - v = find_value 71, :datetime2_7 - if @client.tds_73? + it 'casts datetimeoffset' do + # 1984-01-24T04:20:00.1234567-08:00 + v = find_value 84, :datetimeoffset_7 + if @client.tds_73? + assertions = lambda { assert_instance_of Time, v - assert_equal 1, v.year, 'Year' + assert_equal 1984, v.year, 'Year' assert_equal 1, v.month, 'Month' - assert_equal 1, v.day, 'Day' - assert_equal 0, v.hour, 'Hour' - assert_equal 0, v.min, 'Minute' - assert_equal 0, v.sec, 'Second' - assert_equal 0, v.usec, 'Microseconds' - assert_equal 0, v.nsec, 'Nanoseconds' - else - assert_equal '0001-01-01 00:00:00.0000000', v - end - # 1984-01-24 04:20:00.0000000 - v = find_value 72, :datetime2_7 - if @client.tds_73? - assert_instance_of Time, v - assert_equal 1984, v.year, 'Year' - assert_equal 1, v.month, 'Month' - assert_equal 24, v.day, 'Day' - assert_equal 4, v.hour, 'Hour' - assert_equal 20, v.min, 'Minute' - assert_equal 0, v.sec, 'Second' - assert_equal 0, v.usec, 'Microseconds' - assert_equal 0, v.nsec, 'Nanoseconds' - else - assert_equal '1984-01-24 04:20:00.0000000', v - end - # 9999-12-31 23:59:59.9999999 - v = find_value 73, :datetime2_7 - if @client.tds_73? - assert_instance_of Time, v - assert_equal 9999, v.year, 'Year' - assert_equal 12, v.month, 'Month' - assert_equal 31, v.day, 'Day' - assert_equal 23, v.hour, 'Hour' - assert_equal 59, v.min, 'Minute' - assert_equal 59, v.sec, 'Second' - assert_equal 999999, v.usec, 'Microseconds' - assert_equal 999999900, v.nsec, 'Nanoseconds' - else - assert_equal '9999-12-31 23:59:59.9999999', v - end - # 9999-12-31 23:59:59.123456789 - v = find_value 74, :datetime2_2 - if @client.tds_73? - assert_instance_of Time, v - assert_equal 9999, v.year, 'Year' - assert_equal 12, v.month, 'Month' - assert_equal 31, v.day, 'Day' - assert_equal 23, v.hour, 'Hour' - assert_equal 59, v.min, 'Minute' - assert_equal 59, v.sec, 'Second' - assert_equal 120000, v.usec, 'Microseconds' - assert_equal 120000000, v.nsec, 'Nanoseconds' - else - assert_equal '9999-12-31 23:59:59.12', v - end - end - - it 'casts datetimeoffset' do - # 1984-01-24T04:20:00.1234567-08:00 - v = find_value 84, :datetimeoffset_7 - if @client.tds_73? - assertions = lambda { - assert_instance_of Time, v - assert_equal 1984, v.year, 'Year' - assert_equal 1, v.month, 'Month' - assert_equal 24, v.day, 'Day' - assert_equal 4, v.hour, 'Hour' - assert_equal 20, v.min, 'Minute' - assert_equal 59, v.sec, 'Second' - assert_equal 123456, v.usec, 'Microseconds' - assert_equal 123456700, v.nsec, 'Nanoseconds' - assert_equal (-28800), v.utc_offset, 'Offset' - } - assertions.call - v = find_value 84, :datetimeoffset_7, timezone: :local - assertions.call # Ignores timezone query option. - else - assert_equal '1984-01-24 04:20:59.1234567 -08:00', v - end + assert_equal 24, v.day, 'Day' + assert_equal 4, v.hour, 'Hour' + assert_equal 20, v.min, 'Minute' + assert_equal 59, v.sec, 'Second' + assert_equal 123456, v.usec, 'Microseconds' + assert_equal 123456700, v.nsec, 'Nanoseconds' + assert_equal (-28800), v.utc_offset, 'Offset' + } + assertions.call + v = find_value 84, :datetimeoffset_7, timezone: :local + assertions.call # Ignores timezone query option. + else + assert_equal '1984-01-24 04:20:59.1234567 -08:00', v end + end - # it 'casts geography' do - # value = find_value 111, :geography - # assert_equal '', value - # end - # - # it 'casts geometry' do - # value = find_value 121, :geometry - # assert_equal '', value - # end - # - # it 'casts hierarchyid' do - # value = find_value 131, :hierarchyid - # assert_equal '', value - # end - - end if sqlserver_2008? || sqlserver_2014? || sqlserver_azure? + # it 'casts geography' do + # value = find_value 111, :geography + # assert_equal '', value + # end + # + # it 'casts geometry' do + # value = find_value 121, :geometry + # assert_equal '', value + # end + # + # it 'casts hierarchyid' do + # value = find_value 131, :hierarchyid + # assert_equal '', value + # end end - - - end - - - - - diff --git a/test/test_helper.rb b/test/test_helper.rb index 2cd5e874..fbb89905 100755 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -4,7 +4,7 @@ require 'minitest/autorun' require 'toxiproxy' -TINYTDS_SCHEMAS = ['sqlserver_2000', 'sqlserver_2005', 'sqlserver_2008', 'sqlserver_2014', 'sqlserver_azure', 'sybase_ase'].freeze +TINYTDS_SCHEMAS = ['sqlserver_2016', 'sqlserver_azure'].freeze module TinyTds class TestCase < MiniTest::Spec @@ -12,7 +12,7 @@ class TestCase < MiniTest::Spec class << self def current_schema - ENV['TINYTDS_SCHEMA'] || 'sqlserver_2014' + ENV['TINYTDS_SCHEMA'] || 'sqlserver_2016' end TINYTDS_SCHEMAS.each do |schema| @@ -20,11 +20,6 @@ def current_schema schema == self.current_schema end end - - def sqlserver? - current_schema =~ /sqlserver/ - end - end after { close_client } @@ -41,20 +36,13 @@ def current_schema self.class.current_schema end - def sqlserver? - self.class.sqlserver? - end - def close_client(client=@client) client.close if defined?(client) && client.is_a?(TinyTds::Client) end def new_connection(options={}) client = TinyTds::Client.new(connection_options(options)) - if sybase_ase? - client.execute("SET ANSINULL ON").do - return client - elsif sqlserver_azure? + if sqlserver_azure? client.execute('SET ANSI_NULLS ON').do client.execute('SET CURSOR_CLOSE_ON_COMMIT OFF').do client.execute('SET ANSI_NULL_DFLT_ON ON').do @@ -161,28 +149,6 @@ def load_current_schema end def drop_sql - sybase_ase? ? drop_sql_sybase : drop_sql_microsoft - end - - def drop_sql_sybase - %|IF EXISTS( - SELECT 1 FROM sysobjects WHERE type = 'U' AND name = 'datatypes' - ) DROP TABLE datatypes - IF EXISTS( - SELECT 1 FROM sysobjects WHERE type = 'P' AND name = 'tinytds_TestReturnCodes' - ) DROP PROCEDURE tinytds_TestReturnCodes - IF EXISTS( - SELECT 1 FROM sysobjects WHERE type = 'P' AND name = 'tinytds_TestPrintWithError' - ) DROP PROCEDURE tinytds_TestPrintWithError - IF EXISTS( - SELECT 1 FROM sysobjects WHERE type = 'P' AND name = 'tinytds_TestPrintWithError' - ) DROP PROCEDURE tinytds_TestPrintWithError - IF EXISTS( - SELECT 1 FROM sysobjects WHERE type = 'P' AND name = 'tinytds_TestSeveralPrints' - ) DROP PROCEDURE tinytds_TestSeveralPrints| - end - - def drop_sql_microsoft %|IF EXISTS ( SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES