comparison main/database/src/converters.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
31 #include <sys/socket.h> // for AF_INET, needed in network address types 31 #include <sys/socket.h> // for AF_INET, needed in network address types
32 #endif 32 #endif
33 33
34 #include "converters.h" 34 #include "converters.h"
35 #include "pq_connection.h" 35 #include "pq_connection.h"
36 #include "error-helpers.h"
36 37
37 // remember to adjust OCT_PQ_NUM_CONVERTERS in converters.h 38 // remember to adjust OCT_PQ_NUM_CONVERTERS in converters.h
38 39
39 #define PGSQL_AF_INET6 (AF_INET + 1) // defined so in postgresql, no 40 #define PGSQL_AF_INET6 (AF_INET + 1) // defined so in postgresql, no
40 // public header file available 41 // public header file available
73 } 74 }
74 75
75 int from_octave_str_bool (const octave_pq_connection_rep &conn, 76 int from_octave_str_bool (const octave_pq_connection_rep &conn,
76 const octave_value &ov, oct_pq_dynvec_t &val) 77 const octave_value &ov, oct_pq_dynvec_t &val)
77 { 78 {
78 bool b = ov.bool_value (); 79 bool b, err;
79 80 SET_ERR (b = ov.bool_value (), err);
80 if (error_state) 81
81 { 82 if (err)
82 error ("can not convert octave_value to bool value"); 83 {
84 c_verror ("can not convert octave_value to bool value");
83 return 1; 85 return 1;
84 } 86 }
85 87
86 val.push_back (b ? '1' : '0'); 88 val.push_back (b ? '1' : '0');
87 val.push_back ('\0'); 89 val.push_back ('\0');
90 } 92 }
91 93
92 int from_octave_bin_bool (const octave_pq_connection_rep &conn, 94 int from_octave_bin_bool (const octave_pq_connection_rep &conn,
93 const octave_value &ov, oct_pq_dynvec_t &val) 95 const octave_value &ov, oct_pq_dynvec_t &val)
94 { 96 {
95 bool b = ov.bool_value (); 97 bool b, err;
96 98 SET_ERR (b = ov.bool_value (), err);
97 if (error_state) 99
98 { 100 if (err)
99 error ("can not convert octave_value to bool value"); 101 {
102 c_verror ("can not convert octave_value to bool value");
100 return 1; 103 return 1;
101 } 104 }
102 105
103 val.push_back (char (b)); 106 val.push_back (char (b));
104 107
143 } 146 }
144 147
145 int from_octave_bin_oid (const octave_pq_connection_rep &conn, 148 int from_octave_bin_oid (const octave_pq_connection_rep &conn,
146 const octave_value &ov, oct_pq_dynvec_t &val) 149 const octave_value &ov, oct_pq_dynvec_t &val)
147 { 150 {
148 uint32_t oid = ov.uint_value (); 151 uint32_t oid;
149 152 bool err;
150 if (error_state) 153 SET_ERR (oid = ov.uint_value (), err);
151 { 154
152 error ("can not convert octave_value to oid value"); 155 if (err)
156 {
157 c_verror ("can not convert octave_value to oid value");
153 return 1; 158 return 1;
154 } 159 }
155 160
156 OCT_PQ_PUT(val, uint32_t, htobe32 (oid)) 161 OCT_PQ_PUT(val, uint32_t, htobe32 (oid))
157 162
216 double d; 221 double d;
217 int64_t i; 222 int64_t i;
218 } 223 }
219 swap; 224 swap;
220 225
221 swap.d = ov.double_value (); 226 bool err;
222 227 SET_ERR (swap.d = ov.double_value (), err);
223 if (error_state) 228
224 { 229 if (err)
225 error ("can not convert octave_value to float8 value"); 230 {
231 c_verror ("can not convert octave_value to float8 value");
226 return 1; 232 return 1;
227 } 233 }
228 234
229 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) 235 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i))
230 236
289 float f; 295 float f;
290 int32_t i; 296 int32_t i;
291 } 297 }
292 swap; 298 swap;
293 299
294 swap.f = ov.float_value (); 300 bool err;
295 301 SET_ERR (swap.f = ov.float_value (), err);
296 if (error_state) 302
297 { 303 if (err)
298 error ("can not convert octave_value to float4 value"); 304 {
305 c_verror ("can not convert octave_value to float4 value");
299 return 1; 306 return 1;
300 } 307 }
301 308
302 OCT_PQ_PUT(val, int32_t, htobe32 (swap.i)) 309 OCT_PQ_PUT(val, int32_t, htobe32 (swap.i))
303 310
348 } 355 }
349 356
350 int from_octave_bin_bytea (const octave_pq_connection_rep &conn, 357 int from_octave_bin_bytea (const octave_pq_connection_rep &conn,
351 const octave_value &ov, oct_pq_dynvec_t &val) 358 const octave_value &ov, oct_pq_dynvec_t &val)
352 { 359 {
353 uint8NDArray b = ov.uint8_array_value (); 360 uint8NDArray b;
354 361 bool err;
355 if (error_state) 362 SET_ERR (b = ov.uint8_array_value (), err);
356 { 363
357 error ("can not convert octave_value to bytea representation"); 364 if (err)
365 {
366 c_verror ("can not convert octave_value to bytea representation");
358 return 1; 367 return 1;
359 } 368 }
360 369
361 octave_idx_type nl = b.numel (); 370 octave_idx_type nl = b.numel ();
362 371
406 } 415 }
407 416
408 int from_octave_bin_text (const octave_pq_connection_rep &conn, 417 int from_octave_bin_text (const octave_pq_connection_rep &conn,
409 const octave_value &ov, oct_pq_dynvec_t &val) 418 const octave_value &ov, oct_pq_dynvec_t &val)
410 { 419 {
411 std::string s = ov.string_value (); 420 std::string s;
412 421 bool err;
413 if (error_state) 422 SET_ERR (s = ov.string_value (), err);
414 { 423
415 error ("can not convert octave_value to string"); 424 if (err)
425 {
426 c_verror ("can not convert octave_value to string");
416 return 1; 427 return 1;
417 } 428 }
418 429
419 octave_idx_type l = s.size (); 430 octave_idx_type l = s.size ();
420 431
513 } 524 }
514 525
515 int from_octave_bin_int2 (const octave_pq_connection_rep &conn, 526 int from_octave_bin_int2 (const octave_pq_connection_rep &conn,
516 const octave_value &ov, oct_pq_dynvec_t &val) 527 const octave_value &ov, oct_pq_dynvec_t &val)
517 { 528 {
518 int16_t i2 = ov.int_value (); 529 int16_t i2;
519 530 bool err;
520 if (error_state) 531 SET_ERR (i2 = ov.int_value (), err);
521 { 532
522 error ("can not convert octave_value to int2 value"); 533 if (err)
534 {
535 c_verror ("can not convert octave_value to int2 value");
523 return 1; 536 return 1;
524 } 537 }
525 538
526 OCT_PQ_PUT(val, int16_t, htobe16 (i2)) 539 OCT_PQ_PUT(val, int16_t, htobe16 (i2))
527 540
567 } 580 }
568 581
569 int from_octave_bin_int4 (const octave_pq_connection_rep &conn, 582 int from_octave_bin_int4 (const octave_pq_connection_rep &conn,
570 const octave_value &ov, oct_pq_dynvec_t &val) 583 const octave_value &ov, oct_pq_dynvec_t &val)
571 { 584 {
572 int32_t i4 = ov.int_value (); 585 int32_t i4;
573 586 bool err;
574 if (error_state) 587 SET_ERR (i4 = ov.int_value (), err);
575 { 588
576 error ("can not convert octave_value to int4 value"); 589 if (err)
590 {
591 c_verror ("can not convert octave_value to int4 value");
577 return 1; 592 return 1;
578 } 593 }
579 594
580 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) 595 OCT_PQ_PUT(val, int32_t, htobe32 (i4))
581 596
621 } 636 }
622 637
623 int from_octave_bin_int8 (const octave_pq_connection_rep &conn, 638 int from_octave_bin_int8 (const octave_pq_connection_rep &conn,
624 const octave_value &ov, oct_pq_dynvec_t &val) 639 const octave_value &ov, oct_pq_dynvec_t &val)
625 { 640 {
626 int64_t i8 = ov.int64_scalar_value (); 641 int64_t i8;
627 642 bool err;
628 if (error_state) 643 SET_ERR (i8 = ov.int64_scalar_value (), err);
629 { 644
630 error ("can not convert octave_value to int8 value"); 645 if (err)
646 {
647 c_verror ("can not convert octave_value to int8 value");
631 return 1; 648 return 1;
632 } 649 }
633 650
634 OCT_PQ_PUT(val, int64_t, htobe64 (i8)) 651 OCT_PQ_PUT(val, int64_t, htobe64 (i8))
635 652
700 if (int_dt) 717 if (int_dt)
701 { 718 {
702 // don't convert automatically because of possible overflow 719 // don't convert automatically because of possible overflow
703 if (ov.is_float_type ()) 720 if (ov.is_float_type ())
704 { 721 {
705 error ("floating point octave_value provided for 8-byte time value, but postgresql is configured for int64"); 722 c_verror ("floating point octave_value provided for 8-byte time value, but postgresql is configured for int64");
706 return 1; 723 return 1;
707 } 724 }
708 725
709 int64_t i8 = ov.int64_scalar_value (); 726 int64_t i8;
710 727 bool err;
711 if (error_state) 728 SET_ERR (i8 = ov.int64_scalar_value (), err);
729
730 if (err)
712 { 731 {
713 error ("can not convert octave_value to int64 time value"); 732 c_verror ("can not convert octave_value to int64 time value");
714 return 1; 733 return 1;
715 } 734 }
716 735
717 OCT_PQ_PUT(val, int64_t, htobe64 (i8)) 736 OCT_PQ_PUT(val, int64_t, htobe64 (i8))
718 737
721 else 740 else
722 { 741 {
723 // don't convert automatically because of possible loss of accuracy 742 // don't convert automatically because of possible loss of accuracy
724 if (ov.is_integer_type ()) 743 if (ov.is_integer_type ())
725 { 744 {
726 error ("integer type octave_value provided for 8-byte time value, but postgresql is configured for double"); 745 c_verror ("integer type octave_value provided for 8-byte time value, but postgresql is configured for double");
727 return 1; 746 return 1;
728 } 747 }
729 748
730 union 749 union
731 { 750 {
732 double d; 751 double d;
733 int64_t i; 752 int64_t i;
734 } 753 }
735 swap; 754 swap;
736 755
737 swap.d = ov.double_value (); 756 bool err;
738 757 SET_ERR (swap.d = ov.double_value (), err);
739 if (error_state) 758
759 if (err)
740 { 760 {
741 error ("can not convert octave_value to double time value"); 761 c_verror ("can not convert octave_value to double time value");
742 return 1; 762 return 1;
743 } 763 }
744 764
745 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) 765 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i))
746 766
845 } 865 }
846 866
847 int from_octave_bin_interval (const octave_pq_connection_rep &conn, 867 int from_octave_bin_interval (const octave_pq_connection_rep &conn,
848 const octave_value &ov, oct_pq_dynvec_t &val) 868 const octave_value &ov, oct_pq_dynvec_t &val)
849 { 869 {
850 Cell iv = ov.cell_value (); 870 Cell iv;
851 if (error_state || iv.numel () != 3) 871 bool err;
852 { 872 SET_ERR (iv = ov.cell_value (), err);
853 error ("interval: can not convert octave_value to cell with 3 elements"); 873 if (err || iv.numel () != 3)
874 {
875 c_verror ("interval: can not convert octave_value to cell with 3 elements");
854 return 1; 876 return 1;
855 } 877 }
856 878
857 if (time_8byte_from_octave (iv(0), val, conn.get_integer_datetimes ())) 879 if (time_8byte_from_octave (iv(0), val, conn.get_integer_datetimes ()))
858 return 1; 880 return 1;
859 881
860 for (int id = 1; id < 3; id++) 882 for (int id = 1; id < 3; id++)
861 { 883 {
862 int32_t i4 = iv(id).int_value (); 884 int32_t i4;
863 885 bool err;
864 if (error_state) 886 SET_ERR (i4 = iv(id).int_value (), err);
887
888 if (err)
865 { 889 {
866 error ("interval: can not convert octave_value to int4 value"); 890 c_verror ("interval: can not convert octave_value to int4 value");
867 return 1; 891 return 1;
868 } 892 }
869 893
870 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) 894 OCT_PQ_PUT(val, int32_t, htobe32 (i4))
871 } 895 }
962 } 986 }
963 987
964 int from_octave_bin_timetz (const octave_pq_connection_rep &conn, 988 int from_octave_bin_timetz (const octave_pq_connection_rep &conn,
965 const octave_value &ov, oct_pq_dynvec_t &val) 989 const octave_value &ov, oct_pq_dynvec_t &val)
966 { 990 {
967 Cell iv = ov.cell_value (); 991 Cell iv;
968 if (error_state || iv.numel () != 2) 992 bool err;
969 { 993 SET_ERR (iv = ov.cell_value (), err);
970 error ("timetz: can not convert octave_value to cell with 2 elements"); 994 if (err || iv.numel () != 2)
995 {
996 c_verror ("timetz: can not convert octave_value to cell with 2 elements");
971 return 1; 997 return 1;
972 } 998 }
973 999
974 if (time_8byte_from_octave (iv(0), val, conn.get_integer_datetimes ())) 1000 if (time_8byte_from_octave (iv(0), val, conn.get_integer_datetimes ()))
975 return 1; 1001 return 1;
976 1002
977 int32_t i4 = iv(1).int_value (); 1003 int32_t i4;
978 1004 SET_ERR (i4 = iv(1).int_value (), err);
979 if (error_state) 1005
980 { 1006 if (err)
981 error ("timetz: can not convert octave_value to int4 value"); 1007 {
1008 c_verror ("timetz: can not convert octave_value to int4 value");
982 return 1; 1009 return 1;
983 } 1010 }
984 1011
985 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) 1012 OCT_PQ_PUT(val, int32_t, htobe32 (i4))
986 1013
1025 } 1052 }
1026 1053
1027 int from_octave_bin_date (const octave_pq_connection_rep &conn, 1054 int from_octave_bin_date (const octave_pq_connection_rep &conn,
1028 const octave_value &ov, oct_pq_dynvec_t &val) 1055 const octave_value &ov, oct_pq_dynvec_t &val)
1029 { 1056 {
1030 int32_t i4 = ov.int_value (); 1057 int32_t i4;
1031 1058 bool err;
1032 if (error_state) 1059 SET_ERR (i4 = ov.int_value (), err);
1033 { 1060
1034 error ("date: can not convert octave_value to int4 value"); 1061 if (err)
1062 {
1063 c_verror ("date: can not convert octave_value to int4 value");
1035 return 1; 1064 return 1;
1036 } 1065 }
1037 1066
1038 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) 1067 OCT_PQ_PUT(val, int32_t, htobe32 (i4))
1039 1068
1094 } 1123 }
1095 1124
1096 int from_octave_bin_point (const octave_pq_connection_rep &conn, 1125 int from_octave_bin_point (const octave_pq_connection_rep &conn,
1097 const octave_value &ov, oct_pq_dynvec_t &val) 1126 const octave_value &ov, oct_pq_dynvec_t &val)
1098 { 1127 {
1099 NDArray m = ov.array_value (); 1128 NDArray m;
1100 1129 bool err;
1101 if (error_state || m.numel () != 2) 1130 SET_ERR (m = ov.array_value (), err);
1102 { 1131
1103 error ("can not convert octave_value to point representation"); 1132 if (err || m.numel () != 2)
1133 {
1134 c_verror ("can not convert octave_value to point representation");
1104 return 1; 1135 return 1;
1105 } 1136 }
1106 1137
1107 union 1138 union
1108 { 1139 {
1175 } 1206 }
1176 1207
1177 int from_octave_bin_lseg (const octave_pq_connection_rep &conn, 1208 int from_octave_bin_lseg (const octave_pq_connection_rep &conn,
1178 const octave_value &ov, oct_pq_dynvec_t &val) 1209 const octave_value &ov, oct_pq_dynvec_t &val)
1179 { 1210 {
1180 NDArray m = ov.array_value (); 1211 NDArray m;
1181 1212 bool err;
1182 if (error_state || m.numel () != 4) 1213 SET_ERR (m = ov.array_value (), err);
1183 { 1214
1184 error ("can not convert octave_value to 4 doubles"); 1215 if (err || m.numel () != 4)
1216 {
1217 c_verror ("can not convert octave_value to 4 doubles");
1185 return 1; 1218 return 1;
1186 } 1219 }
1187 1220
1188 union 1221 union
1189 { 1222 {
1290 } 1323 }
1291 1324
1292 int from_octave_bin_circle (const octave_pq_connection_rep &conn, 1325 int from_octave_bin_circle (const octave_pq_connection_rep &conn,
1293 const octave_value &ov, oct_pq_dynvec_t &val) 1326 const octave_value &ov, oct_pq_dynvec_t &val)
1294 { 1327 {
1295 NDArray m = ov.array_value (); 1328 NDArray m;
1296 1329 bool err;
1297 if (error_state || m.numel () != 3) 1330 SET_ERR (m = ov.array_value (), err);
1298 { 1331
1299 error ("can not convert octave_value to circle representation"); 1332 if (err || m.numel () != 3)
1333 {
1334 c_verror ("can not convert octave_value to circle representation");
1300 return 1; 1335 return 1;
1301 } 1336 }
1302 1337
1303 union 1338 union
1304 { 1339 {
1377 int from_octave_bin_polygon (const octave_pq_connection_rep &conn, 1412 int from_octave_bin_polygon (const octave_pq_connection_rep &conn,
1378 const octave_value &ov, oct_pq_dynvec_t &val) 1413 const octave_value &ov, oct_pq_dynvec_t &val)
1379 { 1414 {
1380 octave_idx_type nel; 1415 octave_idx_type nel;
1381 1416
1382 NDArray m = ov.array_value (); 1417 NDArray m;
1383 1418 bool err;
1384 if (error_state || (nel = m.numel ()) % 2) 1419 SET_ERR (m = ov.array_value (), err);
1385 { 1420
1386 error ("can not convert octave_value to polygon representation"); 1421 if (err || (nel = m.numel ()) % 2)
1422 {
1423 c_verror ("can not convert octave_value to polygon representation");
1387 return 1; 1424 return 1;
1388 } 1425 }
1389 1426
1390 union 1427 union
1391 { 1428 {
1472 } 1509 }
1473 1510
1474 int from_octave_bin_path (const octave_pq_connection_rep &conn, 1511 int from_octave_bin_path (const octave_pq_connection_rep &conn,
1475 const octave_value &ov, oct_pq_dynvec_t &val) 1512 const octave_value &ov, oct_pq_dynvec_t &val)
1476 { 1513 {
1477 octave_scalar_map tp = ov.scalar_map_value (); 1514 octave_scalar_map tp;
1478 if (error_state || ! tp.isfield ("closed") || ! tp.isfield ("path")) 1515 bool err;
1479 { 1516 SET_ERR (tp = ov.scalar_map_value (), err);
1480 error ("can not convert octave_value to path representation"); 1517 if (err || ! tp.isfield ("closed") || ! tp.isfield ("path"))
1518 {
1519 c_verror ("can not convert octave_value to path representation");
1481 return 1; 1520 return 1;
1482 } 1521 }
1483 1522
1484 octave_idx_type nel; 1523 octave_idx_type nel;
1485 1524
1486 char closed = char (tp.contents ("closed").bool_value ()); 1525 char closed;
1487 1526 SET_ERR (closed = char (tp.contents ("closed").bool_value ()), err);
1488 NDArray m = tp.contents ("path").array_value (); 1527
1489 1528 NDArray m;
1490 if (error_state || (nel = m.numel ()) % 2) 1529 if (! err)
1491 { 1530 {
1492 error ("can not convert octave_value to path representation"); 1531 SET_ERR (m = tp.contents ("path").array_value (), err);
1532 }
1533
1534 if (err || (nel = m.numel ()) % 2)
1535 {
1536 c_verror ("can not convert octave_value to path representation");
1493 return 1; 1537 return 1;
1494 } 1538 }
1495 1539
1496 union 1540 union
1497 { 1541 {
1540 // "no converter found" error thrown. 1584 // "no converter found" error thrown.
1541 1585
1542 int to_octave_str_unknown (const octave_pq_connection_rep &conn, 1586 int to_octave_str_unknown (const octave_pq_connection_rep &conn,
1543 const char *c, octave_value &ov, int nb) 1587 const char *c, octave_value &ov, int nb)
1544 { 1588 {
1545 error ("can not convert postgresql type 'unknown'"); 1589 c_verror ("can not convert postgresql type 'unknown'");
1546 1590
1547 return 1; 1591 return 1;
1548 } 1592 }
1549 1593
1550 int to_octave_bin_unknown (const octave_pq_connection_rep &conn, 1594 int to_octave_bin_unknown (const octave_pq_connection_rep &conn,
1551 const char *c, octave_value &ov, int nb) 1595 const char *c, octave_value &ov, int nb)
1552 { 1596 {
1553 error ("can not convert postgresql type 'unknown'"); 1597 c_verror ("can not convert postgresql type 'unknown'");
1554 1598
1555 return 1; 1599 return 1;
1556 } 1600 }
1557 1601
1558 int from_octave_str_unknown (const octave_pq_connection_rep &conn, 1602 int from_octave_str_unknown (const octave_pq_connection_rep &conn,
1559 const octave_value &ov, oct_pq_dynvec_t &val) 1603 const octave_value &ov, oct_pq_dynvec_t &val)
1560 { 1604 {
1561 error ("can not convert postgresql type 'unknown'"); 1605 c_verror ("can not convert postgresql type 'unknown'");
1562 1606
1563 return 1; 1607 return 1;
1564 } 1608 }
1565 1609
1566 int from_octave_bin_unknown (const octave_pq_connection_rep &conn, 1610 int from_octave_bin_unknown (const octave_pq_connection_rep &conn,
1567 const octave_value &ov, oct_pq_dynvec_t &val) 1611 const octave_value &ov, oct_pq_dynvec_t &val)
1568 { 1612 {
1569 error ("can not convert postgresql type 'unknown'"); 1613 c_verror ("can not convert postgresql type 'unknown'");
1570 1614
1571 return 1; 1615 return 1;
1572 } 1616 }
1573 1617
1574 oct_pq_conv_t conv_unknown = {0, 1618 oct_pq_conv_t conv_unknown = {0,
1606 if (nb < 0) 1650 if (nb < 0)
1607 nb = 0; 1651 nb = 0;
1608 1652
1609 if (nb > 4) 1653 if (nb > 4)
1610 { 1654 {
1611 error ("internal error: received too many bytes for AF_INET type"); 1655 c_verror ("internal error: received too many bytes for AF_INET type");
1612 1656
1613 return 1; 1657 return 1;
1614 } 1658 }
1615 1659
1616 for (int8_t i = 0; i < nb; i++, c++) 1660 for (int8_t i = 0; i < nb; i++, c++)
1631 if (nb < 0) 1675 if (nb < 0)
1632 nb = 0; 1676 nb = 0;
1633 1677
1634 if (nb > 16) 1678 if (nb > 16)
1635 { 1679 {
1636 error ("internal error: received too many bytes for AF_INET6 type"); 1680 c_verror ("internal error: received too many bytes for AF_INET6 type");
1637 1681
1638 return 1; 1682 return 1;
1639 } 1683 }
1640 1684
1641 int8_t n = nb / 2; 1685 int8_t n = nb / 2;
1663 { 1707 {
1664 int nl = ov.numel (); 1708 int nl = ov.numel ();
1665 1709
1666 uint8_t n_mbits; 1710 uint8_t n_mbits;
1667 1711
1712 bool err;
1713
1668 if (nl == 4 || nl == 5) 1714 if (nl == 4 || nl == 5)
1669 { 1715 {
1670 uint8NDArray a = ov.uint8_array_value (); 1716 uint8NDArray a;
1671 1717 SET_ERR (a = ov.uint8_array_value (), err);
1672 if (error_state) 1718
1719 if (err)
1673 { 1720 {
1674 error ("can not convert octave_value to network type representation"); 1721 c_verror ("can not convert octave_value to network type representation");
1675 return 1; 1722 return 1;
1676 } 1723 }
1677 1724
1678 if (nl == 5) 1725 if (nl == 5)
1679 n_mbits = a(4).value (); 1726 n_mbits = a(4).value ();
1687 for (int i = 0; i < 4; i++) 1734 for (int i = 0; i < 4; i++)
1688 val.push_back (a(i).value ()); 1735 val.push_back (a(i).value ());
1689 } 1736 }
1690 else if (nl == 8 || nl == 9) 1737 else if (nl == 8 || nl == 9)
1691 { 1738 {
1692 uint16NDArray a = ov.uint16_array_value (); 1739 uint16NDArray a;
1693 1740 SET_ERR (a = ov.uint16_array_value (), err);
1694 if (error_state) 1741
1742 if (err)
1695 { 1743 {
1696 error ("can not convert octave_value to network type representation"); 1744 c_verror ("can not convert octave_value to network type representation");
1697 return 1; 1745 return 1;
1698 } 1746 }
1699 1747
1700 if (nl == 9) 1748 if (nl == 9)
1701 n_mbits = a(8).value (); 1749 n_mbits = a(8).value ();
1711 OCT_PQ_PUT(val, uint16_t, htobe16(a(i).value ())) 1759 OCT_PQ_PUT(val, uint16_t, htobe16(a(i).value ()))
1712 } 1760 }
1713 } 1761 }
1714 else 1762 else
1715 { 1763 {
1716 error ("invalid network type representation"); 1764 c_verror ("invalid network type representation");
1717 return 1; 1765 return 1;
1718 } 1766 }
1719 1767
1720 return 0; 1768 return 0;
1721 } 1769 }
1738 if (to_octave_bin_cidr_inet (c, ov, cidr)) 1786 if (to_octave_bin_cidr_inet (c, ov, cidr))
1739 return 1; 1787 return 1;
1740 1788
1741 if (! cidr) 1789 if (! cidr)
1742 { 1790 {
1743 error ("internal error: unexpected flag in cidr type"); 1791 c_verror ("internal error: unexpected flag in cidr type");
1744 1792
1745 return 1; 1793 return 1;
1746 } 1794 }
1747 1795
1748 return 0; 1796 return 0;
1791 if (to_octave_bin_cidr_inet (c, ov, cidr)) 1839 if (to_octave_bin_cidr_inet (c, ov, cidr))
1792 return 1; 1840 return 1;
1793 1841
1794 if (cidr) 1842 if (cidr)
1795 { 1843 {
1796 error ("internal error: unexpected flag in inet type"); 1844 c_verror ("internal error: unexpected flag in inet type");
1797 1845
1798 return 1; 1846 return 1;
1799 } 1847 }
1800 1848
1801 return 0; 1849 return 0;
1856 } 1904 }
1857 1905
1858 int from_octave_bin_macaddr (const octave_pq_connection_rep &conn, 1906 int from_octave_bin_macaddr (const octave_pq_connection_rep &conn,
1859 const octave_value &ov, oct_pq_dynvec_t &val) 1907 const octave_value &ov, oct_pq_dynvec_t &val)
1860 { 1908 {
1861 uint8NDArray a = ov.uint8_array_value (); 1909 uint8NDArray a;
1862 1910 bool err;
1863 if (error_state) 1911 SET_ERR (a = ov.uint8_array_value (), err);
1864 { 1912
1865 error ("can not convert octave_value to macaddr representation"); 1913 if (err)
1914 {
1915 c_verror ("can not convert octave_value to macaddr representation");
1866 return 1; 1916 return 1;
1867 } 1917 }
1868 1918
1869 if (a.numel () != 6) 1919 if (a.numel () != 6)
1870 { 1920 {
1871 error ("macaddr representation must have 6 elements"); 1921 c_verror ("macaddr representation must have 6 elements");
1872 return 1; 1922 return 1;
1873 } 1923 }
1874 1924
1875 for (int i = 0; i < 6; i++) 1925 for (int i = 0; i < 6; i++)
1876 val.push_back (a(i).value ()); 1926 val.push_back (a(i).value ());
1931 } 1981 }
1932 1982
1933 int from_octave_bin_bit (const octave_pq_connection_rep &conn, 1983 int from_octave_bin_bit (const octave_pq_connection_rep &conn,
1934 const octave_value &ov, oct_pq_dynvec_t &val) 1984 const octave_value &ov, oct_pq_dynvec_t &val)
1935 { 1985 {
1936 octave_scalar_map tp = ov.scalar_map_value (); 1986 octave_scalar_map tp;
1937 if (error_state || ! tp.isfield ("bitlen") || ! tp.isfield ("bits")) 1987 bool err;
1938 { 1988 SET_ERR (tp = ov.scalar_map_value (), err);
1939 error ("can not convert octave_value to bitstring representation"); 1989 if (err || ! tp.isfield ("bitlen") || ! tp.isfield ("bits"))
1940 return 1; 1990 {
1941 } 1991 c_verror ("can not convert octave_value to bitstring representation");
1942 1992 return 1;
1943 int32_t nbits = tp.contents ("bitlen").int_value (); 1993 }
1944 1994
1945 uint8NDArray a = tp.contents ("bits").uint8_array_value (); 1995 int32_t nbits;
1946 1996 SET_ERR (nbits = tp.contents ("bitlen").int_value (), err);
1947 if (error_state || nbits < 0) 1997
1948 { 1998 uint8NDArray a;
1949 error ("can not convert octave_value to bitstring representation"); 1999 if (! err)
2000 {
2001 SET_ERR (a = tp.contents ("bits").uint8_array_value (), err);
2002 }
2003
2004 if (err || nbits < 0)
2005 {
2006 c_verror ("can not convert octave_value to bitstring representation");
1950 return 1; 2007 return 1;
1951 } 2008 }
1952 2009
1953 int32_t nbytes = (nbits + 7) / 8; 2010 int32_t nbytes = (nbits + 7) / 8;
1954 2011
1955 if (a.numel () != nbytes) 2012 if (a.numel () != nbytes)
1956 { 2013 {
1957 error ("wrong number of elements in bitstring representation"); 2014 c_verror ("wrong number of elements in bitstring representation");
1958 return 1; 2015 return 1;
1959 } 2016 }
1960 2017
1961 OCT_PQ_PUT(val, int32_t, htobe32 (nbits)) 2018 OCT_PQ_PUT(val, int32_t, htobe32 (nbits))
1962 2019
2027 } 2084 }
2028 2085
2029 int from_octave_bin_uuid (const octave_pq_connection_rep &conn, 2086 int from_octave_bin_uuid (const octave_pq_connection_rep &conn,
2030 const octave_value &ov, oct_pq_dynvec_t &val) 2087 const octave_value &ov, oct_pq_dynvec_t &val)
2031 { 2088 {
2032 uint8NDArray b = ov.uint8_array_value (); 2089 uint8NDArray b;
2033 2090 bool err;
2034 if (error_state) 2091 SET_ERR (b = ov.uint8_array_value (), err);
2035 { 2092
2036 error ("can not convert octave_value to uuid representation"); 2093 if (err)
2094 {
2095 c_verror ("can not convert octave_value to uuid representation");
2037 return 1; 2096 return 1;
2038 } 2097 }
2039 2098
2040 if (b.numel () != 16) 2099 if (b.numel () != 16)
2041 { 2100 {
2042 error ("uuid representation must have 16 elements"); 2101 c_verror ("uuid representation must have 16 elements");
2043 return 1; 2102 return 1;
2044 } 2103 }
2045 2104
2046 for (int i = 0; i < 16; i++) 2105 for (int i = 0; i < 16; i++)
2047 val.push_back (b(i).value ()); 2106 val.push_back (b(i).value ());
2089 } 2148 }
2090 2149
2091 int from_octave_bin_xml (const octave_pq_connection_rep &conn, 2150 int from_octave_bin_xml (const octave_pq_connection_rep &conn,
2092 const octave_value &ov, oct_pq_dynvec_t &val) 2151 const octave_value &ov, oct_pq_dynvec_t &val)
2093 { 2152 {
2094 std::string s = ov.string_value (); 2153 std::string s;
2095 2154 bool err;
2096 if (error_state) 2155 SET_ERR (s = ov.string_value (), err);
2097 { 2156
2098 error ("can not convert octave_value to string"); 2157 if (err)
2158 {
2159 c_verror ("can not convert octave_value to string");
2099 return 1; 2160 return 1;
2100 } 2161 }
2101 2162
2102 octave_idx_type l = s.size (); 2163 octave_idx_type l = s.size ();
2103 2164
2178 return 1; 2239 return 1;
2179 break; 2240 break;
2180 2241
2181 default: 2242 default:
2182 // should not get here 2243 // should not get here
2183 error ("'record' converter: internal error, undefined type identifier"); 2244 c_verror ("'record' converter: internal error, undefined type identifier");
2184 return 1; 2245 return 1;
2185 } 2246 }
2186 2247
2187 p += nb_el; 2248 p += nb_el;
2188 2249
2202 } 2263 }
2203 2264
2204 int from_octave_bin_record (const octave_pq_connection_rep &conn, 2265 int from_octave_bin_record (const octave_pq_connection_rep &conn,
2205 const octave_value &ov, oct_pq_dynvec_t &val) 2266 const octave_value &ov, oct_pq_dynvec_t &val)
2206 { 2267 {
2207 error ("Type 'record' can't be sent to postgresql."); 2268 c_verror ("Type 'record' can't be sent to postgresql.");
2208 2269
2209 return 1; 2270 return 1;
2210 } 2271 }
2211 2272
2212 oct_pq_conv_t conv_record = {0, 2273 oct_pq_conv_t conv_record = {0,