Mercurial > forge
annotate main/database/src/converters.cc @ 11715:ed5361361a0f octave-forge
Added converter for type 'record'. Some 'const' corrections.
author | i7tiol |
---|---|
date | Mon, 20 May 2013 08:02:13 +0000 |
parents | f4c52c68f744 |
children | 67adec29dee0 |
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> |
11697 | 21 #include <octave/ov-struct.h> |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
22 #include <octave/ov-float.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
23 #include <octave/ov-uint8.h> |
11668
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
24 #include <octave/Cell.h> |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
25 |
11553
35e9e4b6ab34
Fix configuration of postgresql include directories.
i7tiol
parents:
11480
diff
changeset
|
26 #include <libpq-fe.h> |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
27 |
11708 | 28 #include <sys/socket.h> // for AF_INET, needed in network address types |
29 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
30 #include "converters.h" |
11661 | 31 #include "pq_connection.h" |
11394
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 // remember to adjust OCT_PQ_NUM_CONVERTERS in converters.h |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
34 |
11708 | 35 #define PGSQL_AF_INET6 (AF_INET + 1) // defined so in postgresql, no |
36 // public header file available | |
37 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
38 // helper function for debugging |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
39 void print_conv (oct_pq_conv_t *c) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
40 { |
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:
11429
diff
changeset
|
41 printf ("oid: %u, aoid: %u, c: %i, e: %i, nc: %i, n: %s, to_s: %i, to_b: %i, fr_s: %i, fr_b: %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:
11429
diff
changeset
|
42 c->oid, c->aoid, c->is_composite, c->is_enum, c->is_not_constant, c->name.c_str (), c->to_octave_str ? 1 : 0, c->to_octave_bin ? 1 : 0, c->from_octave_str ? 1 : 0, c->from_octave_bin ? 1 : 0); |
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:
11429
diff
changeset
|
43 |
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:
11429
diff
changeset
|
44 printf (", el_oids:"); |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11553
diff
changeset
|
45 for (size_t i = 0; i < c->el_oids.size (); i++) |
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:
11429
diff
changeset
|
46 printf (" %u", c->el_oids[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:
11429
diff
changeset
|
47 |
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:
11429
diff
changeset
|
48 printf ("\n"); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
49 } |
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 /* type bool */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
52 |
11657 | 53 int to_octave_str_bool (const octave_pq_connection &conn, |
54 const char *c, octave_value &ov, int nb) | |
11394
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 bool tp = (*c == 't' ? true : false); |
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 ov = octave_value (tp); |
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 return 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 |
11657 | 63 int to_octave_bin_bool (const octave_pq_connection &conn, |
64 const char *c, octave_value &ov, int nb) | |
11394
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 ov = octave_value (bool (*c)); |
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 return 0; |
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 |
11657 | 71 int from_octave_str_bool (const octave_pq_connection &conn, |
72 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 bool b = ov.bool_value (); |
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 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
77 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
78 error ("can not convert octave_value to bool value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
79 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
80 } |
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 val.push_back (b ? '1' : '0'); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
83 val.push_back ('\0'); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
84 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
85 return 0; |
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 |
11657 | 88 int from_octave_bin_bool (const octave_pq_connection &conn, |
89 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
90 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
91 bool b = ov.bool_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
92 |
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 ("can not convert octave_value to bool value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
96 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
97 } |
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 val.push_back (char (b)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
100 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
101 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
102 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
103 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
104 oct_pq_conv_t conv_bool = {0, // 16 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
105 0, // 1000 |
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:
11429
diff
changeset
|
106 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
107 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
108 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
109 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
110 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
111 "bool", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
112 &to_octave_str_bool, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
113 &to_octave_bin_bool, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
114 &from_octave_str_bool, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
115 &from_octave_bin_bool}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
116 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
117 /* end type bool */ |
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 /* type oid */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
120 |
11657 | 121 int to_octave_str_oid (const octave_pq_connection &conn, |
122 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
123 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
124 return 1; |
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 |
11657 | 127 int to_octave_bin_oid (const octave_pq_connection &conn, |
128 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
129 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
130 ov = octave_value (octave_uint32 (be32toh (*((uint32_t *) c)))); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
131 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
132 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
133 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
134 |
11657 | 135 int from_octave_str_oid (const octave_pq_connection &conn, |
136 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
137 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
138 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
139 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
140 |
11657 | 141 int from_octave_bin_oid (const octave_pq_connection &conn, |
142 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
143 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
144 uint32_t oid = ov.uint_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
145 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
146 if (error_state) |
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 ("can not convert octave_value to oid value"); |
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 OCT_PQ_PUT(val, uint32_t, htobe32 (oid)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
153 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
154 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
155 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
156 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
157 oct_pq_conv_t conv_oid = {0, // 26 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
158 0, |
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:
11429
diff
changeset
|
159 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
160 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
161 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
162 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
163 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
164 "oid", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
165 &to_octave_str_oid, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
166 &to_octave_bin_oid, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
167 &from_octave_str_oid, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
168 &from_octave_bin_oid}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
169 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
170 /* end type oid */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
171 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
172 /* type float8 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
173 |
11657 | 174 int to_octave_str_float8 (const octave_pq_connection &conn, |
175 const char *c, octave_value &ov, int nb) | |
11394
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 // not implemented |
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 return 1; |
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 |
11657 | 182 int to_octave_bin_float8 (const octave_pq_connection &conn, |
183 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
184 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
185 union |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
186 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
187 double d; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
188 int64_t i; |
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 swap; |
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 swap.i = be64toh (*((int64_t *) c)); |
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 ov = octave_value (swap.d); |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
197 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
198 |
11657 | 199 int from_octave_str_float8 (const octave_pq_connection &conn, |
200 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
201 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
202 // not implemented |
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
205 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
206 |
11657 | 207 int from_octave_bin_float8 (const octave_pq_connection &conn, |
208 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
209 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
210 union |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
211 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
212 double d; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
213 int64_t i; |
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 swap; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
216 |
11655
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
217 swap.d = ov.double_value (); |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
218 |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
219 if (error_state) |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
220 { |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
221 error ("can not convert octave_value to float8 value"); |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
222 return 1; |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
223 } |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
224 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
225 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
226 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
227 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
228 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
229 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
230 oct_pq_conv_t conv_float8 = {0, // 701 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
231 0, // 1022 |
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:
11429
diff
changeset
|
232 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
233 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
234 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
235 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
236 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
237 "float8", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
238 &to_octave_str_float8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
239 &to_octave_bin_float8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
240 &from_octave_str_float8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
241 &from_octave_bin_float8}; |
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 /* end type float8 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
244 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
245 /* type float4 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
246 |
11657 | 247 int to_octave_str_float4 (const octave_pq_connection &conn, |
248 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
249 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
250 // not implemented |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
251 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
252 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
253 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
254 |
11657 | 255 int to_octave_bin_float4 (const octave_pq_connection &conn, |
256 const char *c, octave_value &ov, int nb) | |
11394
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 union |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
259 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
260 float f; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
261 int32_t i; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
262 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
263 swap; |
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 swap.i = be32toh (*((int32_t *) c)); |
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 ov = octave_value (swap.f); |
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 |
11657 | 272 int from_octave_str_float4 (const octave_pq_connection &conn, |
273 const octave_value &ov, oct_pq_dynvec_t &val) | |
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 |
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 |
11657 | 280 int from_octave_bin_float4 (const octave_pq_connection &conn, |
281 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
282 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
283 union |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
284 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
285 float f; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
286 int32_t i; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
287 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
288 swap; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
289 |
11655
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
290 swap.f = ov.float_value (); |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
291 |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
292 if (error_state) |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
293 { |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
294 error ("can not convert octave_value to float4 value"); |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
295 return 1; |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
296 } |
11394
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 OCT_PQ_PUT(val, int32_t, htobe32 (swap.i)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
299 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
300 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
301 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
302 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
303 oct_pq_conv_t conv_float4 = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
304 0, |
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:
11429
diff
changeset
|
305 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
306 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
307 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
308 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
309 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
310 "float4", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
311 &to_octave_str_float4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
312 &to_octave_bin_float4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
313 &from_octave_str_float4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
314 &from_octave_bin_float4}; |
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 /* end type float4 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
317 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
318 /* type bytea */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
319 |
11657 | 320 int to_octave_str_bytea (const octave_pq_connection &conn, |
321 const char *c, octave_value &ov, int nb) | |
11394
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 return 1; |
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 |
11657 | 326 int to_octave_bin_bytea (const octave_pq_connection &conn, |
327 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
328 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
329 uint8NDArray m (dim_vector (nb, 1)); |
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 uint8_t *p = (uint8_t *) m.fortran_vec (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
332 for (octave_idx_type i = 0; i < nb; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
333 *(p++) = uint8_t (*(c++)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
334 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
335 ov = octave_value (m); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
336 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
337 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
338 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
339 |
11657 | 340 int from_octave_str_bytea (const octave_pq_connection &conn, |
341 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
342 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
343 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
344 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
345 |
11657 | 346 int from_octave_bin_bytea (const octave_pq_connection &conn, |
347 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
348 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
349 uint8NDArray b = ov.uint8_array_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
350 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
351 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
352 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
353 error ("can not convert octave_value to bytea representation"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
354 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
355 } |
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 octave_idx_type nl = b.numel (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
358 |
11712 | 359 for (octave_idx_type i = 0; i < nl; i++) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
360 val.push_back (b(i).value ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
361 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
362 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
363 } |
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 oct_pq_conv_t conv_bytea = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
366 0, |
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:
11429
diff
changeset
|
367 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
368 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
369 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
370 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
371 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
372 "bytea", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
373 &to_octave_str_bytea, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
374 &to_octave_bin_bytea, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
375 &from_octave_str_bytea, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
376 &from_octave_bin_bytea}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
377 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
378 /* end type bytea */ |
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 /* type text */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
381 |
11657 | 382 int to_octave_str_text (const octave_pq_connection &conn, |
383 const char *c, octave_value &ov, int nb) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
386 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
387 |
11657 | 388 int to_octave_bin_text (const octave_pq_connection &conn, |
389 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
390 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
391 std::string s (c, nb); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
392 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
393 ov = octave_value (s); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
394 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
395 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
396 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
397 |
11657 | 398 int from_octave_str_text (const octave_pq_connection &conn, |
399 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
402 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
403 |
11657 | 404 int from_octave_bin_text (const octave_pq_connection &conn, |
405 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
406 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
407 std::string s = ov.string_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
408 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
409 if (error_state) |
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 error ("can not convert octave_value to string"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
412 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
413 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
414 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
415 octave_idx_type l = s.size (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
416 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
417 for (int i = 0; i < l; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
418 val.push_back (s[i]); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
419 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
420 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
421 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
422 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
423 oct_pq_conv_t conv_text = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
424 0, |
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:
11429
diff
changeset
|
425 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
426 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
427 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
428 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
429 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
430 "text", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
431 &to_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
432 &to_octave_bin_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
433 &from_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
434 &from_octave_bin_text}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
435 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
436 /* end type text */ |
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 /* type varchar */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
439 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
440 oct_pq_conv_t conv_varchar = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
441 0, |
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:
11429
diff
changeset
|
442 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
443 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
444 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
445 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
446 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
447 "varchar", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
448 &to_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
449 &to_octave_bin_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
450 &from_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
451 &from_octave_bin_text}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
452 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
453 /* end type varchar */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
454 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
455 /* type bpchar */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
456 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
457 oct_pq_conv_t conv_bpchar = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
458 0, |
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:
11429
diff
changeset
|
459 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
460 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
461 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
462 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
463 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
464 "bpchar", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
465 &to_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
466 &to_octave_bin_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
467 &from_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
468 &from_octave_bin_text}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
469 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
470 /* end type bpchar */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
471 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
472 /* type name */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
473 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
474 oct_pq_conv_t conv_name = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
475 0, |
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:
11429
diff
changeset
|
476 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
477 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
478 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
479 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
480 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
481 "name", |
11658 | 482 &to_octave_str_text, |
483 &to_octave_bin_text, | |
484 &from_octave_str_text, | |
485 &from_octave_bin_text}; | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
486 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
487 /* end type name */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
488 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
489 /* type int2 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
490 |
11657 | 491 int to_octave_str_int2 (const octave_pq_connection &conn, |
492 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
493 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
494 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
495 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
496 |
11657 | 497 int to_octave_bin_int2 (const octave_pq_connection &conn, |
498 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
499 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
500 ov = octave_value (octave_int16 (int16_t (be16toh (*((int16_t *) c))))); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
501 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
502 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
503 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
504 |
11657 | 505 int from_octave_str_int2 (const octave_pq_connection &conn, |
506 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
507 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
508 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
509 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
510 |
11657 | 511 int from_octave_bin_int2 (const octave_pq_connection &conn, |
512 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
513 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
514 int16_t i2 = ov.int_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
515 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
516 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
517 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
518 error ("can not convert octave_value to int2 value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
519 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
520 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
521 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
522 OCT_PQ_PUT(val, int16_t, htobe16 (i2)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
523 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
524 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
525 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
526 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
527 oct_pq_conv_t conv_int2 = {0, // 26 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
528 0, |
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:
11429
diff
changeset
|
529 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
530 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
531 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
532 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
533 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
534 "int2", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
535 &to_octave_str_int2, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
536 &to_octave_bin_int2, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
537 &from_octave_str_int2, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
538 &from_octave_bin_int2}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
539 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
540 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
541 /* end type int2 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
542 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
543 /* type int4 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
544 |
11657 | 545 int to_octave_str_int4 (const octave_pq_connection &conn, |
546 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
547 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
548 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
549 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
550 |
11657 | 551 int to_octave_bin_int4 (const octave_pq_connection &conn, |
552 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
553 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
554 ov = octave_value (octave_int32 (int32_t (be32toh (*((int32_t *) c))))); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
555 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
556 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
557 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
558 |
11657 | 559 int from_octave_str_int4 (const octave_pq_connection &conn, |
560 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
561 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
562 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
563 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
564 |
11657 | 565 int from_octave_bin_int4 (const octave_pq_connection &conn, |
566 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
567 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
568 int32_t i4 = ov.int_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
569 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
570 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
571 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
572 error ("can not convert octave_value to int4 value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
573 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
574 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
575 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
576 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
577 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
578 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
579 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
580 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
581 oct_pq_conv_t conv_int4 = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
582 0, |
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:
11429
diff
changeset
|
583 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
584 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
585 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
586 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
587 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
588 "int4", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
589 &to_octave_str_int4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
590 &to_octave_bin_int4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
591 &from_octave_str_int4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
592 &from_octave_bin_int4}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
593 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
594 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
595 /* end type int4 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
596 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
597 /* type int8 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
598 |
11657 | 599 int to_octave_str_int8 (const octave_pq_connection &conn, |
600 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
601 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
602 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
603 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
604 |
11657 | 605 int to_octave_bin_int8 (const octave_pq_connection &conn, |
606 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
607 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
608 ov = octave_value (octave_int64 (int64_t (be64toh (*((int64_t *) c))))); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
609 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
610 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
611 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
612 |
11657 | 613 int from_octave_str_int8 (const octave_pq_connection &conn, |
614 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
615 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
616 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
617 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
618 |
11657 | 619 int from_octave_bin_int8 (const octave_pq_connection &conn, |
620 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
621 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
622 int64_t i8 = ov.int64_scalar_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
623 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
624 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
625 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
626 error ("can not convert octave_value to int8 value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
627 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
628 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
629 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
630 OCT_PQ_PUT(val, int64_t, htobe64 (i8)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
631 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
632 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
633 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
634 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
635 oct_pq_conv_t conv_int8 = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
636 0, |
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:
11429
diff
changeset
|
637 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
638 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
639 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
640 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
641 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
642 "int8", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
643 &to_octave_str_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
644 &to_octave_bin_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
645 &from_octave_str_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
646 &from_octave_bin_int8}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
647 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
648 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
649 /* end type int8 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
650 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
651 /* type money */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
652 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
653 oct_pq_conv_t conv_money = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
654 0, |
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:
11429
diff
changeset
|
655 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
656 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
657 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
658 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
659 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
660 "money", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
661 &to_octave_str_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
662 &to_octave_bin_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
663 &from_octave_str_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
664 &from_octave_bin_int8}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
665 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
666 /* end type money */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
667 |
11661 | 668 // helpers for time types |
669 | |
11667 | 670 static inline octave_value time_8byte_to_octave (const char *c, |
671 const bool &int_dt) | |
11661 | 672 { |
673 if (int_dt) | |
674 { | |
675 return octave_value (octave_int64 (int64_t (be64toh (*((int64_t *) c))))); | |
676 } | |
677 else | |
678 { | |
679 union | |
680 { | |
681 double d; | |
682 int64_t i; | |
683 } | |
684 swap; | |
685 | |
686 swap.i = be64toh (*((int64_t *) c)); | |
687 | |
688 return octave_value (swap.d); | |
689 } | |
690 } | |
691 | |
692 static inline int time_8byte_from_octave (const octave_value &ov, | |
693 oct_pq_dynvec_t &val, | |
11667 | 694 const bool &int_dt) |
11661 | 695 { |
696 if (int_dt) | |
697 { | |
698 // don't convert automatically because of possible overflow | |
699 if (ov.is_float_type ()) | |
700 { | |
701 error ("floating point octave_value provided for 8-byte time value, but postgresql is configured for int64"); | |
702 return 1; | |
703 } | |
704 | |
705 int64_t i8 = ov.int64_scalar_value (); | |
706 | |
707 if (error_state) | |
708 { | |
709 error ("can not convert octave_value to int64 time value"); | |
710 return 1; | |
711 } | |
712 | |
713 OCT_PQ_PUT(val, int64_t, htobe64 (i8)) | |
714 | |
715 return 0; | |
716 } | |
717 else | |
718 { | |
719 // don't convert automatically because of possible loss of accuracy | |
720 if (ov.is_integer_type ()) | |
721 { | |
722 error ("integer type octave_value provided for 8-byte time value, but postgresql is configured for double"); | |
723 return 1; | |
724 } | |
725 | |
726 union | |
727 { | |
728 double d; | |
729 int64_t i; | |
730 } | |
731 swap; | |
732 | |
733 swap.d = ov.double_value (); | |
734 | |
735 if (error_state) | |
736 { | |
737 error ("can not convert octave_value to double time value"); | |
738 return 1; | |
739 } | |
740 | |
741 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
742 | |
743 return 0; | |
744 } | |
745 } | |
746 | |
747 // end helpers for time types | |
748 | |
749 /* type timestamp */ | |
750 | |
751 int to_octave_str_timestamp (const octave_pq_connection &conn, | |
752 const char *c, octave_value &ov, int nb) | |
753 { | |
754 return 1; | |
755 } | |
756 | |
757 int to_octave_bin_timestamp (const octave_pq_connection &conn, | |
758 const char *c, octave_value &ov, int nb) | |
759 { | |
11667 | 760 ov = time_8byte_to_octave (c, conn.get_integer_datetimes ()); |
11661 | 761 |
762 return 0; | |
763 } | |
764 | |
765 int from_octave_str_timestamp (const octave_pq_connection &conn, | |
766 const octave_value &ov, oct_pq_dynvec_t &val) | |
767 { | |
768 return 1; | |
769 } | |
770 | |
771 int from_octave_bin_timestamp (const octave_pq_connection &conn, | |
772 const octave_value &ov, oct_pq_dynvec_t &val) | |
773 { | |
11667 | 774 return (time_8byte_from_octave (ov, val, conn.get_integer_datetimes ())); |
11661 | 775 } |
776 | |
777 oct_pq_conv_t conv_timestamp = {0, | |
778 0, | |
779 oct_pq_el_oids_t (), | |
780 oct_pq_conv_cache_t (), | |
781 false, | |
782 false, | |
783 false, | |
784 "timestamp", | |
785 &to_octave_str_timestamp, | |
786 &to_octave_bin_timestamp, | |
787 &from_octave_str_timestamp, | |
788 &from_octave_bin_timestamp}; | |
789 | |
790 /* end type timestamp */ | |
791 | |
11667 | 792 /* type timestamptz */ |
793 | |
794 oct_pq_conv_t conv_timestamptz = {0, | |
795 0, | |
796 oct_pq_el_oids_t (), | |
797 oct_pq_conv_cache_t (), | |
798 false, | |
799 false, | |
800 false, | |
801 "timestamptz", | |
802 &to_octave_str_timestamp, | |
803 &to_octave_bin_timestamp, | |
804 &from_octave_str_timestamp, | |
805 &from_octave_bin_timestamp}; | |
806 | |
807 /* end type timestamptz */ | |
808 | |
11668
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
809 /* type interval */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
810 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
811 int to_octave_str_interval (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
812 const char *c, octave_value &ov, int nb) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
813 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
814 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
815 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
816 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
817 int to_octave_bin_interval (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
818 const char *c, octave_value &ov, int nb) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
819 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
820 Cell tp (dim_vector (3, 1)); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
821 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
822 tp(0) = time_8byte_to_octave (c, conn.get_integer_datetimes ()); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
823 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
824 c += 8; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
825 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
826 tp(1) = octave_value (octave_int32 (int32_t (be32toh (*((int32_t *) c))))); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
827 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
828 c += 4; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
829 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
830 tp(2) = octave_value (octave_int32 (int32_t (be32toh (*((int32_t *) c))))); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
831 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
832 ov = octave_value (tp); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
833 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
834 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
835 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
836 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
837 int from_octave_str_interval (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
838 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
839 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
840 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
841 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
842 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
843 int from_octave_bin_interval (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
844 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
845 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
846 Cell iv = ov.cell_value (); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
847 if (error_state || iv.numel () != 3) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
848 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
849 error ("interval: can not convert octave_value to cell with 3 elements"); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
850 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
851 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
852 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
853 if (time_8byte_from_octave (iv(0), val, conn.get_integer_datetimes ())) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
854 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
855 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
856 for (int id = 1; id < 3; id++) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
857 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
858 int32_t i4 = iv(id).int_value (); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
859 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
860 if (error_state) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
861 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
862 error ("interval: can not convert octave_value to int4 value"); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
863 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
864 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
865 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
866 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
867 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
868 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
869 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
870 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
871 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
872 oct_pq_conv_t conv_interval = {0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
873 0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
874 oct_pq_el_oids_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
875 oct_pq_conv_cache_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
876 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
877 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
878 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
879 "interval", |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
880 &to_octave_str_interval, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
881 &to_octave_bin_interval, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
882 &from_octave_str_interval, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
883 &from_octave_bin_interval}; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
884 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
885 /* end type interval */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
886 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
887 /* type time */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
888 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
889 int to_octave_str_time (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
890 const char *c, octave_value &ov, int nb) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
891 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
892 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
893 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
894 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
895 int to_octave_bin_time (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
896 const char *c, octave_value &ov, int nb) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
897 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
898 ov = time_8byte_to_octave (c, conn.get_integer_datetimes ()); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
899 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
900 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
901 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
902 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
903 int from_octave_str_time (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
904 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
905 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
906 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
907 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
908 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
909 int from_octave_bin_time (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
910 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
911 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
912 return (time_8byte_from_octave (ov, val, conn.get_integer_datetimes ())); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
913 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
914 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
915 oct_pq_conv_t conv_time = {0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
916 0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
917 oct_pq_el_oids_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
918 oct_pq_conv_cache_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
919 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
920 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
921 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
922 "time", |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
923 &to_octave_str_time, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
924 &to_octave_bin_time, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
925 &from_octave_str_time, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
926 &from_octave_bin_time}; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
927 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
928 /* end type time */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
929 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
930 /* type timetz */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
931 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
932 int to_octave_str_timetz (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
933 const char *c, octave_value &ov, int nb) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
934 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
935 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
936 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
937 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
938 int to_octave_bin_timetz (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
939 const char *c, octave_value &ov, int nb) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
940 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
941 Cell tp (dim_vector (2, 1)); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
942 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
943 tp(0) = time_8byte_to_octave (c, conn.get_integer_datetimes ()); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
944 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
945 c += 8; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
946 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
947 tp(1) = octave_value (octave_int32 (int32_t (be32toh (*((int32_t *) c))))); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
948 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
949 ov = octave_value (tp); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
950 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
951 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
952 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
953 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
954 int from_octave_str_timetz (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
955 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
956 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
957 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
958 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
959 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
960 int from_octave_bin_timetz (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
961 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
962 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
963 Cell iv = ov.cell_value (); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
964 if (error_state || iv.numel () != 2) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
965 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
966 error ("timetz: can not convert octave_value to cell with 2 elements"); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
967 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
968 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
969 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
970 if (time_8byte_from_octave (iv(0), val, conn.get_integer_datetimes ())) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
971 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
972 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
973 int32_t i4 = iv(1).int_value (); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
974 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
975 if (error_state) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
976 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
977 error ("timetz: can not convert octave_value to int4 value"); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
978 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
979 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
980 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
981 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
982 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
983 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
984 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
985 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
986 oct_pq_conv_t conv_timetz = {0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
987 0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
988 oct_pq_el_oids_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
989 oct_pq_conv_cache_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
990 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
991 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
992 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
993 "timetz", |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
994 &to_octave_str_timetz, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
995 &to_octave_bin_timetz, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
996 &from_octave_str_timetz, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
997 &from_octave_bin_timetz}; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
998 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
999 /* end type timetz */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1000 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1001 /* type date */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1002 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1003 int to_octave_str_date (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1004 const char *c, octave_value &ov, int nb) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1005 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1006 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1007 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1008 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1009 int to_octave_bin_date (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1010 const char *c, octave_value &ov, int nb) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1011 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1012 ov = octave_value (octave_int32 (int32_t (be32toh (*((int32_t *) c))))); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1013 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1014 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1015 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1016 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1017 int from_octave_str_date (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1018 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1019 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1020 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1021 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1022 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1023 int from_octave_bin_date (const octave_pq_connection &conn, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1024 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1025 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1026 int32_t i4 = ov.int_value (); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1027 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1028 if (error_state) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1029 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1030 error ("date: can not convert octave_value to int4 value"); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1031 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1032 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1033 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1034 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1035 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1036 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1037 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1038 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1039 oct_pq_conv_t conv_date = {0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1040 0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1041 oct_pq_el_oids_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1042 oct_pq_conv_cache_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1043 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1044 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1045 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1046 "date", |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1047 &to_octave_str_date, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1048 &to_octave_bin_date, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1049 &from_octave_str_date, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1050 &from_octave_bin_date}; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1051 |
11697 | 1052 /* end type date */ |
11668
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1053 |
11697 | 1054 /* type point */ |
1055 | |
1056 int to_octave_str_point (const octave_pq_connection &conn, | |
1057 const char *c, octave_value &ov, int nb) | |
1058 { | |
1059 return 1; | |
1060 } | |
1061 | |
1062 int to_octave_bin_point (const octave_pq_connection &conn, | |
1063 const char *c, octave_value &ov, int nb) | |
1064 { | |
1065 ColumnVector m (2); | |
1066 | |
1067 union | |
1068 { | |
1069 double d; | |
1070 int64_t i; | |
1071 } | |
1072 swap; | |
1073 | |
1074 for (int id = 0; id < 2; id++, c += 8) | |
1075 { | |
1076 swap.i = be64toh (*((int64_t *) c)); | |
1077 | |
1078 m(id) = swap.d; | |
1079 } | |
1080 | |
1081 ov = octave_value (m); | |
1082 | |
1083 return 0; | |
1084 } | |
1085 | |
1086 int from_octave_str_point (const octave_pq_connection &conn, | |
1087 const octave_value &ov, oct_pq_dynvec_t &val) | |
1088 { | |
1089 return 1; | |
1090 } | |
1091 | |
1092 int from_octave_bin_point (const octave_pq_connection &conn, | |
1093 const octave_value &ov, oct_pq_dynvec_t &val) | |
1094 { | |
1095 NDArray m = ov.array_value (); | |
1096 | |
1097 if (error_state || m.numel () != 2) | |
1098 { | |
1099 error ("can not convert octave_value to point representation"); | |
1100 return 1; | |
1101 } | |
1102 | |
1103 union | |
1104 { | |
1105 double d; | |
1106 int64_t i; | |
1107 } | |
1108 swap; | |
1109 | |
1110 for (int id = 0; id < 2; id++) | |
1111 { | |
1112 swap.d = m(id); | |
1113 | |
1114 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1115 } | |
1116 | |
1117 return 0; | |
1118 } | |
1119 | |
1120 oct_pq_conv_t conv_point = {0, | |
1121 0, | |
1122 oct_pq_el_oids_t (), | |
1123 oct_pq_conv_cache_t (), | |
1124 false, | |
1125 false, | |
1126 false, | |
1127 "point", | |
1128 &to_octave_str_point, | |
1129 &to_octave_bin_point, | |
1130 &from_octave_str_point, | |
1131 &from_octave_bin_point}; | |
1132 | |
1133 /* end type point */ | |
1134 | |
1135 /* type lseg */ | |
1136 | |
1137 int to_octave_str_lseg (const octave_pq_connection &conn, | |
1138 const char *c, octave_value &ov, int nb) | |
1139 { | |
1140 return 1; | |
1141 } | |
1142 | |
1143 int to_octave_bin_lseg (const octave_pq_connection &conn, | |
1144 const char *c, octave_value &ov, int nb) | |
1145 { | |
1146 Matrix m (2, 2); | |
1147 | |
1148 union | |
1149 { | |
1150 double d; | |
1151 int64_t i; | |
1152 } | |
1153 swap; | |
1154 | |
1155 for (int id = 0; id < 4; id++, c += 8) | |
1156 { | |
1157 swap.i = be64toh (*((int64_t *) c)); | |
1158 | |
1159 m(id) = swap.d; | |
1160 } | |
1161 | |
1162 ov = octave_value (m); | |
1163 | |
1164 return 0; | |
1165 } | |
1166 | |
1167 int from_octave_str_lseg (const octave_pq_connection &conn, | |
1168 const octave_value &ov, oct_pq_dynvec_t &val) | |
1169 { | |
1170 return 1; | |
1171 } | |
1172 | |
1173 int from_octave_bin_lseg (const octave_pq_connection &conn, | |
1174 const octave_value &ov, oct_pq_dynvec_t &val) | |
1175 { | |
1176 NDArray m = ov.array_value (); | |
1177 | |
1178 if (error_state || m.numel () != 4) | |
1179 { | |
1180 error ("can not convert octave_value to 4 doubles"); | |
1181 return 1; | |
1182 } | |
1183 | |
1184 union | |
1185 { | |
1186 double d; | |
1187 int64_t i; | |
1188 } | |
1189 swap; | |
1190 | |
1191 for (int id = 0; id < 4; id++) | |
1192 { | |
1193 swap.d = m(id); | |
1194 | |
1195 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1196 } | |
1197 | |
1198 return 0; | |
1199 } | |
1200 | |
1201 oct_pq_conv_t conv_lseg = {0, | |
1202 0, | |
1203 oct_pq_el_oids_t (), | |
1204 oct_pq_conv_cache_t (), | |
1205 false, | |
1206 false, | |
1207 false, | |
1208 "lseg", | |
1209 &to_octave_str_lseg, | |
1210 &to_octave_bin_lseg, | |
1211 &from_octave_str_lseg, | |
1212 &from_octave_bin_lseg}; | |
1213 | |
1214 /* end type lseg */ | |
1215 | |
1216 /* type line */ | |
1217 | |
1218 oct_pq_conv_t conv_line = {0, | |
1219 0, | |
1220 oct_pq_el_oids_t (), | |
1221 oct_pq_conv_cache_t (), | |
1222 false, | |
1223 false, | |
1224 false, | |
1225 "line", | |
1226 &to_octave_str_lseg, | |
1227 &to_octave_bin_lseg, | |
1228 &from_octave_str_lseg, | |
1229 &from_octave_bin_lseg}; | |
1230 | |
1231 /* end type line */ | |
1232 | |
1233 /* type box */ | |
1234 | |
1235 oct_pq_conv_t conv_box = {0, | |
1236 0, | |
1237 oct_pq_el_oids_t (), | |
1238 oct_pq_conv_cache_t (), | |
1239 false, | |
1240 false, | |
1241 false, | |
1242 "box", | |
1243 &to_octave_str_lseg, | |
1244 &to_octave_bin_lseg, | |
1245 &from_octave_str_lseg, | |
1246 &from_octave_bin_lseg}; | |
1247 | |
1248 /* end type box */ | |
1249 | |
1250 /* type circle */ | |
1251 | |
1252 int to_octave_str_circle (const octave_pq_connection &conn, | |
1253 const char *c, octave_value &ov, int nb) | |
1254 { | |
1255 return 1; | |
1256 } | |
1257 | |
1258 int to_octave_bin_circle (const octave_pq_connection &conn, | |
1259 const char *c, octave_value &ov, int nb) | |
1260 { | |
1261 ColumnVector m (3); | |
1262 | |
1263 union | |
1264 { | |
1265 double d; | |
1266 int64_t i; | |
1267 } | |
1268 swap; | |
1269 | |
1270 for (int id = 0; id < 3; id++, c += 8) | |
1271 { | |
1272 swap.i = be64toh (*((int64_t *) c)); | |
1273 | |
1274 m(id) = swap.d; | |
1275 } | |
1276 | |
1277 ov = octave_value (m); | |
1278 | |
1279 return 0; | |
1280 } | |
1281 | |
1282 int from_octave_str_circle (const octave_pq_connection &conn, | |
1283 const octave_value &ov, oct_pq_dynvec_t &val) | |
1284 { | |
1285 return 1; | |
1286 } | |
1287 | |
1288 int from_octave_bin_circle (const octave_pq_connection &conn, | |
1289 const octave_value &ov, oct_pq_dynvec_t &val) | |
1290 { | |
1291 NDArray m = ov.array_value (); | |
1292 | |
1293 if (error_state || m.numel () != 3) | |
1294 { | |
1295 error ("can not convert octave_value to circle representation"); | |
1296 return 1; | |
1297 } | |
1298 | |
1299 union | |
1300 { | |
1301 double d; | |
1302 int64_t i; | |
1303 } | |
1304 swap; | |
1305 | |
1306 for (int id = 0; id < 3; id++) | |
1307 { | |
1308 swap.d = m(id); | |
1309 | |
1310 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1311 } | |
1312 | |
1313 return 0; | |
1314 } | |
1315 | |
1316 oct_pq_conv_t conv_circle = {0, | |
1317 0, | |
1318 oct_pq_el_oids_t (), | |
1319 oct_pq_conv_cache_t (), | |
1320 false, | |
1321 false, | |
1322 false, | |
1323 "circle", | |
1324 &to_octave_str_circle, | |
1325 &to_octave_bin_circle, | |
1326 &from_octave_str_circle, | |
1327 &from_octave_bin_circle}; | |
1328 | |
1329 /* end type circle */ | |
1330 | |
1331 /* type polygon */ | |
1332 | |
1333 int to_octave_str_polygon (const octave_pq_connection &conn, | |
1334 const char *c, octave_value &ov, int nb) | |
1335 { | |
1336 return 1; | |
1337 } | |
1338 | |
1339 int to_octave_bin_polygon (const octave_pq_connection &conn, | |
1340 const char *c, octave_value &ov, int nb) | |
1341 { | |
1342 int32_t np = int32_t (be32toh (*((int32_t *) c))); | |
1343 | |
1344 c += 4; | |
1345 | |
1346 Matrix m (2, np); | |
1347 | |
1348 union | |
1349 { | |
1350 double d; | |
1351 int64_t i; | |
1352 } | |
1353 swap; | |
1354 | |
1355 for (int id = 0; id < np * 2; id++, c += 8) | |
1356 { | |
1357 swap.i = be64toh (*((int64_t *) c)); | |
1358 | |
1359 m(id) = swap.d; | |
1360 } | |
1361 | |
1362 ov = octave_value (m); | |
1363 | |
1364 return 0; | |
1365 } | |
1366 | |
1367 int from_octave_str_polygon (const octave_pq_connection &conn, | |
1368 const octave_value &ov, oct_pq_dynvec_t &val) | |
1369 { | |
1370 return 1; | |
1371 } | |
1372 | |
1373 int from_octave_bin_polygon (const octave_pq_connection &conn, | |
1374 const octave_value &ov, oct_pq_dynvec_t &val) | |
1375 { | |
1376 octave_idx_type nel; | |
1377 | |
1378 NDArray m = ov.array_value (); | |
1379 | |
1380 if (error_state || (nel = m.numel ()) % 2) | |
1381 { | |
1382 error ("can not convert octave_value to polygon representation"); | |
1383 return 1; | |
1384 } | |
1385 | |
1386 union | |
1387 { | |
1388 double d; | |
1389 int64_t i; | |
1390 } | |
1391 swap; | |
1392 | |
1393 int32_t np = nel / 2; | |
1394 | |
1395 OCT_PQ_PUT(val, int32_t, htobe32 (np)) | |
1396 | |
1397 for (int id = 0; id < nel; id++) | |
1398 { | |
1399 swap.d = m(id); | |
1400 | |
1401 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1402 } | |
1403 | |
1404 return 0; | |
1405 } | |
1406 | |
1407 oct_pq_conv_t conv_polygon = {0, | |
1408 0, | |
1409 oct_pq_el_oids_t (), | |
1410 oct_pq_conv_cache_t (), | |
1411 false, | |
1412 false, | |
1413 false, | |
1414 "polygon", | |
1415 &to_octave_str_polygon, | |
1416 &to_octave_bin_polygon, | |
1417 &from_octave_str_polygon, | |
1418 &from_octave_bin_polygon}; | |
1419 | |
1420 /* end type polygon */ | |
1421 | |
1422 /* type path */ | |
1423 | |
1424 int to_octave_str_path (const octave_pq_connection &conn, | |
1425 const char *c, octave_value &ov, int nb) | |
1426 { | |
1427 return 1; | |
1428 } | |
1429 | |
1430 int to_octave_bin_path (const octave_pq_connection &conn, | |
1431 const char *c, octave_value &ov, int nb) | |
1432 { | |
1433 bool closed = bool (*(c++)); | |
1434 | |
1435 int32_t np = int32_t (be32toh (*((int32_t *) c))); | |
1436 | |
1437 c += 4; | |
1438 | |
1439 Matrix m (2, np); | |
1440 | |
1441 union | |
1442 { | |
1443 double d; | |
1444 int64_t i; | |
1445 } | |
1446 swap; | |
1447 | |
1448 for (int id = 0; id < np * 2; id++, c += 8) | |
1449 { | |
1450 swap.i = be64toh (*((int64_t *) c)); | |
1451 | |
1452 m(id) = swap.d; | |
1453 } | |
1454 | |
1455 octave_scalar_map tp; | |
1456 tp.assign ("closed", octave_value (closed)); | |
1457 tp.assign ("path", octave_value (m)); | |
1458 | |
1459 ov = octave_value (tp); | |
1460 | |
1461 return 0; | |
1462 } | |
1463 | |
1464 int from_octave_str_path (const octave_pq_connection &conn, | |
1465 const octave_value &ov, oct_pq_dynvec_t &val) | |
1466 { | |
1467 return 1; | |
1468 } | |
1469 | |
1470 int from_octave_bin_path (const octave_pq_connection &conn, | |
1471 const octave_value &ov, oct_pq_dynvec_t &val) | |
1472 { | |
1473 octave_scalar_map tp = ov.scalar_map_value (); | |
1474 if (error_state || ! tp.isfield ("closed") || ! tp.isfield ("path")) | |
1475 { | |
1476 error ("can not convert octave_value to path representation"); | |
1477 return 1; | |
1478 } | |
1479 | |
1480 octave_idx_type nel; | |
1481 | |
1482 char closed = char (tp.contents ("closed").bool_value ()); | |
1483 | |
1484 NDArray m = tp.contents ("path").array_value (); | |
1485 | |
1486 if (error_state || (nel = m.numel ()) % 2) | |
1487 { | |
1488 error ("can not convert octave_value to path representation"); | |
1489 return 1; | |
1490 } | |
1491 | |
1492 union | |
1493 { | |
1494 double d; | |
1495 int64_t i; | |
1496 } | |
1497 swap; | |
1498 | |
1499 int32_t np = nel / 2; | |
1500 | |
1501 val.push_back (closed); | |
1502 | |
1503 OCT_PQ_PUT(val, int32_t, htobe32 (np)) | |
1504 | |
1505 for (int id = 0; id < nel; id++) | |
1506 { | |
1507 swap.d = m(id); | |
1508 | |
1509 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1510 } | |
1511 | |
1512 return 0; | |
1513 } | |
1514 | |
1515 oct_pq_conv_t conv_path = {0, | |
1516 0, | |
1517 oct_pq_el_oids_t (), | |
1518 oct_pq_conv_cache_t (), | |
1519 false, | |
1520 false, | |
1521 false, | |
1522 "path", | |
1523 &to_octave_str_path, | |
1524 &to_octave_bin_path, | |
1525 &from_octave_str_path, | |
1526 &from_octave_bin_path}; | |
1527 | |
1528 /* end type path */ | |
11668
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1529 |
11698
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1530 /* type unknown */ |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1531 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1532 // These are pseudo-converters for postgresql type 'unknown'. They do |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1533 // nothing except signalling an error. The rationale is that the only |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1534 // values of type 'unknown' may be NULL, in which case the converter |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1535 // will not be called, but because a converter exists there won't be a |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1536 // "no converter found" error thrown. |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1537 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1538 int to_octave_str_unknown (const octave_pq_connection &conn, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1539 const char *c, octave_value &ov, int nb) |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1540 { |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1541 error ("can not convert postgresql type 'unknown'"); |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1542 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1543 return 1; |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1544 } |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1545 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1546 int to_octave_bin_unknown (const octave_pq_connection &conn, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1547 const char *c, octave_value &ov, int nb) |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1548 { |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1549 error ("can not convert postgresql type 'unknown'"); |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1550 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1551 return 1; |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1552 } |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1553 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1554 int from_octave_str_unknown (const octave_pq_connection &conn, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1555 const octave_value &ov, oct_pq_dynvec_t &val) |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1556 { |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1557 error ("can not convert postgresql type 'unknown'"); |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1558 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1559 return 1; |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1560 } |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1561 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1562 int from_octave_bin_unknown (const octave_pq_connection &conn, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1563 const octave_value &ov, oct_pq_dynvec_t &val) |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1564 { |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1565 error ("can not convert postgresql type 'unknown'"); |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1566 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1567 return 1; |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1568 } |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1569 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1570 oct_pq_conv_t conv_unknown = {0, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1571 0, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1572 oct_pq_el_oids_t (), |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1573 oct_pq_conv_cache_t (), |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1574 false, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1575 false, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1576 false, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1577 "unknown", |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1578 &to_octave_str_unknown, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1579 &to_octave_bin_unknown, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1580 &from_octave_str_unknown, |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1581 &from_octave_bin_unknown}; |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1582 |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1583 /* end type unknown */ |
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
1584 |
11708 | 1585 // helpers for network types |
1586 | |
1587 static inline | |
1588 int to_octave_bin_cidr_inet (const char *c, octave_value &ov, bool &cidr) | |
1589 { | |
1590 int8_t nb; | |
1591 | |
1592 if (*(c++) == AF_INET) | |
1593 { | |
1594 uint8NDArray a (dim_vector (5, 1), 0); | |
1595 | |
1596 a(4) = uint8_t (*(c++)); // number of set mask bits | |
1597 | |
1598 cidr = *(c++); | |
1599 | |
1600 nb = *(c++); | |
1601 | |
1602 if (nb < 0) | |
1603 nb = 0; | |
1604 | |
1605 if (nb > 4) | |
1606 { | |
1607 error ("internal error: received too many bytes for AF_INET type"); | |
1608 | |
1609 return 1; | |
1610 } | |
1611 | |
1612 for (int8_t i = 0; i < nb; i++, c++) | |
1613 a(i) = uint8_t (*c); | |
1614 | |
1615 ov = octave_value (a); | |
1616 } | |
1617 else | |
1618 { | |
1619 uint16NDArray a (dim_vector (9, 1), 0); | |
1620 | |
1621 a(8) = uint16_t (uint8_t (*(c++))); // number of set mask bits | |
1622 | |
1623 cidr = *(c++); | |
1624 | |
1625 nb = *(c++); | |
1626 | |
1627 if (nb < 0) | |
1628 nb = 0; | |
1629 | |
1630 if (nb > 16) | |
1631 { | |
1632 error ("internal error: received too many bytes for AF_INET6 type"); | |
1633 | |
1634 return 1; | |
1635 } | |
1636 | |
1637 int8_t n = nb / 2; | |
1638 bool odd = nb % 2; | |
1639 | |
1640 for (int8_t i = 0; i < n; i++, c += 2) | |
1641 a(i) = uint16_t (be16toh (*((uint16_t *) c))); | |
1642 | |
1643 if (odd) | |
1644 { | |
1645 uint16_t tp = *c; | |
1646 | |
1647 a(n) = uint16_t (be16toh (tp)); | |
1648 } | |
1649 | |
1650 ov = octave_value (a); | |
1651 } | |
1652 | |
1653 return 0; | |
1654 } | |
1655 | |
1656 static inline | |
1657 int from_octave_bin_cidr_inet (const octave_value &ov, oct_pq_dynvec_t &val, | |
1658 bool cidr) | |
1659 { | |
1660 int nl = ov.numel (); | |
1661 | |
1662 uint8_t n_mbits; | |
1663 | |
1664 if (nl == 4 || nl == 5) | |
1665 { | |
1666 uint8NDArray a = ov.uint8_array_value (); | |
1667 | |
1668 if (error_state) | |
1669 { | |
1670 error ("can not convert octave_value to network type representation"); | |
1671 return 1; | |
1672 } | |
1673 | |
1674 if (nl == 5) | |
1675 n_mbits = a(4).value (); | |
1676 else | |
1677 n_mbits = 32; | |
1678 | |
1679 val.push_back (AF_INET); | |
1680 val.push_back (n_mbits); | |
1681 val.push_back (cidr); | |
1682 val.push_back (4); | |
1683 for (int i = 0; i < 4; i++) | |
1684 val.push_back (a(i).value ()); | |
1685 } | |
1686 else if (nl == 8 || nl == 9) | |
1687 { | |
1688 uint16NDArray a = ov.uint16_array_value (); | |
1689 | |
1690 if (error_state) | |
1691 { | |
1692 error ("can not convert octave_value to network type representation"); | |
1693 return 1; | |
1694 } | |
1695 | |
1696 if (nl == 9) | |
1697 n_mbits = a(8).value (); | |
1698 else | |
1699 n_mbits = 128; | |
1700 | |
1701 val.push_back (PGSQL_AF_INET6); | |
1702 val.push_back (n_mbits); | |
1703 val.push_back (cidr); | |
1704 val.push_back (16); | |
1705 for (int i = 0; i < 8; i++) | |
1706 { | |
1707 OCT_PQ_PUT(val, uint16_t, htobe16(a(i).value ())) | |
1708 } | |
1709 } | |
1710 else | |
1711 { | |
1712 error ("invalid network type representation"); | |
1713 return 1; | |
1714 } | |
1715 | |
1716 return 0; | |
1717 } | |
1718 | |
1719 // end helpers for network types | |
1720 | |
1721 /* type cidr */ | |
1722 | |
1723 int to_octave_str_cidr (const octave_pq_connection &conn, | |
1724 const char *c, octave_value &ov, int nb) | |
1725 { | |
1726 return 1; | |
1727 } | |
1728 | |
1729 int to_octave_bin_cidr (const octave_pq_connection &conn, | |
1730 const char *c, octave_value &ov, int nb) | |
1731 { | |
1732 bool cidr = false; | |
1733 | |
1734 if (to_octave_bin_cidr_inet (c, ov, cidr)) | |
1735 return 1; | |
1736 | |
1737 if (! cidr) | |
1738 { | |
1739 error ("internal error: unexpected flag in cidr type"); | |
1740 | |
1741 return 1; | |
1742 } | |
1743 | |
1744 return 0; | |
1745 } | |
1746 | |
1747 int from_octave_str_cidr (const octave_pq_connection &conn, | |
1748 const octave_value &ov, oct_pq_dynvec_t &val) | |
1749 { | |
1750 return 1; | |
1751 } | |
1752 | |
1753 int from_octave_bin_cidr (const octave_pq_connection &conn, | |
1754 const octave_value &ov, oct_pq_dynvec_t &val) | |
1755 { | |
1756 return from_octave_bin_cidr_inet (ov, val, true); | |
1757 } | |
1758 | |
1759 oct_pq_conv_t conv_cidr = {0, | |
1760 0, | |
1761 oct_pq_el_oids_t (), | |
1762 oct_pq_conv_cache_t (), | |
1763 false, | |
1764 false, | |
1765 false, | |
1766 "cidr", | |
1767 &to_octave_str_cidr, | |
1768 &to_octave_bin_cidr, | |
1769 &from_octave_str_cidr, | |
1770 &from_octave_bin_cidr}; | |
1771 | |
1772 /* end type cidr */ | |
1773 | |
1774 /* type inet */ | |
1775 | |
1776 int to_octave_str_inet (const octave_pq_connection &conn, | |
1777 const char *c, octave_value &ov, int nb) | |
1778 { | |
1779 return 1; | |
1780 } | |
1781 | |
1782 int to_octave_bin_inet (const octave_pq_connection &conn, | |
1783 const char *c, octave_value &ov, int nb) | |
1784 { | |
1785 bool cidr = false; | |
1786 | |
1787 if (to_octave_bin_cidr_inet (c, ov, cidr)) | |
1788 return 1; | |
1789 | |
1790 if (cidr) | |
1791 { | |
1792 error ("internal error: unexpected flag in inet type"); | |
1793 | |
1794 return 1; | |
1795 } | |
1796 | |
1797 return 0; | |
1798 } | |
1799 | |
1800 int from_octave_str_inet (const octave_pq_connection &conn, | |
1801 const octave_value &ov, oct_pq_dynvec_t &val) | |
1802 { | |
1803 return 1; | |
1804 } | |
1805 | |
1806 int from_octave_bin_inet (const octave_pq_connection &conn, | |
1807 const octave_value &ov, oct_pq_dynvec_t &val) | |
1808 { | |
1809 return from_octave_bin_cidr_inet (ov, val, false); | |
1810 } | |
1811 | |
1812 oct_pq_conv_t conv_inet = {0, | |
1813 0, | |
1814 oct_pq_el_oids_t (), | |
1815 oct_pq_conv_cache_t (), | |
1816 false, | |
1817 false, | |
1818 false, | |
1819 "inet", | |
1820 &to_octave_str_inet, | |
1821 &to_octave_bin_inet, | |
1822 &from_octave_str_inet, | |
1823 &from_octave_bin_inet}; | |
1824 | |
1825 /* end type inet */ | |
1826 | |
1827 /* type macaddr */ | |
1828 | |
1829 int to_octave_str_macaddr (const octave_pq_connection &conn, | |
1830 const char *c, octave_value &ov, int nb) | |
1831 { | |
1832 return 1; | |
1833 } | |
1834 | |
1835 int to_octave_bin_macaddr (const octave_pq_connection &conn, | |
1836 const char *c, octave_value &ov, int nb) | |
1837 { | |
1838 uint8NDArray a (dim_vector (6, 1)); | |
1839 | |
1840 for (int i = 0; i < 6; i++, c++) | |
1841 a(i) = uint8_t (*c); | |
1842 | |
1843 ov = octave_value (a); | |
1844 | |
1845 return 0; | |
1846 } | |
1847 | |
1848 int from_octave_str_macaddr (const octave_pq_connection &conn, | |
1849 const octave_value &ov, oct_pq_dynvec_t &val) | |
1850 { | |
1851 return 1; | |
1852 } | |
1853 | |
1854 int from_octave_bin_macaddr (const octave_pq_connection &conn, | |
1855 const octave_value &ov, oct_pq_dynvec_t &val) | |
1856 { | |
1857 uint8NDArray a = ov.uint8_array_value (); | |
1858 | |
1859 if (error_state) | |
1860 { | |
1861 error ("can not convert octave_value to macaddr representation"); | |
1862 return 1; | |
1863 } | |
1864 | |
1865 if (a.numel () != 6) | |
1866 { | |
1867 error ("macaddr representation must have 6 elements"); | |
1868 return 1; | |
1869 } | |
1870 | |
1871 for (int i = 0; i < 6; i++) | |
1872 val.push_back (a(i).value ()); | |
1873 | |
1874 return 0; | |
1875 } | |
1876 | |
1877 oct_pq_conv_t conv_macaddr = {0, | |
1878 0, | |
1879 oct_pq_el_oids_t (), | |
1880 oct_pq_conv_cache_t (), | |
1881 false, | |
1882 false, | |
1883 false, | |
1884 "macaddr", | |
1885 &to_octave_str_macaddr, | |
1886 &to_octave_bin_macaddr, | |
1887 &from_octave_str_macaddr, | |
1888 &from_octave_bin_macaddr}; | |
1889 | |
1890 /* end type macaddr */ | |
1891 | |
11710 | 1892 /* type bit */ |
1893 | |
1894 int to_octave_str_bit (const octave_pq_connection &conn, | |
1895 const char *c, octave_value &ov, int nb) | |
1896 { | |
1897 return 1; | |
1898 } | |
1899 | |
1900 int to_octave_bin_bit (const octave_pq_connection &conn, | |
1901 const char *c, octave_value &ov, int nb) | |
1902 { | |
1903 int32_t nbits = int32_t (be32toh (*((int32_t *) c))); | |
1904 | |
1905 c += 4; | |
1906 | |
1907 int32_t nbytes = (nbits + 7) / 8; | |
1908 | |
1909 uint8NDArray a (dim_vector (nbytes, 1)); | |
1910 | |
1911 for (int i = 0; i < nbytes; i++, c++) | |
1912 a(i) = uint8_t (*c); | |
1913 | |
1914 octave_scalar_map tp; | |
1915 tp.assign ("bitlen", octave_value (octave_int32 (nbits))); | |
1916 tp.assign ("bits", octave_value (a)); | |
1917 | |
1918 ov = octave_value (tp); | |
1919 | |
1920 return 0; | |
1921 } | |
1922 | |
1923 int from_octave_str_bit (const octave_pq_connection &conn, | |
1924 const octave_value &ov, oct_pq_dynvec_t &val) | |
1925 { | |
1926 return 1; | |
1927 } | |
1928 | |
1929 int from_octave_bin_bit (const octave_pq_connection &conn, | |
1930 const octave_value &ov, oct_pq_dynvec_t &val) | |
1931 { | |
1932 octave_scalar_map tp = ov.scalar_map_value (); | |
1933 if (error_state || ! tp.isfield ("bitlen") || ! tp.isfield ("bits")) | |
1934 { | |
1935 error ("can not convert octave_value to bitstring representation"); | |
1936 return 1; | |
1937 } | |
1938 | |
1939 int32_t nbits = tp.contents ("bitlen").int_value (); | |
1940 | |
1941 uint8NDArray a = tp.contents ("bits").uint8_array_value (); | |
1942 | |
1943 if (error_state || nbits < 0) | |
1944 { | |
1945 error ("can not convert octave_value to bitstring representation"); | |
1946 return 1; | |
1947 } | |
1948 | |
1949 int32_t nbytes = (nbits + 7) / 8; | |
1950 | |
1951 if (a.numel () != nbytes) | |
1952 { | |
1953 error ("wrong number of elements in bitstring representation"); | |
1954 return 1; | |
1955 } | |
1956 | |
1957 OCT_PQ_PUT(val, int32_t, htobe32 (nbits)) | |
1958 | |
1959 for (int i = 0; i < nbytes; i++) | |
1960 val.push_back (a(i).value ()); | |
1961 | |
1962 return 0; | |
1963 } | |
1964 | |
1965 oct_pq_conv_t conv_bit = {0, | |
1966 0, | |
1967 oct_pq_el_oids_t (), | |
1968 oct_pq_conv_cache_t (), | |
1969 false, | |
1970 false, | |
1971 false, | |
1972 "bit", | |
1973 &to_octave_str_bit, | |
1974 &to_octave_bin_bit, | |
1975 &from_octave_str_bit, | |
1976 &from_octave_bin_bit}; | |
1977 | |
1978 /* end type bit */ | |
1979 | |
1980 /* type varbit */ | |
1981 | |
1982 oct_pq_conv_t conv_varbit = {0, | |
1983 0, | |
1984 oct_pq_el_oids_t (), | |
1985 oct_pq_conv_cache_t (), | |
1986 false, | |
1987 false, | |
1988 false, | |
1989 "varbit", | |
1990 &to_octave_str_bit, | |
1991 &to_octave_bin_bit, | |
1992 &from_octave_str_bit, | |
1993 &from_octave_bin_bit}; | |
1994 | |
1995 /* end type varbit */ | |
1996 | |
11712 | 1997 /* type uuid */ |
1998 | |
1999 int to_octave_str_uuid (const octave_pq_connection &conn, | |
2000 const char *c, octave_value &ov, int nb) | |
2001 { | |
2002 return 1; | |
2003 } | |
2004 | |
2005 int to_octave_bin_uuid (const octave_pq_connection &conn, | |
2006 const char *c, octave_value &ov, int nb) | |
2007 { | |
2008 uint8NDArray m (dim_vector (16, 1)); | |
2009 | |
2010 uint8_t *p = (uint8_t *) m.fortran_vec (); | |
2011 for (int i = 0; i < 16; i++, c++) | |
2012 *(p++) = uint8_t (*c); | |
2013 | |
2014 ov = octave_value (m); | |
2015 | |
2016 return 0; | |
2017 } | |
2018 | |
2019 int from_octave_str_uuid (const octave_pq_connection &conn, | |
2020 const octave_value &ov, oct_pq_dynvec_t &val) | |
2021 { | |
2022 return 1; | |
2023 } | |
2024 | |
2025 int from_octave_bin_uuid (const octave_pq_connection &conn, | |
2026 const octave_value &ov, oct_pq_dynvec_t &val) | |
2027 { | |
2028 uint8NDArray b = ov.uint8_array_value (); | |
2029 | |
2030 if (error_state) | |
2031 { | |
2032 error ("can not convert octave_value to uuid representation"); | |
2033 return 1; | |
2034 } | |
2035 | |
2036 if (b.numel () != 16) | |
2037 { | |
2038 error ("uuid representation must have 16 elements"); | |
2039 return 1; | |
2040 } | |
2041 | |
2042 for (int i = 0; i < 16; i++) | |
2043 val.push_back (b(i).value ()); | |
2044 | |
2045 return 0; | |
2046 } | |
2047 | |
2048 oct_pq_conv_t conv_uuid = {0, | |
2049 0, | |
2050 oct_pq_el_oids_t (), | |
2051 oct_pq_conv_cache_t (), | |
2052 false, | |
2053 false, | |
2054 false, | |
2055 "uuid", | |
2056 &to_octave_str_uuid, | |
2057 &to_octave_bin_uuid, | |
2058 &from_octave_str_uuid, | |
2059 &from_octave_bin_uuid}; | |
2060 | |
2061 /* end type uuid */ | |
2062 | |
2063 /* type xml */ | |
2064 | |
2065 int to_octave_str_xml (const octave_pq_connection &conn, | |
2066 const char *c, octave_value &ov, int nb) | |
2067 { | |
2068 return 1; | |
2069 } | |
2070 | |
2071 int to_octave_bin_xml (const octave_pq_connection &conn, | |
2072 const char *c, octave_value &ov, int nb) | |
2073 { | |
2074 std::string s (c, nb); | |
2075 | |
2076 ov = octave_value (s); | |
2077 | |
2078 return 0; | |
2079 } | |
2080 | |
2081 int from_octave_str_xml (const octave_pq_connection &conn, | |
2082 const octave_value &ov, oct_pq_dynvec_t &val) | |
2083 { | |
2084 return 1; | |
2085 } | |
2086 | |
2087 int from_octave_bin_xml (const octave_pq_connection &conn, | |
2088 const octave_value &ov, oct_pq_dynvec_t &val) | |
2089 { | |
2090 std::string s = ov.string_value (); | |
2091 | |
2092 if (error_state) | |
2093 { | |
2094 error ("can not convert octave_value to string"); | |
2095 return 1; | |
2096 } | |
2097 | |
2098 octave_idx_type l = s.size (); | |
2099 | |
2100 for (int i = 0; i < l; i++) | |
2101 val.push_back (s[i]); | |
2102 | |
2103 return 0; | |
2104 } | |
2105 | |
2106 oct_pq_conv_t conv_xml = {0, | |
2107 0, | |
2108 oct_pq_el_oids_t (), | |
2109 oct_pq_conv_cache_t (), | |
2110 false, | |
2111 false, | |
2112 false, | |
2113 "xml", | |
2114 &to_octave_str_text, | |
2115 &to_octave_bin_text, | |
2116 &from_octave_str_text, | |
2117 &from_octave_bin_text}; | |
2118 | |
2119 /* end type xml */ | |
2120 | |
11715
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2121 /* type record */ |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2122 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2123 int to_octave_str_record (const octave_pq_connection &conn, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2124 const char *c, octave_value &ov, int nb) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2125 { |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2126 return 1; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2127 } |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2128 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2129 int to_octave_bin_record (const octave_pq_connection &conn, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2130 const char *v, octave_value &ov, int nb) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2131 { |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2132 const char *p = v; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2133 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2134 // ncols |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2135 OCT_PQ_DECL_GET_INT32(nl, p, int32_t) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2136 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2137 // elements |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2138 Cell c (nl, 1); |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2139 for (int i = 0; i < nl; i++) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2140 { |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2141 // element OID |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2142 OCT_PQ_DECL_GET_INT32(oid, p, uint32_t) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2143 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2144 OCT_PQ_DECL_GET_INT32(null_id, p, int32_t) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2145 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2146 if (null_id == -1) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2147 // NULL |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2148 c(i) = octave_value (octave_NA); |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2149 else |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2150 { |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2151 uint32_t nb_el = uint32_t (null_id); |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2152 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2153 oct_pq_conv_t *el_conv; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2154 pq_oct_type_t oct_type; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2155 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2156 if (! (el_conv = pgtype_from_spec (conn, oid, oct_type))) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2157 return 1; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2158 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2159 octave_value el; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2160 switch (oct_type) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2161 { |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2162 case simple: |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2163 if (el_conv->to_octave_bin (conn, p, el, nb_el)) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2164 return 1; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2165 break; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2166 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2167 case array: |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2168 if (to_octave_bin_array (conn, p, el, nb_el, el_conv)) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2169 return 1; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2170 break; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2171 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2172 case composite: |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2173 if (to_octave_bin_composite (conn, p, el, nb_el, el_conv)) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2174 return 1; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2175 break; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2176 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2177 default: |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2178 // should not get here |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2179 error ("'record' converter: internal error, undefined type identifier"); |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2180 return 1; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2181 } |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2182 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2183 p += nb_el; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2184 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2185 c(i) = el; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2186 } |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2187 } |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2188 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2189 ov = octave_value (c); |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2190 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2191 return 0; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2192 } |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2193 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2194 int from_octave_str_record (const octave_pq_connection &conn, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2195 const octave_value &ov, oct_pq_dynvec_t &val) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2196 { |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2197 return 1; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2198 } |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2199 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2200 int from_octave_bin_record (const octave_pq_connection &conn, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2201 const octave_value &ov, oct_pq_dynvec_t &val) |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2202 { |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2203 error ("Type 'record' can't be sent to postgresql."); |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2204 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2205 return 1; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2206 } |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2207 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2208 oct_pq_conv_t conv_record = {0, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2209 0, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2210 oct_pq_el_oids_t (), |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2211 oct_pq_conv_cache_t (), |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2212 false, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2213 false, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2214 false, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2215 "record", |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2216 &to_octave_str_record, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2217 &to_octave_bin_record, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2218 &from_octave_str_record, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2219 &from_octave_bin_record}; |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2220 |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2221 /* end type record */ |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2222 |
11429 | 2223 oct_pq_conv_t *t_conv_ptrs[OCT_PQ_NUM_CONVERTERS] = {&conv_bool, |
2224 &conv_oid, | |
2225 &conv_float8, | |
2226 &conv_float4, | |
2227 &conv_text, | |
2228 &conv_varchar, | |
2229 &conv_bpchar, | |
2230 &conv_name, | |
2231 &conv_bytea, | |
2232 &conv_int2, | |
2233 &conv_int4, | |
2234 &conv_int8, | |
11661 | 2235 &conv_money, |
11667 | 2236 &conv_timestamp, |
11668
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
2237 &conv_timestamptz, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
2238 &conv_interval, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
2239 &conv_time, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
2240 &conv_timetz, |
11697 | 2241 &conv_date, |
2242 &conv_point, | |
2243 &conv_lseg, | |
2244 &conv_line, | |
2245 &conv_box, | |
2246 &conv_circle, | |
2247 &conv_polygon, | |
11698
b3cbebad8a26
Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents:
11697
diff
changeset
|
2248 &conv_path, |
11708 | 2249 &conv_unknown, |
2250 &conv_cidr, | |
2251 &conv_inet, | |
11710 | 2252 &conv_macaddr, |
2253 &conv_bit, | |
11712 | 2254 &conv_varbit, |
2255 &conv_uuid, | |
11715
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2256 &conv_xml, |
ed5361361a0f
Added converter for type 'record'. Some 'const' corrections.
i7tiol
parents:
11712
diff
changeset
|
2257 &conv_record}; |
11429 | 2258 |
2259 oct_pq_conv_ptrs_t conv_ptrs (OCT_PQ_NUM_CONVERTERS, t_conv_ptrs); |