annotate main/database/src/pq_exec.cc @ 12665:393b940d7ee2 octave-forge

pq_connection.h: Call register_type() only once.
author i7tiol
date Wed, 08 Jul 2015 13:54:27 +0000
parents 9cb56e0cd09b
children 1af86934c14e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
1 /*
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
2
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
3 Copyright (C) 2012, 2013 Olaf Till <i7tiol@t-online.de>
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
4
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
8 (at your option) any later version.
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
9
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
13 GNU General Public License for more details.
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
14
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
16 along with this program; If not, see <http://www.gnu.org/licenses/>.
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
17
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
18 */
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
19
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
20 #include <octave/oct.h>
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
21 #include <octave/parse.h>
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
22 #include <octave/ov-struct.h>
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
23 #include <octave/Cell.h>
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
24
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
25 #include "command.h"
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
26
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
27 // PKG_disabled_ADD: autoload ("pq_exec", "pq_interface.oct");
12613
9cb56e0cd09b Remove autoloaded functions at package unload.
i7tiol
parents: 12612
diff changeset
28 // PKG_disabled_DEL: autoload ("pq_exec", "pq_interface.oct", "remove");
11551
7c0dae992c31 Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents: 11499
diff changeset
29 // PKG_ADD: autoload ("__pq_exec_params__", "pq_interface.oct");
12613
9cb56e0cd09b Remove autoloaded functions at package unload.
i7tiol
parents: 12612
diff changeset
30 // PKG_DEL: autoload ("__pq_exec_params__", "pq_interface.oct", "remove");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
31
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
32
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
33 #if 0
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
34
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
35 // I left this here because of its (formerly working) functionality of
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
36 // reading more than one result. But the code (and the helptext, too)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
37 // has not been adapted to general changes and is not working, and it
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
38 // would need converters for text mode to be useful. Anyway I don't
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
39 // see why one should need to execute many commands with one line,
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
40 // except if one wants to use some unchanged external SQL code. I'll
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
41 // probably wait till someone expresses such a need.
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
42
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
43 DEFUN_DLD (pq_exec, args, ,
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
44 "-*- texinfo -*-\n\
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
45 @deftypefn {Loadable Function} {@var{id}} pq_exec (@var{connection}, @var{command})\n\
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
46 @deftypefnx {Loadable Function} {@var{id}} pq_exec (@var{connection}, @var{command}, @var{copydata}, @dots{})\n\
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
47 Sends the string @var{command}, which should contain one or more SQL commands, over the connection @var{connection} and returns multiple output values, one for each command. For queries (commands potentially returning data), the output will be a structure with fields @code{data} (containing a cell array with the data) and @code{columns} (containing the column headers). For other commands, the output will be the number of affected rows in the database. For each command in @var{command} containing a @code{COPY FROM STDIN}, an additional argument @var{copydata} must be supplied which is either a cell-array with suitable data or a handle for a function which will return parts of this cell-array successively, one for each call, and @code{0} when ready.\n\
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
48 \n\
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
49 @end deftypefn")
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
50 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
51 std::string fname ("pq_exec");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
52
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
53 octave_value_list retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
54
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
55 if (args.length () < 2 || args.length () > 3 ||
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
56 args(0).type_id () != octave_pq_connection::static_type_id ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
57 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
58 print_usage ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
59
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
60 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
61 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
62
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
63 std::string cmd (args(1).string_value ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
64
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
65 if (error_state)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
66 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
67 error ("%s: second argument can not be converted to a string", fname.c_str ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
68
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
69 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
70 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
71
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
72 const octave_base_value& rep = (args(0).get_rep ());
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
73
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
74 const octave_pq_connection &oct_pq_conn =
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
75 dynamic_cast<const octave_pq_connection&> (rep);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
76
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
77 Cell rettypes; // not implemented here
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
78
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
79 command c (*(oct_pq_conn.get_rep ()), cmd, rettypes, fname);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
80
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
81 if (c.good ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
82 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
83 while (true)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
84 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
85 octave_value val;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
86
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
87 val = c.process_single_result ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
88
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
89 if (! c.good () || c.all_results_fetched ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
90 break;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
91 else
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
92 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
93 int l = retval.length ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
94
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
95 retval.resize (l + 1);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
96
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
97 retval (l) = val;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
98 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
99 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
100 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
101
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
102 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
103 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
104
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
105 #endif // code disabled
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
106
11551
7c0dae992c31 Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents: 11499
diff changeset
107 DEFUN_DLD (__pq_exec_params__, args, nargout,
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
108 "-*- texinfo -*-\n\
11551
7c0dae992c31 Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents: 11499
diff changeset
109 undifined internal function, meant to be called by @code{pq_exec_params}")
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
110 {
11551
7c0dae992c31 Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents: 11499
diff changeset
111 std::string fname ("__pq_exec_params__");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
112
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
113 octave_value retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
114
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
115 int nargs = args.length ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
116
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
117 if (nargs < 2 || nargs > 4 ||
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
118 args(0).type_id () != octave_pq_connection::static_type_id ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
119 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
120 print_usage ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
121
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
122 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
123 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
124
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
125 std::string cmd (args(1).string_value ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
126
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
127 if (error_state)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
128 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
129 error ("%s: second argument can not be converted to a string", fname.c_str ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
130
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
131 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
132 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
133
12665
393b940d7ee2 pq_connection.h: Call register_type() only once.
i7tiol
parents: 12613
diff changeset
134 const octave_base_value &rep = args(0).get_rep ();
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
135
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
136 const octave_pq_connection &oct_pq_conn =
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
137 dynamic_cast<const octave_pq_connection&> (rep);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
138
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
139
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
140 /*
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
141 printf ("oid map:\n");
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
142 for (oct_pq_conv_map_t::iterator it = oct_pq_conn.get_rep ()->conv_map.begin ();
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
143 it != oct_pq_conn.get_rep ()->conv_map.end (); it++)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
144 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
145 printf ("key: %u; ", it->first);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
146 print_conv (it->second);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
147 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
148 printf ("\n");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
149
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
150 printf ("name map:\n");
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
151 for (oct_pq_name_conv_map_t::iterator it = oct_pq_conn.get_rep ()->name_conv_map.begin ();
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
152 it != oct_pq_conn.get_rep ()->name_conv_map.end (); it++)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
153 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
154 printf ("key: %s; ", it->first);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
155 print_conv (it->second);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
156 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
157 printf ("\n");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
158 */
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
159
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
160
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
161 Cell params;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
162
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
163 octave_scalar_map settings;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
164
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
165 if (nargs == 3)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
166 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
167 if (args(2).is_cell ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
168 params = args(2).cell_value ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
169 else
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
170 settings = args(2).scalar_map_value ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
171
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
172 if (error_state)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
173 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
174 error ("%s: third argument neither cell-array nor scalar structure",
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
175 fname.c_str ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
176
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
177 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
178 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
179 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
180 else if (nargs == 4)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
181 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
182 params = args(2).cell_value ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
183 if (error_state)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
184 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
185 error ("%s: could not convert third argument to cell-array",
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
186 fname.c_str ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
187
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
188 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
189 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
190 settings = args(3).scalar_map_value ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
191 if (error_state)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
192 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
193 error ("%s: could not convert fourth argument to scalar structure");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
194
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
195 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
196 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
197 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
198
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
199 int nparams = params.length ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
200
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
201 dim_vector pdims = params.dims ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
202
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
203 if (pdims.length () > 2 || (pdims(0) > 1 && pdims(1) > 1))
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
204 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
205 error ("%s: cell-array of parameters must not be more than one-dimensional",
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
206 fname.c_str ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
207
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
208 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
209 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
210
11398
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
211 // get option settings
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
212
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
213 octave_value_list f_args (3);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
214
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
215 octave_value_list f_ret;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
216
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
217 f_args(0) = octave_value (settings);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
218 f_args(1) = octave_value ("param_types");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
219 f_args(2) = octave_value (Cell (1, nparams));
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
220
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
221 f_ret = feval ("getdbopts", f_args, 1);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
222 Cell ptypes = f_ret(0).cell_value ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
223 if (error_state)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
224 {
11484
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
225 error ("%s: could not convert param_types to cell",
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
226 fname.c_str ());
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
227
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
228 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
229 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
230
11398
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
231 f_args(1) = octave_value ("copy_in_path");
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
232 f_args(2) = octave_value ("");
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
233
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
234 f_ret = feval ("getdbopts", f_args, 1);
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
235 std::string cin_path = f_ret(0).string_value ();
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
236 if (error_state)
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
237 {
11484
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
238 error ("%s: could not convert copy_in_path to string",
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
239 fname.c_str ());
11398
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
240
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
241 return retval;
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
242 }
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
243
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
244 f_args(1) = octave_value ("copy_out_path");
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
245 f_args(2) = octave_value ("");
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
246
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
247 f_ret = feval ("getdbopts", f_args, 1);
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
248 std::string cout_path = f_ret(0).string_value ();
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
249 if (error_state)
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
250 {
11484
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
251 error ("%s: could not convert copy_out_path to string",
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
252 fname.c_str ());
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
253
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
254 return retval;
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
255 }
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
256
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
257 f_args(1) = octave_value ("copy_in_data");
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
258 f_args(2) = octave_value (Cell ());
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
259
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
260 f_ret = feval ("getdbopts", f_args, 1);
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
261 Cell cin_data = f_ret(0).cell_value ();
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
262 if (error_state)
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
263 {
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
264 error ("%s: could not convert copy_in_data to cell",
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
265 fname.c_str ());
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
266
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
267 return retval;
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
268 }
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
269
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
270 f_args(1) = octave_value ("copy_in_with_oids");
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
271 f_args(2) = octave_value (false);
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
272
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
273 f_ret = feval ("getdbopts", f_args, 1);
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
274 bool cin_with_oids = f_ret(0).bool_value ();
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
275 if (error_state)
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
276 {
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
277 error ("%s: could not convert copy_in_with_oids to bool",
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
278 fname.c_str ());
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
279
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
280 return retval;
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
281 }
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
282
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
283 f_args(1) = octave_value ("copy_in_types");
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
284 f_args(2) = octave_value (Cell ());
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
285
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
286 f_ret = feval ("getdbopts", f_args, 1);
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
287 Cell cin_types = f_ret(0).cell_value ();
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
288 if (error_state)
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
289 {
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
290 error ("%s: could not convert copy_in_types to cell",
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
291 fname.c_str ());
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
292
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
293 return retval;
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
294 }
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
295
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
296 f_args(1) = octave_value ("copy_in_from_variable");
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
297 f_args(2) = octave_value (false);
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
298
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
299 f_ret = feval ("getdbopts", f_args, 1);
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
300 bool cin_from_variable = f_ret(0).bool_value ();
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
301 if (error_state)
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
302 {
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
303 error ("%s: could not convert copy_in_from_variable to bool",
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
304 fname.c_str ());
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
305
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
306 return retval;
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
307 }
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
308
11398
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
309 // check option settings
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
310
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
311 if (ptypes.length () != nparams)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
312 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
313 error ("%s: if given, cell-array of parameter types must have same length as cell-array of parameters",
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
314 fname.c_str ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
315
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
316 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
317 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
318
11484
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
319 dim_vector cind_dv = cin_data.dims ();
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
320 if (cind_dv.length () > 2)
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
321 {
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
322 error ("%s: copy-in data must not be more than two-dimensional",
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
323 fname.c_str ());
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
324
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
325 return retval;
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
326 }
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
327
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
328 if (cin_types.is_empty ())
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
329 cin_types.resize (dim_vector (1, cind_dv(1)));
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
330 if (cin_types.numel () != cind_dv(1))
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
331 {
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
332 error ("%s: copy_in_types has wrong number of elements");
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
333
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
334 return retval;
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
335 }
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
336
11398
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
337 //
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
338
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
339 Cell rtypes;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
340
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11551
diff changeset
341 command c (*(oct_pq_conn.get_rep ()), cmd, params, ptypes, rtypes, fname);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
342
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
343 if (c.good ())
11484
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
344 retval = c.process_single_result
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11429
diff changeset
345 (cin_path, cout_path, cin_data, cin_types, cin_with_oids,
11499
1176424db5df Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents: 11484
diff changeset
346 cin_from_variable);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
347
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
348 return retval;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
349 }