Mercurial > forge
annotate main/database/src/converters.cc @ 11697:9e624fa135a1 octave-forge
Added converters for geometric types.
author | i7tiol |
---|---|
date | Sun, 12 May 2013 10:19:34 +0000 |
parents | abd563353849 |
children | b3cbebad8a26 |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
28 #include "converters.h" |
11661 | 29 #include "pq_connection.h" |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
30 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
31 // remember to adjust OCT_PQ_NUM_CONVERTERS in converters.h |
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 // helper function for debugging |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
34 void print_conv (oct_pq_conv_t *c) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
35 { |
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
|
36 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
|
37 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
|
38 |
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
|
39 printf (", el_oids:"); |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11553
diff
changeset
|
40 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
|
41 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
|
42 |
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 printf ("\n"); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
44 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
45 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
46 /* type bool */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
47 |
11657 | 48 int to_octave_str_bool (const octave_pq_connection &conn, |
49 const char *c, octave_value &ov, int nb) | |
11394
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 bool tp = (*c == 't' ? true : false); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
52 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
53 ov = octave_value (tp); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
54 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
55 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
56 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
57 |
11657 | 58 int to_octave_bin_bool (const octave_pq_connection &conn, |
59 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
60 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
61 ov = octave_value (bool (*c)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
62 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
63 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
64 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
65 |
11657 | 66 int from_octave_str_bool (const octave_pq_connection &conn, |
67 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
68 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
69 bool b = ov.bool_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
70 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
71 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
72 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
73 error ("can not convert octave_value to bool value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
74 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
75 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
76 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
77 val.push_back (b ? '1' : '0'); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
78 val.push_back ('\0'); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
79 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
80 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
81 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
82 |
11657 | 83 int from_octave_bin_bool (const octave_pq_connection &conn, |
84 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
85 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
86 bool b = ov.bool_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
87 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
88 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
89 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
90 error ("can not convert octave_value to bool value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
91 return 1; |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
94 val.push_back (char (b)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
95 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
96 return 0; |
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 oct_pq_conv_t conv_bool = {0, // 16 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
100 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
|
101 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
102 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
103 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
104 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
105 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
106 "bool", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
107 &to_octave_str_bool, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
108 &to_octave_bin_bool, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
109 &from_octave_str_bool, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
110 &from_octave_bin_bool}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
111 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
112 /* end type bool */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
113 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
114 /* type oid */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
115 |
11657 | 116 int to_octave_str_oid (const octave_pq_connection &conn, |
117 const char *c, octave_value &ov, int nb) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
120 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
121 |
11657 | 122 int to_octave_bin_oid (const octave_pq_connection &conn, |
123 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
124 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
125 ov = octave_value (octave_uint32 (be32toh (*((uint32_t *) c)))); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
126 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
127 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
128 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
129 |
11657 | 130 int from_octave_str_oid (const octave_pq_connection &conn, |
131 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
132 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
133 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
134 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
135 |
11657 | 136 int from_octave_bin_oid (const octave_pq_connection &conn, |
137 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
138 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
139 uint32_t oid = ov.uint_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
140 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
141 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
142 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
143 error ("can not convert octave_value to oid value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
144 return 1; |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
147 OCT_PQ_PUT(val, uint32_t, htobe32 (oid)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
148 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
149 return 0; |
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_conv_t conv_oid = {0, // 26 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
153 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
|
154 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
155 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
156 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
157 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
158 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
159 "oid", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
160 &to_octave_str_oid, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
161 &to_octave_bin_oid, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
162 &from_octave_str_oid, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
163 &from_octave_bin_oid}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
164 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
165 /* end type oid */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
166 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
167 /* type float8 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
168 |
11657 | 169 int to_octave_str_float8 (const octave_pq_connection &conn, |
170 const char *c, octave_value &ov, int nb) | |
11394
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 // not implemented |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
173 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
174 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
175 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
176 |
11657 | 177 int to_octave_bin_float8 (const octave_pq_connection &conn, |
178 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
179 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
180 union |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
181 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
182 double d; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
183 int64_t i; |
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 swap; |
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 swap.i = be64toh (*((int64_t *) c)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
188 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
189 ov = octave_value (swap.d); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
190 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
191 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
192 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
193 |
11657 | 194 int from_octave_str_float8 (const octave_pq_connection &conn, |
195 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
196 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
197 // not implemented |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
198 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
199 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
200 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
201 |
11657 | 202 int from_octave_bin_float8 (const octave_pq_connection &conn, |
203 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
204 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
205 union |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
206 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
207 double d; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
208 int64_t i; |
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 swap; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
211 |
11655
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
212 swap.d = ov.double_value (); |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
213 |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
214 if (error_state) |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
215 { |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
216 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
|
217 return 1; |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
218 } |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
219 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
220 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
221 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
222 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
223 } |
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_conv_t conv_float8 = {0, // 701 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
226 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
|
227 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
228 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
229 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
230 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
231 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
232 "float8", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
233 &to_octave_str_float8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
234 &to_octave_bin_float8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
235 &from_octave_str_float8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
236 &from_octave_bin_float8}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
237 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
238 /* end type float8 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
239 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
240 /* type float4 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
241 |
11657 | 242 int to_octave_str_float4 (const octave_pq_connection &conn, |
243 const char *c, octave_value &ov, int nb) | |
11394
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 // not implemented |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
246 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
247 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
248 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
249 |
11657 | 250 int to_octave_bin_float4 (const octave_pq_connection &conn, |
251 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
252 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
253 union |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
254 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
255 float f; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
256 int32_t i; |
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 swap; |
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 swap.i = be32toh (*((int32_t *) c)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
261 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
262 ov = octave_value (swap.f); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
263 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
264 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
265 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
266 |
11657 | 267 int from_octave_str_float4 (const octave_pq_connection &conn, |
268 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
269 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
270 // not implemented |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
271 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
272 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
273 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
274 |
11657 | 275 int from_octave_bin_float4 (const octave_pq_connection &conn, |
276 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
277 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
278 union |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
279 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
280 float f; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
281 int32_t i; |
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 swap; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
284 |
11655
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
285 swap.f = ov.float_value (); |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
286 |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
287 if (error_state) |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
288 { |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
289 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
|
290 return 1; |
6bbb1584d933
More efficient code order in float converters (probably useless with -O0).
i7tiol
parents:
11645
diff
changeset
|
291 } |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
292 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
293 OCT_PQ_PUT(val, int32_t, htobe32 (swap.i)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
294 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
295 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
296 } |
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_conv_t conv_float4 = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
299 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
|
300 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
301 oct_pq_conv_cache_t (), |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
302 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
303 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
304 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
305 "float4", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
306 &to_octave_str_float4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
307 &to_octave_bin_float4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
308 &from_octave_str_float4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
309 &from_octave_bin_float4}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
310 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
311 /* end type float4 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
312 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
313 /* type bytea */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
314 |
11657 | 315 int to_octave_str_bytea (const octave_pq_connection &conn, |
316 const char *c, octave_value &ov, int nb) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
319 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
320 |
11657 | 321 int to_octave_bin_bytea (const octave_pq_connection &conn, |
322 const char *c, octave_value &ov, int nb) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
323 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
324 uint8NDArray m (dim_vector (nb, 1)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
325 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
326 uint8_t *p = (uint8_t *) m.fortran_vec (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
327 for (octave_idx_type i = 0; i < nb; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
328 *(p++) = uint8_t (*(c++)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
329 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
330 ov = octave_value (m); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
331 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
332 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
333 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
334 |
11657 | 335 int from_octave_str_bytea (const octave_pq_connection &conn, |
336 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
337 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
338 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
339 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
340 |
11657 | 341 int from_octave_bin_bytea (const octave_pq_connection &conn, |
342 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
343 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
344 uint8NDArray b = ov.uint8_array_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
345 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
346 if (! error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
347 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
348 dim_vector dv = b.dims (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
349 if (dv.length () > 2 || (dv(0) > 1 && dv(1) > 1)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
350 error ("bytea representation must be one-dimensional"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
351 } |
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 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
354 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
355 error ("can not convert octave_value to bytea representation"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
356 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
357 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
358 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
359 octave_idx_type nl = b.numel (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
360 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
361 for (int i = 0; i < nl; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
362 val.push_back (b(i).value ()); |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
365 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
366 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
367 oct_pq_conv_t conv_bytea = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
368 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
|
369 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
370 oct_pq_conv_cache_t (), |
11394
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 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
373 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
374 "bytea", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
375 &to_octave_str_bytea, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
376 &to_octave_bin_bytea, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
377 &from_octave_str_bytea, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
378 &from_octave_bin_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 /* end type bytea */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
381 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
382 /* type text */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
383 |
11657 | 384 int to_octave_str_text (const octave_pq_connection &conn, |
385 const char *c, octave_value &ov, int nb) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
388 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
389 |
11657 | 390 int to_octave_bin_text (const octave_pq_connection &conn, |
391 const char *c, octave_value &ov, int nb) | |
11394
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 std::string s (c, nb); |
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 ov = octave_value (s); |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
398 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
399 |
11657 | 400 int from_octave_str_text (const octave_pq_connection &conn, |
401 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
404 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
405 |
11657 | 406 int from_octave_bin_text (const octave_pq_connection &conn, |
407 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 std::string s = ov.string_value (); |
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 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
412 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
413 error ("can not convert octave_value to string"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
414 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
415 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
416 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
417 octave_idx_type l = s.size (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
418 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
419 for (int i = 0; i < l; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
420 val.push_back (s[i]); |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
423 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
424 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
425 oct_pq_conv_t conv_text = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
426 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
|
427 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
428 oct_pq_conv_cache_t (), |
11394
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 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
431 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
432 "text", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
433 &to_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
434 &to_octave_bin_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
435 &from_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
436 &from_octave_bin_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 /* end type text */ |
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 /* type varchar */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
441 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
442 oct_pq_conv_t conv_varchar = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
443 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
|
444 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
445 oct_pq_conv_cache_t (), |
11394
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 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
448 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
449 "varchar", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
450 &to_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
451 &to_octave_bin_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
452 &from_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
453 &from_octave_bin_text}; |
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 /* end type varchar */ |
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 /* type bpchar */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
458 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
459 oct_pq_conv_t conv_bpchar = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
460 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
|
461 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
462 oct_pq_conv_cache_t (), |
11394
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 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
465 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
466 "bpchar", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
467 &to_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
468 &to_octave_bin_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
469 &from_octave_str_text, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
470 &from_octave_bin_text}; |
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 /* end type bpchar */ |
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 /* type name */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
475 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
476 oct_pq_conv_t conv_name = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
477 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
|
478 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
479 oct_pq_conv_cache_t (), |
11394
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 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
482 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
483 "name", |
11658 | 484 &to_octave_str_text, |
485 &to_octave_bin_text, | |
486 &from_octave_str_text, | |
487 &from_octave_bin_text}; | |
11394
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 /* end type name */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
490 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
491 /* type int2 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
492 |
11657 | 493 int to_octave_str_int2 (const octave_pq_connection &conn, |
494 const char *c, octave_value &ov, int nb) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
497 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
498 |
11657 | 499 int to_octave_bin_int2 (const octave_pq_connection &conn, |
500 const char *c, octave_value &ov, int nb) | |
11394
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 ov = octave_value (octave_int16 (int16_t (be16toh (*((int16_t *) c))))); |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
505 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
506 |
11657 | 507 int from_octave_str_int2 (const octave_pq_connection &conn, |
508 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
511 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
512 |
11657 | 513 int from_octave_bin_int2 (const octave_pq_connection &conn, |
514 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 int16_t i2 = ov.int_value (); |
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 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
519 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
520 error ("can not convert octave_value to int2 value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
521 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
522 } |
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 OCT_PQ_PUT(val, int16_t, htobe16 (i2)) |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
527 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
528 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
529 oct_pq_conv_t conv_int2 = {0, // 26 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
530 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
|
531 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
532 oct_pq_conv_cache_t (), |
11394
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 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
535 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
536 "int2", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
537 &to_octave_str_int2, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
538 &to_octave_bin_int2, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
539 &from_octave_str_int2, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
540 &from_octave_bin_int2}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
541 |
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 /* end type int2 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
544 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
545 /* type int4 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
546 |
11657 | 547 int to_octave_str_int4 (const octave_pq_connection &conn, |
548 const char *c, octave_value &ov, int nb) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
551 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
552 |
11657 | 553 int to_octave_bin_int4 (const octave_pq_connection &conn, |
554 const char *c, octave_value &ov, int nb) | |
11394
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 ov = octave_value (octave_int32 (int32_t (be32toh (*((int32_t *) c))))); |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
559 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
560 |
11657 | 561 int from_octave_str_int4 (const octave_pq_connection &conn, |
562 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
565 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
566 |
11657 | 567 int from_octave_bin_int4 (const octave_pq_connection &conn, |
568 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 int32_t i4 = ov.int_value (); |
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 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
573 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
574 error ("can not convert octave_value to int4 value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
575 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
576 } |
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 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
581 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
582 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
583 oct_pq_conv_t conv_int4 = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
584 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
|
585 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
586 oct_pq_conv_cache_t (), |
11394
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 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
589 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
590 "int4", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
591 &to_octave_str_int4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
592 &to_octave_bin_int4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
593 &from_octave_str_int4, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
594 &from_octave_bin_int4}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
595 |
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 /* end type int4 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
598 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
599 /* type int8 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
600 |
11657 | 601 int to_octave_str_int8 (const octave_pq_connection &conn, |
602 const char *c, octave_value &ov, int nb) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
605 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
606 |
11657 | 607 int to_octave_bin_int8 (const octave_pq_connection &conn, |
608 const char *c, octave_value &ov, int nb) | |
11394
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 ov = octave_value (octave_int64 (int64_t (be64toh (*((int64_t *) c))))); |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
613 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
614 |
11657 | 615 int from_octave_str_int8 (const octave_pq_connection &conn, |
616 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
619 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
620 |
11657 | 621 int from_octave_bin_int8 (const octave_pq_connection &conn, |
622 const octave_value &ov, oct_pq_dynvec_t &val) | |
11394
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 int64_t i8 = ov.int64_scalar_value (); |
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 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
627 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
628 error ("can not convert octave_value to int8 value"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
629 return 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
630 } |
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 OCT_PQ_PUT(val, int64_t, htobe64 (i8)) |
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 return 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
635 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
636 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
637 oct_pq_conv_t conv_int8 = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
638 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
|
639 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
640 oct_pq_conv_cache_t (), |
11394
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 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
643 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
644 "int8", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
645 &to_octave_str_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
646 &to_octave_bin_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
647 &from_octave_str_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
648 &from_octave_bin_int8}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
649 |
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 /* end type int8 */ |
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 /* type money */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
654 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
655 oct_pq_conv_t conv_money = {0, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
656 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
|
657 oct_pq_el_oids_t (), |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11474
diff
changeset
|
658 oct_pq_conv_cache_t (), |
11394
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 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
661 false, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
662 "money", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
663 &to_octave_str_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
664 &to_octave_bin_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
665 &from_octave_str_int8, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
666 &from_octave_bin_int8}; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
667 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
668 /* end type money */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
669 |
11661 | 670 // helpers for time types |
671 | |
11667 | 672 static inline octave_value time_8byte_to_octave (const char *c, |
673 const bool &int_dt) | |
11661 | 674 { |
675 if (int_dt) | |
676 { | |
677 return octave_value (octave_int64 (int64_t (be64toh (*((int64_t *) c))))); | |
678 } | |
679 else | |
680 { | |
681 union | |
682 { | |
683 double d; | |
684 int64_t i; | |
685 } | |
686 swap; | |
687 | |
688 swap.i = be64toh (*((int64_t *) c)); | |
689 | |
690 return octave_value (swap.d); | |
691 } | |
692 } | |
693 | |
694 static inline int time_8byte_from_octave (const octave_value &ov, | |
695 oct_pq_dynvec_t &val, | |
11667 | 696 const bool &int_dt) |
11661 | 697 { |
698 if (int_dt) | |
699 { | |
700 // don't convert automatically because of possible overflow | |
701 if (ov.is_float_type ()) | |
702 { | |
703 error ("floating point octave_value provided for 8-byte time value, but postgresql is configured for int64"); | |
704 return 1; | |
705 } | |
706 | |
707 int64_t i8 = ov.int64_scalar_value (); | |
708 | |
709 if (error_state) | |
710 { | |
711 error ("can not convert octave_value to int64 time value"); | |
712 return 1; | |
713 } | |
714 | |
715 OCT_PQ_PUT(val, int64_t, htobe64 (i8)) | |
716 | |
717 return 0; | |
718 } | |
719 else | |
720 { | |
721 // don't convert automatically because of possible loss of accuracy | |
722 if (ov.is_integer_type ()) | |
723 { | |
724 error ("integer type octave_value provided for 8-byte time value, but postgresql is configured for double"); | |
725 return 1; | |
726 } | |
727 | |
728 union | |
729 { | |
730 double d; | |
731 int64_t i; | |
732 } | |
733 swap; | |
734 | |
735 swap.d = ov.double_value (); | |
736 | |
737 if (error_state) | |
738 { | |
739 error ("can not convert octave_value to double time value"); | |
740 return 1; | |
741 } | |
742 | |
743 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
744 | |
745 return 0; | |
746 } | |
747 } | |
748 | |
749 // end helpers for time types | |
750 | |
751 /* type timestamp */ | |
752 | |
753 int to_octave_str_timestamp (const octave_pq_connection &conn, | |
754 const char *c, octave_value &ov, int nb) | |
755 { | |
756 return 1; | |
757 } | |
758 | |
759 int to_octave_bin_timestamp (const octave_pq_connection &conn, | |
760 const char *c, octave_value &ov, int nb) | |
761 { | |
11667 | 762 ov = time_8byte_to_octave (c, conn.get_integer_datetimes ()); |
11661 | 763 |
764 return 0; | |
765 } | |
766 | |
767 int from_octave_str_timestamp (const octave_pq_connection &conn, | |
768 const octave_value &ov, oct_pq_dynvec_t &val) | |
769 { | |
770 return 1; | |
771 } | |
772 | |
773 int from_octave_bin_timestamp (const octave_pq_connection &conn, | |
774 const octave_value &ov, oct_pq_dynvec_t &val) | |
775 { | |
11667 | 776 return (time_8byte_from_octave (ov, val, conn.get_integer_datetimes ())); |
11661 | 777 } |
778 | |
779 oct_pq_conv_t conv_timestamp = {0, | |
780 0, | |
781 oct_pq_el_oids_t (), | |
782 oct_pq_conv_cache_t (), | |
783 false, | |
784 false, | |
785 false, | |
786 "timestamp", | |
787 &to_octave_str_timestamp, | |
788 &to_octave_bin_timestamp, | |
789 &from_octave_str_timestamp, | |
790 &from_octave_bin_timestamp}; | |
791 | |
792 /* end type timestamp */ | |
793 | |
11667 | 794 /* type timestamptz */ |
795 | |
796 oct_pq_conv_t conv_timestamptz = {0, | |
797 0, | |
798 oct_pq_el_oids_t (), | |
799 oct_pq_conv_cache_t (), | |
800 false, | |
801 false, | |
802 false, | |
803 "timestamptz", | |
804 &to_octave_str_timestamp, | |
805 &to_octave_bin_timestamp, | |
806 &from_octave_str_timestamp, | |
807 &from_octave_bin_timestamp}; | |
808 | |
809 /* end type timestamptz */ | |
810 | |
11668
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
811 /* type interval */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
812 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
813 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
|
814 const char *c, octave_value &ov, int nb) |
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 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
817 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
818 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
819 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
|
820 const char *c, octave_value &ov, int nb) |
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 Cell tp (dim_vector (3, 1)); |
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 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
|
825 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
826 c += 8; |
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 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
|
829 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
830 c += 4; |
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 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
|
833 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
834 ov = octave_value (tp); |
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 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
837 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
838 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
839 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
|
840 const octave_value &ov, oct_pq_dynvec_t &val) |
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 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
843 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
844 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
845 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
|
846 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
847 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
848 Cell iv = ov.cell_value (); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
849 if (error_state || iv.numel () != 3) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
850 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
851 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
|
852 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
853 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
854 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
855 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
|
856 return 1; |
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 for (int id = 1; id < 3; id++) |
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 int32_t i4 = iv(id).int_value (); |
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 if (error_state) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
863 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
864 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
|
865 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
866 } |
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 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
869 } |
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 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
872 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
873 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
874 oct_pq_conv_t conv_interval = {0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
875 0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
876 oct_pq_el_oids_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
877 oct_pq_conv_cache_t (), |
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 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
880 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
881 "interval", |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
882 &to_octave_str_interval, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
883 &to_octave_bin_interval, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
884 &from_octave_str_interval, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
885 &from_octave_bin_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 /* end type interval */ |
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 /* type time */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
890 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
891 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
|
892 const char *c, octave_value &ov, int nb) |
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 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
895 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
896 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
897 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
|
898 const char *c, octave_value &ov, int nb) |
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 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
|
901 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
902 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
903 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
904 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
905 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
|
906 const octave_value &ov, oct_pq_dynvec_t &val) |
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 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
909 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
910 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
911 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
|
912 const octave_value &ov, oct_pq_dynvec_t &val) |
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 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
|
915 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
916 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
917 oct_pq_conv_t conv_time = {0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
918 0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
919 oct_pq_el_oids_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
920 oct_pq_conv_cache_t (), |
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 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
923 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
924 "time", |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
925 &to_octave_str_time, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
926 &to_octave_bin_time, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
927 &from_octave_str_time, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
928 &from_octave_bin_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 /* end type time */ |
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 /* type timetz */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
933 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
934 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
|
935 const char *c, octave_value &ov, int nb) |
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 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
938 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
939 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
940 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
|
941 const char *c, octave_value &ov, int nb) |
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 Cell tp (dim_vector (2, 1)); |
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 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
|
946 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
947 c += 8; |
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 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
|
950 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
951 ov = octave_value (tp); |
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 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
954 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
955 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
956 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
|
957 const octave_value &ov, oct_pq_dynvec_t &val) |
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 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
960 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
961 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
962 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
|
963 const octave_value &ov, oct_pq_dynvec_t &val) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
964 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
965 Cell iv = ov.cell_value (); |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
966 if (error_state || iv.numel () != 2) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
967 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
968 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
|
969 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
970 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
971 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
972 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
|
973 return 1; |
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 int32_t i4 = iv(1).int_value (); |
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 if (error_state) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
978 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
979 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
|
980 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
981 } |
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 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) |
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 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
986 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
987 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
988 oct_pq_conv_t conv_timetz = {0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
989 0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
990 oct_pq_el_oids_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
991 oct_pq_conv_cache_t (), |
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 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
994 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
995 "timetz", |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
996 &to_octave_str_timetz, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
997 &to_octave_bin_timetz, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
998 &from_octave_str_timetz, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
999 &from_octave_bin_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 /* end type timetz */ |
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 /* type date */ |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1004 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1005 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
|
1006 const char *c, octave_value &ov, int nb) |
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 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1009 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1010 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1011 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
|
1012 const char *c, octave_value &ov, int nb) |
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 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
|
1015 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1016 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1017 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1018 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1019 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
|
1020 const octave_value &ov, oct_pq_dynvec_t &val) |
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 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1023 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1024 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1025 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
|
1026 const octave_value &ov, oct_pq_dynvec_t &val) |
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 int32_t i4 = ov.int_value (); |
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 if (error_state) |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1031 { |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1032 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
|
1033 return 1; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1034 } |
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 OCT_PQ_PUT(val, int32_t, htobe32 (i4)) |
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 return 0; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1039 } |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1040 |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1041 oct_pq_conv_t conv_date = {0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1042 0, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1043 oct_pq_el_oids_t (), |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1044 oct_pq_conv_cache_t (), |
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 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1047 false, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1048 "date", |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1049 &to_octave_str_date, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1050 &to_octave_bin_date, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1051 &from_octave_str_date, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1052 &from_octave_bin_date}; |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1053 |
11697 | 1054 /* end type date */ |
11668
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1055 |
11697 | 1056 /* type point */ |
1057 | |
1058 int to_octave_str_point (const octave_pq_connection &conn, | |
1059 const char *c, octave_value &ov, int nb) | |
1060 { | |
1061 return 1; | |
1062 } | |
1063 | |
1064 int to_octave_bin_point (const octave_pq_connection &conn, | |
1065 const char *c, octave_value &ov, int nb) | |
1066 { | |
1067 ColumnVector m (2); | |
1068 | |
1069 union | |
1070 { | |
1071 double d; | |
1072 int64_t i; | |
1073 } | |
1074 swap; | |
1075 | |
1076 for (int id = 0; id < 2; id++, c += 8) | |
1077 { | |
1078 swap.i = be64toh (*((int64_t *) c)); | |
1079 | |
1080 m(id) = swap.d; | |
1081 } | |
1082 | |
1083 ov = octave_value (m); | |
1084 | |
1085 return 0; | |
1086 } | |
1087 | |
1088 int from_octave_str_point (const octave_pq_connection &conn, | |
1089 const octave_value &ov, oct_pq_dynvec_t &val) | |
1090 { | |
1091 return 1; | |
1092 } | |
1093 | |
1094 int from_octave_bin_point (const octave_pq_connection &conn, | |
1095 const octave_value &ov, oct_pq_dynvec_t &val) | |
1096 { | |
1097 NDArray m = ov.array_value (); | |
1098 | |
1099 if (error_state || m.numel () != 2) | |
1100 { | |
1101 error ("can not convert octave_value to point representation"); | |
1102 return 1; | |
1103 } | |
1104 | |
1105 union | |
1106 { | |
1107 double d; | |
1108 int64_t i; | |
1109 } | |
1110 swap; | |
1111 | |
1112 for (int id = 0; id < 2; id++) | |
1113 { | |
1114 swap.d = m(id); | |
1115 | |
1116 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1117 } | |
1118 | |
1119 return 0; | |
1120 } | |
1121 | |
1122 oct_pq_conv_t conv_point = {0, | |
1123 0, | |
1124 oct_pq_el_oids_t (), | |
1125 oct_pq_conv_cache_t (), | |
1126 false, | |
1127 false, | |
1128 false, | |
1129 "point", | |
1130 &to_octave_str_point, | |
1131 &to_octave_bin_point, | |
1132 &from_octave_str_point, | |
1133 &from_octave_bin_point}; | |
1134 | |
1135 /* end type point */ | |
1136 | |
1137 /* type lseg */ | |
1138 | |
1139 int to_octave_str_lseg (const octave_pq_connection &conn, | |
1140 const char *c, octave_value &ov, int nb) | |
1141 { | |
1142 return 1; | |
1143 } | |
1144 | |
1145 int to_octave_bin_lseg (const octave_pq_connection &conn, | |
1146 const char *c, octave_value &ov, int nb) | |
1147 { | |
1148 Matrix m (2, 2); | |
1149 | |
1150 union | |
1151 { | |
1152 double d; | |
1153 int64_t i; | |
1154 } | |
1155 swap; | |
1156 | |
1157 for (int id = 0; id < 4; id++, c += 8) | |
1158 { | |
1159 swap.i = be64toh (*((int64_t *) c)); | |
1160 | |
1161 m(id) = swap.d; | |
1162 } | |
1163 | |
1164 ov = octave_value (m); | |
1165 | |
1166 return 0; | |
1167 } | |
1168 | |
1169 int from_octave_str_lseg (const octave_pq_connection &conn, | |
1170 const octave_value &ov, oct_pq_dynvec_t &val) | |
1171 { | |
1172 return 1; | |
1173 } | |
1174 | |
1175 int from_octave_bin_lseg (const octave_pq_connection &conn, | |
1176 const octave_value &ov, oct_pq_dynvec_t &val) | |
1177 { | |
1178 NDArray m = ov.array_value (); | |
1179 | |
1180 if (error_state || m.numel () != 4) | |
1181 { | |
1182 error ("can not convert octave_value to 4 doubles"); | |
1183 return 1; | |
1184 } | |
1185 | |
1186 union | |
1187 { | |
1188 double d; | |
1189 int64_t i; | |
1190 } | |
1191 swap; | |
1192 | |
1193 for (int id = 0; id < 4; id++) | |
1194 { | |
1195 swap.d = m(id); | |
1196 | |
1197 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1198 } | |
1199 | |
1200 return 0; | |
1201 } | |
1202 | |
1203 oct_pq_conv_t conv_lseg = {0, | |
1204 0, | |
1205 oct_pq_el_oids_t (), | |
1206 oct_pq_conv_cache_t (), | |
1207 false, | |
1208 false, | |
1209 false, | |
1210 "lseg", | |
1211 &to_octave_str_lseg, | |
1212 &to_octave_bin_lseg, | |
1213 &from_octave_str_lseg, | |
1214 &from_octave_bin_lseg}; | |
1215 | |
1216 /* end type lseg */ | |
1217 | |
1218 /* type line */ | |
1219 | |
1220 oct_pq_conv_t conv_line = {0, | |
1221 0, | |
1222 oct_pq_el_oids_t (), | |
1223 oct_pq_conv_cache_t (), | |
1224 false, | |
1225 false, | |
1226 false, | |
1227 "line", | |
1228 &to_octave_str_lseg, | |
1229 &to_octave_bin_lseg, | |
1230 &from_octave_str_lseg, | |
1231 &from_octave_bin_lseg}; | |
1232 | |
1233 /* end type line */ | |
1234 | |
1235 /* type box */ | |
1236 | |
1237 oct_pq_conv_t conv_box = {0, | |
1238 0, | |
1239 oct_pq_el_oids_t (), | |
1240 oct_pq_conv_cache_t (), | |
1241 false, | |
1242 false, | |
1243 false, | |
1244 "box", | |
1245 &to_octave_str_lseg, | |
1246 &to_octave_bin_lseg, | |
1247 &from_octave_str_lseg, | |
1248 &from_octave_bin_lseg}; | |
1249 | |
1250 /* end type box */ | |
1251 | |
1252 /* type circle */ | |
1253 | |
1254 int to_octave_str_circle (const octave_pq_connection &conn, | |
1255 const char *c, octave_value &ov, int nb) | |
1256 { | |
1257 return 1; | |
1258 } | |
1259 | |
1260 int to_octave_bin_circle (const octave_pq_connection &conn, | |
1261 const char *c, octave_value &ov, int nb) | |
1262 { | |
1263 ColumnVector m (3); | |
1264 | |
1265 union | |
1266 { | |
1267 double d; | |
1268 int64_t i; | |
1269 } | |
1270 swap; | |
1271 | |
1272 for (int id = 0; id < 3; id++, c += 8) | |
1273 { | |
1274 swap.i = be64toh (*((int64_t *) c)); | |
1275 | |
1276 m(id) = swap.d; | |
1277 } | |
1278 | |
1279 ov = octave_value (m); | |
1280 | |
1281 return 0; | |
1282 } | |
1283 | |
1284 int from_octave_str_circle (const octave_pq_connection &conn, | |
1285 const octave_value &ov, oct_pq_dynvec_t &val) | |
1286 { | |
1287 return 1; | |
1288 } | |
1289 | |
1290 int from_octave_bin_circle (const octave_pq_connection &conn, | |
1291 const octave_value &ov, oct_pq_dynvec_t &val) | |
1292 { | |
1293 NDArray m = ov.array_value (); | |
1294 | |
1295 if (error_state || m.numel () != 3) | |
1296 { | |
1297 error ("can not convert octave_value to circle representation"); | |
1298 return 1; | |
1299 } | |
1300 | |
1301 union | |
1302 { | |
1303 double d; | |
1304 int64_t i; | |
1305 } | |
1306 swap; | |
1307 | |
1308 for (int id = 0; id < 3; id++) | |
1309 { | |
1310 swap.d = m(id); | |
1311 | |
1312 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1313 } | |
1314 | |
1315 return 0; | |
1316 } | |
1317 | |
1318 oct_pq_conv_t conv_circle = {0, | |
1319 0, | |
1320 oct_pq_el_oids_t (), | |
1321 oct_pq_conv_cache_t (), | |
1322 false, | |
1323 false, | |
1324 false, | |
1325 "circle", | |
1326 &to_octave_str_circle, | |
1327 &to_octave_bin_circle, | |
1328 &from_octave_str_circle, | |
1329 &from_octave_bin_circle}; | |
1330 | |
1331 /* end type circle */ | |
1332 | |
1333 /* type polygon */ | |
1334 | |
1335 int to_octave_str_polygon (const octave_pq_connection &conn, | |
1336 const char *c, octave_value &ov, int nb) | |
1337 { | |
1338 return 1; | |
1339 } | |
1340 | |
1341 int to_octave_bin_polygon (const octave_pq_connection &conn, | |
1342 const char *c, octave_value &ov, int nb) | |
1343 { | |
1344 int32_t np = int32_t (be32toh (*((int32_t *) c))); | |
1345 | |
1346 c += 4; | |
1347 | |
1348 Matrix m (2, np); | |
1349 | |
1350 union | |
1351 { | |
1352 double d; | |
1353 int64_t i; | |
1354 } | |
1355 swap; | |
1356 | |
1357 for (int id = 0; id < np * 2; id++, c += 8) | |
1358 { | |
1359 swap.i = be64toh (*((int64_t *) c)); | |
1360 | |
1361 m(id) = swap.d; | |
1362 } | |
1363 | |
1364 ov = octave_value (m); | |
1365 | |
1366 return 0; | |
1367 } | |
1368 | |
1369 int from_octave_str_polygon (const octave_pq_connection &conn, | |
1370 const octave_value &ov, oct_pq_dynvec_t &val) | |
1371 { | |
1372 return 1; | |
1373 } | |
1374 | |
1375 int from_octave_bin_polygon (const octave_pq_connection &conn, | |
1376 const octave_value &ov, oct_pq_dynvec_t &val) | |
1377 { | |
1378 octave_idx_type nel; | |
1379 | |
1380 NDArray m = ov.array_value (); | |
1381 | |
1382 if (error_state || (nel = m.numel ()) % 2) | |
1383 { | |
1384 error ("can not convert octave_value to polygon representation"); | |
1385 return 1; | |
1386 } | |
1387 | |
1388 union | |
1389 { | |
1390 double d; | |
1391 int64_t i; | |
1392 } | |
1393 swap; | |
1394 | |
1395 int32_t np = nel / 2; | |
1396 | |
1397 OCT_PQ_PUT(val, int32_t, htobe32 (np)) | |
1398 | |
1399 for (int id = 0; id < nel; id++) | |
1400 { | |
1401 swap.d = m(id); | |
1402 | |
1403 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1404 } | |
1405 | |
1406 return 0; | |
1407 } | |
1408 | |
1409 oct_pq_conv_t conv_polygon = {0, | |
1410 0, | |
1411 oct_pq_el_oids_t (), | |
1412 oct_pq_conv_cache_t (), | |
1413 false, | |
1414 false, | |
1415 false, | |
1416 "polygon", | |
1417 &to_octave_str_polygon, | |
1418 &to_octave_bin_polygon, | |
1419 &from_octave_str_polygon, | |
1420 &from_octave_bin_polygon}; | |
1421 | |
1422 /* end type polygon */ | |
1423 | |
1424 /* type path */ | |
1425 | |
1426 int to_octave_str_path (const octave_pq_connection &conn, | |
1427 const char *c, octave_value &ov, int nb) | |
1428 { | |
1429 return 1; | |
1430 } | |
1431 | |
1432 int to_octave_bin_path (const octave_pq_connection &conn, | |
1433 const char *c, octave_value &ov, int nb) | |
1434 { | |
1435 bool closed = bool (*(c++)); | |
1436 | |
1437 int32_t np = int32_t (be32toh (*((int32_t *) c))); | |
1438 | |
1439 c += 4; | |
1440 | |
1441 Matrix m (2, np); | |
1442 | |
1443 union | |
1444 { | |
1445 double d; | |
1446 int64_t i; | |
1447 } | |
1448 swap; | |
1449 | |
1450 for (int id = 0; id < np * 2; id++, c += 8) | |
1451 { | |
1452 swap.i = be64toh (*((int64_t *) c)); | |
1453 | |
1454 m(id) = swap.d; | |
1455 } | |
1456 | |
1457 octave_scalar_map tp; | |
1458 tp.assign ("closed", octave_value (closed)); | |
1459 tp.assign ("path", octave_value (m)); | |
1460 | |
1461 ov = octave_value (tp); | |
1462 | |
1463 return 0; | |
1464 } | |
1465 | |
1466 int from_octave_str_path (const octave_pq_connection &conn, | |
1467 const octave_value &ov, oct_pq_dynvec_t &val) | |
1468 { | |
1469 return 1; | |
1470 } | |
1471 | |
1472 int from_octave_bin_path (const octave_pq_connection &conn, | |
1473 const octave_value &ov, oct_pq_dynvec_t &val) | |
1474 { | |
1475 octave_scalar_map tp = ov.scalar_map_value (); | |
1476 if (error_state || ! tp.isfield ("closed") || ! tp.isfield ("path")) | |
1477 { | |
1478 error ("can not convert octave_value to path representation"); | |
1479 return 1; | |
1480 } | |
1481 | |
1482 octave_idx_type nel; | |
1483 | |
1484 char closed = char (tp.contents ("closed").bool_value ()); | |
1485 | |
1486 NDArray m = tp.contents ("path").array_value (); | |
1487 | |
1488 if (error_state || (nel = m.numel ()) % 2) | |
1489 { | |
1490 error ("can not convert octave_value to path representation"); | |
1491 return 1; | |
1492 } | |
1493 | |
1494 union | |
1495 { | |
1496 double d; | |
1497 int64_t i; | |
1498 } | |
1499 swap; | |
1500 | |
1501 int32_t np = nel / 2; | |
1502 | |
1503 val.push_back (closed); | |
1504 | |
1505 OCT_PQ_PUT(val, int32_t, htobe32 (np)) | |
1506 | |
1507 for (int id = 0; id < nel; id++) | |
1508 { | |
1509 swap.d = m(id); | |
1510 | |
1511 OCT_PQ_PUT(val, int64_t, htobe64 (swap.i)) | |
1512 } | |
1513 | |
1514 return 0; | |
1515 } | |
1516 | |
1517 oct_pq_conv_t conv_path = {0, | |
1518 0, | |
1519 oct_pq_el_oids_t (), | |
1520 oct_pq_conv_cache_t (), | |
1521 false, | |
1522 false, | |
1523 false, | |
1524 "path", | |
1525 &to_octave_str_path, | |
1526 &to_octave_bin_path, | |
1527 &from_octave_str_path, | |
1528 &from_octave_bin_path}; | |
1529 | |
1530 /* end type path */ | |
11668
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1531 |
11429 | 1532 oct_pq_conv_t *t_conv_ptrs[OCT_PQ_NUM_CONVERTERS] = {&conv_bool, |
1533 &conv_oid, | |
1534 &conv_float8, | |
1535 &conv_float4, | |
1536 &conv_text, | |
1537 &conv_varchar, | |
1538 &conv_bpchar, | |
1539 &conv_name, | |
1540 &conv_bytea, | |
1541 &conv_int2, | |
1542 &conv_int4, | |
1543 &conv_int8, | |
11661 | 1544 &conv_money, |
11667 | 1545 &conv_timestamp, |
11668
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1546 &conv_timestamptz, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1547 &conv_interval, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1548 &conv_time, |
abd563353849
Added remaining date/time converters (time, timetz, date, interval).
i7tiol
parents:
11667
diff
changeset
|
1549 &conv_timetz, |
11697 | 1550 &conv_date, |
1551 &conv_point, | |
1552 &conv_lseg, | |
1553 &conv_line, | |
1554 &conv_box, | |
1555 &conv_circle, | |
1556 &conv_polygon, | |
1557 &conv_path}; | |
11429 | 1558 |
1559 oct_pq_conv_ptrs_t conv_ptrs (OCT_PQ_NUM_CONVERTERS, t_conv_ptrs); |