Improved accuracy of names and decltypes
This commit is contained in:
@@ -97,22 +97,12 @@
|
|||||||
pagecache_size := stats(),
|
pagecache_size := stats(),
|
||||||
malloc_count := stats() }.
|
malloc_count := stats() }.
|
||||||
-type stats() :: #{ used := non_neg_integer(), highwater := non_neg_integer() }.
|
-type stats() :: #{ used := non_neg_integer(), highwater := non_neg_integer() }.
|
||||||
|
-type rowid() :: esqlite3_nif:rowid().
|
||||||
|
-type cell() :: esqlite3_nif:cell().
|
||||||
|
-type row() :: esqlite3_nif:row().
|
||||||
|
-type error() :: esqlite3_nif:error().
|
||||||
|
|
||||||
%% erlang -> sqlite type conversions
|
-export_type([esqlite3/0, esqlite3_stmt/0, esqlite3_backup/0, prepare_flags/0, sql/0, row/0, rowid/0, cell/0]).
|
||||||
%%
|
|
||||||
%% 'undefined' -> null
|
|
||||||
%% 'null' -> null
|
|
||||||
%% atom() -> text
|
|
||||||
%% int() -> int or int64
|
|
||||||
%% float() -> double
|
|
||||||
%% string() -> text
|
|
||||||
%% binary() -> text
|
|
||||||
|
|
||||||
-type rowid() :: integer().
|
|
||||||
-type cell_type() :: undefined | integer() | binary() | float().
|
|
||||||
-type row() :: list(cell_type()). % tuple of cell_type
|
|
||||||
|
|
||||||
-export_type([esqlite3/0, esqlite3_stmt/0, esqlite3_backup/0, prepare_flags/0, sql/0, row/0, rowid/0, cell_type/0]).
|
|
||||||
|
|
||||||
%% @doc Opens a sqlite3 database mentioned in Filename.
|
%% @doc Opens a sqlite3 database mentioned in Filename.
|
||||||
%%
|
%%
|
||||||
@@ -121,7 +111,7 @@
|
|||||||
%% information about this can be found here: [https://sqlite.org/uri.html]
|
%% information about this can be found here: [https://sqlite.org/uri.html]
|
||||||
%%
|
%%
|
||||||
%% Example:
|
%% Example:
|
||||||
%%
|
%
|
||||||
%% ```open("file:data.db")'''
|
%% ```open("file:data.db")'''
|
||||||
%% Opens "data.db" in the current working directory
|
%% Opens "data.db" in the current working directory
|
||||||
%% ```open("file:data.db?mode=ro&cache=private")'''
|
%% ```open("file:data.db?mode=ro&cache=private")'''
|
||||||
@@ -131,7 +121,7 @@
|
|||||||
%%
|
%%
|
||||||
-spec open(Filename) -> OpenResult
|
-spec open(Filename) -> OpenResult
|
||||||
when Filename :: string(),
|
when Filename :: string(),
|
||||||
OpenResult :: {ok, esqlite3()} | esqlite3_nif:error().
|
OpenResult :: {ok, esqlite3()} | error().
|
||||||
open(Filename) ->
|
open(Filename) ->
|
||||||
case esqlite3_nif:open(Filename) of
|
case esqlite3_nif:open(Filename) of
|
||||||
{ok, Connection} ->
|
{ok, Connection} ->
|
||||||
@@ -185,7 +175,7 @@ set_update_hook(#esqlite3{db=Connection}, Pid) ->
|
|||||||
-spec q(Connection, Sql) -> Result when
|
-spec q(Connection, Sql) -> Result when
|
||||||
Connection :: esqlite3(),
|
Connection :: esqlite3(),
|
||||||
Sql :: sql(),
|
Sql :: sql(),
|
||||||
Result :: list(row()) | {error, _}.
|
Result :: list(row()) | error().
|
||||||
q(Connection, Sql) ->
|
q(Connection, Sql) ->
|
||||||
q(Connection, Sql, []).
|
q(Connection, Sql, []).
|
||||||
|
|
||||||
@@ -194,7 +184,7 @@ q(Connection, Sql) ->
|
|||||||
Connection :: esqlite3(),
|
Connection :: esqlite3(),
|
||||||
Sql :: sql(),
|
Sql :: sql(),
|
||||||
Args :: list(),
|
Args :: list(),
|
||||||
Result :: list(row()) | {error, _}.
|
Result :: list(row()) | error().
|
||||||
q(Connection, Sql, []) ->
|
q(Connection, Sql, []) ->
|
||||||
case prepare(Connection, Sql) of
|
case prepare(Connection, Sql) of
|
||||||
{ok, Statement} ->
|
{ok, Statement} ->
|
||||||
@@ -223,7 +213,7 @@ q(Connection, Sql, Args) ->
|
|||||||
% @doc Fetch all rows from the prepared statement.
|
% @doc Fetch all rows from the prepared statement.
|
||||||
-spec fetchall(Statement) -> Result when
|
-spec fetchall(Statement) -> Result when
|
||||||
Statement :: esqlite3_stmt(),
|
Statement :: esqlite3_stmt(),
|
||||||
Result :: list(row()) | {error, _}.
|
Result :: list(row()) | error().
|
||||||
fetchall(Statement) ->
|
fetchall(Statement) ->
|
||||||
fetchall1(Statement, []).
|
fetchall1(Statement, []).
|
||||||
|
|
||||||
@@ -269,7 +259,7 @@ get_autocommit(#esqlite3{db=Connection}) ->
|
|||||||
-spec exec(Connection, Sql) -> ExecResult
|
-spec exec(Connection, Sql) -> ExecResult
|
||||||
when Connection :: esqlite3(),
|
when Connection :: esqlite3(),
|
||||||
Sql :: sql(),
|
Sql :: sql(),
|
||||||
ExecResult :: ok | esqlite3_nif:error().
|
ExecResult :: ok | error().
|
||||||
exec(#esqlite3{db=Connection}, Sql) ->
|
exec(#esqlite3{db=Connection}, Sql) ->
|
||||||
esqlite3_nif:exec(Connection, Sql).
|
esqlite3_nif:exec(Connection, Sql).
|
||||||
|
|
||||||
@@ -283,7 +273,7 @@ exec(#esqlite3{db=Connection}, Sql) ->
|
|||||||
-spec prepare(Connection, Sql) -> PrepareResult
|
-spec prepare(Connection, Sql) -> PrepareResult
|
||||||
when Connection :: esqlite3(),
|
when Connection :: esqlite3(),
|
||||||
Sql :: sql(),
|
Sql :: sql(),
|
||||||
PrepareResult :: {ok, esqlite3_stmt()} | esqlite3_nif:error().
|
PrepareResult :: {ok, esqlite3_stmt()} | error().
|
||||||
prepare(Connection, Sql) ->
|
prepare(Connection, Sql) ->
|
||||||
prepare(Connection, Sql, []).
|
prepare(Connection, Sql, []).
|
||||||
|
|
||||||
@@ -351,7 +341,7 @@ bind_arg(Statement, Column, {blob, Value}) ->
|
|||||||
Statement :: esqlite3_stmt(),
|
Statement :: esqlite3_stmt(),
|
||||||
Index :: integer(),
|
Index :: integer(),
|
||||||
Value :: integer(),
|
Value :: integer(),
|
||||||
BindResult :: ok | esqlite3_nif:error().
|
BindResult :: ok | error().
|
||||||
bind_int(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
bind_int(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
||||||
esqlite3_nif:bind_int(Stmt, Index, Value).
|
esqlite3_nif:bind_int(Stmt, Index, Value).
|
||||||
|
|
||||||
@@ -359,7 +349,7 @@ bind_int(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
|||||||
Statement :: esqlite3_stmt(),
|
Statement :: esqlite3_stmt(),
|
||||||
Index :: non_neg_integer(),
|
Index :: non_neg_integer(),
|
||||||
Value :: integer(),
|
Value :: integer(),
|
||||||
BindResult :: ok | esqlite3_nif:error().
|
BindResult :: ok | error().
|
||||||
bind_int64(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
bind_int64(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
||||||
esqlite3_nif:bind_int64(Stmt, Index, Value).
|
esqlite3_nif:bind_int64(Stmt, Index, Value).
|
||||||
|
|
||||||
@@ -367,7 +357,7 @@ bind_int64(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
|||||||
when Statement :: esqlite3_stmt(),
|
when Statement :: esqlite3_stmt(),
|
||||||
Index :: integer(),
|
Index :: integer(),
|
||||||
Value :: float(),
|
Value :: float(),
|
||||||
BindResult :: ok | esqlite3_nif:error().
|
BindResult :: ok | error().
|
||||||
bind_double(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
bind_double(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
||||||
esqlite3_nif:bind_double(Stmt, Index, Value).
|
esqlite3_nif:bind_double(Stmt, Index, Value).
|
||||||
|
|
||||||
@@ -375,7 +365,7 @@ bind_double(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
|||||||
when Statement :: esqlite3_stmt(),
|
when Statement :: esqlite3_stmt(),
|
||||||
Index :: integer(),
|
Index :: integer(),
|
||||||
Value :: iodata(),
|
Value :: iodata(),
|
||||||
BindResult :: ok | esqlite3_nif:error().
|
BindResult :: ok | error().
|
||||||
bind_text(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
bind_text(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
||||||
esqlite3_nif:bind_text(Stmt, Index, Value).
|
esqlite3_nif:bind_text(Stmt, Index, Value).
|
||||||
|
|
||||||
@@ -383,26 +373,27 @@ bind_text(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
|||||||
when Statement :: esqlite3_stmt(),
|
when Statement :: esqlite3_stmt(),
|
||||||
Index :: integer(),
|
Index :: integer(),
|
||||||
Value :: iodata(),
|
Value :: iodata(),
|
||||||
BindResult :: ok | esqlite3_nif:error().
|
BindResult :: ok | error().
|
||||||
bind_blob(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
bind_blob(#esqlite3_stmt{stmt=Stmt}, Index, Value) ->
|
||||||
esqlite3_nif:bind_blob(Stmt, Index, Value).
|
esqlite3_nif:bind_blob(Stmt, Index, Value).
|
||||||
|
|
||||||
-spec bind_null(Statement, Index) -> BindResult
|
-spec bind_null(Statement, Index) -> BindResult
|
||||||
when Statement :: esqlite3_stmt(),
|
when Statement :: esqlite3_stmt(),
|
||||||
Index :: integer(),
|
Index :: integer(),
|
||||||
BindResult :: ok | esqlite3_nif:error().
|
BindResult :: ok | error().
|
||||||
bind_null(#esqlite3_stmt{stmt=Stmt}, Index) ->
|
bind_null(#esqlite3_stmt{stmt=Stmt}, Index) ->
|
||||||
esqlite3_nif:bind_null(Stmt, Index).
|
esqlite3_nif:bind_null(Stmt, Index).
|
||||||
|
|
||||||
-spec step(Statement) -> StepResult
|
-spec step(Statement) -> StepResult
|
||||||
when Statement :: esqlite3_stmt(),
|
when Statement :: esqlite3_stmt(),
|
||||||
StepResult:: row() | '$done' | {error, _}.
|
StepResult:: row() | '$done' | error().
|
||||||
step(#esqlite3_stmt{stmt=Stmt}) ->
|
step(#esqlite3_stmt{stmt=Stmt}) ->
|
||||||
esqlite3_nif:step(Stmt).
|
esqlite3_nif:step(Stmt).
|
||||||
|
|
||||||
|
% @doc Reset the prepared statement.
|
||||||
-spec reset(Statement) -> ResetResult
|
-spec reset(Statement) -> ResetResult
|
||||||
when Statement :: esqlite3_stmt(),
|
when Statement :: esqlite3_stmt(),
|
||||||
ResetResult:: ok | {error, _}.
|
ResetResult:: ok | error().
|
||||||
reset(#esqlite3_stmt{stmt=Stmt}) ->
|
reset(#esqlite3_stmt{stmt=Stmt}) ->
|
||||||
esqlite3_nif:reset(Stmt).
|
esqlite3_nif:reset(Stmt).
|
||||||
|
|
||||||
|
|||||||
@@ -63,6 +63,9 @@
|
|||||||
-type esqlite3_stmt_ref() :: reference(). % Reference to a prepared statement object. See [https://sqlite.org/c3ref/stmt.html] for more details.
|
-type esqlite3_stmt_ref() :: reference(). % Reference to a prepared statement object. See [https://sqlite.org/c3ref/stmt.html] for more details.
|
||||||
-type esqlite3_backup_ref() :: reference(). % Reference to a online backup object. See [https://sqlite.org/c3ref/backup.html] for more details.
|
-type esqlite3_backup_ref() :: reference(). % Reference to a online backup object. See [https://sqlite.org/c3ref/backup.html] for more details.
|
||||||
-type sql() :: iodata(). % Make sure the iodata contains utf-8 encoded data.
|
-type sql() :: iodata(). % Make sure the iodata contains utf-8 encoded data.
|
||||||
|
-type rowid() :: integer().
|
||||||
|
-type cell() :: undefined | integer() | float() | binary().
|
||||||
|
-type row() :: list(cell()).
|
||||||
-type extended_errcode() :: integer(). % Extended sqlite3 error code. See [https://sqlite.org/rescode.html] for more details.
|
-type extended_errcode() :: integer(). % Extended sqlite3 error code. See [https://sqlite.org/rescode.html] for more details.
|
||||||
-type error() :: {error, extended_errcode()}.
|
-type error() :: {error, extended_errcode()}.
|
||||||
-type error_info() :: #{ errcode := integer(),
|
-type error_info() :: #{ errcode := integer(),
|
||||||
@@ -72,7 +75,7 @@
|
|||||||
error_offset := integer() % The byte offset to the token in the input sql.
|
error_offset := integer() % The byte offset to the token in the input sql.
|
||||||
}. % See: [https://sqlite.org/c3ref/errcode.html] for more information.
|
}. % See: [https://sqlite.org/c3ref/errcode.html] for more information.
|
||||||
|
|
||||||
-export_type([esqlite3_ref/0, esqlite3_stmt_ref/0, esqlite3_backup_ref/0, sql/0, error/0, error_info/0]).
|
-export_type([esqlite3_ref/0, esqlite3_stmt_ref/0, esqlite3_backup_ref/0, sql/0, rowid/0, cell/0, row/0, error/0, error_info/0]).
|
||||||
|
|
||||||
-on_load(init/0).
|
-on_load(init/0).
|
||||||
|
|
||||||
@@ -191,21 +194,31 @@ bind_blob(_Statement, _Index, _Value) ->
|
|||||||
bind_null(_Statement, _Index) ->
|
bind_null(_Statement, _Index) ->
|
||||||
erlang:nif_error(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
|
-spec step(Statement) -> StepResult when
|
||||||
|
Statement :: esqlite3_stmt_ref(),
|
||||||
|
StepResult :: row() | '$done' | error().
|
||||||
step(_Statement) ->
|
step(_Statement) ->
|
||||||
erlang:nif_error(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
|
-spec reset(Statement) -> ResetResult when
|
||||||
|
Statement :: esqlite3_stmt_ref(),
|
||||||
|
ResetResult :: ok | error().
|
||||||
reset(_Statement) ->
|
reset(_Statement) ->
|
||||||
erlang:nif_error(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc Retrieve the column names of the prepared statement
|
%% @doc Retrieve the column names of the prepared statement
|
||||||
%%
|
%%
|
||||||
-spec column_names(esqlite3_stmt_ref()) -> list(binary()) | {error, _}.
|
-spec column_names(Statement) -> Names when
|
||||||
|
Statement :: esqlite3_stmt_ref(),
|
||||||
|
Names :: list(unicode:unicode_binary()).
|
||||||
column_names(_Stmt) ->
|
column_names(_Stmt) ->
|
||||||
erlang:nif_error(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
%% @doc Retrieve the declared datatypes of all columns.
|
%% @doc Retrieve the declared datatypes of all columns.
|
||||||
%%
|
%%
|
||||||
-spec column_decltypes(esqlite3_stmt_ref()) -> list(undefined | binary()) | {error, _}.
|
-spec column_decltypes(Statement) -> Types when
|
||||||
|
Statement :: esqlite3_stmt_ref(),
|
||||||
|
Types :: list(undefined | unicode:unicode_binary()).
|
||||||
column_decltypes(_Stmt) ->
|
column_decltypes(_Stmt) ->
|
||||||
erlang:nif_error(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
@@ -240,7 +253,7 @@ interrupt(_Db) ->
|
|||||||
|
|
||||||
%% @doc Get the last insert rowid.
|
%% @doc Get the last insert rowid.
|
||||||
%%
|
%%
|
||||||
-spec last_insert_rowid(esqlite3_ref()) -> integer().
|
-spec last_insert_rowid(esqlite3_ref()) -> rowid().
|
||||||
last_insert_rowid(_Connection) ->
|
last_insert_rowid(_Connection) ->
|
||||||
erlang:nif_error(nif_library_not_loaded).
|
erlang:nif_error(nif_library_not_loaded).
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user