Mercurial > forge
diff main/database/src/pq_lo.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 | 9cb56e0cd09b |
children | 52ca082757c2 |
line wrap: on
line diff
--- a/main/database/src/pq_lo.cc Fri Feb 26 15:07:46 2016 +0000 +++ b/main/database/src/pq_lo.cc Sat Feb 27 11:11:04 2016 +0000 @@ -24,6 +24,7 @@ #include <stdio.h> #include "command.h" +#include "error-helpers.h" #include <libpq/libpq-fs.h> // PKG_ADD: autoload ("pq_lo_import", "pq_interface.oct"); @@ -128,7 +129,7 @@ if (nb) return; if (pclose (fp) == -1) - error ("error closing pipe"); + c_verror ("error closing pipe"); fp = NULL; @@ -145,7 +146,7 @@ if (lod != -1) { if (lo_close (conn, lod)) - error ("%s", PQerrorMessage (conn)); + c_verror ("%s", PQerrorMessage (conn)); lod = -1; } @@ -153,7 +154,7 @@ if (oid && ! oid_valid) { if (lo_unlink (conn, oid) == -1) - error ("error unlinking new large object with oid %i", oid); + c_verror ("error unlinking new large object with oid %i", oid); } else oid = 0; @@ -161,7 +162,7 @@ if (fp) { if (pclose (fp) == -1) - error ("error closing pipe"); + c_verror ("error closing pipe"); fp = NULL; } @@ -179,7 +180,7 @@ c.process_single_result (); if (! c.good ()) - error ("pq_lo_import: could not commit"); + c_verror ("%s: could not commit", caller.c_str ()); } } @@ -269,7 +270,7 @@ if (pnb) return; if (pclose (fp) == -1) - error ("error closing pipe"); + c_verror ("error closing pipe"); fp = NULL; @@ -286,7 +287,7 @@ if (lod != -1) { if (lo_close (conn, lod)) - error ("%s", PQerrorMessage (conn)); + c_verror ("%s", PQerrorMessage (conn)); lod = -1; } @@ -294,7 +295,7 @@ if (fp) { if (pclose (fp) == -1) - error ("error closing pipe"); + c_verror ("error closing pipe"); fp = NULL; } @@ -312,7 +313,7 @@ c.process_single_result (); if (! c.good ()) - error ("pq_lo_export: could not commit"); + c_verror ("%s: could not commit", caller.c_str ()); } } @@ -334,15 +335,10 @@ return retval; } - std::string path (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 path; + CHECK_ERROR (path = args(1).string_value (), retval, + "%s: second argument can not be converted to a string", + fname.c_str ()); bool from_pipe = false; unsigned int l = path.size (); @@ -389,17 +385,15 @@ case PQTRANS_INERROR: error ("%s: can't manipulate large objects within a failed transaction block", fname.c_str ()); - break; + return retval; case PQTRANS_UNKNOWN: error ("%s: connection is bad", fname.c_str ()); - break; + return retval; default: // includes PQTRANS_ACTIVE error ("%s: unexpected connection state", fname.c_str ()); + return retval; } - if (error_state) - return retval; - if (make_tblock) { std::string cmd ("begin;"); @@ -459,13 +453,17 @@ } if (import_error) - error ("%s: large object import failed: %s", fname.c_str (), msg.c_str ()); + c_verror ("%s: large object import failed: %s", + fname.c_str (), msg.c_str ()); if (commit_error) - error ("%s: could not commit transaction", fname.c_str ()); + c_verror ("%s: could not commit transaction", fname.c_str ()); - if (error_state) - return retval; + if (import_error || commit_error) + { + error ("%s failed", fname.c_str ()); + return retval; + } retval = octave_value (octave_uint32 (oid)); @@ -491,15 +489,10 @@ return retval; } - std::string path (args(2).string_value ()); - - if (error_state) - { - error ("%s: third argument can not be converted to a string", - fname.c_str ()); - - return retval; - } + std::string path; + CHECK_ERROR (path = args(2).string_value (), retval, + "%s: third argument can not be converted to a string", + fname.c_str ()); bool to_pipe = false; if (! path.empty () && path[0] == '|') @@ -517,15 +510,10 @@ to_pipe = true; } - Oid oid = args(1).uint_value (); - - if (error_state) - { - error ("%s: second argument can not be converted to an oid", - fname.c_str ()); - - return retval; - } + Oid oid; + CHECK_ERROR (oid = args(1).uint_value (), retval, + "%s: second argument can not be converted to an oid", + fname.c_str ()); const octave_base_value& rep = (args(0).get_rep ()); @@ -551,17 +539,15 @@ case PQTRANS_INERROR: error ("%s: can't manipulate large objects within a failed transaction block", fname.c_str ()); - break; + return retval; case PQTRANS_UNKNOWN: error ("%s: connection is bad", fname.c_str ()); - break; + return retval; default: // includes PQTRANS_ACTIVE error ("%s: unexpected connection state", fname.c_str ()); + return retval; } - if (error_state) - return retval; - if (make_tblock) { std::string cmd ("begin;"); @@ -617,10 +603,14 @@ } if (export_error) - error ("%s: large object export failed: %s", fname.c_str (), msg.c_str ()); + c_verror ("%s: large object export failed: %s", + fname.c_str (), msg.c_str ()); if (commit_error) - error ("%s: could not commit transaction", fname.c_str ()); + c_verror ("%s: could not commit transaction", fname.c_str ()); + + if (export_error || commit_error) + error ("%s failed", fname.c_str ()); return retval; } @@ -644,15 +634,10 @@ return retval; } - Oid oid = args(1).uint_value (); - - if (error_state) - { - error ("%s: second argument can not be converted to an oid", - fname.c_str ()); - - return retval; - } + Oid oid; + CHECK_ERROR (oid = args(1).uint_value (), retval, + "%s: second argument can not be converted to an oid", + fname.c_str ()); const octave_base_value& rep = (args(0).get_rep ()); @@ -678,17 +663,15 @@ case PQTRANS_INERROR: error ("%s: can't manipulate large objects within a failed transaction block", fname.c_str ()); - break; + return retval; case PQTRANS_UNKNOWN: error ("%s: connection is bad", fname.c_str ()); - break; + return retval; default: // includes PQTRANS_ACTIVE error ("%s: unexpected connection state", fname.c_str ()); + return retval; } - if (error_state) - return retval; - if (make_tblock) { std::string cmd ("begin;"); @@ -734,10 +717,14 @@ } if (unlink_error) - error ("%s: large object unlink failed: %s", fname.c_str (), msg.c_str ()); + c_verror ("%s: large object unlink failed: %s", + fname.c_str (), msg.c_str ()); if (commit_error) - error ("%s: could not commit transaction", fname.c_str ()); + c_verror ("%s: could not commit transaction", fname.c_str ()); + + if (unlink_error || commit_error) + error ("%s failed", fname.c_str ()); return retval; }