Merged with http://github.com/dreid/erlang-sqlite3
This commit is contained in:
8
.gitignore
vendored
8
.gitignore
vendored
@@ -1,7 +1,4 @@
|
||||
doc
|
||||
config.log
|
||||
config.status
|
||||
autom4te.cache
|
||||
sqlite3.plt
|
||||
.svn
|
||||
*/.svn
|
||||
@@ -9,3 +6,8 @@ sqlite3.plt
|
||||
*.swp
|
||||
*~
|
||||
erl_crash.dump
|
||||
*.o
|
||||
.eunit
|
||||
*.orig
|
||||
ebin
|
||||
priv
|
||||
|
||||
8
AUTHORS
Normal file
8
AUTHORS
Normal file
@@ -0,0 +1,8 @@
|
||||
Original Author:
|
||||
ttyerl <tty.erlang@gmail.com> - http://github.com/ttyerl/sqlite-erlang
|
||||
|
||||
Forkers:
|
||||
Max Lapshin - http://github.com/maxlapshin/erlang-sqlite3
|
||||
Sergey Miryanov - http://github.com/sergey-miryanov/erlang-sqlite3
|
||||
Alexey Romanov - http://github.com/alexeyr/erlang-sqlite3
|
||||
David Reid - http://github.com/dreid/erlang-sqlite3
|
||||
48
Makefile
48
Makefile
@@ -1,46 +1,24 @@
|
||||
ERL=/usr/local/bin/erl
|
||||
ERLC=/usr/local/bin/erlc
|
||||
ERL_ERTS=/usr/local/lib/erlang/lib/erts-5.8.1
|
||||
ERL_KERNEL=/usr/local/lib/erlang/lib/kernel-2.14.1
|
||||
ERL_STDLIB=/usr/local/lib/erlang/lib/stdlib-1.17.1
|
||||
ERL_CRYPTO=/usr/local/lib/erlang/lib/crypto-2.0.1
|
||||
ERL_COMPILER=/usr/local/lib/erlang/lib/compiler-4.7.1
|
||||
ERL_HIPE=/usr/local/lib/erlang/lib/hipe-3.7.7
|
||||
ERL_SYNTAX_TOOLS=/usr/local/lib/erlang/lib/syntax_tools-1.6.6
|
||||
OTP_TOP=/usr/lib/erlang/lib
|
||||
PLT_SRC=$(ERL_ERTS)/ebin $(ERL_KERNEL)/ebin $(ERL_STDLIB)/ebin $(ERL_CRYPTO)/ebin $(ERL_COMPILER)/ebin $(ERL_HIPE)/ebin $(ERL_SYNTAX_TOOLS)/ebin
|
||||
REBAR=./rebar
|
||||
|
||||
all: compile docs
|
||||
all: compile
|
||||
|
||||
test: compile_test
|
||||
$(ERL) -noshell -pa ebin \
|
||||
-eval 'eunit:test({dir, "ebin"})' \
|
||||
-s init stop
|
||||
compile:
|
||||
$(REBAR) get-deps compile
|
||||
|
||||
compile: compile_c
|
||||
$(ERL) -make
|
||||
test: all
|
||||
$(REBAR) skip_deps=true eunit
|
||||
|
||||
compile_test: compile_c
|
||||
erl -noshell -eval "make:all([{d, 'TEST'}])." -s init stop
|
||||
clean:
|
||||
$(REBAR) clean
|
||||
-rm -rvf deps ebin
|
||||
|
||||
compile_c:
|
||||
test -d ebin || mkdir ebin
|
||||
cd priv && make
|
||||
docs:
|
||||
$(REBAR) doc
|
||||
|
||||
ifeq ($(wildcard sqlite3.plt),)
|
||||
static:
|
||||
dialyzer --build_plt --output_plt sqlite3.plt -r $(PLT_SRC)
|
||||
dialyzer --add_to_plt --plt sqlite3.plt -r ebin --get_warnings
|
||||
dialyzer --build_plt --output_plt sqlite3.plt --apps erts kernel stdlib crypto compiler hipe syntax_tools -r ebin
|
||||
else
|
||||
static:
|
||||
dialyzer --add_to_plt --plt sqlite3.plt -r ebin --get_warnings
|
||||
endif
|
||||
|
||||
clean:
|
||||
- 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 "'sqlite3'" '"."' '[{title,"Welcome to sqlite3"},{hidden,false},{private,false}]' -s erlang halt
|
||||
endif
|
||||
46
Makefile.in
46
Makefile.in
@@ -1,46 +0,0 @@
|
||||
ERL=@ERL@
|
||||
ERLC=@ERLC@
|
||||
ERL_ERTS=@ERLANG_LIB_DIR_erts@
|
||||
ERL_KERNEL=@ERLANG_LIB_DIR_kernel@
|
||||
ERL_STDLIB=@ERLANG_LIB_DIR_stdlib@
|
||||
ERL_CRYPTO=@ERLANG_LIB_DIR_crypto@
|
||||
ERL_COMPILER=@ERLANG_LIB_DIR_compiler@
|
||||
ERL_HIPE=@ERLANG_LIB_DIR_hipe@
|
||||
ERL_SYNTAX_TOOLS=@ERLANG_LIB_DIR_syntax_tools@
|
||||
OTP_TOP=/usr/lib/erlang/lib
|
||||
PLT_SRC=$(ERL_ERTS)/ebin $(ERL_KERNEL)/ebin $(ERL_STDLIB)/ebin $(ERL_CRYPTO)/ebin $(ERL_COMPILER)/ebin $(ERL_HIPE)/ebin $(ERL_SYNTAX_TOOLS)/ebin
|
||||
|
||||
all: compile docs
|
||||
|
||||
test: compile_test
|
||||
$(ERL) -noshell -pa ebin \
|
||||
-eval 'eunit:test({dir, "ebin"})' \
|
||||
-s init stop
|
||||
|
||||
compile: compile_c
|
||||
$(ERL) -make
|
||||
|
||||
compile_test: compile_c
|
||||
erl -noshell -eval "make:all([{d, 'TEST'}])." -s init stop
|
||||
|
||||
compile_c:
|
||||
test -d ebin || mkdir ebin
|
||||
cd priv && make
|
||||
|
||||
ifeq ($(wildcard sqlite3.plt),)
|
||||
static:
|
||||
dialyzer --build_plt --output_plt sqlite3.plt -r $(PLT_SRC)
|
||||
dialyzer --add_to_plt --plt sqlite3.plt -r ebin --get_warnings
|
||||
else
|
||||
static:
|
||||
dialyzer --add_to_plt --plt sqlite3.plt -r ebin --get_warnings
|
||||
endif
|
||||
|
||||
clean:
|
||||
- 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 "'sqlite3'" '"."' '[{title,"Welcome to sqlite3"},{hidden,false},{private,false}]' -s erlang halt
|
||||
22
README.rst
Normal file
22
README.rst
Normal file
@@ -0,0 +1,22 @@
|
||||
Compiling
|
||||
---------
|
||||
|
||||
1. Run 'make'
|
||||
|
||||
|
||||
Running Test Suite
|
||||
------------------
|
||||
|
||||
1. make test
|
||||
|
||||
|
||||
Example Usage
|
||||
-------------
|
||||
|
||||
Use src/sqlite3_test.erl as an example.
|
||||
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
See ./AUTHORS
|
||||
33
Readme
33
Readme
@@ -1,33 +0,0 @@
|
||||
Compiling
|
||||
---------
|
||||
|
||||
1. Run './configure'
|
||||
|
||||
2. Run 'make'
|
||||
|
||||
3. Run 'make static' for dialyzer
|
||||
|
||||
|
||||
Running Test Suite
|
||||
------------------
|
||||
|
||||
Either
|
||||
|
||||
1. Run ./test.erl
|
||||
|
||||
or
|
||||
|
||||
2. $ROOT refers to the parent directory for erlang-sqlite3.
|
||||
|
||||
3. Run erl -pa $ROOT/priv -pa $ROOT/ebin.
|
||||
|
||||
4. ct:run("src").
|
||||
|
||||
|
||||
Example Usage
|
||||
-------------
|
||||
|
||||
Use src/test/sqlite_test_SUITE.erl as an example for your own usage. Look at both init_per_testcase and create_table.
|
||||
|
||||
|
||||
Author: tty.erlang@gmail.com
|
||||
55
configure.ac
55
configure.ac
@@ -1,55 +0,0 @@
|
||||
# -*- Autoconf -*-
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.63])
|
||||
AC_INIT([FULL-PACKAGE-NAME], [VERSION], [BUG-REPORT-ADDRESS])
|
||||
AC_CONFIG_SRCDIR([priv/erl_comm.c])
|
||||
#AC_CONFIG_HEADERS([config.h])
|
||||
#AC_CANONICAL_TARGET
|
||||
|
||||
# Checks for programs.
|
||||
AC_PROG_CC
|
||||
AC_PROG_MAKE_SET
|
||||
|
||||
## Checks for libraries.
|
||||
## FIXME: Replace `main' with a function in `-lei':
|
||||
#AC_CHECK_LIB([ei], [main])
|
||||
## FIXME: Replace `main' with a function in `-lerl_interface':
|
||||
#AC_CHECK_LIB([erl_interface], [main])
|
||||
## FIXME: Replace `main' with a function in `-lsqlite3':
|
||||
#AC_CHECK_LIB([sqlite3], [main])
|
||||
|
||||
# Checks for header files.
|
||||
AC_CHECK_HEADERS([stdlib.h string.h unistd.h])
|
||||
|
||||
# Checks for typedefs, structures, and compiler characteristics.
|
||||
AC_C_INLINE
|
||||
|
||||
# Checks for library functions.
|
||||
AC_FUNC_MALLOC
|
||||
AC_FUNC_REALLOC
|
||||
AC_CHECK_FUNCS([bzero strstr])
|
||||
|
||||
AC_ERLANG_NEED_ERLC
|
||||
AC_ERLANG_SUBST_ROOT_DIR
|
||||
AC_ERLANG_SUBST_LIB_DIR
|
||||
AC_ERLANG_CHECK_LIB(erts)
|
||||
AC_ERLANG_CHECK_LIB(erl_interface)
|
||||
AC_ERLANG_CHECK_LIB(kernel)
|
||||
AC_ERLANG_CHECK_LIB(stdlib)
|
||||
AC_ERLANG_CHECK_LIB(crypto)
|
||||
AC_ERLANG_CHECK_LIB(compiler)
|
||||
AC_ERLANG_CHECK_LIB(hipe)
|
||||
AC_ERLANG_CHECK_LIB(syntax_tools)
|
||||
|
||||
AC_ARG_ENABLE([null-atom],
|
||||
[AC_HELP_STRING([--enable-null-atom=atom],
|
||||
[Set to configure null-atom, default 'null'])],
|
||||
[ ac_null_atom=$enableval ],
|
||||
[ ac_null_atom=null ])
|
||||
|
||||
NULL_ATOM="$ac_null_atom"
|
||||
AC_SUBST([NULL_ATOM])
|
||||
AC_CONFIG_FILES([Makefile
|
||||
priv/Makefile])
|
||||
AC_OUTPUT
|
||||
3
ebin/.gitignore
vendored
3
ebin/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
*.beam
|
||||
*.so
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
ERL_INTERFACE=@ERLANG_LIB_DIR_erl_interface@
|
||||
ERL_ROOT=@ERLANG_ROOT_DIR@
|
||||
GCC=gcc
|
||||
LDFLAGS=-shared -L/usr/lib -lsqlite3 -undefined -fPIC -lerl_interface -L$(ERL_INTERFACE)/lib -lei
|
||||
SRCS=sqlite3_drv.c sqlite3_drv.h
|
||||
OUTPUT=sqlite3_drv.so
|
||||
CFLAGS=-o ../ebin/${OUTPUT} -I$(ERL_ROOT)/usr/include/ -I$(ERL_INTERFACE)/include/ -DNULL_ATOM=@NULL_ATOM@
|
||||
|
||||
all: ../ebin/${OUTPUT}
|
||||
|
||||
|
||||
../ebin/${OUTPUT}: sqlite3_drv.c sqlite3_drv.h
|
||||
${GCC} sqlite3_drv.c ${LDFLAGS} ${CFLAGS}
|
||||
|
||||
clean:
|
||||
rm -rf ../ebin/${OUTPUT}
|
||||
4
rebar.config
Normal file
4
rebar.config
Normal file
@@ -0,0 +1,4 @@
|
||||
% -*- mode: erlang -*-
|
||||
{port_envs, [{"DRV_LDFLAGS", "$DRV_LDFLAGS -lsqlite3"}]}.
|
||||
{cover_enabled, true}.
|
||||
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
|
||||
10
src/sqlite3.app.src
Normal file
10
src/sqlite3.app.src
Normal file
@@ -0,0 +1,10 @@
|
||||
{application, sqlite3,
|
||||
[
|
||||
{description, "SQLite3 Interface"},
|
||||
{vsn, "1"},
|
||||
{modules, []},
|
||||
{registered, []},
|
||||
{applications, [kernel, stdlib, crypto, inets, lhttpc]},
|
||||
{mod, {sqlite3, []}},
|
||||
{env, []}
|
||||
]}.
|
||||
@@ -1,7 +1,7 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : sqlite3.erl
|
||||
%%% @author Tee Teoh
|
||||
%%% @copyright 21 Jun 2008 by Tee Teoh
|
||||
%%% @copyright 21 Jun 2008 by Tee Teoh
|
||||
%%% @version 1.0.0
|
||||
%%% @doc Library module for sqlite3
|
||||
%%% @end
|
||||
@@ -32,7 +32,7 @@
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
|
||||
terminate/2, code_change/3]).
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-define('DRIVER_NAME', 'sqlite3_drv').
|
||||
-record(state, {port, ops = []}).
|
||||
@@ -70,24 +70,24 @@ start_link(Db) ->
|
||||
%% read/2, delete/2 and drop_table/1. There can be only one start_link
|
||||
%% call per node.
|
||||
%%
|
||||
%% To open multiple dbases on the same node use open/1 or open/2.
|
||||
%% To open multiple dbases on the same node use open/1 or open/2.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
-spec start_link(atom(), [{atom(), any()}]) -> result().
|
||||
start_link(Db, Options) ->
|
||||
Opts = case proplists:get_value(db, Options) of
|
||||
undefined -> [{db, "./" ++ atom_to_list(Db) ++ ".db"} | Options];
|
||||
_ -> Options
|
||||
end,
|
||||
undefined -> [{db, "./" ++ atom_to_list(Db) ++ ".db"} | Options];
|
||||
_ -> Options
|
||||
end,
|
||||
?MODULE:open(Db, Opts).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec open(Db :: atom()) -> {ok, Pid :: pid()} | ignore | {error, Error}
|
||||
%% @doc
|
||||
%% 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
|
||||
%% 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
|
||||
%% create_table/3, list_tables/1, table_info/2, write/3, read/3, delete/3
|
||||
%% and drop_table/2.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
@@ -98,13 +98,13 @@ open(Db) ->
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec open(Db :: atom(), Options :: [{atom(), any()}]) -> {ok, Pid :: pid()} | ignore | {error, Error}
|
||||
%% @doc
|
||||
%% 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 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.
|
||||
%% 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 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.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
-spec open(atom(), [{atom(), any()}]) -> result().
|
||||
@@ -114,7 +114,7 @@ open(Db, Options) ->
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec close(Db :: atom()) -> ok
|
||||
%% @doc
|
||||
%% Closes the Db sqlite3 dbase.
|
||||
%% Closes the Db sqlite3 dbase.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
-spec close(atom()) -> 'ok'.
|
||||
@@ -130,7 +130,7 @@ close(Db) ->
|
||||
-spec stop() -> 'ok'.
|
||||
stop() ->
|
||||
?MODULE:close(?MODULE).
|
||||
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec sql_exec(Sql :: iodata()) -> term()
|
||||
%% @doc
|
||||
@@ -144,7 +144,7 @@ sql_exec(SQL) ->
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec sql_exec(Db :: atom(), Sql :: iodata()) -> any()
|
||||
%% @doc
|
||||
%% Executes the Sql statement directly on the Db dbase. Returns the
|
||||
%% Executes the Sql statement directly on the Db dbase. Returns the
|
||||
%% result of the Sql call.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
@@ -155,7 +155,7 @@ sql_exec(Db, SQL) ->
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec create_table(Tbl :: atom(), TblInfo :: [{atom(), atom()}]) -> any()
|
||||
%% @doc
|
||||
%% Creates the Tbl table using TblInfo as the table structure. The
|
||||
%% Creates the Tbl table using TblInfo as the table structure. The
|
||||
%% table structure is a list of {column name, column type} pairs.
|
||||
%% e.g. [{name, text}, {age, integer}]
|
||||
%%
|
||||
@@ -167,8 +167,8 @@ create_table(Tbl, Options) ->
|
||||
?MODULE:create_table(?MODULE, Tbl, Options).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec create_table(Db :: atom(), Tbl :: atom(), TblInfo) -> any()
|
||||
%% TblInfo = [{atom(), atom()}]
|
||||
%% @spec create_table(Db :: atom(), Tbl :: atom(), Columns) -> any()
|
||||
%% Columns = [{atom(), atom()}]
|
||||
%% @doc
|
||||
%% Creates the Tbl table in Db using Columns as the table structure.
|
||||
%% The table structure is a list of {column name, column type} pairs.
|
||||
@@ -269,8 +269,8 @@ write(Db, Tbl, Data) ->
|
||||
%% Result = {ok, ID} | Unknown
|
||||
%% Unknown = term()
|
||||
%% @doc
|
||||
%% Updates rows into Tbl table such that the Value matches the
|
||||
%% value in Key with Data. Returns ID of the first updated
|
||||
%% Updates rows into Tbl table such that the Value matches the
|
||||
%% value in Key with Data. Returns ID of the first updated
|
||||
%% record.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
@@ -284,8 +284,8 @@ update(Tbl, Key, Value, Data) ->
|
||||
%% Result = {ok, ID} | Unknown
|
||||
%% Unknown = term()
|
||||
%% @doc
|
||||
%% Updates rows into Tbl table in Db dbase such that the Value
|
||||
%% matches the value in Key with Data. Returns ID of the first
|
||||
%% Updates rows into Tbl table in Db dbase such that the Value
|
||||
%% matches the value in Key with Data. Returns ID of the first
|
||||
%% updated record.
|
||||
%% @end
|
||||
%%--------------------------------------------------------------------
|
||||
@@ -382,7 +382,6 @@ drop_table(Db, Tbl) ->
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec create_function(Db :: atom(), FunctionName :: atom(), Function :: function()) -> term()
|
||||
%%
|
||||
%% @doc
|
||||
%% Creates function under name FunctionName.
|
||||
%%
|
||||
@@ -394,12 +393,12 @@ create_function(Db, FunctionName, Function) ->
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec value_to_sql_unsafe(Value :: sql_value()) -> iolist()
|
||||
%% @doc
|
||||
%% @doc
|
||||
%% Converts an Erlang term to an SQL string.
|
||||
%% Currently supports integers, floats, 'null' atom, and iodata
|
||||
%% Currently supports integers, floats, 'null' atom, and iodata
|
||||
%% (binaries and iolists) which are treated as SQL strings.
|
||||
%%
|
||||
%% Note that it opens opportunity for injection if an iolist includes
|
||||
%% Note that it opens opportunity for injection if an iolist includes
|
||||
%% single quotes! Replace all single quotes (') with '' manually, or
|
||||
%% use value_to_sql/1 if you are not sure if your strings contain
|
||||
%% single quotes (e.g. can be entered by users).
|
||||
@@ -412,9 +411,9 @@ value_to_sql_unsafe(X) -> sqlite3_lib:value_to_sql_unsafe(X).
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec value_to_sql(Value :: sql_value()) -> iolist()
|
||||
%% @doc
|
||||
%% @doc
|
||||
%% Converts an Erlang term to an SQL string.
|
||||
%% Currently supports integers, floats, 'null' atom, and iodata
|
||||
%% Currently supports integers, floats, 'null' atom, and iodata
|
||||
%% (binaries and iolists) which are treated as SQL strings.
|
||||
%%
|
||||
%% All single quotes (') will be replaced with ''.
|
||||
@@ -443,16 +442,16 @@ value_to_sql(X) -> sqlite3_lib:value_to_sql(X).
|
||||
init(Options) ->
|
||||
Dbase = proplists:get_value(db, Options),
|
||||
{?MODULE, _, FileName} = code:get_object_code(?MODULE),
|
||||
SearchDir = filename:dirname(FileName),
|
||||
SearchDir = filename:join(filename:dirname(FileName), "../priv"),
|
||||
case erl_ddll:load(SearchDir, atom_to_list(?DRIVER_NAME)) of
|
||||
ok ->
|
||||
ok ->
|
||||
Port = open_port({spawn, string:join([atom_to_list(?DRIVER_NAME), Dbase], " ")}, [binary]),
|
||||
{ok, #state{port = Port, ops = Options}};
|
||||
{error, Error} ->
|
||||
Msg = io_lib:format("Error loading ~p: ~p", [?DRIVER_NAME, erl_ddll:format_error(Error)]),
|
||||
{stop, lists:flatten(Msg)}
|
||||
end.
|
||||
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% @spec handle_call(Request, From, State) -> {reply, Reply, State} |
|
||||
%% {reply, Reply, State, Timeout} |
|
||||
@@ -603,15 +602,15 @@ create_cmd(Dbase) ->
|
||||
|
||||
wait_result(Port) ->
|
||||
receive
|
||||
{Port, Reply} ->
|
||||
{Port, Reply} ->
|
||||
% io:format("Reply: ~p~n", [Reply]),
|
||||
Reply;
|
||||
{error, Reason} ->
|
||||
io:format("Error: ~p~n", [Reason]),
|
||||
{error, Reason};
|
||||
_Else ->
|
||||
io:format("Else: ~p~n", [_Else]),
|
||||
_Else
|
||||
Reply;
|
||||
{error, Reason} ->
|
||||
io:format("Error: ~p~n", [Reason]),
|
||||
{error, Reason};
|
||||
_Else ->
|
||||
io:format("Else: ~p~n", [_Else]),
|
||||
_Else
|
||||
end.
|
||||
|
||||
exec(_Port, {create_function, _FunctionName, _Function}) ->
|
||||
@@ -627,10 +626,10 @@ exec(Port, {sql_exec, Cmd}) ->
|
||||
|
||||
parse_table_info(Info) ->
|
||||
[_, Tail] = string:tokens(Info, "()"),
|
||||
Cols = string:tokens(Tail, ","),
|
||||
Cols = string:tokens(Tail, ","),
|
||||
build_table_info(lists:map(fun(X) ->
|
||||
string:tokens(X, " ")
|
||||
end, Cols), []).
|
||||
string:tokens(X, " ")
|
||||
end, Cols), []).
|
||||
|
||||
build_table_info([], Acc) ->
|
||||
lists:reverse(Acc);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : sqlite3_test.erl
|
||||
%%% Author : Tee Teoh <tteoh@teemac.ott.cti.com>
|
||||
%%% Description :
|
||||
%%% Description :
|
||||
%%%
|
||||
%%% Created : 10 Jun 2008 by Tee Teoh <tteoh@teemac.ott.cti.com>
|
||||
%%%-------------------------------------------------------------------
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% File : sqlite_test_SUITE.erl
|
||||
%%% Author : Tee Teoh <tteoh@teemac.ott.cti.com>
|
||||
%%% Description :
|
||||
%%%
|
||||
%%% Created : 4 Sep 2008 by Tee Teoh <tteoh@teemac.ott.cti.com>
|
||||
%%%-------------------------------------------------------------------
|
||||
-module(sqlite_test_SUITE).
|
||||
|
||||
%% Note: This directive should only be used in test suites.
|
||||
-compile(export_all).
|
||||
|
||||
-include("ct.hrl").
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% COMMON TEST CALLBACK FUNCTIONS
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: suite() -> Info
|
||||
%%
|
||||
%% Info = [tuple()]
|
||||
%% List of key/value pairs.
|
||||
%%
|
||||
%% Description: Returns list of tuples to set default properties
|
||||
%% for the suite.
|
||||
%%
|
||||
%% Note: The suite/0 function is only meant to be used to return
|
||||
%% default data values, not perform any other operations.
|
||||
%%--------------------------------------------------------------------
|
||||
suite() ->
|
||||
[{timetrap,{minutes,10}}].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: init_per_suite(Config0) ->
|
||||
%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
|
||||
%%
|
||||
%% Config0 = Config1 = [tuple()]
|
||||
%% A list of key/value pairs, holding the test case configuration.
|
||||
%% Reason = term()
|
||||
%% The reason for skipping the suite.
|
||||
%%
|
||||
%% Description: Initialization before the suite.
|
||||
%%
|
||||
%% Note: This function is free to add any key/value pairs to the Config
|
||||
%% variable, but should NOT alter/remove any existing entries.
|
||||
%%--------------------------------------------------------------------
|
||||
init_per_suite(Config) ->
|
||||
%%[{dbase, userct} | Config].
|
||||
Config.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: end_per_suite(Config0) -> void() | {save_config,Config1}
|
||||
%%
|
||||
%% Config0 = Config1 = [tuple()]
|
||||
%% A list of key/value pairs, holding the test case configuration.
|
||||
%%
|
||||
%% Description: Cleanup after the suite.
|
||||
%%--------------------------------------------------------------------
|
||||
end_per_suite(Config) ->
|
||||
ok.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: init_per_testcase(TestCase, Config0) ->
|
||||
%% Config1 | {skip,Reason} | {skip_and_save,Reason,Config1}
|
||||
%%
|
||||
%% TestCase = atom()
|
||||
%% Name of the test case that is about to run.
|
||||
%% Config0 = Config1 = [tuple()]
|
||||
%% A list of key/value pairs, holding the test case configuration.
|
||||
%% Reason = term()
|
||||
%% The reason for skipping the test case.
|
||||
%%
|
||||
%% Description: Initialization before each test case.
|
||||
%%
|
||||
%% Note: This function is free to add any key/value pairs to the Config
|
||||
%% variable, but should NOT alter/remove any existing entries.
|
||||
%%--------------------------------------------------------------------
|
||||
init_per_testcase(TestCase, Config) ->
|
||||
sqlite3:open(TestCase),
|
||||
[{db, TestCase} | Config].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: end_per_testcase(TestCase, Config0) ->
|
||||
%% void() | {save_config,Config1}
|
||||
%%
|
||||
%% TestCase = atom()
|
||||
%% Name of the test case that is finished.
|
||||
%% Config0 = Config1 = [tuple()]
|
||||
%% A list of key/value pairs, holding the test case configuration.
|
||||
%%
|
||||
%% Description: Cleanup after each test case.
|
||||
%%--------------------------------------------------------------------
|
||||
end_per_testcase(TestCase, _Config) ->
|
||||
sqlite3:close(TestCase),
|
||||
ok.
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: sequences() -> Sequences
|
||||
%%
|
||||
%% Sequences = [{SeqName,TestCases}]
|
||||
%% SeqName = atom()
|
||||
%% Name of a sequence.
|
||||
%% TestCases = [atom()]
|
||||
%% List of test cases that are part of the sequence
|
||||
%%
|
||||
%% Description: Specifies test case sequences.
|
||||
%%--------------------------------------------------------------------
|
||||
sequences() ->
|
||||
[].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: all() -> TestCases | {skip,Reason}
|
||||
%%
|
||||
%% TestCases = [TestCase | {sequence,SeqName}]
|
||||
%% TestCase = atom()
|
||||
%% Name of a test case.
|
||||
%% SeqName = atom()
|
||||
%% Name of a test case sequence.
|
||||
%% Reason = term()
|
||||
%% The reason for skipping all test cases.
|
||||
%%
|
||||
%% Description: Returns the list of test cases that are to be executed.
|
||||
%%--------------------------------------------------------------------
|
||||
all() ->
|
||||
[create_table].
|
||||
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% TEST CASES
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: TestCase() -> Info
|
||||
%%
|
||||
%% Info = [tuple()]
|
||||
%% List of key/value pairs.
|
||||
%%
|
||||
%% Description: Test case info function - returns list of tuples to set
|
||||
%% properties for the test case.
|
||||
%%
|
||||
%% Note: This function is only meant to be used to return a list of
|
||||
%% values, not perform any other operations.
|
||||
%%--------------------------------------------------------------------
|
||||
create_table() ->
|
||||
[].
|
||||
|
||||
%%--------------------------------------------------------------------
|
||||
%% Function: TestCase(Config0) ->
|
||||
%% ok | exit() | {skip,Reason} | {comment,Comment} |
|
||||
%% {save_config,Config1} | {skip_and_save,Reason,Config1}
|
||||
%%
|
||||
%% Config0 = Config1 = [tuple()]
|
||||
%% A list of key/value pairs, holding the test case configuration.
|
||||
%% Reason = term()
|
||||
%% The reason for skipping the test case.
|
||||
%% Comment = term()
|
||||
%% A comment about the test case that will be printed in the html log.
|
||||
%%
|
||||
%% Description: Test case function. (The name of it must be specified in
|
||||
%% the all/0 list for the test case to be executed).
|
||||
%%--------------------------------------------------------------------
|
||||
create_table(Config) ->
|
||||
Dbase = proplists:get_value(db, Config),
|
||||
sqlite3:open(Dbase),
|
||||
sqlite3:create_table(Dbase, user, [{name, text}, {age, integer}, {wage, integer}]),
|
||||
[user] = sqlite3:list_tables(Dbase),
|
||||
[{name, primary_key}, {age, integer}, {wage, integer}] = sqlite3:table_info(Dbase, user),
|
||||
sqlite3:write(Dbase, user, [{name, "abby"}, {age, 20}, {wage, 2000}]),
|
||||
sqlite3:write(Dbase, user, [{name, "marge"}, {age, 30}, {wage, 3000}]),
|
||||
[{columns, Columns}, {rows, Rows}] = sqlite3:sql_exec(Dbase, "select * from user;"),
|
||||
Columns = ["name","age","wage"],
|
||||
Rows = [{<<"abby">>,20,2000}, {<<"marge">>,30,3000}],
|
||||
[{columns, Columns}, {rows, RowsAbby}] = sqlite3:read(Dbase, user, {name, "abby"}),
|
||||
RowsAbby = [{<<"abby">>,20,2000}],
|
||||
sqlite3:delete(Dbase, user, {name, "abby"}),
|
||||
sqlite3:drop_table(Dbase, user),
|
||||
ok.
|
||||
Reference in New Issue
Block a user