src/sqlite3.erl: remove white spaces

This commit is contained in:
booo
2012-06-14 17:45:32 +02:00
parent a1e3fbc4b0
commit a95bb19811

View File

@@ -10,7 +10,7 @@
%%%------------------------------------------------------------------- %%%-------------------------------------------------------------------
-module(sqlite3). -module(sqlite3).
-include("sqlite3.hrl"). -include("sqlite3.hrl").
-export_types([sql_value/0, sql_type/0, table_info/0, sqlite_error/0, -export_types([sql_value/0, sql_type/0, table_info/0, sqlite_error/0,
sql_params/0, sql_non_query_result/0, sql_result/0]). sql_params/0, sql_non_query_result/0, sql_result/0]).
-behaviour(gen_server). -behaviour(gen_server).
@@ -19,8 +19,8 @@
-export([open/1, open/2]). -export([open/1, open/2]).
-export([start_link/1, start_link/2]). -export([start_link/1, start_link/2]).
-export([stop/0, close/1, close_timeout/2]). -export([stop/0, close/1, close_timeout/2]).
-export([sql_exec/1, sql_exec/2, sql_exec_timeout/3, -export([sql_exec/1, sql_exec/2, sql_exec_timeout/3,
sql_exec_script/2, sql_exec_script_timeout/3, sql_exec_script/2, sql_exec_script_timeout/3,
sql_exec/3, sql_exec_timeout/4]). sql_exec/3, sql_exec_timeout/4]).
-export([prepare/2, bind/3, next/2, reset/2, clear_bindings/2, finalize/2, -export([prepare/2, bind/3, next/2, reset/2, clear_bindings/2, finalize/2,
columns/2, prepare_timeout/3, bind_timeout/4, next_timeout/3, columns/2, prepare_timeout/3, bind_timeout/4, next_timeout/3,
@@ -28,12 +28,12 @@
columns_timeout/3]). columns_timeout/3]).
-export([create_table/2, create_table/3, create_table/4, create_table_timeout/4, -export([create_table/2, create_table/3, create_table/4, create_table_timeout/4,
create_table_timeout/5]). create_table_timeout/5]).
-export([list_tables/0, list_tables/1, list_tables_timeout/2, -export([list_tables/0, list_tables/1, list_tables_timeout/2,
table_info/1, table_info/2, table_info_timeout/3]). table_info/1, table_info/2, table_info_timeout/3]).
-export([write/2, write/3, write_timeout/4, write_many/2, write_many/3, -export([write/2, write/3, write_timeout/4, write_many/2, write_many/3,
write_many_timeout/4]). write_many_timeout/4]).
-export([update/3, update/4, update_timeout/5]). -export([update/3, update/4, update_timeout/5]).
-export([read_all/2, read_all/3, read_all_timeout/3, read_all_timeout/4, -export([read_all/2, read_all/3, read_all_timeout/3, read_all_timeout/4,
read/2, read/3, read/4, read_timeout/4, read_timeout/5]). read/2, read/3, read/4, read_timeout/4, read_timeout/5]).
-export([delete/2, delete/3, delete_timeout/4]). -export([delete/2, delete/3, delete_timeout/4]).
-export([drop_table/1, drop_table/2, drop_table_timeout/3]). -export([drop_table/1, drop_table/2, drop_table_timeout/3]).
@@ -54,8 +54,8 @@
%% API %% API
%%==================================================================== %%====================================================================
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Opens the sqlite3 database in file Db.db in the working directory %% Opens the sqlite3 database in file Db.db in the working directory
%% (creating this file if necessary). This is the same as open/1. %% (creating this file if necessary). This is the same as open/1.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -67,12 +67,12 @@ start_link(Db) ->
open(Db, []). open(Db, []).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Opens a sqlite3 database creating one if necessary. By default the %% Opens a sqlite3 database creating one if necessary. By default the
%% database will be called Db.db in the current path. This can be changed %% database will be called Db.db in the current path. This can be changed
%% by passing the option {file, DbFile :: String()}. DbFile must be the %% by passing the option {file, DbFile :: String()}. DbFile must be the
%% full path to the sqlite3 db file. start_link/1 can be use with stop/0, %% full path to the sqlite3 db file. start_link/1 can be use with stop/0,
%% sql_exec/1, create_table/2, list_tables/0, table_info/1, write/2, %% sql_exec/1, create_table/2, list_tables/0, table_info/1, write/2,
%% read/2, delete/2 and drop_table/1. This is the same as open/2. %% read/2, delete/2 and drop_table/1. This is the same as open/2.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -82,7 +82,7 @@ start_link(Db, Options) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Opens the sqlite3 database in file Db.db in the working directory %% Opens the sqlite3 database in file Db.db in the working directory
%% (creating this file if necessary). This is the same as open/1. %% (creating this file if necessary). This is the same as open/1.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -93,7 +93,7 @@ open(Db) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @spec open(Db :: atom(), Options :: [option()]) -> {ok, Pid :: pid()} | ignore | {error, Error} %% @spec open(Db :: atom(), Options :: [option()]) -> {ok, Pid :: pid()} | ignore | {error, Error}
%% @type option() = {file, DbFile :: string()} | in_memory | temporary %% @type option() = {file, DbFile :: string()} | in_memory | temporary
%% %%
%% @doc %% @doc
%% Opens a sqlite3 database creating one if necessary. By default the database %% Opens a sqlite3 database creating one if necessary. By default the database
%% will be called Db.db in the current path. This can be changed by %% will be called Db.db in the current path. This can be changed by
@@ -109,18 +109,18 @@ open(Db, Options) ->
Opts = case proplists:lookup(file, Options) of Opts = case proplists:lookup(file, Options) of
none -> none ->
DbName = case proplists:is_defined(temporary, Options) of DbName = case proplists:is_defined(temporary, Options) of
true -> true ->
""; "";
false -> false ->
case proplists:is_defined(in_memory, Options) of case proplists:is_defined(in_memory, Options) of
true -> true ->
":memory:"; ":memory:";
false -> false ->
"./" ++ atom_to_list(Db) ++ ".db" "./" ++ atom_to_list(Db) ++ ".db"
end end
end, end,
[{file, DbName} | Options]; [{file, DbName} | Options];
{file, _} -> {file, _} ->
Options Options
end, end,
gen_server:start_link({local, Db}, ?MODULE, Opts, []). gen_server:start_link({local, Db}, ?MODULE, Opts, []).
@@ -173,11 +173,11 @@ sql_exec(Db, SQL) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Executes the Sql statement with parameters Params directly on the Db %% Executes the Sql statement with parameters Params directly on the Db
%% database. Returns the result of the Sql call. %% database. Returns the result of the Sql call.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec sql_exec(atom(), iodata(), [sql_value() | {atom() | string() | integer(), sql_value()}]) -> -spec sql_exec(atom(), iodata(), [sql_value() | {atom() | string() | integer(), sql_value()}]) ->
sql_result(). sql_result().
sql_exec(Db, SQL, Params) -> sql_exec(Db, SQL, Params) ->
gen_server:call(Db, {sql_bind_and_exec, SQL, Params}). gen_server:call(Db, {sql_bind_and_exec, SQL, Params}).
@@ -194,19 +194,19 @@ sql_exec_timeout(Db, SQL, Timeout) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Executes the Sql statement with parameters Params directly on the Db %% Executes the Sql statement with parameters Params directly on the Db
%% database. Returns the result of the Sql call. %% database. Returns the result of the Sql call.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec sql_exec_timeout(atom(), iodata(), [sql_value() | {atom() | string() | integer(), sql_value()}], timeout()) -> -spec sql_exec_timeout(atom(), iodata(), [sql_value() | {atom() | string() | integer(), sql_value()}], timeout()) ->
sql_result(). sql_result().
sql_exec_timeout(Db, SQL, Params, Timeout) -> sql_exec_timeout(Db, SQL, Params, Timeout) ->
gen_server:call(Db, {sql_bind_and_exec, SQL, Params}, Timeout). gen_server:call(Db, {sql_bind_and_exec, SQL, Params}, Timeout).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Executes the Sql script (consisting of semicolon-separated statements) %% Executes the Sql script (consisting of semicolon-separated statements)
%% directly on the Db database. %% directly on the Db database.
%% %%
%% If an error happens while executing a statement, no further statements are executed. %% If an error happens while executing a statement, no further statements are executed.
%% %%
@@ -219,7 +219,7 @@ sql_exec_script(Db, SQL) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Executes the Sql script (consisting of semicolon-separated statements) %% Executes the Sql script (consisting of semicolon-separated statements)
%% directly on the Db database. %% directly on the Db database.
%% %%
%% If an error happens while executing a statement, no further statements are executed. %% If an error happens while executing a statement, no further statements are executed.
@@ -302,8 +302,8 @@ create_table(Tbl, Columns) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Creates the Tbl table in Db using Columns as the table structure. %% Creates the Tbl table in Db using Columns as the table structure.
%% The table structure is a list of {column name, column type} pairs. %% The table structure is a list of {column name, column type} pairs.
%% e.g. [{name, text}, {age, integer}] %% e.g. [{name, text}, {age, integer}]
%% %%
%% Returns the result of the create table call. %% Returns the result of the create table call.
@@ -315,8 +315,8 @@ create_table(Db, Tbl, Columns) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Creates the Tbl table in Db using Columns as the table structure. %% Creates the Tbl table in Db using Columns as the table structure.
%% The table structure is a list of {column name, column type} pairs. %% The table structure is a list of {column name, column type} pairs.
%% e.g. [{name, text}, {age, integer}] %% e.g. [{name, text}, {age, integer}]
%% %%
%% Returns the result of the create table call. %% Returns the result of the create table call.
@@ -329,14 +329,14 @@ create_table_timeout(Db, Tbl, Columns, Timeout) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Creates the Tbl table in Db using Columns as the table structure and %% Creates the Tbl table in Db using Columns as the table structure and
%% Constraints as table constraints. %% Constraints as table constraints.
%% The table structure is a list of {column name, column type} pairs. %% The table structure is a list of {column name, column type} pairs.
%% e.g. [{name, text}, {age, integer}] %% e.g. [{name, text}, {age, integer}]
%% %%
%% Returns the result of the create table call. %% Returns the result of the create table call.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec create_table(atom(), table_id(), table_info(), table_constraints()) -> -spec create_table(atom(), table_id(), table_info(), table_constraints()) ->
sql_non_query_result(). sql_non_query_result().
create_table(Db, Tbl, Columns, Constraints) -> create_table(Db, Tbl, Columns, Constraints) ->
gen_server:call(Db, {create_table, Tbl, Columns, Constraints}). gen_server:call(Db, {create_table, Tbl, Columns, Constraints}).
@@ -344,14 +344,14 @@ create_table(Db, Tbl, Columns, Constraints) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Creates the Tbl table in Db using Columns as the table structure and %% Creates the Tbl table in Db using Columns as the table structure and
%% Constraints as table constraints. %% Constraints as table constraints.
%% The table structure is a list of {column name, column type} pairs. %% The table structure is a list of {column name, column type} pairs.
%% e.g. [{name, text}, {age, integer}] %% e.g. [{name, text}, {age, integer}]
%% %%
%% Returns the result of the create table call. %% Returns the result of the create table call.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec create_table_timeout(atom(), table_id(), table_info(), table_constraints(), timeout()) -> -spec create_table_timeout(atom(), table_id(), table_info(), table_constraints(), timeout()) ->
sql_non_query_result(). sql_non_query_result().
create_table_timeout(Db, Tbl, Columns, Constraints, Timeout) -> create_table_timeout(Db, Tbl, Columns, Constraints, Timeout) ->
gen_server:call(Db, {create_table, Tbl, Columns, Constraints}, Timeout). gen_server:call(Db, {create_table, Tbl, Columns, Constraints}, Timeout).
@@ -412,7 +412,7 @@ table_info_timeout(Db, Tbl, Timeout) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Write Data into Tbl table. Value must be of the same type as %% Write Data into Tbl table. Value must be of the same type as
%% determined from table_info/2. %% determined from table_info/2.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -422,7 +422,7 @@ write(Tbl, Data) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Write Data into Tbl table in Db database. Value must be of the %% Write Data into Tbl table in Db database. Value must be of the
%% same type as determined from table_info/3. %% same type as determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -432,18 +432,18 @@ write(Db, Tbl, Data) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Write Data into Tbl table in Db database. Value must be of the %% Write Data into Tbl table in Db database. Value must be of the
%% same type as determined from table_info/3. %% same type as determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec write_timeout(atom(), table_id(), [{column_id(), sql_value()}], timeout()) -> -spec write_timeout(atom(), table_id(), [{column_id(), sql_value()}], timeout()) ->
sql_non_query_result(). sql_non_query_result().
write_timeout(Db, Tbl, Data, Timeout) -> write_timeout(Db, Tbl, Data, Timeout) ->
gen_server:call(Db, {write, Tbl, Data}, Timeout). gen_server:call(Db, {write, Tbl, Data}, Timeout).
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Write all records in Data into table Tbl. Value must be of the %% Write all records in Data into table Tbl. Value must be of the
%% same type as determined from table_info/2. %% same type as determined from table_info/2.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -453,7 +453,7 @@ write_many(Tbl, Data) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Write all records in Data into table Tbl in database Db. Value %% Write all records in Data into table Tbl in database Db. Value
%% must be of the same type as determined from table_info/3. %% must be of the same type as determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -463,11 +463,11 @@ write_many(Db, Tbl, Data) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Write all records in Data into table Tbl in database Db. Value %% Write all records in Data into table Tbl in database Db. Value
%% must be of the same type as determined from table_info/3. %% must be of the same type as determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec write_many_timeout(atom(), table_id(), [[{column_id(), sql_value()}]], timeout()) -> -spec write_many_timeout(atom(), table_id(), [[{column_id(), sql_value()}]], timeout()) ->
[sql_result()]. [sql_result()].
write_many_timeout(Db, Tbl, Data, Timeout) -> write_many_timeout(Db, Tbl, Data, Timeout) ->
gen_server:call(Db, {write_many, Tbl, Data}, Timeout). gen_server:call(Db, {write_many, Tbl, Data}, Timeout).
@@ -478,7 +478,7 @@ write_many_timeout(Db, Tbl, Data, Timeout) ->
%% value in Key with Data. %% value in Key with Data.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec update(table_id(), {column_id(), sql_value()}, [{column_id(), sql_value()}]) -> -spec update(table_id(), {column_id(), sql_value()}, [{column_id(), sql_value()}]) ->
sql_non_query_result(). sql_non_query_result().
update(Tbl, {Key, Value}, Data) -> update(Tbl, {Key, Value}, Data) ->
update(?MODULE, Tbl, {Key, Value}, Data). update(?MODULE, Tbl, {Key, Value}, Data).
@@ -489,7 +489,7 @@ update(Tbl, {Key, Value}, Data) ->
%% matches the value in Key with Data. %% matches the value in Key with Data.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec update(atom(), table_id(), {column_id(), sql_value()}, [{column_id(), sql_value()}]) -> -spec update(atom(), table_id(), {column_id(), sql_value()}, [{column_id(), sql_value()}]) ->
sql_non_query_result(). sql_non_query_result().
update(Db, Tbl, {Key, Value}, Data) -> update(Db, Tbl, {Key, Value}, Data) ->
gen_server:call(Db, {update, Tbl, Key, Value, Data}). gen_server:call(Db, {update, Tbl, Key, Value, Data}).
@@ -500,7 +500,7 @@ update(Db, Tbl, {Key, Value}, Data) ->
%% matches the value in Key with Data. %% matches the value in Key with Data.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-spec update_timeout(atom(), table_id(), {column_id(), sql_value()}, [{column_id(), sql_value()}], timeout()) -> -spec update_timeout(atom(), table_id(), {column_id(), sql_value()}, [{column_id(), sql_value()}], timeout()) ->
sql_non_query_result(). sql_non_query_result().
update_timeout(Db, Tbl, {Key, Value}, Data, Timeout) -> update_timeout(Db, Tbl, {Key, Value}, Data, Timeout) ->
gen_server:call(Db, {update, Tbl, Key, Value, Data}, Timeout). gen_server:call(Db, {update, Tbl, Key, Value, Data}, Timeout).
@@ -543,8 +543,8 @@ read_all_timeout(Db, Tbl, Columns, Timeout) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Reads a row from Tbl table such that the Value matches the %% Reads a row from Tbl table such that the Value matches the
%% value in Column. Value must have the same type as determined %% value in Column. Value must have the same type as determined
%% from table_info/2. %% from table_info/2.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -554,8 +554,8 @@ read(Tbl, Key) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Reads a row from Tbl table in Db database such that the Value %% Reads a row from Tbl table in Db database such that the Value
%% matches the value in Column. ColValue must have the same type %% matches the value in Column. ColValue must have the same type
%% as determined from table_info/3. %% as determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -566,7 +566,7 @@ read(Db, Tbl, {Column, Value}) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Reads a row from Tbl table in Db database such that the Value %% Reads a row from Tbl table in Db database such that the Value
%% matches the value in Column. Value must have the same type as %% matches the value in Column. Value must have the same type as
%% determined from table_info/3. %% determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -576,8 +576,8 @@ read(Db, Tbl, {Key, Value}, Columns) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Reads a row from Tbl table in Db database such that the Value %% Reads a row from Tbl table in Db database such that the Value
%% matches the value in Column. ColValue must have the same type %% matches the value in Column. ColValue must have the same type
%% as determined from table_info/3. %% as determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -588,7 +588,7 @@ read_timeout(Db, Tbl, {Column, Value}, Timeout) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Reads a row from Tbl table in Db database such that the Value %% Reads a row from Tbl table in Db database such that the Value
%% matches the value in Column. Value must have the same type as %% matches the value in Column. Value must have the same type as
%% determined from table_info/3. %% determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -598,8 +598,8 @@ read_timeout(Db, Tbl, {Key, Value}, Columns, Timeout) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Delete a row from Tbl table in Db database such that the Value %% Delete a row from Tbl table in Db database such that the Value
%% matches the value in Column. %% matches the value in Column.
%% Value must have the same type as determined from table_info/3. %% Value must have the same type as determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -609,8 +609,8 @@ delete(Tbl, Key) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Delete a row from Tbl table in Db database such that the Value %% Delete a row from Tbl table in Db database such that the Value
%% matches the value in Column. %% matches the value in Column.
%% Value must have the same type as determined from table_info/3. %% Value must have the same type as determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -620,8 +620,8 @@ delete_timeout(Db, Tbl, Key, Timeout) ->
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @doc %% @doc
%% Delete a row from Tbl table in Db database such that the Value %% Delete a row from Tbl table in Db database such that the Value
%% matches the value in Column. %% matches the value in Column.
%% Value must have the same type as determined from table_info/3. %% Value must have the same type as determined from table_info/3.
%% @end %% @end
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
@@ -746,9 +746,9 @@ init(Options) ->
{ok, #state{port = Port, ops = Options}}; {ok, #state{port = Port, ops = Options}};
{error, permanent} -> %% already loaded! {error, permanent} -> %% already loaded!
Port = open_port({spawn, create_port_cmd(DbFile)}, [binary]), Port = open_port({spawn, create_port_cmd(DbFile)}, [binary]),
{ok, #state{port = Port, ops = Options}}; {ok, #state{port = Port, ops = Options}};
{error, Error} -> {error, Error} ->
Msg = io_lib:format("Error loading ~p: ~s", Msg = io_lib:format("Error loading ~p: ~s",
[?DRIVER_NAME, erl_ddll:format_error(Error)]), [?DRIVER_NAME, erl_ddll:format_error(Error)]),
{stop, lists:flatten(Msg)} {stop, lists:flatten(Msg)}
end. end.
@@ -828,8 +828,8 @@ handle_call({write, Tbl, Data}, _From, State) ->
{reply, {error, Exception}, State} {reply, {error, Exception}, State}
end; end;
handle_call({write_many, Tbl, DataList}, _From, State) -> handle_call({write_many, Tbl, DataList}, _From, State) ->
SQLScript = ["BEGIN;", SQLScript = ["BEGIN;",
[sqlite3_lib:write_sql(Tbl, Data) || Data <- DataList], [sqlite3_lib:write_sql(Tbl, Data) || Data <- DataList],
"COMMIT;"], "COMMIT;"],
Reply = do_sql_exec_script(SQLScript, State), Reply = do_sql_exec_script(SQLScript, State),
{reply, Reply, State}; {reply, Reply, State};
@@ -968,12 +968,12 @@ terminate(_Reason, #state{port = Port}) ->
port_close(Port) port_close(Port)
end, end,
case erl_ddll:unload(?DRIVER_NAME) of case erl_ddll:unload(?DRIVER_NAME) of
ok -> ok ->
ok; ok;
{error, permanent} -> {error, permanent} ->
ok; %% FIXME is this the correct behavior? ok; %% FIXME is this the correct behavior?
{error, ErrorDesc} -> {error, ErrorDesc} ->
error_logger:error_msg("Error unloading sqlite3 driver: ~s~n", error_logger:error_msg("Error unloading sqlite3 driver: ~s~n",
[erl_ddll:format_error(ErrorDesc)]) [erl_ddll:format_error(ErrorDesc)])
end, end,
ok. ok.
@@ -1035,7 +1035,7 @@ do_sql_exec_script(SQL, #state{port = Port}) ->
[_|_] -> [_|_] ->
case lists:last(Results) of case lists:last(Results) of
{error, _Code, Reason} -> {error, _Code, Reason} ->
error_logger:error_msg("sqlite3 driver error: ~s~n", error_logger:error_msg("sqlite3 driver error: ~s~n",
[Reason]); [Reason]);
_ -> ok _ -> ok
end; end;
@@ -1082,7 +1082,7 @@ wait_result(Port) ->
{Port, Reply} -> {Port, Reply} ->
case Reply of case Reply of
{error, Code, Reason} -> {error, Code, Reason} ->
error_logger:error_msg("sqlite3 driver error: ~s~n", error_logger:error_msg("sqlite3 driver error: ~s~n",
[Reason]), [Reason]),
% ?dbg("Error: ~p~n", [Reason]), % ?dbg("Error: ~p~n", [Reason]),
{error, Code, Reason}; {error, Code, Reason};
@@ -1091,12 +1091,12 @@ wait_result(Port) ->
Reply Reply
end; end;
{'EXIT', Port, Reason} -> {'EXIT', Port, Reason} ->
error_logger:error_msg("sqlite3 driver port closed with reason ~p~n", error_logger:error_msg("sqlite3 driver port closed with reason ~p~n",
[Reason]), [Reason]),
% ?dbg("Error: ~p~n", [Reason]), % ?dbg("Error: ~p~n", [Reason]),
{error, Reason}; {error, Reason};
Other when is_tuple(Other), element(1, Other) =/= '$gen_call', element(1, Other) =/= '$gen_cast' -> Other when is_tuple(Other), element(1, Other) =/= '$gen_call', element(1, Other) =/= '$gen_cast' ->
error_logger:error_msg("sqlite3 unexpected reply ~p~n", error_logger:error_msg("sqlite3 unexpected reply ~p~n",
[Other]), [Other]),
Other Other
end. end.
@@ -1108,28 +1108,28 @@ parse_table_info(Info) ->
Rest1 = list_init(Rest), Rest1 = list_init(Rest),
Cols = string:tokens(Rest1, ","), Cols = string:tokens(Rest1, ","),
build_table_info(lists:map(fun(X) -> build_table_info(lists:map(fun(X) ->
string:tokens(X, " ") string:tokens(X, " ")
end, Cols), []). end, Cols), []).
build_table_info([], Acc) -> build_table_info([], Acc) ->
lists:reverse(Acc); lists:reverse(Acc);
build_table_info([[ColName, ColType] | Tl], Acc) -> build_table_info([[ColName, ColType] | Tl], Acc) ->
build_table_info(Tl, [{list_to_atom(ColName), sqlite3_lib:col_type_to_atom(ColType)}| Acc]); build_table_info(Tl, [{list_to_atom(ColName), sqlite3_lib:col_type_to_atom(ColType)}| Acc]);
build_table_info([[ColName, ColType | Constraints] | Tl], Acc) -> build_table_info([[ColName, ColType | Constraints] | Tl], Acc) ->
build_table_info(Tl, [{list_to_atom(ColName), sqlite3_lib:col_type_to_atom(ColType), build_constraints(Constraints)} | Acc]). build_table_info(Tl, [{list_to_atom(ColName), sqlite3_lib:col_type_to_atom(ColType), build_constraints(Constraints)} | Acc]).
%% TODO conflict-clause parsing %% TODO conflict-clause parsing
build_constraints([]) -> []; build_constraints([]) -> [];
build_constraints(["PRIMARY", "KEY" | Tail]) -> build_constraints(["PRIMARY", "KEY" | Tail]) ->
{Constraint, Rest} = build_primary_key_constraint(Tail), {Constraint, Rest} = build_primary_key_constraint(Tail),
[Constraint | build_constraints(Rest)]; [Constraint | build_constraints(Rest)];
build_constraints(["UNIQUE" | Tail]) -> build_constraints(["UNIQUE" | Tail]) ->
[unique | build_constraints(Tail)]; [unique | build_constraints(Tail)];
build_constraints(["NOT", "NULL" | Tail]) -> build_constraints(["NOT", "NULL" | Tail]) ->
[not_null | build_constraints(Tail)]; [not_null | build_constraints(Tail)];
build_constraints(["DEFAULT", DefaultValue | Tail]) -> build_constraints(["DEFAULT", DefaultValue | Tail]) ->
[{default, sqlite3_lib:sql_to_value(DefaultValue)} | build_constraints(Tail)]; [{default, sqlite3_lib:sql_to_value(DefaultValue)} | build_constraints(Tail)];
build_constraints(["CHECK", _ | Tail]) -> build_constraints(["CHECK", _ | Tail]) ->
%% currently ignored %% currently ignored
build_constraints(Tail). build_constraints(Tail).
% build_constraints(["REFERENCES", Check | Tail]) -> ... % build_constraints(["REFERENCES", Check | Tail]) -> ...
@@ -1177,12 +1177,12 @@ list_init([H|T]) -> [H|list_init(T)].
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% @type sql_value() = null | number() | iodata() | {blob, binary()}. %% @type sql_value() = null | number() | iodata() | {blob, binary()}.
%% %%
%% Values accepted in SQL statements are atom 'null', numbers, %% Values accepted in SQL statements are atom 'null', numbers,
%% strings (represented as iodata()) and blobs. %% strings (represented as iodata()) and blobs.
%% @end %% @end
%% @type sql_type() = integer | text | double | blob | atom() | string(). %% @type sql_type() = integer | text | double | blob | atom() | string().
%% %%
%% Types of SQLite columns are represented by atoms 'integer', 'text', 'double', %% Types of SQLite columns are represented by atoms 'integer', 'text', 'double',
%% 'blob'. Other atoms and strings may also be used (e.g. "VARCHAR(20)", 'smallint', etc.) %% 'blob'. Other atoms and strings may also be used (e.g. "VARCHAR(20)", 'smallint', etc.)
%% See [http://www.sqlite.org/datatype3.html]. %% See [http://www.sqlite.org/datatype3.html].
@@ -1197,19 +1197,19 @@ list_init([H|T]) -> [H|list_init(T)].
%% @type column_constraints() = column_constraint() | [column_constraint()]. %% @type column_constraints() = column_constraint() | [column_constraint()].
%% See {@link table_info()}. %% See {@link table_info()}.
%% @type table_info() = [{atom(), sql_type()} | {atom(), sql_type(), column_constraints()}]. %% @type table_info() = [{atom(), sql_type()} | {atom(), sql_type(), column_constraints()}].
%% %%
%% Describes the columns of an SQLite table: each tuple contains name, type and constraints (if any) %% Describes the columns of an SQLite table: each tuple contains name, type and constraints (if any)
%% of one column. %% of one column.
%% @end %% @end
%% @type table_constraint() = {primary_key, [atom()]} | {unique, [atom()]}. %% @type table_constraint() = {primary_key, [atom()]} | {unique, [atom()]}.
%% @type table_constraints() = table_constraint() | [table_constraint()]. %% @type table_constraints() = table_constraint() | [table_constraint()].
%% %%
%% Currently supported constraints for {@link table_info()} and {@link sqlite3:create_table/4}. %% Currently supported constraints for {@link table_info()} and {@link sqlite3:create_table/4}.
%% @end %% @end
%% @type sqlite_error() = {'error', integer(), string()} | {'error', any()}. %% @type sqlite_error() = {'error', integer(), string()} | {'error', any()}.
%% %%
%% Errors reported by SQLite side are represented by 3-element tuples containing %% Errors reported by SQLite side are represented by 3-element tuples containing
%% atom 'error', SQLite result code ([http://www.sqlite.org/c3ref/c_abort.html], %% atom 'error', SQLite result code ([http://www.sqlite.org/c3ref/c_abort.html],
%% [http://www.sqlite.org/c3ref/c_busy_recovery.html]) and an English-language error %% [http://www.sqlite.org/c3ref/c_busy_recovery.html]) and an English-language error
%% message. %% message.
%% %%