a
554325746@qq.com
2019-12-25 84e391f79e4c298e31b990667a54d991d645949f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
%% @author Maas-Maarten Zeeman <mmzeeman@xs4all.nl>
%% @copyright 2011 - 2017 Maas-Maarten Zeeman
 
%% @doc Low level erlang API for sqlite3 databases
 
%% Copyright 2011 - 2017 Maas-Maarten Zeeman
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%%     http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
 
-module(esqlite3_nif).
-author("Maas-Maarten Zeeman <mmzeeman@xs4all.nl>").
 
%% low-level exports
-export([start/0,
         open/4,
         set_update_hook/4,
         exec/4,
         changes/3,
         insert/4,
         get_autocommit/3,
         prepare/4,
         multi_step/5,
         reset/4,
         finalize/4,
         bind/5,
         column_names/4,
         column_types/4,
         close/3
        ]).
 
-on_load(init/0).
 
init() ->
    NifName = "esqlite3_nif",
    NifFileName = case code:priv_dir(esqlite) of
                      {error, bad_name} -> filename:join("priv", NifName);
                      Dir -> filename:join(Dir, NifName)
                  end,
    ok = erlang:load_nif(NifFileName, 0).
 
%% @doc Start a low level thread which will can handle sqlite3 calls.
%%
%% @spec start() -> {ok, connection()} | {error, msg()}
start() ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc Open the specified sqlite3 database.
%%
%% Sends an asynchronous open command over the connection and returns
%% ok immediately. When the database is opened
%%
%%  @spec open(connection(), reference(), pid(), string()) -> ok | {error, message()}
 
open(_Db, _Ref, _Dest, _Filename) ->
    erlang:nif_error(nif_library_not_loaded).
 
set_update_hook(_Db, _Ref, _Dest, _Pid) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc Exec the query.
%%
%% Sends an asynchronous exec command over the connection and returns
%% ok immediately.
%%
%% When the statement is executed Dest will receive message {Ref, answer()}
%% with answer() integer | {error, reason()}
%%
%%  @spec exec(connection(), Ref::reference(), Dest::pid(), string()) -> ok | {error, message()}
exec(_Db, _Ref, _Dest, _Sql) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc Get the number of affected rows of last statement
%%
%% When the statement is executed Dest will receive message {Ref, answer()}
%% with answer() integer | {error, reason()}
%%
changes(_Db, _Ref, _Dest) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc
%%
%% @spec prepare(connection(), reference(), pid(), string()) -> ok | {error, message()}
prepare(_Db, _Ref, _Dest, _Sql) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc
%%
%% @spec multi_step(statement(), pos_integer(), reference(), pid()) -> {term(), list(tuple)} | {error, message()}
multi_step(_Db, _Stmt, _Chunk_Size, _Ref, _Dest) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc
%%
%% @spec reset(statement(), reference(), pid()) -> ok | {error, message()}
reset(_Db, _Stmt, _Ref, _Dest) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc
%%
%%
finalize(_Db, _Stmt, _Ref, _Dest) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc Bind parameters to a prepared statement.
%%
%% @spec bind(connection(), statement(), reference(), pid(), []) -> ok | {error, message()}
bind(_Db, _Stmt, _Ref, _Dest, _Args) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc Retrieve the column names of the prepared statement
%%
%% @spec column_names(connection(), statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
column_names(_Db, _Stmt, _Ref, _Dest) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc Retrieve the column types of the prepared statement
%%
%% @spec column_types(connection(), statement(), reference(), pid()) -> {ok, tuple()} | {error, message()}
column_types(_Db, _Stmt, _Ref, _Dest) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc Close the connection.
%%
%% @spec close(connection(), reference(), pid()) -> ok | {error, message()}
close(_Db, _Ref, _Dest) ->
    erlang:nif_error(nif_library_not_loaded).
 
 
%% @doc Insert record
%%
%% @spec insert(connection(), Ref::reference(), Dest::pid(), string()) -> {ok, integer()} | {error, message()}
insert(_Db, _Ref, _Dest, _Sql) ->
    erlang:nif_error(nif_library_not_loaded).
 
%% @doc Get automcommit
%%
%% @spec get_autocommit(connection(), Ref::reference(), Dest::pid()) -> true | false
get_autocommit(_Db, _Ref, _Dest) ->
    erlang:nif_error(nif_library_not_loaded).