From eb221011fc30dfd7c5718b68e8a6e95d3d74a964 Mon Sep 17 00:00:00 2001 From: Max Lapshin Date: Tue, 13 Oct 2009 00:35:27 +0400 Subject: [PATCH] renaming to sqlite3 --- .gitignore | 2 ++ Emakefile | 6 ++-- Makefile | 6 ++-- ebin/.gitignore | 3 ++ sqlite.pub | 9 ----- src/{sqlite.erl => sqlite3.erl} | 42 +++++++++++------------ src/{sqlite_lib.erl => sqlite3_lib.erl} | 16 ++++----- src/{sqlite_test.erl => sqlite3_test.erl} | 28 +++++++-------- test.erl | 4 +-- 9 files changed, 56 insertions(+), 60 deletions(-) create mode 100644 .gitignore delete mode 100644 sqlite.pub rename src/{sqlite.erl => sqlite3.erl} (93%) rename src/{sqlite_lib.erl => sqlite3_lib.erl} (94%) rename src/{sqlite_test.erl => sqlite3_test.erl} (58%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..da8eb4f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +doc + diff --git a/Emakefile b/Emakefile index afb7134..227a4d5 100644 --- a/Emakefile +++ b/Emakefile @@ -1,3 +1,3 @@ -{'src/sqlite_lib.erl',[debug_info,{outdir,"ebin"}]}. -{'src/sqlite.erl',[debug_info,{outdir,"ebin"}]}. -{'src/sqlite_test.erl',[debug_info,{outdir,"ebin"}]}. +{'src/sqlite3_lib.erl',[debug_info,{outdir,"ebin"}]}. +{'src/sqlite3.erl',[debug_info,{outdir,"ebin"}]}. +{'src/sqlite3_test.erl',[debug_info,{outdir,"ebin"}]}. diff --git a/Makefile b/Makefile index 887c835..e1ed6c1 100644 --- a/Makefile +++ b/Makefile @@ -9,13 +9,13 @@ compile: cd priv && make static: - dialyzer --build_plt --output_plt sqlite.plt -r ebin $(PLT_SRC) + dialyzer --build_plt --output_plt sqlite3.plt -r ebin $(PLT_SRC) clean: - - rm -rf ebin/*.beam doc/* sqlite.plt src/test/*.beam + - rm -rf ebin/*.beam doc/* sqlite3.plt src/test/*.beam - rm -rf ct_run* all_runs.html variables* index.html find . -name "*~" | xargs rm cd priv && make clean docs: - $(ERL) -noshell -run edoc_run application "'sqlite'" '"."' '[{title,"Welcome to sqlite"},{hidden,false},{private,false}]' -s erlang halt + $(ERL) -noshell -run edoc_run application "'sqlite3'" '"."' '[{title,"Welcome to sqlite3"},{hidden,false},{private,false}]' -s erlang halt diff --git a/ebin/.gitignore b/ebin/.gitignore index e69de29..bd1b594 100644 --- a/ebin/.gitignore +++ b/ebin/.gitignore @@ -0,0 +1,3 @@ +*.beam +*.so + diff --git a/sqlite.pub b/sqlite.pub deleted file mode 100644 index e53ac8f..0000000 --- a/sqlite.pub +++ /dev/null @@ -1,9 +0,0 @@ -{author, {"Tee Teoh", "tty.erlang@gmail.com", {2008,6,8}}}. -{packager, {"Tee Teoh", "tty.erlang@gmail.com"}}. -{category, ["database","driver"]}. -{name, "sqlite"}. -{vsn, "1.0.0"}. -{depends, ["kernel","proplists","lists","string","stdlib"]}. -{keywords, ["database","sqlite","driver"]}. -{summary, "sqlite driver"}. -{abstract, "Manages a sqlite database."}. diff --git a/src/sqlite.erl b/src/sqlite3.erl similarity index 93% rename from src/sqlite.erl rename to src/sqlite3.erl index 1cd5757..a6f9d1c 100644 --- a/src/sqlite.erl +++ b/src/sqlite3.erl @@ -1,12 +1,12 @@ %%%------------------------------------------------------------------- -%%% File : sqlite.erl +%%% File : sqlite3.erl %%% @author Tee Teoh %%% @copyright 21 Jun 2008 by Tee Teoh %%% @version 1.0.0 -%%% @doc Library module for sqlite +%%% @doc Library module for sqlite3 %%% @end %%%------------------------------------------------------------------- --module(sqlite). +-module(sqlite3). -behaviour(gen_server). @@ -37,7 +37,7 @@ %% @spec start_link(Db) -> {ok,Pid} | ignore | {error,Error} %% Db = atom() %% @doc -%% Opens a sqlite dbase creating one if necessary. The dbase must +%% Opens a sqlite3 dbase creating one if necessary. The dbase must %% be called Db.db in the current path. start_link/1 can be use %% with stop/0, sql_exec/1, create_table/2, list_tables/0, %% table_info/1, write/2, read/2, delete/2 and drop_table/1. @@ -56,10 +56,10 @@ start_link(Db) -> %% @spec start_link(Db, Options) -> {ok,Pid} | ignore | {error,Error} %% Db = atom() %% @doc -%% Opens a sqlite dbase creating one if necessary. By default the +%% Opens a sqlite3 dbase creating one if necessary. By default the %% dbase will be called Db.db in the current path. This can be changed %% by passing the option {db, DbFile :: String()}. DbFile must be the -%% full path to the sqlite 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, %% read/2, delete/2 and drop_table/1. There can be only one start_link %% call per node. @@ -78,8 +78,8 @@ start_link(Db, Options) -> %%-------------------------------------------------------------------- %% @spec open(Db :: atom()) -> {ok, Pid::pid()} | ignore | {error, Error} %% @doc -%% Opens a sqlite dbase creating one if necessary. The dbase must be -%% called Db.db in the current path. Can be use to open multiple sqlite +%% Opens a sqlite3 dbase creating one if necessary. The dbase must be +%% called Db.db in the current path. Can be use to open multiple sqlite3 %% dbases per node. Must be use in conjunction with stop/1, sql_exec/2, %% create_table/3, list_tables/1, table_info/2, write/3, read/3, delete/3 %% and drop_table/2. @@ -92,10 +92,10 @@ open(Db) -> %%-------------------------------------------------------------------- %% @spec open(Db::atom(), Options::[tuple()]) -> {ok, Pid::pid()} | ignore | {error, Error} %% @doc -%% Opens a sqlite dbase creating one if necessary. By default the dbase +%% Opens a sqlite3 dbase creating one if necessary. By default the dbase %% will be called Db.db in the current path. This can be changed by %% passing the option {db, DbFile :: String()}. DbFile must be the full -%% path to the sqlite db file. Can be use to open multiple sqlite dbases +%% path to the sqlite3 db file. Can be use to open multiple sqlite3 dbases %% per node. Must be use in conjunction with stop/1, sql_exec/2, %% create_table/3, list_tables/1, table_info/2, write/3, read/3, delete/3 %% and drop_table/2. @@ -108,7 +108,7 @@ open(Db, Options) -> %%-------------------------------------------------------------------- %% @spec close(Db::atom()) -> ok %% @doc -%% Closes the Db sqlite dbase. +%% Closes the Db sqlite3 dbase. %% @end %%-------------------------------------------------------------------- -spec(close/1::(atom()) -> 'ok'). @@ -118,7 +118,7 @@ close(Db) -> %%-------------------------------------------------------------------- %% @spec stop() -> ok %% @doc -%% Closes the sqlite dbase. +%% Closes the sqlite3 dbase. %% @end %%-------------------------------------------------------------------- -spec(stop/0::() -> 'ok'). @@ -365,29 +365,29 @@ handle_call(list_tables, _From, #state{port = Port} = State) -> handle_call({table_info, Tbl}, _From, #state{port = Port} = State) -> % make sure we only get table info. % SQL Injection warning - SQL = io_lib:format("select sql from sqlite_master where tbl_name = '~p' and type='table';", [Tbl]), + SQL = io_lib:format("select sql from sqlite3_master where tbl_name = '~p' and type='table';", [Tbl]), [{Info}] = exec(Port, {sql_exec, SQL}), Reply = parse_table_info(Info), {reply, Reply, State}; handle_call({create_table, Tbl, Options}, _From, #state{port = Port} = State) -> - SQL = sqlite_lib:create_table_sql(Tbl, Options), + SQL = sqlite3_lib:create_table_sql(Tbl, Options), Cmd = {sql_exec, SQL}, Reply = exec(Port, Cmd), {reply, Reply, State}; handle_call({write, Tbl, Data}, _From, #state{port = Port} = State) -> % insert into t1 (data,num) values ('This is sample data',3); - Reply = exec(Port, {sql_exec, sqlite_lib:write_sql(Tbl, Data)}), + Reply = exec(Port, {sql_exec, sqlite3_lib:write_sql(Tbl, Data)}), {reply, Reply, State}; handle_call({read, Tbl, {Key, Value}}, _From, #state{port = Port} = State) -> % select * from Tbl where Key = Value; - Reply = exec(Port, {sql_exec, sqlite_lib:read_sql(Tbl, Key, Value)}), + Reply = exec(Port, {sql_exec, sqlite3_lib:read_sql(Tbl, Key, Value)}), {reply, Reply, State}; handle_call({delete, Tbl, {Key, Value}}, _From, #state{port = Port} = State) -> % delete from Tbl where Key = Value; - Reply = exec(Port, {sql_exec, sqlite_lib:delete_sql(Tbl, Key, Value)}), + Reply = exec(Port, {sql_exec, sqlite3_lib:delete_sql(Tbl, Key, Value)}), {reply, Reply, State}; handle_call({drop_table, Tbl}, _From, #state{port = Port} = State) -> - Reply = exec(Port, {sql_exec, sqlite_lib:drop_table(Tbl)}), + Reply = exec(Port, {sql_exec, sqlite3_lib:drop_table(Tbl)}), {reply, Reply, State}; handle_call(_Request, _From, State) -> Reply = ok, @@ -450,7 +450,7 @@ code_change(_OldVsn, State, _Extra) -> %%-------------------------------------------------------------------- create_cmd(Dbase) -> - "sqlite_port " ++ Dbase. + "sqlite3_port " ++ Dbase. exec(Port, Cmd) -> port_command(Port, term_to_binary(Cmd)), @@ -476,7 +476,7 @@ parse_table_info(Info) -> build_table_info([], Acc) -> lists:reverse(Acc); build_table_info([[ColName, ColType] | Tl], Acc) -> - build_table_info(Tl, [{list_to_atom(ColName), sqlite_lib:col_type(ColType)}| Acc]); + build_table_info(Tl, [{list_to_atom(ColName), sqlite3_lib:col_type(ColType)}| Acc]); build_table_info([[ColName, ColType, "PRIMARY", "KEY"] | Tl], Acc) -> - build_table_info(Tl, [{list_to_atom(ColName), sqlite_lib:col_type(ColType)}| Acc]). + build_table_info(Tl, [{list_to_atom(ColName), sqlite3_lib:col_type(ColType)}| Acc]). diff --git a/src/sqlite_lib.erl b/src/sqlite3_lib.erl similarity index 94% rename from src/sqlite_lib.erl rename to src/sqlite3_lib.erl index e2d5f15..a7ee4b0 100644 --- a/src/sqlite_lib.erl +++ b/src/sqlite3_lib.erl @@ -1,12 +1,12 @@ %%%------------------------------------------------------------------- -%%% File : sqlite_lib.erl +%%% File : sqlite3_lib.erl %%% @author Tee Teoh %%% @copyright 21 Jun 2008 by Tee Teoh %%% @version 1.0.0 -%%% @doc Library module for sqlite +%%% @doc Library module for sqlite3 %%% @end %%%------------------------------------------------------------------- --module(sqlite_lib). +-module(sqlite3_lib). %% API -export([col_type/1]). @@ -18,7 +18,7 @@ %%==================================================================== %%-------------------------------------------------------------------- %% @spec col_type(Type :: term()) -> term() -%% @doc Maps sqlite column type. +%% @doc Maps sqlite3 column type. %%-------------------------------------------------------------------- -spec(col_type/1::(atom() | string()) -> atom() | string()). col_type(integer) -> @@ -77,10 +77,10 @@ write_col_sql(Cols) -> -spec(create_table_sql/2::(atom(), [{atom(), string()}]) -> string()). create_table_sql(Tbl, [{ColName, Type} | Tl]) -> CT = io_lib:format("CREATE TABLE ~p ", [Tbl]), - Start = io_lib:format("(~p ~s PRIMARY KEY, ", [ColName, sqlite_lib:col_type(Type)]), + Start = io_lib:format("(~p ~s PRIMARY KEY, ", [ColName, sqlite3_lib:col_type(Type)]), End = string:join( lists:map(fun({Name0, Type0}) -> - io_lib:format("~p ~s", [Name0, sqlite_lib:col_type(Type0)]) + io_lib:format("~p ~s", [Name0, sqlite3_lib:col_type(Type0)]) end, Tl), ", ") ++ ");", lists:flatten(CT ++ Start ++ End). @@ -99,8 +99,8 @@ write_sql(Tbl, Data) -> lists:flatten( io_lib:format("INSERT INTO ~p (~s) values (~s);", [Tbl, - sqlite_lib:write_col_sql(Cols), - sqlite_lib:write_value_sql(Values)])). + sqlite3_lib:write_col_sql(Cols), + sqlite3_lib:write_value_sql(Values)])). %%-------------------------------------------------------------------- %% @spec read_sql(Tbl, Key, Value) -> string() diff --git a/src/sqlite_test.erl b/src/sqlite3_test.erl similarity index 58% rename from src/sqlite_test.erl rename to src/sqlite3_test.erl index 62a54d0..7f46730 100644 --- a/src/sqlite_test.erl +++ b/src/sqlite3_test.erl @@ -1,11 +1,11 @@ %%%------------------------------------------------------------------- -%%% File : sqlite_test.erl +%%% File : sqlite3_test.erl %%% Author : Tee Teoh %%% Description : %%% %%% Created : 10 Jun 2008 by Tee Teoh %%%------------------------------------------------------------------- --module(sqlite_test). +-module(sqlite3_test). %% API -export([create_table_test/0]). @@ -20,18 +20,18 @@ %% Description: %%-------------------------------------------------------------------- create_table_test() -> - sqlite:open(ct), - sqlite:create_table(ct, user, [{name, text}, {age, integer}, {wage, integer}]), - [user] = sqlite:list_tables(ct), - [{name, text}, {age, integer}, {wage, integer}] = sqlite:table_info(ct, user), - sqlite:write(ct, user, [{name, "abby"}, {age, 20}, {wage, 2000}]), - sqlite:write(ct, user, [{name, "marge"}, {age, 30}, {wage, 3000}]), - sqlite:sql_exec(ct, "select * from user;"), - sqlite:read(ct, user, {name, "abby"}), - sqlite:delete(ct, user, {name, "abby"}), - sqlite:drop_table(ct, user), -%sqlite:delete_db(ct) - sqlite:close(ct). + sqlite3:open(ct), + sqlite3:create_table(ct, user, [{name, text}, {age, integer}, {wage, integer}]), + [user] = sqlite3:list_tables(ct), + [{name, text}, {age, integer}, {wage, integer}] = sqlite3:table_info(ct, user), + sqlite3:write(ct, user, [{name, "abby"}, {age, 20}, {wage, 2000}]), + sqlite3:write(ct, user, [{name, "marge"}, {age, 30}, {wage, 3000}]), + sqlite3:sql_exec(ct, "select * from user;"), + sqlite3:read(ct, user, {name, "abby"}), + sqlite3:delete(ct, user, {name, "abby"}), + sqlite3:drop_table(ct, user), +%sqlite3:delete_db(ct) + sqlite3:close(ct). % create, read, update, delete %%==================================================================== %% Internal functions diff --git a/test.erl b/test.erl index 73a5e40..592cd16 100755 --- a/test.erl +++ b/test.erl @@ -1,5 +1,5 @@ #!/usr/bin/env escript -%%! -smp enable -pa ebin +%%! -smp enable -pa ebin -name testsqlite3 main(_) -> - sqlite3_store:start_link(). + ct:run("src").