Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send parameters with nil type as type :string #162

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tds/parameter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule Tds.Parameter do
def fix_data_type(%__MODULE__{type: nil, value: nil} = param) do
# should fix ecto has_one, on_change :nulify issue where type is not know when ecto
# build query/statement for on_chage callback
%{param | type: :binary}
%{param | type: :string}
end

def fix_data_type(%__MODULE__{value: value} = param)
Expand Down
18 changes: 18 additions & 0 deletions test/elixir_calendar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@ defmodule ElixirCalendarTest do
assert [[date]] == query("select @1", [%P{name: "@1", value: date}])
end

test "Elixir.Date insert nil value", context do
:ok = query("CREATE TABLE #date_test (x date)", [])

:ok =
query("insert into #date_test values (@param1), (@param2)", [
%Tds.Parameter{
name: "@param1",
value: ~D[2024-01-01]
},
%Tds.Parameter{
name: "@param2",
value: nil
}
])

assert [[~D[2024-01-01]], [nil]] = query("select x from #date_test", [])
end

test "Elixir.NaiveDateTime type", context do
# sql server datetime precision is not exacly 3 decimals precise, value is rader
# round up to nearest .000, .003, .007. In case of near midnigh day is incremented
Expand Down
Loading