Mercurial > forge
diff 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 |
line wrap: on
line diff
--- a/main/database/src/pq_exec.cc Fri Feb 26 15:07:46 2016 +0000 +++ b/main/database/src/pq_exec.cc Sat Feb 27 11:11:04 2016 +0000 @@ -23,6 +23,7 @@ #include <octave/Cell.h> #include "command.h" +#include "error-helpers.h" // PKG_disabled_ADD: autoload ("pq_exec", "pq_interface.oct"); // PKG_disabled_DEL: autoload ("pq_exec", "pq_interface.oct", "remove"); @@ -122,14 +123,10 @@ return retval; } - std::string cmd (args(1).string_value ()); - - if (error_state) - { - error ("%s: second argument can not be converted to a string", fname.c_str ()); - - return retval; - } + std::string cmd; + CHECK_ERROR (cmd = args(1).string_value (), retval, + "%s: second argument can not be converted to a string", + fname.c_str ()); const octave_base_value &rep = args(0).get_rep (); @@ -162,14 +159,20 @@ octave_scalar_map settings; + bool err; + if (nargs == 3) { if (args(2).is_cell ()) - params = args(2).cell_value (); + { + SET_ERR (params = args(2).cell_value (), err); + } else - settings = args(2).scalar_map_value (); + { + SET_ERR (settings = args(2).scalar_map_value (), err); + } - if (error_state) + if (err) { error ("%s: third argument neither cell-array nor scalar structure", fname.c_str ()); @@ -179,24 +182,14 @@ } else if (nargs == 4) { - params = args(2).cell_value (); - if (error_state) - { - error ("%s: could not convert third argument to cell-array", - fname.c_str ()); - - return retval; - } - settings = args(3).scalar_map_value (); - if (error_state) - { - error ("%s: could not convert fourth argument to scalar structure"); - - return retval; - } + CHECK_ERROR (params = args(2).cell_value (), retval, + "%s: could not convert third argument to cell-array", + fname.c_str ()); + CHECK_ERROR (settings = args(3).scalar_map_value (), retval, + "%s: could not convert fourth argument to scalar structure"); } - int nparams = params.length (); + int nparams = params.numel (); dim_vector pdims = params.dims (); @@ -218,97 +211,72 @@ f_args(1) = octave_value ("param_types"); f_args(2) = octave_value (Cell (1, nparams)); - f_ret = feval ("getdbopts", f_args, 1); - Cell ptypes = f_ret(0).cell_value (); - if (error_state) - { - error ("%s: could not convert param_types to cell", - fname.c_str ()); - - return retval; - } + CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, + "%s: error calling getdbopts", + fname.c_str ()); + Cell ptypes; + CHECK_ERROR (ptypes = f_ret(0).cell_value (), retval, + "%s: could not convert param_types to cell", fname.c_str ()); f_args(1) = octave_value ("copy_in_path"); f_args(2) = octave_value (""); - f_ret = feval ("getdbopts", f_args, 1); - std::string cin_path = f_ret(0).string_value (); - if (error_state) - { - error ("%s: could not convert copy_in_path to string", - fname.c_str ()); - - return retval; - } + CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, + "%s: error calling getdbopts", fname.c_str ()); + std::string cin_path; + CHECK_ERROR (cin_path = f_ret(0).string_value (), retval, + "%s: could not convert copy_in_path to string", fname.c_str ()); f_args(1) = octave_value ("copy_out_path"); f_args(2) = octave_value (""); - f_ret = feval ("getdbopts", f_args, 1); - std::string cout_path = f_ret(0).string_value (); - if (error_state) - { - error ("%s: could not convert copy_out_path to string", - fname.c_str ()); - - return retval; - } + CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, + "%s: error calling getdbopts", fname.c_str ()); + std::string cout_path; + CHECK_ERROR (cout_path = f_ret(0).string_value (), retval, + "%s: could not convert copy_out_path to string", fname.c_str ()); f_args(1) = octave_value ("copy_in_data"); f_args(2) = octave_value (Cell ()); - f_ret = feval ("getdbopts", f_args, 1); - Cell cin_data = f_ret(0).cell_value (); - if (error_state) - { - error ("%s: could not convert copy_in_data to cell", - fname.c_str ()); - - return retval; - } + CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, + "%s: error calling getdbopts", fname.c_str ()); + Cell cin_data; + CHECK_ERROR (cin_data = f_ret(0).cell_value (), retval, + "%s: could not convert copy_in_data to cell", fname.c_str ()); f_args(1) = octave_value ("copy_in_with_oids"); f_args(2) = octave_value (false); - f_ret = feval ("getdbopts", f_args, 1); - bool cin_with_oids = f_ret(0).bool_value (); - if (error_state) - { - error ("%s: could not convert copy_in_with_oids to bool", - fname.c_str ()); - - return retval; - } + CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, + "%s: error calling getdbopts", fname.c_str ()); + bool cin_with_oids; + CHECK_ERROR (cin_with_oids = f_ret(0).bool_value (), retval, + "%s: could not convert copy_in_with_oids to bool", + fname.c_str ()); f_args(1) = octave_value ("copy_in_types"); f_args(2) = octave_value (Cell ()); - f_ret = feval ("getdbopts", f_args, 1); - Cell cin_types = f_ret(0).cell_value (); - if (error_state) - { - error ("%s: could not convert copy_in_types to cell", - fname.c_str ()); - - return retval; - } + CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, + "%s: error calling getdbopts", fname.c_str ()); + Cell cin_types; + CHECK_ERROR (cin_types = f_ret(0).cell_value (), retval, + "%s: could not convert copy_in_types to cell", fname.c_str ()); f_args(1) = octave_value ("copy_in_from_variable"); f_args(2) = octave_value (false); - f_ret = feval ("getdbopts", f_args, 1); - bool cin_from_variable = f_ret(0).bool_value (); - if (error_state) - { - error ("%s: could not convert copy_in_from_variable to bool", - fname.c_str ()); - - return retval; - } + CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, + "%s: error calling getdbopts", fname.c_str ()); + bool cin_from_variable; + CHECK_ERROR (cin_from_variable = f_ret(0).bool_value (), retval, + "%s: could not convert copy_in_from_variable to bool", + fname.c_str ()); // check option settings - if (ptypes.length () != nparams) + if (ptypes.numel () != nparams) { error ("%s: if given, cell-array of parameter types must have same length as cell-array of parameters", fname.c_str ()); @@ -345,5 +313,8 @@ (cin_path, cout_path, cin_data, cin_types, cin_with_oids, cin_from_variable); + if (! c.good ()) + error ("%s: error processing result", fname.c_str ()); + return retval; }