Mercurial > forge
comparison main/database/src/pq_exec.cc @ 12718:1af86934c14e octave-forge
Make compatible with Octaves new exception-based error handling.
Retain compatibility with Octaves old error handling based on
error_state.
* src/error_helpers.[h,cc]: Added.
* src/Makefile.in: Integrate error-helpers.[h,cc].
* src/config.h.in: Added.
* configure.ac, src/config.h.in: Test presence of 'error_state' and
presence of 'verror (octave_execution_exception&, const char *,
va_list)'.
* src/__pq_connect__.cc, src/command.cc, src/command.h,
src/converters.cc, src/converters_arr_comp.cc, src/pq_connection.cc,
src/pq_conninfo.cc, src/pq_exec.cc, src/pq_lo.cc,
src/pq_update_types.cc: If necessary, include error-helpers.h, replace
error() with c_verror(), set and check a different error indicator
than error_state, use CHECK_ERROR or SET_ERR, explicitely check for
errors instead of relying on Octave checking error_state when
returning to the prompt.
author | i7tiol |
---|---|
date | Sat, 27 Feb 2016 11:11:04 +0000 |
parents | 393b940d7ee2 |
children | 52ca082757c2 |
comparison
equal
deleted
inserted
replaced
12717:87989220360f | 12718:1af86934c14e |
---|---|
21 #include <octave/parse.h> | 21 #include <octave/parse.h> |
22 #include <octave/ov-struct.h> | 22 #include <octave/ov-struct.h> |
23 #include <octave/Cell.h> | 23 #include <octave/Cell.h> |
24 | 24 |
25 #include "command.h" | 25 #include "command.h" |
26 #include "error-helpers.h" | |
26 | 27 |
27 // PKG_disabled_ADD: autoload ("pq_exec", "pq_interface.oct"); | 28 // PKG_disabled_ADD: autoload ("pq_exec", "pq_interface.oct"); |
28 // PKG_disabled_DEL: autoload ("pq_exec", "pq_interface.oct", "remove"); | 29 // PKG_disabled_DEL: autoload ("pq_exec", "pq_interface.oct", "remove"); |
29 // PKG_ADD: autoload ("__pq_exec_params__", "pq_interface.oct"); | 30 // PKG_ADD: autoload ("__pq_exec_params__", "pq_interface.oct"); |
30 // PKG_DEL: autoload ("__pq_exec_params__", "pq_interface.oct", "remove"); | 31 // PKG_DEL: autoload ("__pq_exec_params__", "pq_interface.oct", "remove"); |
120 print_usage (); | 121 print_usage (); |
121 | 122 |
122 return retval; | 123 return retval; |
123 } | 124 } |
124 | 125 |
125 std::string cmd (args(1).string_value ()); | 126 std::string cmd; |
126 | 127 CHECK_ERROR (cmd = args(1).string_value (), retval, |
127 if (error_state) | 128 "%s: second argument can not be converted to a string", |
128 { | 129 fname.c_str ()); |
129 error ("%s: second argument can not be converted to a string", fname.c_str ()); | |
130 | |
131 return retval; | |
132 } | |
133 | 130 |
134 const octave_base_value &rep = args(0).get_rep (); | 131 const octave_base_value &rep = args(0).get_rep (); |
135 | 132 |
136 const octave_pq_connection &oct_pq_conn = | 133 const octave_pq_connection &oct_pq_conn = |
137 dynamic_cast<const octave_pq_connection&> (rep); | 134 dynamic_cast<const octave_pq_connection&> (rep); |
160 | 157 |
161 Cell params; | 158 Cell params; |
162 | 159 |
163 octave_scalar_map settings; | 160 octave_scalar_map settings; |
164 | 161 |
162 bool err; | |
163 | |
165 if (nargs == 3) | 164 if (nargs == 3) |
166 { | 165 { |
167 if (args(2).is_cell ()) | 166 if (args(2).is_cell ()) |
168 params = args(2).cell_value (); | 167 { |
168 SET_ERR (params = args(2).cell_value (), err); | |
169 } | |
169 else | 170 else |
170 settings = args(2).scalar_map_value (); | 171 { |
171 | 172 SET_ERR (settings = args(2).scalar_map_value (), err); |
172 if (error_state) | 173 } |
174 | |
175 if (err) | |
173 { | 176 { |
174 error ("%s: third argument neither cell-array nor scalar structure", | 177 error ("%s: third argument neither cell-array nor scalar structure", |
175 fname.c_str ()); | 178 fname.c_str ()); |
176 | 179 |
177 return retval; | 180 return retval; |
178 } | 181 } |
179 } | 182 } |
180 else if (nargs == 4) | 183 else if (nargs == 4) |
181 { | 184 { |
182 params = args(2).cell_value (); | 185 CHECK_ERROR (params = args(2).cell_value (), retval, |
183 if (error_state) | 186 "%s: could not convert third argument to cell-array", |
184 { | 187 fname.c_str ()); |
185 error ("%s: could not convert third argument to cell-array", | 188 CHECK_ERROR (settings = args(3).scalar_map_value (), retval, |
186 fname.c_str ()); | 189 "%s: could not convert fourth argument to scalar structure"); |
187 | 190 } |
188 return retval; | 191 |
189 } | 192 int nparams = params.numel (); |
190 settings = args(3).scalar_map_value (); | |
191 if (error_state) | |
192 { | |
193 error ("%s: could not convert fourth argument to scalar structure"); | |
194 | |
195 return retval; | |
196 } | |
197 } | |
198 | |
199 int nparams = params.length (); | |
200 | 193 |
201 dim_vector pdims = params.dims (); | 194 dim_vector pdims = params.dims (); |
202 | 195 |
203 if (pdims.length () > 2 || (pdims(0) > 1 && pdims(1) > 1)) | 196 if (pdims.length () > 2 || (pdims(0) > 1 && pdims(1) > 1)) |
204 { | 197 { |
216 | 209 |
217 f_args(0) = octave_value (settings); | 210 f_args(0) = octave_value (settings); |
218 f_args(1) = octave_value ("param_types"); | 211 f_args(1) = octave_value ("param_types"); |
219 f_args(2) = octave_value (Cell (1, nparams)); | 212 f_args(2) = octave_value (Cell (1, nparams)); |
220 | 213 |
221 f_ret = feval ("getdbopts", f_args, 1); | 214 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
222 Cell ptypes = f_ret(0).cell_value (); | 215 "%s: error calling getdbopts", |
223 if (error_state) | 216 fname.c_str ()); |
224 { | 217 Cell ptypes; |
225 error ("%s: could not convert param_types to cell", | 218 CHECK_ERROR (ptypes = f_ret(0).cell_value (), retval, |
226 fname.c_str ()); | 219 "%s: could not convert param_types to cell", fname.c_str ()); |
227 | |
228 return retval; | |
229 } | |
230 | 220 |
231 f_args(1) = octave_value ("copy_in_path"); | 221 f_args(1) = octave_value ("copy_in_path"); |
232 f_args(2) = octave_value (""); | 222 f_args(2) = octave_value (""); |
233 | 223 |
234 f_ret = feval ("getdbopts", f_args, 1); | 224 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
235 std::string cin_path = f_ret(0).string_value (); | 225 "%s: error calling getdbopts", fname.c_str ()); |
236 if (error_state) | 226 std::string cin_path; |
237 { | 227 CHECK_ERROR (cin_path = f_ret(0).string_value (), retval, |
238 error ("%s: could not convert copy_in_path to string", | 228 "%s: could not convert copy_in_path to string", fname.c_str ()); |
239 fname.c_str ()); | |
240 | |
241 return retval; | |
242 } | |
243 | 229 |
244 f_args(1) = octave_value ("copy_out_path"); | 230 f_args(1) = octave_value ("copy_out_path"); |
245 f_args(2) = octave_value (""); | 231 f_args(2) = octave_value (""); |
246 | 232 |
247 f_ret = feval ("getdbopts", f_args, 1); | 233 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
248 std::string cout_path = f_ret(0).string_value (); | 234 "%s: error calling getdbopts", fname.c_str ()); |
249 if (error_state) | 235 std::string cout_path; |
250 { | 236 CHECK_ERROR (cout_path = f_ret(0).string_value (), retval, |
251 error ("%s: could not convert copy_out_path to string", | 237 "%s: could not convert copy_out_path to string", fname.c_str ()); |
252 fname.c_str ()); | |
253 | |
254 return retval; | |
255 } | |
256 | 238 |
257 f_args(1) = octave_value ("copy_in_data"); | 239 f_args(1) = octave_value ("copy_in_data"); |
258 f_args(2) = octave_value (Cell ()); | 240 f_args(2) = octave_value (Cell ()); |
259 | 241 |
260 f_ret = feval ("getdbopts", f_args, 1); | 242 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
261 Cell cin_data = f_ret(0).cell_value (); | 243 "%s: error calling getdbopts", fname.c_str ()); |
262 if (error_state) | 244 Cell cin_data; |
263 { | 245 CHECK_ERROR (cin_data = f_ret(0).cell_value (), retval, |
264 error ("%s: could not convert copy_in_data to cell", | 246 "%s: could not convert copy_in_data to cell", fname.c_str ()); |
265 fname.c_str ()); | |
266 | |
267 return retval; | |
268 } | |
269 | 247 |
270 f_args(1) = octave_value ("copy_in_with_oids"); | 248 f_args(1) = octave_value ("copy_in_with_oids"); |
271 f_args(2) = octave_value (false); | 249 f_args(2) = octave_value (false); |
272 | 250 |
273 f_ret = feval ("getdbopts", f_args, 1); | 251 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
274 bool cin_with_oids = f_ret(0).bool_value (); | 252 "%s: error calling getdbopts", fname.c_str ()); |
275 if (error_state) | 253 bool cin_with_oids; |
276 { | 254 CHECK_ERROR (cin_with_oids = f_ret(0).bool_value (), retval, |
277 error ("%s: could not convert copy_in_with_oids to bool", | 255 "%s: could not convert copy_in_with_oids to bool", |
278 fname.c_str ()); | 256 fname.c_str ()); |
279 | |
280 return retval; | |
281 } | |
282 | 257 |
283 f_args(1) = octave_value ("copy_in_types"); | 258 f_args(1) = octave_value ("copy_in_types"); |
284 f_args(2) = octave_value (Cell ()); | 259 f_args(2) = octave_value (Cell ()); |
285 | 260 |
286 f_ret = feval ("getdbopts", f_args, 1); | 261 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
287 Cell cin_types = f_ret(0).cell_value (); | 262 "%s: error calling getdbopts", fname.c_str ()); |
288 if (error_state) | 263 Cell cin_types; |
289 { | 264 CHECK_ERROR (cin_types = f_ret(0).cell_value (), retval, |
290 error ("%s: could not convert copy_in_types to cell", | 265 "%s: could not convert copy_in_types to cell", fname.c_str ()); |
291 fname.c_str ()); | |
292 | |
293 return retval; | |
294 } | |
295 | 266 |
296 f_args(1) = octave_value ("copy_in_from_variable"); | 267 f_args(1) = octave_value ("copy_in_from_variable"); |
297 f_args(2) = octave_value (false); | 268 f_args(2) = octave_value (false); |
298 | 269 |
299 f_ret = feval ("getdbopts", f_args, 1); | 270 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
300 bool cin_from_variable = f_ret(0).bool_value (); | 271 "%s: error calling getdbopts", fname.c_str ()); |
301 if (error_state) | 272 bool cin_from_variable; |
302 { | 273 CHECK_ERROR (cin_from_variable = f_ret(0).bool_value (), retval, |
303 error ("%s: could not convert copy_in_from_variable to bool", | 274 "%s: could not convert copy_in_from_variable to bool", |
304 fname.c_str ()); | 275 fname.c_str ()); |
305 | |
306 return retval; | |
307 } | |
308 | 276 |
309 // check option settings | 277 // check option settings |
310 | 278 |
311 if (ptypes.length () != nparams) | 279 if (ptypes.numel () != nparams) |
312 { | 280 { |
313 error ("%s: if given, cell-array of parameter types must have same length as cell-array of parameters", | 281 error ("%s: if given, cell-array of parameter types must have same length as cell-array of parameters", |
314 fname.c_str ()); | 282 fname.c_str ()); |
315 | 283 |
316 return retval; | 284 return retval; |
343 if (c.good ()) | 311 if (c.good ()) |
344 retval = c.process_single_result | 312 retval = c.process_single_result |
345 (cin_path, cout_path, cin_data, cin_types, cin_with_oids, | 313 (cin_path, cout_path, cin_data, cin_types, cin_with_oids, |
346 cin_from_variable); | 314 cin_from_variable); |
347 | 315 |
316 if (! c.good ()) | |
317 error ("%s: error processing result", fname.c_str ()); | |
318 | |
348 return retval; | 319 return retval; |
349 } | 320 } |