Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: erlangbureau/jamdb_oracle
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.5.10
Choose a base ref
...
head repository: erlangbureau/jamdb_oracle
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 8 commits
  • 6 files changed
  • 2 contributors

Commits on Aug 15, 2024

  1. Copy the full SHA
    1b6ac1c View commit details
  2. Successfully match constraint names when errors are formatted with ~c

    Elixir 1.17 formats charlists with sigil_c. The connection error that
    is returned when encountering constraint errors seems to inspect the
    charlist, so the string is formatted as `"~c\"ORA-ERR: message\""`.
    Because of this, `unique_constraint` was not respected in Elixir 1.17
    because the constraints errors messages could not be matched.
    sax committed Aug 15, 2024
    Copy the full SHA
    3aea81f View commit details

Commits on Sep 7, 2024

  1. Update jamdb_oracle_query.ex

    vstavskyi authored Sep 7, 2024
    Copy the full SHA
    883419f View commit details
  2. Merge pull request #180 from sax/elixir-17-fixes

    Elixir 17 fixes for charlist sigils
    vstavskyi authored Sep 7, 2024
    Copy the full SHA
    0262d72 View commit details
  3. Update jamdb_oracle.ex

    vstavskyi authored Sep 7, 2024
    Copy the full SHA
    23adb37 View commit details
  4. Update mix.exs

    vstavskyi authored Sep 7, 2024
    Copy the full SHA
    f6b64ca View commit details

Commits on Sep 29, 2024

  1. Copy the full SHA
    3d9e15b View commit details
  2. Update jamdb_oracle_tns_decoder.erl

    vstavskyi authored Sep 29, 2024
    Copy the full SHA
    a75b7c6 View commit details
Showing with 26 additions and 20 deletions.
  1. +3 −3 lib/jamdb_oracle.ex
  2. +7 −8 lib/jamdb_oracle_query.ex
  3. +4 −4 lib/jamdb_oracle_sql.ex
  4. +3 −3 mix.exs
  5. +2 −2 src/jamdb_oracle_conn.erl
  6. +7 −0 src/jamdb_oracle_tns_decoder.erl
6 changes: 3 additions & 3 deletions lib/jamdb_oracle.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Jamdb.Oracle do
@vsn "0.5.10"
@vsn "0.5.11"
@moduledoc """
Adapter module for Oracle. `DBConnection` behaviour implementation.
@@ -233,15 +233,15 @@ defmodule Jamdb.Oracle do

@impl true
def checkout(%{pid: pid, timeout: timeout} = s) do
case sql_query(pid, 'SESSION', timeout) do
case sql_query(pid, ~c'SESSION', timeout) do
{:ok, _} -> {:ok, s}
{:error, err} -> {:disconnect, error!(err), s}
end
end

@impl true
def ping(%{pid: pid, timeout: timeout, idle_interval: idle_interval} = s) do
case sql_query(pid, 'PING', min(timeout, idle_interval)) do
case sql_query(pid, ~c'PING', min(timeout, idle_interval)) do
{:ok, _} -> {:ok, s}
{:error, err} -> {:disconnect, error!(err), s}
end
15 changes: 7 additions & 8 deletions lib/jamdb_oracle_query.ex
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ defmodule Jamdb.Oracle.Query do
defstruct [:statement, :name, :batch]

@parent_as __MODULE__
alias Ecto.Query.{BooleanExpr, JoinExpr, QueryExpr, WithExpr}
alias Ecto.Query.{BooleanExpr, ByExpr, JoinExpr, QueryExpr, WithExpr}

@doc false
def all(query, as_prefix \\ []) do
@@ -182,10 +182,10 @@ defmodule Jamdb.Oracle.Query do
defp hints([]), do: []

defp distinct(nil, _, _), do: []
defp distinct(%QueryExpr{expr: []}, _, _), do: {[], []}
defp distinct(%QueryExpr{expr: true}, _, _), do: "DISTINCT "
defp distinct(%QueryExpr{expr: false}, _, _), do: []
defp distinct(%QueryExpr{expr: exprs}, _, _) when is_list(exprs), do: "DISTINCT "
defp distinct(%ByExpr{expr: []}, _, _), do: {[], []}
defp distinct(%ByExpr{expr: true}, _, _), do: "DISTINCT "
defp distinct(%ByExpr{expr: false}, _, _), do: []
defp distinct(%ByExpr{expr: exprs}, _, _) when is_list(exprs), do: "DISTINCT "

defp from(%{from: %{source: source, hints: hints}} = query, sources) do
{from, name} = get_source(query, sources, 0, source)
@@ -272,7 +272,7 @@ defmodule Jamdb.Oracle.Query do
defp group_by(%{group_bys: group_bys} = query, sources) do
[" GROUP BY " |
intersperse_map(group_bys, ", ", fn
%QueryExpr{expr: expr} ->
%ByExpr{expr: expr} ->
intersperse_map(expr, ", ", &expr(&1, sources, query))
end)]
end
@@ -304,8 +304,7 @@ defmodule Jamdb.Oracle.Query do
defp order_by(%{order_bys: []}, _sources), do: []
defp order_by(%{order_bys: order_bys} = query, sources) do
[" ORDER BY " |
intersperse_map(order_bys, ", ", fn
%QueryExpr{expr: expr} ->
intersperse_map(order_bys, ", ", fn %ByExpr{expr: expr} ->
intersperse_map(expr, ", ", &order_by_expr(&1, sources, query))
end)]
end
8 changes: 4 additions & 4 deletions lib/jamdb_oracle_sql.ex
Original file line number Diff line number Diff line change
@@ -304,29 +304,29 @@ defmodule Jamdb.Oracle.SQL do
end

defp unique_constraint?(err) do
match_or_nil(~r/'ORA-00001: unique constraint \((.*)\) violated\\n'/, err.message, fn name ->
match_or_nil(~r/ORA-00001: unique constraint \((.*)\) violated/, err.message, fn name ->
[unique: name]
end)
end

defp integrity_child_constraint?(err) do
match_or_nil(
~r/'ORA-02292: integrity constraint \((.*)\) violated - child record found\\n'/,
~r/ORA-02292: integrity constraint \((.*)\) violated - child record found/,
err.message,
fn name -> [foreign_key: name] end
)
end

defp integrity_parent_constraint?(err) do
match_or_nil(
~r/'ORA-02291: integrity constraint \((.*)\) violated - parent key not found\\n'/,
~r/ORA-02291: integrity constraint \((.*)\) violated - parent key not found/,
err.message,
fn name -> [foreign_key: name] end
)
end

defp check_constraint?(err) do
match_or_nil(~r/'ORA-02290: check constraint \((.*)\) violated\\n'/, err.message, fn name ->
match_or_nil(~r/ORA-02290: check constraint \((.*)\) violated/, err.message, fn name ->
[check: name]
end)
end
6 changes: 3 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -3,8 +3,8 @@ defmodule Jamdb.Oracle.Mixfile do

def project do
[app: :jamdb_oracle,
version: "0.5.10",
elixir: "~> 1.10",
version: "0.5.11",
elixir: "~> 1.11",
description: description(),
package: package(),
deps: deps()]
@@ -18,7 +18,7 @@ defmodule Jamdb.Oracle.Mixfile do

defp deps do
[
{:ecto_sql, "~> 3.8"}
{:ecto_sql, "~> 3.12"}
]
end

4 changes: 2 additions & 2 deletions src/jamdb_oracle_conn.erl
Original file line number Diff line number Diff line change
@@ -145,8 +145,8 @@ handle_login(#oraclient{socket=Socket, env=Env, sdu=Length, timeouts=Touts} = St
handle_login(State2);
{ok, ?TNS_MARKER, _Data} ->
handle_req(marker, State, []);
{ok, ?TNS_REDIRECT, <<_Length:16,_Bin:80,Rest/bits>>} ->
{ok, Opts} = ?DECODER:decode_token(net, {Rest, Env}),
{ok, ?TNS_REDIRECT, Data} ->
{ok, Opts} = ?DECODER:decode_token(net, {Data, Env}),
reconnect(State#oraclient{env=Opts});
{ok, ?TNS_REFUSE, <<_Bin:16,_Length:16,Rest/bits>>} ->
handle_error(local, binary_to_list(Rest), State);
7 changes: 7 additions & 0 deletions src/jamdb_oracle_tns_decoder.erl
Original file line number Diff line number Diff line change
@@ -21,6 +21,13 @@ decode_packet(<<PacketSize:16, _PacketFlags:16, ?TNS_DATA, _Flags:8, 0:16, _Data
end;
decode_packet(<<_PacketSize:16, _PacketFlags:16, ?TNS_MARKER, _Flags:8, 0:16, Rest/bits>>, _Length) ->
{ok, ?TNS_MARKER, Rest, <<>>};
decode_packet(<<_PacketSize:16, _PacketFlags:16, ?TNS_REDIRECT, _Flags:8, 0:16, _DataFlags:16, Rest/bits>>, Length) ->
case decode_packet(Rest, Length) of
{ok, ?TNS_DATA, PacketBody, <<>>} ->
{ok, ?TNS_REDIRECT, PacketBody, <<>>};
_ ->
{error, more}
end;
decode_packet(<<PacketSize:16, _PacketFlags:16, Type, _Flags:8, 0:16, Rest/bits>>, _Length) ->
BodySize = PacketSize-8,
case Rest of