Mercurial > forge
comparison main/database/src/converters_arr_comp.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 | 2257648e8ce1 |
children | 52ca082757c2 |
comparison
equal
deleted
inserted
replaced
12717:87989220360f | 12718:1af86934c14e |
---|---|
24 | 24 |
25 #include <stdint.h> | 25 #include <stdint.h> |
26 | 26 |
27 #include "converters.h" | 27 #include "converters.h" |
28 #include "pq_connection.h" | 28 #include "pq_connection.h" |
29 #include "error-helpers.h" | |
29 | 30 |
30 #define ERROR_RETURN_NO_PG_TYPE \ | 31 #define ERROR_RETURN_NO_PG_TYPE \ |
31 { \ | 32 { \ |
32 error ("could not determine postgresql type for Octave parameter"); \ | 33 c_verror ("could not determine postgresql type for Octave parameter"); \ |
33 return NULL; \ | 34 return NULL; \ |
34 } | 35 } |
35 | 36 |
36 oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection_rep &conn, | 37 oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection_rep &conn, |
37 std::string &name, | 38 std::string &name, |
53 | 54 |
54 oct_pq_name_conv_map_t::const_iterator iter; | 55 oct_pq_name_conv_map_t::const_iterator iter; |
55 | 56 |
56 if ((iter = conn.name_conv_map.find (name.c_str ())) == | 57 if ((iter = conn.name_conv_map.find (name.c_str ())) == |
57 conn.name_conv_map.end ()) | 58 conn.name_conv_map.end ()) |
58 error ("no converter found for type %s", | 59 { |
59 name.c_str ()); | 60 c_verror ("no converter found for type %s", |
61 name.c_str ()); | |
62 return NULL; | |
63 } | |
60 else | 64 else |
61 { | 65 { |
62 // printf ("(looked up in name map) "); | 66 // printf ("(looked up in name map) "); |
63 | 67 |
64 conv = iter->second.get_copy (); | 68 conv = iter->second.get_copy (); |
65 | 69 |
66 if (oct_type == array && ! conv->aoid) | 70 if (oct_type == array && ! conv->aoid) |
67 { | 71 { |
68 error ("%s: internal error, type %s, specified as array, has no array type in system catalog", name.c_str ()); | 72 c_verror ("%s: internal error, type %s, specified as array, has no array type in system catalog", name.c_str ()); |
69 return conv; | 73 return NULL; |
70 } | 74 } |
71 | 75 |
72 if (! (oct_type == array) && conv->is_composite) | 76 if (! (oct_type == array) && conv->is_composite) |
73 { | 77 { |
74 oct_type = composite; | 78 oct_type = composite; |
91 | 95 |
92 oct_pq_conv_map_t::const_iterator iter; | 96 oct_pq_conv_map_t::const_iterator iter; |
93 | 97 |
94 if ((iter = conn.conv_map.find (oid)) == conn.conv_map.end ()) | 98 if ((iter = conn.conv_map.find (oid)) == conn.conv_map.end ()) |
95 { | 99 { |
96 error ("no converter found for element oid %u", oid); | 100 c_verror ("no converter found for element oid %u", oid); |
97 return conv; | 101 return NULL; |
98 } | 102 } |
99 conv = iter->second.get_copy (); | 103 conv = iter->second.get_copy (); |
100 // printf ("(looked up %s in oid map) ", conv->name.c_str ()); | 104 // printf ("(looked up %s in oid map) ", conv->name.c_str ()); |
101 | 105 |
102 if (conv->aoid == oid) | 106 if (conv->aoid == oid) |
271 | 275 |
272 int from_octave_bin_array (const octave_pq_connection_rep &conn, | 276 int from_octave_bin_array (const octave_pq_connection_rep &conn, |
273 const octave_value &oct_arr, | 277 const octave_value &oct_arr, |
274 oct_pq_dynvec_t &val, oct_pq_conv_t *conv) | 278 oct_pq_dynvec_t &val, oct_pq_conv_t *conv) |
275 { | 279 { |
276 octave_scalar_map m = oct_arr.scalar_map_value (); | 280 octave_scalar_map m; |
277 if (error_state) | 281 bool err; |
278 { | 282 SET_ERR (m= oct_arr.scalar_map_value (), err); |
279 error ("Postgresql array parameter no Octave structure"); | 283 if (err) |
284 { | |
285 c_verror ("Postgresql array parameter no Octave structure"); | |
280 return 1; | 286 return 1; |
281 } | 287 } |
282 | 288 |
283 if (! m.isfield ("ndims") || ! m.isfield ("data")) | 289 if (! m.isfield ("ndims") || ! m.isfield ("data")) |
284 { | 290 { |
285 error ("field 'ndims' or 'data' missing in parameter for Postgresql array"); | 291 c_verror ("field 'ndims' or 'data' missing in parameter for Postgresql array"); |
286 return 1; | 292 return 1; |
287 } | 293 } |
288 | 294 |
289 octave_idx_type nd_pq = m.contents ("ndims").int_value (); | 295 octave_idx_type nd_pq; |
290 Cell arr = m.contents ("data").cell_value (); | 296 SET_ERR (nd_pq = m.contents ("ndims").int_value (), err); |
291 if (error_state || nd_pq < 0) | 297 |
292 { | 298 Cell arr; |
293 error ("'ndims' and 'data' could not be converted to non-negative integer and cell-array in parameter for Postgresql array"); | 299 if (! err) |
300 { | |
301 SET_ERR (arr = m.contents ("data").cell_value (), err); | |
302 } | |
303 if (err || nd_pq < 0) | |
304 { | |
305 c_verror ("'ndims' and 'data' could not be converted to non-negative integer and cell-array in parameter for Postgresql array"); | |
294 return 1; | 306 return 1; |
295 } | 307 } |
296 | 308 |
297 RowVector lb; | 309 RowVector lb; |
298 | 310 |
299 // Are lbounds given? | 311 // Are lbounds given? |
300 if (m.isfield ("lbounds")) | 312 if (m.isfield ("lbounds")) |
301 { | 313 { |
302 lb = m.contents ("lbounds").row_vector_value (); | 314 SET_ERR (lb = m.contents ("lbounds").row_vector_value (), err); |
303 if (error_state) | 315 if (err) |
304 { | 316 { |
305 error ("could not convert given enumeration bases for array to row vector"); | 317 c_verror ("could not convert given enumeration bases for array to row vector"); |
306 return 1; | 318 return 1; |
307 } | 319 } |
308 } | 320 } |
309 | 321 |
310 octave_idx_type nl = arr.numel (); | 322 octave_idx_type nl = arr.numel (); |
317 nd_oct = 1; | 329 nd_oct = 1; |
318 | 330 |
319 // check dimensions | 331 // check dimensions |
320 if (nd_oct > nd_pq) | 332 if (nd_oct > nd_pq) |
321 { | 333 { |
322 error ("given representation of postgresql array has more dimensions than specified"); | 334 c_verror ("given representation of postgresql array has more dimensions than specified"); |
323 return 1; | 335 return 1; |
324 } | 336 } |
325 | 337 |
326 // check lbounds | 338 // check lbounds |
327 if (nd_pq > 0 && lb.is_empty ()) | 339 if (nd_pq > 0 && lb.is_empty ()) |
328 lb.resize (nd_pq, 1); // fill with 1 | 340 lb.resize (nd_pq, 1); // fill with 1 |
329 else if (lb.length () != nd_pq) | 341 else if (lb.numel () != nd_pq) |
330 { | 342 { |
331 error ("number of specified enumeration bases for array does not match specified number of dimensions"); | 343 c_verror ("number of specified enumeration bases for array does not match specified number of dimensions"); |
332 return 1; | 344 return 1; |
333 } | 345 } |
334 | 346 |
335 // ndim | 347 // ndim |
336 OCT_PQ_PUT(val, int32_t, htobe32 ((int32_t) nd_pq)) | 348 OCT_PQ_PUT(val, int32_t, htobe32 ((int32_t) nd_pq)) |
380 int from_octave_bin_composite (const octave_pq_connection_rep &conn, | 392 int from_octave_bin_composite (const octave_pq_connection_rep &conn, |
381 const octave_value &oct_comp, | 393 const octave_value &oct_comp, |
382 oct_pq_dynvec_t &val, | 394 oct_pq_dynvec_t &val, |
383 oct_pq_conv_t *conv) | 395 oct_pq_conv_t *conv) |
384 { | 396 { |
385 Cell rec (oct_comp.cell_value ()); | 397 Cell rec; |
386 if (error_state) | 398 bool err; |
387 { | 399 SET_ERR (rec = oct_comp.cell_value (), err); |
388 error ("Octaves representation of a composite type could not be converted to cell-array"); | 400 if (err) |
401 { | |
402 c_verror ("Octaves representation of a composite type could not be converted to cell-array"); | |
389 return 1; | 403 return 1; |
390 } | 404 } |
391 | 405 |
392 octave_idx_type nl = rec.numel (); | 406 octave_idx_type nl = rec.numel (); |
393 | 407 |
394 if (size_t (nl) != conv->el_oids.size ()) | 408 if (size_t (nl) != conv->el_oids.size ()) |
395 { | 409 { |
396 error ("Octaves representation of a composite type has incorrect number of elements (%i, should have %i)", | 410 c_verror ("Octaves representation of a composite type has incorrect number of elements (%i, should have %i)", |
397 nl, conv->el_oids.size ()); | 411 nl, conv->el_oids.size ()); |
398 | 412 |
399 return 1; | 413 return 1; |
400 } | 414 } |
401 | 415 |
440 return 1; | 454 return 1; |
441 break; | 455 break; |
442 | 456 |
443 default: | 457 default: |
444 // should not get here | 458 // should not get here |
445 error ("internal error, undefined type identifier"); | 459 c_verror ("internal error, undefined type identifier"); |
446 return 1; | 460 return 1; |
447 } | 461 } |
448 | 462 |
449 OCT_PQ_FILL_UINT32_PLACEHOLDER(val, temp_pos) | 463 OCT_PQ_FILL_UINT32_PLACEHOLDER(val, temp_pos) |
450 } | 464 } |
456 int from_octave_str_array (const octave_pq_connection_rep &conn, | 470 int from_octave_str_array (const octave_pq_connection_rep &conn, |
457 const octave_value &oct_arr, | 471 const octave_value &oct_arr, |
458 oct_pq_dynvec_t &val, octave_value &type) | 472 oct_pq_dynvec_t &val, octave_value &type) |
459 { | 473 { |
460 // not implemented | 474 // not implemented |
461 error ("not implemented"); | 475 c_verror ("not implemented"); |
462 return 1; | 476 return 1; |
463 | 477 |
464 return 0; | 478 return 0; |
465 } | 479 } |
466 | 480 |
468 const octave_value &oct_comp, | 482 const octave_value &oct_comp, |
469 oct_pq_dynvec_t &val, | 483 oct_pq_dynvec_t &val, |
470 octave_value &type) | 484 octave_value &type) |
471 { | 485 { |
472 // not implemented | 486 // not implemented |
473 error ("not implemented"); | 487 c_verror ("not implemented"); |
474 return 1; | 488 return 1; |
475 | 489 |
476 return 0; | 490 return 0; |
477 } | 491 } |
478 | 492 |
494 OCT_PQ_DECL_GET_INT32(oid, p, uint32_t) | 508 OCT_PQ_DECL_GET_INT32(oid, p, uint32_t) |
495 | 509 |
496 // check element OID | 510 // check element OID |
497 if (oid != conv->oid) | 511 if (oid != conv->oid) |
498 { | 512 { |
499 error ("element oid %i sent by server does not match element oid %i expected for array with oid %i", | 513 c_verror ("element oid %i sent by server does not match element oid %i expected for array with oid %i", |
500 oid, conv->oid, conv->aoid); | 514 oid, conv->oid, conv->aoid); |
501 return 1; | 515 return 1; |
502 } | 516 } |
503 | 517 |
504 // dims, lbounds | 518 // dims, lbounds |
611 return 1; | 625 return 1; |
612 break; | 626 break; |
613 | 627 |
614 default: | 628 default: |
615 // should not get here | 629 // should not get here |
616 error ("internal error, undefined type identifier"); | 630 c_verror ("internal error, undefined type identifier"); |
617 return 1; | 631 return 1; |
618 } | 632 } |
619 | 633 |
620 p += nb_el; | 634 p += nb_el; |
621 | 635 |
632 int to_octave_str_array (const octave_pq_connection_rep &conn, | 646 int to_octave_str_array (const octave_pq_connection_rep &conn, |
633 const char *v, octave_value &ov, int nb, | 647 const char *v, octave_value &ov, int nb, |
634 oct_pq_conv_t *conv) | 648 oct_pq_conv_t *conv) |
635 { | 649 { |
636 // not implemented | 650 // not implemented |
637 error ("not implemented"); | 651 c_verror ("not implemented"); |
638 return 1; | 652 return 1; |
639 | 653 |
640 return 0; | 654 return 0; |
641 } | 655 } |
642 | 656 |
643 int to_octave_str_composite (const octave_pq_connection_rep &conn, | 657 int to_octave_str_composite (const octave_pq_connection_rep &conn, |
644 const char *v, octave_value &ov, int nb, | 658 const char *v, octave_value &ov, int nb, |
645 oct_pq_conv_t *conv) | 659 oct_pq_conv_t *conv) |
646 { | 660 { |
647 // not implemented | 661 // not implemented |
648 error ("not implemented"); | 662 c_verror ("not implemented"); |
649 return 1; | 663 return 1; |
650 | 664 |
651 return 0; | 665 return 0; |
652 } | 666 } |