activerecord-sqlserver-adapter 7.1.0 → 7.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.devcontainer/Dockerfile +30 -0
- data/.devcontainer/boot.sh +22 -0
- data/.devcontainer/devcontainer.json +38 -0
- data/.devcontainer/docker-compose.yml +37 -0
- data/CHANGELOG.md +14 -0
- data/README.md +43 -5
- data/RUNNING_UNIT_TESTS.md +3 -4
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/sqlserver/core_ext/preloader.rb +2 -0
- data/lib/active_record/connection_adapters/sqlserver/schema_creation.rb +3 -3
- data/lib/active_record/connection_adapters/sqlserver/schema_statements.rb +20 -0
- data/lib/arel/visitors/sqlserver.rb +4 -5
- data/test/cases/active_schema_test_sqlserver.rb +98 -26
- data/test/cases/coerced_tests.rb +3 -0
- data/test/cases/column_test_sqlserver.rb +4 -1
- data/test/cases/fetch_test_sqlserver.rb +19 -0
- metadata +8 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f3a248aa6570f730031990568b0f9efb68b92995fd218e43e03d806192756e29
|
|
4
|
+
data.tar.gz: a6c68a2c9320d5c510cb223fa6d175946e099503a42e4f3d40cb4c39cda386c2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 34ac63c0508d2874b4e9b535688138749472ed6817ace45ffa887c7fb0b40739d276da48a6f4962e12ae6f1e8547fc66d004740e8cbdf77f745386b060456111
|
|
7
|
+
data.tar.gz: 46c1c6351facef6559cdaacf9e7f6ab99b6e788a73e2d7701b72de6d957c680270b1e774fffdcf1ab7e9af1a4616de17e0a8ac3f9745b9792b4ee0c521485df6
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.191.1/containers/ruby/.devcontainer/base.Dockerfile
|
|
2
|
+
|
|
3
|
+
# [Choice] Ruby version: 3, 3.0, 2, 2.7, 2.6
|
|
4
|
+
ARG VARIANT="3"
|
|
5
|
+
FROM mcr.microsoft.com/devcontainers/ruby:${VARIANT}
|
|
6
|
+
|
|
7
|
+
# TinyTDS
|
|
8
|
+
RUN apt-get -y install libc6-dev \
|
|
9
|
+
&& wget http://www.freetds.org/files/stable/freetds-1.1.32.tar.gz \
|
|
10
|
+
&& tar -xzf freetds-1.1.32.tar.gz \
|
|
11
|
+
&& cd freetds-1.1.32 \
|
|
12
|
+
&& ./configure --prefix=/usr/local --with-tdsver=7.3 \
|
|
13
|
+
&& make \
|
|
14
|
+
&& make install
|
|
15
|
+
|
|
16
|
+
# Install the SQL Server command-line tools
|
|
17
|
+
RUN curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc \
|
|
18
|
+
&& curl https://packages.microsoft.com/config/ubuntu/22.04/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list \
|
|
19
|
+
&& apt-get update \
|
|
20
|
+
&& ACCEPT_EULA=Y apt-get install -y mssql-tools18 unixodbc-dev \
|
|
21
|
+
&& echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> ~/.bashrc \
|
|
22
|
+
&& echo 'export PATH="$PATH:/opt/mssql-tools18/bin"' >> /root/.bashrc
|
|
23
|
+
|
|
24
|
+
# Add the SQL Server main Gemfile and install the gems.
|
|
25
|
+
RUN mkdir -p /tmp/activerecord-sqlserver-adapter
|
|
26
|
+
COPY Gemfile VERSION activerecord-sqlserver-adapter.gemspec /tmp/activerecord-sqlserver-adapter/
|
|
27
|
+
RUN cd /tmp/activerecord-sqlserver-adapter \
|
|
28
|
+
&& bundle install \
|
|
29
|
+
&& rm -rf /tmp/activerecord-sqlserver-adapter
|
|
30
|
+
RUN chown -R vscode:vscode /usr/local/rvm
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
sudo chown -R vscode:vscode /usr/local/bundle
|
|
2
|
+
|
|
3
|
+
# Wait for 5 seconds to make sure SQL Server came up.
|
|
4
|
+
sleep 5
|
|
5
|
+
|
|
6
|
+
# Setup test databases and users.
|
|
7
|
+
/opt/mssql-tools18/bin/sqlcmd -C -S sqlserver -U sa -P "MSSQLadmin!" <<SQL
|
|
8
|
+
CREATE DATABASE [activerecord_unittest];
|
|
9
|
+
CREATE DATABASE [activerecord_unittest2];
|
|
10
|
+
GO
|
|
11
|
+
CREATE LOGIN [rails] WITH PASSWORD = '', CHECK_POLICY = OFF, DEFAULT_DATABASE = [activerecord_unittest];
|
|
12
|
+
GO
|
|
13
|
+
USE [activerecord_unittest];
|
|
14
|
+
CREATE USER [rails] FOR LOGIN [rails];
|
|
15
|
+
GO
|
|
16
|
+
EXEC sp_addrolemember N'db_owner', N'rails';
|
|
17
|
+
EXEC master..sp_addsrvrolemember @loginame = N'rails', @rolename = N'sysadmin';
|
|
18
|
+
GO
|
|
19
|
+
SQL
|
|
20
|
+
|
|
21
|
+
# Mark directory as safe in Git so that commands run without warnings.
|
|
22
|
+
git config --global --add safe.directory /workspaces/activerecord-sqlserver-adapter
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json.
|
|
2
|
+
{
|
|
3
|
+
"name": "ActiveRecord SQL Server Adapter project development",
|
|
4
|
+
"dockerComposeFile": "docker-compose.yml",
|
|
5
|
+
"service": "activerecord-sqlserver-adapter",
|
|
6
|
+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
|
|
7
|
+
|
|
8
|
+
// Features to add to the dev container. More info: https://containers.dev/features.
|
|
9
|
+
"features": {
|
|
10
|
+
"ghcr.io/devcontainers/features/github-cli:1": {
|
|
11
|
+
"version": "latest"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
"containerEnv": {
|
|
16
|
+
"ACTIVERECORD_UNITTEST_HOST": "sqlserver"
|
|
17
|
+
},
|
|
18
|
+
|
|
19
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
|
20
|
+
// This can be used to network with other containers or the host.
|
|
21
|
+
// "forwardPorts": [3000, 5432],
|
|
22
|
+
|
|
23
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
|
24
|
+
"postCreateCommand": ".devcontainer/boot.sh",
|
|
25
|
+
|
|
26
|
+
// Configure tool-specific properties.
|
|
27
|
+
"customizations": {
|
|
28
|
+
"vscode": {
|
|
29
|
+
// Add the IDs of extensions you want installed when the container is created.
|
|
30
|
+
"extensions": [
|
|
31
|
+
"Shopify.ruby-lsp"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
|
37
|
+
// "remoteUser": "root"
|
|
38
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
version: '3'
|
|
2
|
+
|
|
3
|
+
services:
|
|
4
|
+
activerecord-sqlserver-adapter:
|
|
5
|
+
build:
|
|
6
|
+
context: ..
|
|
7
|
+
dockerfile: .devcontainer/Dockerfile
|
|
8
|
+
|
|
9
|
+
volumes:
|
|
10
|
+
- ../..:/workspaces:cached
|
|
11
|
+
|
|
12
|
+
# Overrides default command so things don't shut down after the process ends.
|
|
13
|
+
command: sleep infinity
|
|
14
|
+
|
|
15
|
+
# Runs app on the same network as the database container, allows "forwardPorts" in devcontainer.json function.
|
|
16
|
+
networks:
|
|
17
|
+
- default
|
|
18
|
+
|
|
19
|
+
depends_on:
|
|
20
|
+
- sqlserver
|
|
21
|
+
|
|
22
|
+
# Use "forwardPorts" in **devcontainer.json** to forward an app port locally.
|
|
23
|
+
# (Adding the "ports" property to this file will not forward from a Codespace.)
|
|
24
|
+
|
|
25
|
+
sqlserver:
|
|
26
|
+
image: mcr.microsoft.com/mssql/server:2022-latest
|
|
27
|
+
restart: unless-stopped
|
|
28
|
+
networks:
|
|
29
|
+
- default
|
|
30
|
+
ports:
|
|
31
|
+
- "1433:1433"
|
|
32
|
+
environment:
|
|
33
|
+
MSSQL_SA_PASSWORD: MSSQLadmin!
|
|
34
|
+
ACCEPT_EULA: Y
|
|
35
|
+
|
|
36
|
+
networks:
|
|
37
|
+
default:
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## v7.1.2
|
|
2
|
+
|
|
3
|
+
#### Fixed
|
|
4
|
+
|
|
5
|
+
- [#1151](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1151) FROM subquery should work if order provided
|
|
6
|
+
|
|
7
|
+
## v7.1.1
|
|
8
|
+
|
|
9
|
+
#### Fixed
|
|
10
|
+
|
|
11
|
+
- [#1145](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1145) Ensure correct order of COLLATE and NOT NULL in CREATE TABLE statements
|
|
12
|
+
- [#1144](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1144) Fix precision handling in time migration
|
|
13
|
+
- [#1143](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/pull/1143) Fix precision handling for datetimeoffset migration
|
|
14
|
+
|
|
1
15
|
## v7.1.0
|
|
2
16
|
|
|
3
17
|
#### Added
|
data/README.md
CHANGED
|
@@ -13,7 +13,7 @@ Interested in older versions? We follow a rational versioning policy that tracks
|
|
|
13
13
|
|
|
14
14
|
| Adapter Version | Rails Version | Support | Branch |
|
|
15
15
|
|-----------------|---------------|---------|--------------------------------------------------------------------------------------------------|
|
|
16
|
-
| `7.1.
|
|
16
|
+
| `7.1.2` | `7.1.x` | Active | [main](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main) |
|
|
17
17
|
| `7.0.5.1` | `7.0.x` | Active | [7-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/7-0-stable) |
|
|
18
18
|
| `6.1.3.0` | `6.1.x` | Active | [6-1-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-1-stable) |
|
|
19
19
|
| `6.0.3` | `6.0.x` | Ended | [6-0-stable](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/6-0-stable) |
|
|
@@ -100,7 +100,7 @@ module ActiveRecord
|
|
|
100
100
|
class SQLServerAdapter < AbstractAdapter
|
|
101
101
|
def configure_connection
|
|
102
102
|
super
|
|
103
|
-
|
|
103
|
+
@raw_connection.execute("SET TEXTSIZE #{64.megabytes}").do
|
|
104
104
|
end
|
|
105
105
|
end
|
|
106
106
|
end
|
|
@@ -183,11 +183,49 @@ gem 'activerecord-sqlserver-adapter'
|
|
|
183
183
|
|
|
184
184
|
## Contributing
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
Please contribute to the project by submitting bug fixes and features. To make sure your fix/feature has
|
|
187
|
+
a high chance of being added, please include tests in your pull request. To run the tests you will need to
|
|
188
|
+
setup your development environment.
|
|
187
189
|
|
|
188
|
-
|
|
189
|
-
* Gitter: https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter
|
|
190
|
+
## Setting Up Your Development Environment
|
|
190
191
|
|
|
192
|
+
To run the test suite you can use any of the following methods below. See [RUNNING_UNIT_TESTS](RUNNING_UNIT_TESTS.md) for
|
|
193
|
+
more detailed information on running unit tests.
|
|
194
|
+
|
|
195
|
+
### Dev Container CLI
|
|
196
|
+
|
|
197
|
+
With [Docker](https://www.docker.com) and [npm](https://github.com/npm/cli) installed, you can run [Dev Container CLI](https://github.com/devcontainers/cli) to
|
|
198
|
+
utilize the [`.devcontainer`](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/main/.devcontainer) configuration from the command line.
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
$ npm install -g @devcontainers/cli
|
|
202
|
+
$ cd rails
|
|
203
|
+
$ devcontainer up --workspace-folder .
|
|
204
|
+
$ devcontainer exec --workspace-folder . bash
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
From within the container, you can run the tests using the following command:
|
|
208
|
+
|
|
209
|
+
```bash
|
|
210
|
+
$ bundle install
|
|
211
|
+
$ bundle exec rake test
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
_Note: The setup we use is based on the [Rails Dev Container setup.](https://guides.rubyonrails.org/contributing_to_ruby_on_rails.html#using-dev-container-cli)_
|
|
215
|
+
|
|
216
|
+
### VirtualBox & Vagrant
|
|
217
|
+
|
|
218
|
+
The [activerecord-sqlserver-adapter-dev-box](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter-dev-box)
|
|
219
|
+
is a Vagrant/VirtualBox virtual machine that has MS SQL Server installed. However, the
|
|
220
|
+
activerecord-sqlserver-adapter-dev-box uses Vagrant and Virtual Box which will not work on Macs with Apple silicon.
|
|
221
|
+
|
|
222
|
+
### Local Development
|
|
223
|
+
|
|
224
|
+
See the [RUNNING_UNIT_TESTS](RUNNING_UNIT_TESTS.md) file for the details of how to run the unit tests locally.
|
|
225
|
+
|
|
226
|
+
## Community
|
|
227
|
+
|
|
228
|
+
There is a [Gitter channel](https://gitter.im/rails-sqlserver/activerecord-sqlserver-adapter) for the project where you are free to ask questions about the project.
|
|
191
229
|
|
|
192
230
|
## Credits & Contributions
|
|
193
231
|
|
data/RUNNING_UNIT_TESTS.md
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
+
# How To Run The Tests Locally
|
|
1
2
|
|
|
2
|
-
|
|
3
|
+
The following is a description of how to run the tests for the SQL Server adapter on a local environment.
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
## MS SQL SERVER
|
|
5
|
+
## MS SQL Server instance
|
|
7
6
|
|
|
8
7
|
If you don't have easy access to MS SQL Server, you can set up a Vagrant/VirtualBox virtual machine with MS SQL Server. [Here's how](https://github.com/rails-sqlserver/activerecord-sqlserver-adapter-dev-box).
|
|
9
8
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
7.1.
|
|
1
|
+
7.1.2
|
|
@@ -51,12 +51,12 @@ module ActiveRecord
|
|
|
51
51
|
|
|
52
52
|
def add_column_options!(sql, options)
|
|
53
53
|
sql << " DEFAULT #{quote_default_expression(options[:default], options[:column])}" if options_include_default?(options)
|
|
54
|
-
if options[:null] == false
|
|
55
|
-
sql << " NOT NULL"
|
|
56
|
-
end
|
|
57
54
|
if options[:collation].present?
|
|
58
55
|
sql << " COLLATE #{options[:collation]}"
|
|
59
56
|
end
|
|
57
|
+
if options[:null] == false
|
|
58
|
+
sql << " NOT NULL"
|
|
59
|
+
end
|
|
60
60
|
if options[:is_identity] == true
|
|
61
61
|
sql << " IDENTITY(1,1)"
|
|
62
62
|
end
|
|
@@ -303,6 +303,16 @@ module ActiveRecord
|
|
|
303
303
|
when 5..8 then "bigint"
|
|
304
304
|
else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.")
|
|
305
305
|
end
|
|
306
|
+
when "time" # https://learn.microsoft.com/en-us/sql/t-sql/data-types/time-transact-sql
|
|
307
|
+
column_type_sql = type.to_s
|
|
308
|
+
if precision
|
|
309
|
+
if (0..7) === precision
|
|
310
|
+
column_type_sql << "(#{precision})"
|
|
311
|
+
else
|
|
312
|
+
raise(ActiveRecordError, "The time type has precision of #{precision}. The allowed range of precision is from 0 to 7")
|
|
313
|
+
end
|
|
314
|
+
end
|
|
315
|
+
column_type_sql
|
|
306
316
|
when "datetime2"
|
|
307
317
|
column_type_sql = super
|
|
308
318
|
if precision
|
|
@@ -313,6 +323,16 @@ module ActiveRecord
|
|
|
313
323
|
end
|
|
314
324
|
end
|
|
315
325
|
column_type_sql
|
|
326
|
+
when "datetimeoffset"
|
|
327
|
+
column_type_sql = super
|
|
328
|
+
if precision
|
|
329
|
+
if (0..7) === precision
|
|
330
|
+
column_type_sql << "(#{precision})"
|
|
331
|
+
else
|
|
332
|
+
raise(ActiveRecordError, "The datetimeoffset type has precision of #{precision}. The allowed range of precision is from 0 to 7")
|
|
333
|
+
end
|
|
334
|
+
end
|
|
335
|
+
column_type_sql
|
|
316
336
|
else
|
|
317
337
|
super
|
|
318
338
|
end
|
|
@@ -213,7 +213,7 @@ module Arel
|
|
|
213
213
|
|
|
214
214
|
def visit_Orders_And_Let_Fetch_Happen(o, collector)
|
|
215
215
|
make_Fetch_Possible_And_Deterministic o
|
|
216
|
-
|
|
216
|
+
if o.orders.any?
|
|
217
217
|
collector << " ORDER BY "
|
|
218
218
|
len = o.orders.length - 1
|
|
219
219
|
o.orders.each_with_index { |x, i|
|
|
@@ -261,15 +261,14 @@ module Arel
|
|
|
261
261
|
|
|
262
262
|
def make_Fetch_Possible_And_Deterministic(o)
|
|
263
263
|
return if o.limit.nil? && o.offset.nil?
|
|
264
|
+
return if o.orders.any?
|
|
264
265
|
|
|
265
266
|
t = table_From_Statement o
|
|
266
267
|
pk = primary_Key_From_Table t
|
|
267
268
|
return unless pk
|
|
268
269
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
o.orders = [pk.asc]
|
|
272
|
-
end
|
|
270
|
+
# Prefer deterministic vs a simple `(SELECT NULL)` expr.
|
|
271
|
+
o.orders = [pk.asc]
|
|
273
272
|
end
|
|
274
273
|
|
|
275
274
|
def distinct_One_As_One_Is_So_Not_Fetch(o)
|
|
@@ -3,43 +3,43 @@
|
|
|
3
3
|
require "cases/helper_sqlserver"
|
|
4
4
|
|
|
5
5
|
class ActiveSchemaTestSQLServer < ActiveRecord::TestCase
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
describe "indexes" do
|
|
7
|
+
before do
|
|
8
|
+
connection.create_table :schema_test_table, force: true, id: false do |t|
|
|
9
|
+
t.column :foo, :string, limit: 100
|
|
10
|
+
t.column :state, :string
|
|
11
|
+
end
|
|
10
12
|
end
|
|
11
|
-
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
after do
|
|
15
|
+
connection.drop_table :schema_test_table rescue nil
|
|
16
|
+
end
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
it 'default index' do
|
|
19
|
+
assert_sql('CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
|
|
20
|
+
connection.add_index :schema_test_table, "foo"
|
|
21
|
+
end
|
|
20
22
|
end
|
|
21
|
-
end
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
it 'unique index' do
|
|
25
|
+
assert_sql('CREATE UNIQUE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
|
|
26
|
+
connection.add_index :schema_test_table, "foo", unique: true
|
|
27
|
+
end
|
|
26
28
|
end
|
|
27
|
-
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
it 'where condition on index' do
|
|
31
|
+
assert_sql("CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo]) WHERE state = 'active'") do
|
|
32
|
+
connection.add_index :schema_test_table, "foo", where: "state = 'active'"
|
|
33
|
+
end
|
|
32
34
|
end
|
|
33
|
-
end
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
it 'if index does not exist' do
|
|
37
|
+
assert_sql("IF NOT EXISTS (SELECT name FROM sysindexes WHERE name = 'index_schema_test_table_on_foo') " \
|
|
38
|
+
"CREATE INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])") do
|
|
39
|
+
connection.add_index :schema_test_table, "foo", if_not_exists: true
|
|
40
|
+
end
|
|
39
41
|
end
|
|
40
|
-
end
|
|
41
42
|
|
|
42
|
-
describe "index types" do
|
|
43
43
|
it 'clustered index' do
|
|
44
44
|
assert_sql('CREATE CLUSTERED INDEX [index_schema_test_table_on_foo] ON [schema_test_table] ([foo])') do
|
|
45
45
|
connection.add_index :schema_test_table, "foo", type: :clustered
|
|
@@ -52,4 +52,76 @@ class ActiveSchemaTestSQLServer < ActiveRecord::TestCase
|
|
|
52
52
|
end
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
|
+
|
|
56
|
+
describe 'collation' do
|
|
57
|
+
it "create column with NOT NULL and COLLATE" do
|
|
58
|
+
assert_nothing_raised do
|
|
59
|
+
connection.create_table :not_null_with_collation_table, force: true, id: false do |t|
|
|
60
|
+
t.text :not_null_text_with_collation, null: false, collation: "Latin1_General_CS_AS"
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
ensure
|
|
64
|
+
connection.drop_table :not_null_with_collation_table rescue nil
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe 'datetimeoffset precision' do
|
|
69
|
+
it 'valid precisions are correct' do
|
|
70
|
+
assert_nothing_raised do
|
|
71
|
+
connection.create_table :datetimeoffset_precisions do |t|
|
|
72
|
+
t.datetimeoffset :precision_default
|
|
73
|
+
t.datetimeoffset :precision_5, precision: 5
|
|
74
|
+
t.datetimeoffset :precision_7, precision: 7
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
columns = connection.columns("datetimeoffset_precisions")
|
|
79
|
+
|
|
80
|
+
assert_equal columns.find { |column| column.name == "precision_default" }.precision, 7
|
|
81
|
+
assert_equal columns.find { |column| column.name == "precision_5" }.precision, 5
|
|
82
|
+
assert_equal columns.find { |column| column.name == "precision_7" }.precision, 7
|
|
83
|
+
ensure
|
|
84
|
+
connection.drop_table :datetimeoffset_precisions rescue nil
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'invalid precision raises exception' do
|
|
88
|
+
assert_raise(ActiveRecord::ActiveRecordError) do
|
|
89
|
+
connection.create_table :datetimeoffset_precisions do |t|
|
|
90
|
+
t.datetimeoffset :precision_8, precision: 8
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
ensure
|
|
94
|
+
connection.drop_table :datetimeoffset_precisions rescue nil
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
describe 'time precision' do
|
|
99
|
+
it 'valid precisions are correct' do
|
|
100
|
+
assert_nothing_raised do
|
|
101
|
+
connection.create_table :time_precisions do |t|
|
|
102
|
+
t.time :precision_default
|
|
103
|
+
t.time :precision_5, precision: 5
|
|
104
|
+
t.time :precision_7, precision: 7
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
columns = connection.columns("time_precisions")
|
|
109
|
+
|
|
110
|
+
assert_equal columns.find { |column| column.name == "precision_default" }.precision, 7
|
|
111
|
+
assert_equal columns.find { |column| column.name == "precision_5" }.precision, 5
|
|
112
|
+
assert_equal columns.find { |column| column.name == "precision_7" }.precision, 7
|
|
113
|
+
ensure
|
|
114
|
+
connection.drop_table :time_precisions rescue nil
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it 'invalid precision raises exception' do
|
|
118
|
+
assert_raise(ActiveRecord::ActiveRecordError) do
|
|
119
|
+
connection.create_table :time_precisions do |t|
|
|
120
|
+
t.time :precision_8, precision: 8
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
ensure
|
|
124
|
+
connection.drop_table :time_precisions rescue nil
|
|
125
|
+
end
|
|
126
|
+
end
|
|
55
127
|
end
|
data/test/cases/coerced_tests.rb
CHANGED
|
@@ -1832,6 +1832,9 @@ class TimePrecisionTest < ActiveRecord::TestCase
|
|
|
1832
1832
|
|
|
1833
1833
|
# SQL Server uses default precision for time.
|
|
1834
1834
|
coerce_tests! :test_no_time_precision_isnt_truncated_on_assignment
|
|
1835
|
+
|
|
1836
|
+
# SQL Server accepts precision of 7 for time.
|
|
1837
|
+
coerce_tests! :test_invalid_time_precision_raises_error
|
|
1835
1838
|
end
|
|
1836
1839
|
|
|
1837
1840
|
class DefaultNumbersTest < ActiveRecord::TestCase
|
|
@@ -435,13 +435,15 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
435
435
|
_(type.limit).must_be_nil
|
|
436
436
|
_(type.precision).must_equal 7
|
|
437
437
|
_(type.scale).must_be_nil
|
|
438
|
-
|
|
438
|
+
|
|
439
|
+
# Can save 100 nanosecond precisions and return again.
|
|
439
440
|
obj.datetimeoffset_7 = Time.new(2010, 4, 1, 12, 34, 56, +18000).change(nsec: 123456755)
|
|
440
441
|
_(obj.datetimeoffset_7).must_equal Time.new(2010, 4, 1, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
|
|
441
442
|
obj.save!
|
|
442
443
|
_(obj.datetimeoffset_7).must_equal Time.new(2010, 4, 1, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
|
|
443
444
|
obj.reload
|
|
444
445
|
_(obj.datetimeoffset_7).must_equal Time.new(2010, 4, 1, 12, 34, 56, +18000).change(nsec: 123456800), "Nanoseconds were <#{obj.datetimeoffset_7.nsec}> vs <123456800>"
|
|
446
|
+
|
|
445
447
|
# Maintains the timezone
|
|
446
448
|
time = ActiveSupport::TimeZone["America/Los_Angeles"].local 2010, 12, 31, 23, 59, 59, Rational(123456800, 1000)
|
|
447
449
|
obj.datetimeoffset_7 = time
|
|
@@ -449,6 +451,7 @@ class ColumnTestSQLServer < ActiveRecord::TestCase
|
|
|
449
451
|
obj.save!
|
|
450
452
|
_(obj.datetimeoffset_7).must_equal time
|
|
451
453
|
_(obj.reload.datetimeoffset_7).must_equal time
|
|
454
|
+
|
|
452
455
|
# With other precisions.
|
|
453
456
|
time = ActiveSupport::TimeZone["America/Los_Angeles"].local 2010, 12, 31, 23, 59, 59, Rational(123456755, 1000)
|
|
454
457
|
col = column("datetimeoffset_3")
|
|
@@ -42,6 +42,25 @@ class FetchTestSqlserver < ActiveRecord::TestCase
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
+
describe "FROM subquery" do
|
|
46
|
+
let(:from_sql) { "(SELECT [books].* FROM [books]) [books]" }
|
|
47
|
+
|
|
48
|
+
it "SQL generated correctly for FROM subquery if order provided" do
|
|
49
|
+
query = Book.from(from_sql).order(:id).limit(5)
|
|
50
|
+
|
|
51
|
+
assert_equal query.to_sql, "SELECT [books].* FROM (SELECT [books].* FROM [books]) [books] ORDER BY [books].[id] ASC OFFSET 0 ROWS FETCH NEXT 5 ROWS ONLY"
|
|
52
|
+
assert_equal query.to_a.count, 5
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "exception thrown if FROM subquery is provided without an order" do
|
|
56
|
+
query = Book.from(from_sql).limit(5)
|
|
57
|
+
|
|
58
|
+
assert_raise(ActiveRecord::StatementInvalid) do
|
|
59
|
+
query.to_sql
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
45
64
|
protected
|
|
46
65
|
|
|
47
66
|
def create_10_books
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-sqlserver-adapter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 7.1.
|
|
4
|
+
version: 7.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ken Collins
|
|
@@ -15,7 +15,7 @@ authors:
|
|
|
15
15
|
autorequire:
|
|
16
16
|
bindir: bin
|
|
17
17
|
cert_chain: []
|
|
18
|
-
date:
|
|
18
|
+
date: 2024-01-23 00:00:00.000000000 Z
|
|
19
19
|
dependencies:
|
|
20
20
|
- !ruby/object:Gem::Dependency
|
|
21
21
|
name: activerecord
|
|
@@ -53,6 +53,10 @@ executables: []
|
|
|
53
53
|
extensions: []
|
|
54
54
|
extra_rdoc_files: []
|
|
55
55
|
files:
|
|
56
|
+
- ".devcontainer/Dockerfile"
|
|
57
|
+
- ".devcontainer/boot.sh"
|
|
58
|
+
- ".devcontainer/devcontainer.json"
|
|
59
|
+
- ".devcontainer/docker-compose.yml"
|
|
56
60
|
- ".editorconfig"
|
|
57
61
|
- ".github/issue_template.md"
|
|
58
62
|
- ".github/workflows/ci.yml"
|
|
@@ -235,8 +239,8 @@ licenses:
|
|
|
235
239
|
- MIT
|
|
236
240
|
metadata:
|
|
237
241
|
bug_tracker_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/issues
|
|
238
|
-
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.1.
|
|
239
|
-
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.
|
|
242
|
+
changelog_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/blob/v7.1.2/CHANGELOG.md
|
|
243
|
+
source_code_uri: https://github.com/rails-sqlserver/activerecord-sqlserver-adapter/tree/v7.1.2
|
|
240
244
|
post_install_message:
|
|
241
245
|
rdoc_options: []
|
|
242
246
|
require_paths:
|