Formatting fixed

This commit is contained in:
Alexey Romanov
2010-10-12 10:08:52 +04:00
parent 0669e26175
commit cb2f1c9121
2 changed files with 100 additions and 99 deletions

View File

@@ -25,7 +25,7 @@
%% @doc Maps sqlite3 column type.
%% @end
%%--------------------------------------------------------------------
-spec(col_type_to_string/1::(atom()) -> string()).
-spec col_type_to_string(atom()) -> string().
col_type_to_string(integer) ->
"INTEGER";
col_type_to_string(text) ->
@@ -40,7 +40,7 @@ col_type_to_string(real) ->
%% @doc Maps sqlite3 column type.
%% @end
%%--------------------------------------------------------------------
-spec(col_type_to_atom/1::(string()) -> atom()).
-spec col_type_to_atom(string()) -> atom().
col_type_to_atom("INTEGER") ->
integer;
col_type_to_atom("TEXT") ->
@@ -61,7 +61,7 @@ col_type_to_atom("REAL") ->
%% single quotes (e.g. can be entered by users).
%% @end
%%--------------------------------------------------------------------
-spec(value_to_sql_unsafe/1::(sql_value()) -> iodata()).
-spec value_to_sql_unsafe(sql_value()) -> iodata().
value_to_sql_unsafe(X) ->
if
is_integer(X) -> integer_to_list(X);
@@ -80,7 +80,7 @@ value_to_sql_unsafe(X) ->
%% All single quotes (') will be replaced with ''.
%% @end
%%--------------------------------------------------------------------
-spec(value_to_sql/1::(sql_value()) -> iolist()).
-spec value_to_sql(sql_value()) -> iolist().
value_to_sql(X) ->
if
is_integer(X) -> integer_to_list(X);
@@ -95,7 +95,7 @@ value_to_sql(X) ->
%% Creates the values portion of the sql stmt.
%% @end
%%--------------------------------------------------------------------
-spec(write_value_sql/1::(any()) -> string()).
-spec write_value_sql(any()) -> string().
write_value_sql(Values) ->
map_intersperse(fun value_to_sql/1, Values, ",").
@@ -104,17 +104,17 @@ write_value_sql(Values) ->
%% @doc Creates the column/data stmt for SQL.
%% @end
%%--------------------------------------------------------------------
-spec(write_col_sql/1::([atom()]) -> string()).
-spec write_col_sql([atom()]) -> string().
write_col_sql(Cols) ->
map_intersperse(fun atom_to_list/1, Cols, ",").
%%--------------------------------------------------------------------
%% @spec replace (String) -> string ()
%% String = string ()
%% @spec replace(String) -> string()
%% String = string()
%% @doc Returns copy of String for which \" replaced with '
%% @end
%%--------------------------------------------------------------------
-spec (replace/1::(string ()) -> string ()).
-spec replace(string()) -> string().
replace([]) -> [];
replace([$" | T]) ->
[$' | replace(T)];
@@ -127,35 +127,35 @@ replace([H | T]) ->
%% @doc Returns copy of IoData with all ' replaced by ''
%% @end
%%--------------------------------------------------------------------
-spec(escape/1::(iodata()) -> iodata()).
-spec escape(iodata()) -> iodata().
escape(IoData) -> re:replace(IoData, "'", "''", [global]).
%%--------------------------------------------------------------------
%% @spec update_set_sql ([{Col, Value}]) -> string ()
%% Col = atom ()
%% Value = number () | atom () | string ()
%% @spec update_set_sql([{Col, Value}]) -> string()
%% Col = atom()
%% Value = number() | atom() | string()
%% @doc
%% Creates update set stmt.
%% Currently supports integer, double/float and strings.
%% For strings \" replaced with '.
%% @end
%%--------------------------------------------------------------------
-spec (update_set_sql/1::(any ()) -> string ()).
update_set_sql (Data) ->
-spec update_set_sql(any()) -> string().
update_set_sql(Data) ->
ColValueToSqlFun =
fun({Col, Value}) ->
[atom_to_list (Col), " = ", value_to_sql(Value)]
[atom_to_list(Col), " = ", value_to_sql(Value)]
end,
map_intersperse(ColValueToSqlFun, Data, ", ").
%%--------------------------------------------------------------------
%% @spec read_cols_sql (Columns::[atom ()]) -> string ()
%% @spec read_cols_sql(Columns::[atom()]) -> string()
%% @doc
%% Creates list of columns for select stmt.
%% @end
%%--------------------------------------------------------------------
-spec (read_cols_sql/1::([atom ()]) -> string ()).
read_cols_sql (Columns) ->
-spec read_cols_sql([atom()]) -> string().
read_cols_sql(Columns) ->
map_intersperse(fun atom_to_list/1, Columns, ", ").
%%--------------------------------------------------------------------
@@ -167,7 +167,7 @@ read_cols_sql (Columns) ->
%% First column listed is considered the primary key.
%% @end
%%--------------------------------------------------------------------
-spec(create_table_sql/2::(atom(), [{atom(), string()}]) -> string()).
-spec create_table_sql(atom(), [{atom(), string()}]) -> string().
create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
CT = ["CREATE TABLE ", atom_to_list(Tbl), " "],
Start = ["(", atom_to_list(ColName), " ", col_type_to_string(Type), " PRIMARY KEY, "],
@@ -178,19 +178,19 @@ create_table_sql(Tbl, [{ColName, Type} | Tl]) ->
[CT, Start, End].
%%--------------------------------------------------------------------
%% @spec update_sql (Tbl, Key, Value, Data) -> string ()
%% Tbl = atom ()
%% Key = atom ()
%% Value = atom ()
%% Data = [{ColName :: atom (), Value :: string () | integer () | float ()}]
%% @spec update_sql(Tbl, Key, Value, Data) -> string()
%% Tbl = atom()
%% Key = atom()
%% Value = atom()
%% Data = [{ColName :: atom(), Value :: string() | integer() | float()}]
%% @doc
%% Using Key as the column name and Data as list of column names
%% and values pairs it creates the proper update SQL stmt for the
%% record with matching Value.
%% @end
%%--------------------------------------------------------------------
-spec (update_sql/4::(atom (), atom (), atom (), [{atom (), sql_value ()}]) -> string ()).
update_sql (Tbl, Key, Value, Data) ->
-spec update_sql(atom(), atom(), atom(), [{atom(), sql_value()}]) -> string().
update_sql(Tbl, Key, Value, Data) ->
["UPDATE ", atom_to_list(Tbl), " SET ", update_set_sql(Data),
" WHERE ", atom_to_list(Key), " = ", value_to_sql(Value), ";"].
@@ -202,7 +202,7 @@ update_sql (Tbl, Key, Value, Data) ->
%% proper insertion SQL stmt.
%% @end
%%--------------------------------------------------------------------
-spec(write_sql/2::(atom(), [{atom(), sql_value()}]) -> string()).
-spec write_sql(atom(), [{atom(), sql_value()}]) -> string().
write_sql(Tbl, Data) ->
{Cols, Values} = lists:unzip(Data),
["INSERT INTO ", atom_to_list(Tbl), " (", sqlite3_lib:write_col_sql(Cols),
@@ -217,24 +217,24 @@ write_sql(Tbl, Data) ->
%% matching Value.
%% @end
%%--------------------------------------------------------------------
-spec(read_sql/3::(atom(), atom(), sql_value()) -> string()).
-spec read_sql(atom(), atom(), sql_value()) -> string().
read_sql(Tbl, Key, Value) ->
["SELECT * FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
" = ", value_to_sql(Value), ";"].
%%--------------------------------------------------------------------
%% @spec read_sql (Tbl, Key, Value, Columns) -> string ()
%% Tbl = atom ()
%% Key = atom ()
%% Value = string () | integer () | float ()
%% Columns = [atom ()]
%% @spec read_sql(Tbl, Key, Value, Columns) -> string()
%% Tbl = atom()
%% Key = atom()
%% Value = string() | integer() | float()
%% Columns = [atom()]
%% @doc
%% Using Key as the column name searhces for the record with
%% matching Value and returns only specified columns Columns.
%% @end
%%--------------------------------------------------------------------
-spec (read_sql/4::(atom (), atom (), sql_value (), [atom ()]) -> string ()).
read_sql (Tbl, Key, Value, Columns) ->
-spec read_sql(atom(), atom(), sql_value(), [atom()]) -> string().
read_sql(Tbl, Key, Value, Columns) ->
["SELECT ", sqlite3_lib:read_cols_sql(Columns), " FROM ",
atom_to_list(Tbl), " WHERE ", atom_to_list(Key), " = ",
value_to_sql(Value), ";"].
@@ -248,7 +248,7 @@ read_sql (Tbl, Key, Value, Columns) ->
%% matching Value then deletes that record.
%% @end
%%--------------------------------------------------------------------
-spec(delete_sql/3::(atom(), atom(), sql_value()) -> string()).
-spec delete_sql(atom(), atom(), sql_value()) -> string().
delete_sql(Tbl, Key, Value) ->
["DELETE FROM ", atom_to_list(Tbl), " WHERE ", atom_to_list(Key),
" = ", value_to_sql(Value), ";"].
@@ -259,7 +259,7 @@ delete_sql(Tbl, Key, Value) ->
%% @doc Drop the table Tbl from the database
%% @end
%%--------------------------------------------------------------------
-spec(drop_table/1::(atom()) -> string()).
-spec drop_table(atom()) -> string().
drop_table(Tbl) ->
["DROP TABLE ", atom_to_list(Tbl), ";"].