-
Notifications
You must be signed in to change notification settings - Fork 0
/
sqlite3.cc
116 lines (100 loc) · 3.1 KB
/
sqlite3.cc
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
// Copyright (C) 2016 Andreas Weber <andy.weber.aw@gmail.com>
//
// This program is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free Software
// Foundation; either version 3 of the License, or (at your option) any later
// version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// this program; if not, see <http://www.gnu.org/licenses/>.
#include "cl_sqlite3_handler.h"
static bool type_loaded = false;
// PKG_ADD: autoload ("sqlite3", which ("sqlite3.oct"));
// PKG_DEL: autoload ("sqlite3", which ("sqlite3.oct"), "remove");
DEFUN_DLD(sqlite3, args, nargout,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {@var{sqlite} =} sqlite3 (@var{filename}, [@var{create}])\n\
Open database @var{filename}.\n\
@seealso{foobar}\n\
@end deftypefn")
{
octave_value_list retval;
int nargin = args.length ();
if (nargin < 1 || nargin > 2)
{
print_usage();
return retval;
}
if (!type_loaded)
{
sqlite3_handler::register_type();
type_loaded = true;
}
string fn = args(0).string_value ();
bool create = 0;
if (nargin > 1)
create = args(1).bool_value ();
if (! error_state)
{
sqlite3_handler *h = new sqlite3_handler ();
h->open (fn, create);
retval.append (octave_value (h));
}
return retval;
}
// PKG_ADD: autoload ("exec_sql", which ("sqlite3.oct"));
// PKG_DEL: autoload ("exec_sql", which ("sqlite3.oct"), "remove");
DEFUN_DLD(exec_sql, args, nargout,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {@var{result} =} exec_sql (@var{sqlite}, @var{sql}, [@var{bind}])\n\
Execute @var{SQL} on @var{SQLITE} object.\n\
\n\
@var{bind} is a Mx1 cell array with parameters which are bind to the\n\
prepared statement. It has to contain as may rows as the @var{sql} command\n\
has parameters and the size of all parameters have to be equal.\n\
@seealso{foobar}\n\
@end deftypefn")
{
octave_value_list retval;
int nargin = args.length ();
if (nargin < 2 || nargin > 3)
{
print_usage();
return retval;
}
sqlite3_handler* h = get_sqlite3_handler_from_ov (args(0));
if (h)
{
string sql = args(1).string_value ();
Cell bind;
if (nargin > 2)
bind = args(2).cell_value ();
h->exec_sql (sql, bind);
}
return retval;
}
// PKG_ADD: autoload ("testme", which ("sqlite3.oct"));
// PKG_DEL: autoload ("testme", which ("sqlite3.oct"), "remove");
DEFUN_DLD(testme, args, nargout,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} testme ()\n\
just for testing.\n\
@end deftypefn")
{
octave_value_list retval;
int nargin = args.length ();
if (nargin != 1)
{
print_usage();
return retval;
}
sqlite3_handler* h = get_sqlite3_handler_from_ov (args(0));
if (h)
h->testme ();
return retval;
}