Mercurial > forge
annotate main/database/src/converters_arr_comp.cc @ 11645:bd5a8f1bdfb8 octave-forge
Clean out harmless warnings and one unnecessarily returned column.
author | i7tiol |
---|---|
date | Mon, 22 Apr 2013 13:40:13 +0000 |
parents | eb48ca3b21a1 |
children | b257244ad466 |
rev | line source |
---|---|
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
1 /* |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
2 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
3 Copyright (C) 2012, 2013 Olaf Till <i7tiol@t-online.de> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
4 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
5 This program is free software; you can redistribute it and/or modify |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
8 (at your option) any later version. |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
9 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
13 GNU General Public License for more details. |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
14 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
16 along with this program; If not, see <http://www.gnu.org/licenses/>. |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
17 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
18 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
19 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
20 #include <octave/oct.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
21 #include <octave/ov-struct.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
22 #include <octave/Cell.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
23 #include <octave/lo-ieee.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
24 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
25 #include <stdint.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
26 |
11644
eb48ca3b21a1
Fix #include <endian.h> for Apple, reported by Kamil Badyla.
i7tiol
parents:
11480
diff
changeset
|
27 #include "wrap_endian.h" |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
28 #include "command.h" |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
29 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
30 octave_idx_type command::count_row_major_order (dim_vector &dv, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
31 count_state &state, bool init) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
32 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
33 if (init) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
34 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
35 state.nd = dv.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
36 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
37 state.cur.resize (state.nd); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
38 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
39 state.pd.resize (state.nd); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
40 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
41 // cannot be done with resize in multiple initializations |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
42 // (resizing to n<2 not possible) and there is no fill() method |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
43 for (octave_idx_type i = 0; i < state.nd; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
44 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
45 state.cur(i) = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
46 state.pd(i) = 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
47 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
48 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
49 for (octave_idx_type i = 0; i < state.nd - 1; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
50 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
51 state.pd(i + 1) = state.pd(i) * dv(i); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
52 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
53 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
54 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
55 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
56 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
57 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
58 octave_idx_type nd = state.nd; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
59 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
60 if (nd > 0) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
61 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
62 octave_idx_type ret = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
63 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
64 state.cur(nd - 1)++; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
65 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
66 for (octave_idx_type i = nd - 1; i > 0; i--) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
67 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
68 if (state.cur(i) == dv(i)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
69 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
70 state.cur(i) = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
71 state.cur(i - 1)++; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
72 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
73 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
74 ret += state.cur(i) * state.pd(i); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
75 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
76 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
77 if (state.cur(0) == dv(0)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
78 ret = -1; // signals overflow |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
79 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
80 ret += state.cur(0) * state.pd(0); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
81 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
82 return ret; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
83 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
84 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
85 return -1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
86 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
87 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
88 |
11407 | 89 int command::from_octave_bin_array (const octave_value &oct_arr, |
90 oct_pq_dynvec_t &val, oct_pq_conv_t *conv) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
91 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
92 octave_scalar_map m = oct_arr.scalar_map_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
93 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
94 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
95 error ("%s: Postgresql array parameter no Octave structure", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
96 caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
97 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
98 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
99 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
100 if (! m.isfield ("ndims") || ! m.isfield ("data")) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
101 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
102 error ("%s: field 'ndims' or 'data' missing in parameter for Postgresql array", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
103 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
104 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
105 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
106 octave_idx_type nd_pq = m.contents ("ndims").int_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
107 Cell arr = m.contents ("data").cell_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
108 if (error_state || nd_pq < 0) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
109 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
110 error ("%s: 'ndims' and 'data' could not be converted to non-negative integer and cell-array in parameter for Postgresql array", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
111 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
112 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
113 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
114 RowVector lb; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
115 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
116 // Are lbounds given? |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
117 if (m.isfield ("lbounds")) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
118 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
119 lb = m.contents ("lbounds").row_vector_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
120 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
121 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
122 error ("%s: could not convert given enumeration bases for array to row vector", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
123 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
124 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
125 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
126 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
127 octave_idx_type nl = arr.numel (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
128 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
129 // dimensions of Octaves representation of postgresql array |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
130 dim_vector d = arr.dims (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
131 d.chop_trailing_singletons (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
132 int nd_oct = d.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
133 if (nd_oct == 2 && d(1) == 1) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
134 nd_oct = 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
135 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
136 // check dimensions |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
137 if (nd_oct > nd_pq) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
138 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
139 error ("given representation of postgresql array has more dimensions than specified"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
140 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
141 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
142 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
143 // check lbounds |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
144 if (nd_pq > 0 && lb.is_empty ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
145 lb.resize (nd_pq, 1); // fill with 1 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
146 else if (lb.length () != nd_pq) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
147 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
148 error ("number of specified enumeration bases for array does not match specified number of dimensions"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
149 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
150 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
151 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
152 // ndim |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
153 OCT_PQ_PUT(val, int32_t, htobe32 ((int32_t) nd_pq)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
154 // always make a NULL-bitmap, we don't scan for NULLs to see if it |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
155 // is really necessary |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
156 OCT_PQ_PUT(val, int32_t, htobe32 ((int32_t) 1)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
157 // element OID |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
158 OCT_PQ_PUT(val, uint32_t, htobe32 ((uint32_t) conv->oid)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
159 // dims, lbounds |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
160 for (int i = 0; i < nd_pq; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
161 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
162 OCT_PQ_PUT(val, int32_t, htobe32 ((int32_t) (i < nd_oct ? d(i) : 1))) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
163 OCT_PQ_PUT(val, int32_t, htobe32 ((int32_t) lb(i))) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
164 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
165 // elements |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
166 count_state state; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
167 count_row_major_order (d, state, true); // initialize counter |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
168 for (int i = 0, ti = 0; ti < nl; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
169 ti++, i = count_row_major_order (d, state, false)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
170 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
171 if (arr(i).is_real_scalar () && arr(i).isna ().bool_value ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
172 // a length value (uint32_t) would not have the 6 highest bits |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
173 // set (while this has all bits set) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
174 { OCT_PQ_PUT(val, int32_t, htobe32 ((int32_t) -1)) } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
175 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
176 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
177 OCT_PQ_SET_UINT32_PLACEHOLDER(val, temp_pos) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
178 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
179 if (conv->is_composite) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
180 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
181 if (from_octave_bin_composite (arr(i), val, conv)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
182 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
183 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
184 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
185 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
186 if (conv->from_octave_bin (arr(i), val)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
187 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
188 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
189 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
190 OCT_PQ_FILL_UINT32_PLACEHOLDER(val, temp_pos) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
191 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
192 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
193 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
194 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
195 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
196 |
11407 | 197 int command::from_octave_bin_composite (const octave_value &oct_comp, |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
198 oct_pq_dynvec_t &val, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
199 oct_pq_conv_t *conv) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
200 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
201 Cell rec (oct_comp.cell_value ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
202 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
203 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
204 error ("%s: Octaves representation of a composite type could not be converted to cell-array", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
205 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
206 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
207 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
208 octave_idx_type nl = rec.numel (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
209 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11644
diff
changeset
|
210 if (size_t (nl) != conv->el_oids.size ()) |
11474
4fd39d36eff5
Retrieve element information of composite types already at connection time. Exclude negative element numbers (system columns) of composite types corresponding to tables.
i7tiol
parents:
11407
diff
changeset
|
211 { |
4fd39d36eff5
Retrieve element information of composite types already at connection time. Exclude negative element numbers (system columns) of composite types corresponding to tables.
i7tiol
parents:
11407
diff
changeset
|
212 error ("%s: Octaves representation of a composite type has incorrect number of elements (%i, should have %i)", |
4fd39d36eff5
Retrieve element information of composite types already at connection time. Exclude negative element numbers (system columns) of composite types corresponding to tables.
i7tiol
parents:
11407
diff
changeset
|
213 caller.c_str (), nl, conv->el_oids.size ()); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
214 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
215 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
216 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
217 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
218 // ncols |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
219 OCT_PQ_PUT(val, int32_t, htobe32 ((int32_t) nl)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
220 // elements |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
221 for (int i = 0; i < nl; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
222 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
223 // element OID |
11474
4fd39d36eff5
Retrieve element information of composite types already at connection time. Exclude negative element numbers (system columns) of composite types corresponding to tables.
i7tiol
parents:
11407
diff
changeset
|
224 OCT_PQ_PUT(val, uint32_t, htobe32 ((uint32_t) conv->el_oids[i])) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
225 if (rec(i).is_real_scalar () && rec(i).isna ().bool_value ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
226 // a length value (uint32_t) would not have the 6 highest bits |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
227 // set (while this has all bits set) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
228 { OCT_PQ_PUT(val, int32_t, htobe32 ((int32_t) -1)) } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
229 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
230 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
231 OCT_PQ_SET_UINT32_PLACEHOLDER(val, temp_pos) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
232 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
233 oct_pq_conv_t *el_conv; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
234 oct_type_t oct_type; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
235 |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
236 if (! (el_conv = pgtype_from_spec (conv->el_oids[i], |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
237 conv->conv_cache[i], |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
238 oct_type))) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
239 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
240 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
241 switch (oct_type) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
242 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
243 case simple: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
244 if (el_conv->from_octave_bin (rec(i), val)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
245 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
246 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
247 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
248 case array: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
249 if (from_octave_bin_array (rec(i), val, el_conv)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
250 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
251 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
252 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
253 case composite: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
254 if (from_octave_bin_composite (rec(i), val, el_conv)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
255 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
256 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
257 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
258 default: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
259 // should not get here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
260 error ("%s: internal error, undefined type identifier", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
261 caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
262 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
263 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
264 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
265 OCT_PQ_FILL_UINT32_PLACEHOLDER(val, temp_pos) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
266 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
267 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
268 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
269 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
270 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
271 |
11407 | 272 int command::from_octave_str_array (const octave_value &oct_arr, |
273 oct_pq_dynvec_t &val, octave_value &type) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
274 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
275 // not implemented |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
276 error ("not implemented"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
277 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
278 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
279 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
280 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
281 |
11407 | 282 int command::from_octave_str_composite (const octave_value &oct_comp, |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
283 oct_pq_dynvec_t &val, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
284 octave_value &type) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
285 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
286 // not implemented |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
287 error ("not implemented"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
288 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
289 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
290 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
291 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
292 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
293 int command::to_octave_bin_array (char *v, octave_value &ov, int nb, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
294 oct_pq_conv_t *conv) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
295 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
296 char *p = v; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
297 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
298 // ndim |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
299 OCT_PQ_DECL_GET_INT32(ndim, p, int32_t) |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11644
diff
changeset
|
300 // Has NULL bitmap. Since this information is not used, comment it |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11644
diff
changeset
|
301 // out to avoid a warning and increase the pointer manually. |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11644
diff
changeset
|
302 // |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11644
diff
changeset
|
303 // OCT_PQ_DECL_GET_INT32(hasnull, p, int32_t) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11644
diff
changeset
|
304 p += 4; |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11644
diff
changeset
|
305 // |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
306 // element OID |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
307 OCT_PQ_DECL_GET_INT32(oid, p, uint32_t) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
308 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
309 // check element OID |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
310 if (oid != conv->oid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
311 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
312 error ("%s: element oid %i sent by server does not match element oid %i expected for array with oid %i", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
313 caller.c_str (), oid, conv->oid, conv->aoid); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
314 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
315 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
316 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
317 // dims, lbounds |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
318 dim_vector dv; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
319 dv.resize (ndim, 0); // ndim < 2 is treated as ndim == 2 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
320 if (ndim == 1) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
321 dv(1) = 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
322 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
323 RowVector lbounds (ndim); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
324 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
325 for (int i = 0; i < ndim; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
326 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
327 OCT_PQ_GET_INT32(dv(i), p, int32_t) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
328 OCT_PQ_GET_INT32(lbounds(i), p, int32_t) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
329 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
330 // |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
331 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
332 // elements |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
333 octave_idx_type nl = dv.numel (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
334 Cell c (dv); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
335 count_state state; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
336 count_row_major_order (dv, state, true); // initialize counter |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
337 for (int i = 0, ti = 0; ti < nl; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
338 ti++, i = count_row_major_order (dv, state, false)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
339 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
340 OCT_PQ_DECL_GET_INT32(null_id, p, int32_t) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
341 if (null_id == -1) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
342 // NULL |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
343 c(i) = octave_value (octave_NA); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
344 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
345 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
346 uint32_t nb_el = uint32_t (null_id); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
347 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
348 octave_value ov_el; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
349 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
350 if (conv->is_composite) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
351 { |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
352 if (to_octave_bin_composite (p, ov_el, nb_el, conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
353 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
354 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
355 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
356 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
357 if (conv->to_octave_bin (p, ov_el, nb_el)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
358 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
359 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
360 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
361 p += nb_el; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
362 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
363 c(i) = ov_el; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
364 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
365 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
366 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
367 octave_scalar_map m; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
368 m.assign ("data", octave_value (c)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
369 m.assign ("ndims", octave_value (ndim)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
370 m.assign ("lbounds", octave_value (lbounds)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
371 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
372 ov = octave_value (m); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
373 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
374 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
375 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
376 |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
377 int command::to_octave_bin_composite (char *v, octave_value &ov, int nb, |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
378 oct_pq_conv_t *conv) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
379 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
380 char *p = v; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
381 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
382 // ncols |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
383 OCT_PQ_DECL_GET_INT32(nl, p, int32_t) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
384 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
385 // elements |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
386 Cell c (nl, 1); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
387 for (int i = 0; i < nl; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
388 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
389 // element OID |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
390 OCT_PQ_DECL_GET_INT32(oid, p, uint32_t) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
391 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
392 OCT_PQ_DECL_GET_INT32(null_id, p, int32_t) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
393 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
394 if (null_id == -1) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
395 // NULL |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
396 c(i) = octave_value (octave_NA); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
397 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
398 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
399 uint32_t nb_el = uint32_t (null_id); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
400 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
401 oct_pq_conv_t *el_conv; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
402 oct_type_t oct_type; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
403 |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
404 if (! (el_conv = pgtype_from_spec (oid, conv->conv_cache[i], |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
405 oct_type))) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
406 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
407 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
408 octave_value el; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
409 switch (oct_type) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
410 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
411 case simple: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
412 if (el_conv->to_octave_bin (p, el, nb_el)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
413 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
414 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
415 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
416 case array: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
417 if (to_octave_bin_array (p, el, nb_el, el_conv)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
418 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
419 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
420 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
421 case composite: |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
422 if (to_octave_bin_composite (p, el, nb_el, el_conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
423 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
424 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
425 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
426 default: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
427 // should not get here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
428 error ("%s: internal error, undefined type identifier", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
429 caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
430 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
431 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
432 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
433 p += nb_el; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
434 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
435 c(i) = el; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
436 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
437 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
438 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
439 ov = octave_value (c); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
440 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
441 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
442 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
443 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
444 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
445 int command::to_octave_str_array (char *v, octave_value &ov, int nb, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
446 oct_pq_conv_t *conv) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
447 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
448 // not implemented |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
449 error ("not implemented"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
450 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
451 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
452 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
453 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
454 |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
455 int command::to_octave_str_composite (char *v, octave_value &ov, int nb, |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
456 oct_pq_conv_t *conv) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
457 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
458 // not implemented |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
459 error ("not implemented"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
460 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
461 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
462 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
463 } |