Skip to content
This repository was archived by the owner on Mar 19, 2021. It is now read-only.

Commit bc5090a

Browse files
authored
Merge pull request #61 from mikestok/master
Get rid of warnings when compiling under 1.5.x #60
2 parents a4e7fd5 + 2aa1585 commit bc5090a

File tree

4 files changed

+38
-13
lines changed

4 files changed

+38
-13
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ elixir:
66
- 1.2.6
77
- 1.3.4
88
- 1.4.0
9+
- 1.5.1
10+
matrix:
11+
include:
12+
- elixir: 1.5.1
13+
otp_release: 20.0
914
after_script:
1015
- MIX_ENV=dev mix deps.get
1116
- MIX_ENV=dev mix inch.report

lib/sqlitex.ex

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
defmodule Sqlitex do
2+
if Version.compare(System.version, "1.3.0") == :lt do
3+
@type charlist :: char_list
4+
end
5+
26
@type connection :: {:connection, reference, String.t}
3-
@type string_or_charlist :: String.t | char_list
4-
@type sqlite_error :: {:error, {:sqlite_error, char_list}}
7+
@type string_or_charlist :: String.t | charlist
8+
@type sqlite_error :: {:error, {:sqlite_error, charlist}}
59

610
@moduledoc """
711
Sqlitex gives you a way to create and query sqlite databases.
@@ -28,8 +32,8 @@ defmodule Sqlitex do
2832
end
2933

3034
@spec open(String.t) :: {:ok, connection}
31-
@spec open(char_list) :: {:ok, connection} | {:error, {atom, char_list}}
32-
def open(path) when is_binary(path), do: open(String.to_char_list(path))
35+
@spec open(charlist) :: {:ok, connection} | {:error, {atom, charlist}}
36+
def open(path) when is_binary(path), do: open(string_to_charlist(path))
3337
def open(path) do
3438
:esqlite3.open(path)
3539
end
@@ -73,4 +77,10 @@ defmodule Sqlitex do
7377
stmt = Sqlitex.SqlBuilder.create_table(name, table_opts, cols)
7478
exec(db, stmt)
7579
end
80+
81+
if Version.compare(System.version, "1.3.0") == :lt do
82+
defp string_to_charlist(string), do: String.to_char_list(string)
83+
else
84+
defp string_to_charlist(string), do: String.to_charlist(string)
85+
end
7686
end

lib/sqlitex/query.ex

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ defmodule Sqlitex.Query do
2121
* {:error, _} on failure.
2222
"""
2323

24-
@spec query(Sqlitex.connection, String.t | char_list) :: [[]] | Sqlitex.sqlite_error
25-
@spec query(Sqlitex.connection, String.t | char_list, [bind: [], into: Enum.t]) :: [Enum.t] | Sqlitex.sqlite_error
24+
if Version.compare(System.version, "1.3.0") == :lt do
25+
@type charlist :: char_list
26+
end
27+
28+
@spec query(Sqlitex.connection, String.t | charlist) :: [[]] | Sqlitex.sqlite_error
29+
@spec query(Sqlitex.connection, String.t | charlist, [bind: [], into: Enum.t]) :: [Enum.t] | Sqlitex.sqlite_error
2630
def query(db, sql, opts \\ []) do
2731
with {:ok, stmt} <- Statement.prepare(db, sql),
2832
{:ok, stmt} <- Statement.bind_values(stmt, Keyword.get(opts, :bind, [])),
@@ -35,8 +39,8 @@ defmodule Sqlitex.Query do
3539
3640
Returns the results otherwise.
3741
"""
38-
@spec query!(Sqlitex.connection, String.t | char_list) :: [[]]
39-
@spec query!(Sqlitex.connection, String.t | char_list, [bind: [], into: Enum.t]) :: [Enum.t]
42+
@spec query!(Sqlitex.connection, String.t | charlist) :: [[]]
43+
@spec query!(Sqlitex.connection, String.t | charlist, [bind: [], into: Enum.t]) :: [Enum.t]
4044
def query!(db, sql, opts \\ []) do
4145
case query(db, sql, opts) do
4246
{:error, reason} -> raise Sqlitex.QueryError, reason: reason
@@ -64,8 +68,8 @@ defmodule Sqlitex.Query do
6468
* {:error, _} on failure.
6569
"""
6670

67-
@spec query_rows(Sqlitex.connection, String.t | char_list) :: {:ok, %{}} | Sqlitex.sqlite_error
68-
@spec query_rows(Sqlitex.connection, String.t | char_list, [bind: []]) :: {:ok, %{}} | Sqlitex.sqlite_error
71+
@spec query_rows(Sqlitex.connection, String.t | charlist) :: {:ok, %{}} | Sqlitex.sqlite_error
72+
@spec query_rows(Sqlitex.connection, String.t | charlist, [bind: []]) :: {:ok, %{}} | Sqlitex.sqlite_error
6973
def query_rows(db, sql, opts \\ []) do
7074
with {:ok, stmt} <- Statement.prepare(db, sql),
7175
{:ok, stmt} <- Statement.bind_values(stmt, Keyword.get(opts, :bind, [])),
@@ -78,8 +82,8 @@ defmodule Sqlitex.Query do
7882
7983
Returns the results otherwise.
8084
"""
81-
@spec query_rows!(Sqlitex.connection, String.t | char_list) :: [[]]
82-
@spec query_rows!(Sqlitex.connection, String.t | char_list, [bind: []]) :: [Enum.t]
85+
@spec query_rows!(Sqlitex.connection, String.t | charlist) :: [[]]
86+
@spec query_rows!(Sqlitex.connection, String.t | charlist, [bind: []]) :: [Enum.t]
8387
def query_rows!(db, sql, opts \\ []) do
8488
case query_rows(db, sql, opts) do
8589
{:error, reason} -> raise Sqlitex.QueryError, reason: reason

lib/sqlitex/row.ex

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ defmodule Sqlitex.Row do
5353
end
5454
defp translate_value({float, "decimal"}), do: Decimal.new(float)
5555
defp translate_value({float, "decimal(" <> rest}) do
56-
[precision, scale] = rest |> String.rstrip(?)) |> String.split(",") |> Enum.map(&String.to_integer/1)
56+
[precision, scale] = rest |> string_rstrip(?)) |> String.split(",") |> Enum.map(&String.to_integer/1)
5757
Decimal.with_context %Decimal.Context{precision: precision, rounding: :down}, fn ->
5858
float |> Float.round(scale) |> Decimal.new |> Decimal.plus
5959
end
@@ -78,4 +78,10 @@ defmodule Sqlitex.Row do
7878
fr = String.to_integer(fr <> String.duplicate("0", 6 - String.length(fr)))
7979
{String.to_integer(hr), String.to_integer(mi), String.to_integer(se), fr}
8080
end
81+
82+
if Version.compare(System.version, "1.5.0") == :lt do
83+
defp string_rstrip(string, char), do: String.rstrip(string, char)
84+
else
85+
defp string_rstrip(string, char), do: String.trim_trailing(string, to_string([char]))
86+
end
8187
end

0 commit comments

Comments
 (0)