Skip to content

Commit 748b2f4

Browse files
committed
meging improvements from support-1.1
nifs for all varchar codepages are included and will be moved to new repo/package
1 parent 2148d65 commit 748b2f4

36 files changed

+3380
-1341
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ cover/
99
.idea/
1010
.code/
1111
.tool-versions
12+
priv/native
13+
native/tds_encoding/target

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@ but any query output will be decoded always into one of above types.
1111
column types `binary_id` (`uuid`).
1212
* For same reason as above `Tds.VarChar` is now `Tds.Types.VarChar`
1313

14+
# v1.2.0
15+
### Improvements
16+
- `char`, `nchar`, `text`, `ntext`, `varchar` and `nvarchar` encoding improvements
17+
for most of the SQL collations. More will be supported.
18+
19+
# v1.1.7
20+
### Bugfix
21+
- Fix for "Error with set_transaction_isolation_level: :read_uncommited" [issue #72](https://github.com/livehelpnow/tds_ecto/issues/72)
22+
23+
1424
# v2.0.0
1525
### Improvements:
1626
* Implements DBConnection v2.0 to support `ecto_sql`. Please note that starting from this version [tds_ecto](https://hex.pm/packages/tds_ecto) is not improved anymore and will not use tds version 2.0.0+, instead use [ecto_sql](https://hex.pm/packages/ecto_sql) where tds_ecto will become part of it starting from version 3.1.0.
1727

28+
1829
# v1.1.5
1930
### Improvements
2031
* Allow users to choose between `:prepare_execute` and `:executesql` style (PR #71) default is `:prepare_execute`

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1-
# Tds
1+
# Tds - MSSQL Driver for Elixir
22

3-
[![Hex.pm](https://img.shields.io/hexpm/v/tds.svg)](https://hex.pm/packages/tds) [![Build status](https://ci.appveyor.com/api/projects/status/aibnqbukppa3kcpt?svg=true)](https://ci.appveyor.com/project/mjaric/tds)
3+
[![Hex.pm](https://img.shields.io/hexpm/v/tds.svg)](https://hex.pm/packages/tds)
4+
[![Coverage Status](https://coveralls.io/repos/github/livehelpnow/tds/badge.svg?branch=support-1.1)](https://coveralls.io/github/livehelpnow/tds?branch=support-1.1)
5+
[![Build status](https://travis-ci.org/livehelpnow/tds.svg?branch=support-1.1)](https://travis-ci.org/livehelpnow/tds)
46

57
MSSQL / TDS Database driver for Elixir.
68

79
### NOTE:
810
Since TDS version 2.0, `tds_ecto` package is deprecated, this version supports `ecto_sql` since version 3.1.0.
911

10-
Please check out the [issues](https://github.com/livehelpnow/tds/issues) for a more complete overview or [CHANGELOG.md](CHANGELOG.md).
12+
Please check out the issues for a more complete overview. This branch should not be considered stable or ready for production yet.
13+
14+
For stable versions always use [hex.pm](https://hex.pm/packages/tds) as source for your mix.exs!!!
1115

1216
## Usage
1317

18+
As of TDS version `>= 1.2`, it requires `rust` to be installed for nif required to
19+
properly encode/decode `char`, `text` and `varchars`. In previous versions only
20+
SQL_Latin1_General was suported. Please follow instructions at [rust website](https://www.rust-lang.org/tools/install)
21+
22+
1423
Add Tds as a dependency in your `mix.exs` file.
1524

1625
```elixir
@@ -85,7 +94,7 @@ Since v1.0.16, additional connection parameters are:
8594
- `:set_lock_timeout` - number in milliseconds > 0
8695
- `:set_remote_proc_transactions` - atom, one of `:on | :off`
8796
- `:set_implicit_transactions` - atom, one of `:on | :off`
88-
- `:set_transaction_isolation_level` - atom, one of `:read_uncommited | :read_commited | :repeatable_read | :snapshot | :serializable`
97+
- `:set_transaction_isolation_level` - atom, one of `:read_uncommitted | :read_committed | :repeatable_read | :snapshot | :serializable`
8998
- `:set_allow_snapshot_isolation` - atom, one of `:on | :off`
9099
- `:set_read_committed_snapshot` - atom, one of `:on | :off`
91100

appveyor.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
os: Visual Studio 2015
2+
version: 1.2.{build}
3+
environment:
4+
SQL_PASSWORD: Password12!
5+
matrix:
6+
### MSVC Toolchains ###
7+
# Stable 64-bit MSVC
8+
- channel: stable
9+
target: x86_64-pc-windows-msvc
10+
# Stable 32-bit MSVC
11+
- channel: stable
12+
target: i686-pc-windows-msvc
13+
# Beta 64-bit MSVC
14+
- channel: beta
15+
target: x86_64-pc-windows-msvc
16+
# Beta 32-bit MSVC
17+
- channel: beta
18+
target: i686-pc-windows-msvc
19+
# Nightly 64-bit MSVC
20+
- channel: nightly
21+
target: x86_64-pc-windows-msvc
22+
#cargoflags: --features "unstable"
23+
# Nightly 32-bit MSVC
24+
- channel: nightly
25+
target: i686-pc-windows-msvc
26+
#cargoflags: --features "unstable"
27+
### GNU Toolchains ###
28+
# Stable 64-bit GNU
29+
- channel: stable
30+
target: x86_64-pc-windows-gnu
31+
# Stable 32-bit GNU
32+
- channel: stable
33+
target: i686-pc-windows-gnu
34+
# Beta 64-bit GNU
35+
- channel: beta
36+
target: x86_64-pc-windows-gnu
37+
# Beta 32-bit GNU
38+
- channel: beta
39+
target: i686-pc-windows-gnu
40+
# Nightly 64-bit GNU
41+
- channel: nightly
42+
target: x86_64-pc-windows-gnu
43+
#cargoflags: --features "unstable"
44+
# Nightly 32-bit GNU
45+
- channel: nightly
46+
target: i686-pc-windows-gnu
47+
#cargoflags: --features "unstable"
48+
matrix:
49+
allow_failures:
50+
- channel: nightly
51+
52+
services: mssql2016
53+
install:
54+
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
55+
- rustup-init -yv --default-toolchain %channel% --default-host %target%
56+
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
57+
- rustc -vV
58+
- cargo -vV
59+
- ps: >-
60+
iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex
61+
choco install elixir -version 1.6.5
62+
refreshenv
63+
build_script:
64+
- cmd: >-
65+
refreshenv
66+
C:\ProgramData\chocolatey\lib\Elixir\bin\mix.bat local.hex --force
67+
C:\ProgramData\chocolatey\lib\Elixir\bin\mix.bat local.rebar --force
68+
C:\ProgramData\chocolatey\lib\Elixir\bin\mix.bat deps.get
69+
test_script:
70+
- cmd: >-
71+
refreshenv
72+
C:\ProgramData\chocolatey\lib\Elixir\bin\mix.bat test
73+
notifications:
74+
- provider: Email
75+
to:
76+
- milan.jaric@gmail.com
77+
subject: TDS build fail
78+
on_build_success: false
79+
on_build_failure: true
80+
on_build_status_changed: true

config/test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ config :tds,
88
username: System.get_env("SQL_USERNAME") || "sa",
99
password: System.get_env("SQL_PASSWORD") || "some!Password",
1010
database: "test",
11+
trace: false,
1112
set_allow_snapshot_isolation: :on
1213
]

lib/tds/date_time.ex

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
defmodule Tds.Date do
2+
@moduledoc """
3+
Struct for MSSQL date.
4+
5+
https://msdn.microsoft.com/en-us/library/bb630352.aspx
6+
7+
## Fields
8+
9+
* `year`
10+
* `month`
11+
* `day`
12+
"""
13+
@type t :: %__MODULE__{year: 1..9999, month: 1..12, day: 1..31}
14+
defstruct year: 1900,
15+
month: 1,
16+
day: 1
17+
end
18+
19+
defmodule Tds.Time do
20+
@moduledoc """
21+
Struct for MSSQL time.
22+
23+
https://msdn.microsoft.com/en-us/library/bb677243.aspx
24+
25+
## Fields
26+
27+
* `hour`
28+
* `min`
29+
* `sec`
30+
* `fsec`
31+
"""
32+
@type t :: %__MODULE__{
33+
hour: 0..23,
34+
min: 0..59,
35+
sec: 0..59,
36+
fsec: 0..9_999_999
37+
}
38+
defstruct hour: 0,
39+
min: 0,
40+
sec: 0,
41+
fsec: 0
42+
end
43+
44+
defmodule Tds.DateTime do
45+
@moduledoc """
46+
Struct for MSSQL DateTime.
47+
48+
https://msdn.microsoft.com/en-us/library/ms187819.aspx
49+
50+
## Fields
51+
52+
* `year`
53+
* `month`
54+
* `day`
55+
* `hour`
56+
* `min`
57+
* `sec`
58+
"""
59+
60+
@type t :: %__MODULE__{
61+
year: 1753..9999,
62+
month: 1..12,
63+
day: 1..31,
64+
hour: 0..23,
65+
min: 0..59,
66+
sec: 0..59,
67+
fsec: 0..999
68+
}
69+
defstruct year: 1900,
70+
month: 1,
71+
day: 1,
72+
hour: 0,
73+
min: 0,
74+
sec: 0,
75+
fsec: 0
76+
end
77+
78+
defmodule Tds.DateTime2 do
79+
@moduledoc """
80+
Struct for MSSQL DateTime2.
81+
82+
https://msdn.microsoft.com/en-us/library/bb677335.aspx
83+
84+
## Fields
85+
86+
* `year`
87+
* `month`
88+
* `day`
89+
* `hour`
90+
* `min`
91+
* `sec`
92+
* `usec`
93+
"""
94+
95+
@type t :: %__MODULE__{
96+
year: 1..9999,
97+
month: 1..12,
98+
day: 1..31,
99+
hour: 0..23,
100+
min: 0..59,
101+
sec: 0..59,
102+
fsec: 0..9_999_999
103+
}
104+
defstruct year: 1900,
105+
month: 1,
106+
day: 1,
107+
hour: 0,
108+
min: 0,
109+
sec: 0,
110+
# fractional secs
111+
fsec: 0
112+
end
113+
114+
defmodule Tds.DateTimeOffset do
115+
@moduledoc """
116+
Struct for MSSQL DateTimeOffset.
117+
https://msdn.microsoft.com/en-us/library/bb630289.aspx
118+
119+
## Fields
120+
121+
* `year`
122+
* `month`
123+
* `day`
124+
* `hour`
125+
* `min`
126+
* `sec`
127+
* `usec`
128+
"""
129+
130+
@type t :: %__MODULE__{
131+
year: 1..9999,
132+
month: 1..12,
133+
day: 1..31,
134+
hour: 0..23,
135+
min: 0..59,
136+
sec: 0..59,
137+
fsec: 0..9_999_999,
138+
offset_hour: -14..14,
139+
offset_min: 0..59
140+
}
141+
defstruct year: 1900,
142+
month: 1,
143+
day: 1,
144+
hour: 0,
145+
min: 0,
146+
sec: 0,
147+
# fractional secs
148+
fsec: 0,
149+
offset_hour: 0,
150+
offset_min: 0
151+
end
152+
153+
defmodule Tds.SmallDateTime do
154+
@moduledoc """
155+
Struct for MSSQL SmallDateTime.
156+
157+
https://msdn.microsoft.com/en-us/library/ms182418.aspx
158+
159+
## Fields
160+
161+
* `year`
162+
* `month`
163+
* `day`
164+
* `hour`
165+
* `min`
166+
* `sec`
167+
"""
168+
169+
@type t :: %__MODULE__{
170+
year: 1900..2079,
171+
month: 1..12,
172+
day: 1..12,
173+
hour: 0..23,
174+
min: 0..59,
175+
sec: 0..59
176+
}
177+
defstruct year: 1900,
178+
month: 1,
179+
day: 1,
180+
hour: 0,
181+
min: 0,
182+
sec: 0
183+
end

lib/tds/encoding.ex

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Tds.Encoding do
2+
use Rustler, otp_app: :tds, crate: "tds_encoding"
3+
4+
# When your NIF is loaded, it will override this function.
5+
def encode(_str, _encoding), do: error()
6+
def decode(_str, _encoding), do: error()
7+
8+
def error(), do: :erlang.nif_error(:nif_not_loaded)
9+
end

0 commit comments

Comments
 (0)