annotate main/database/src/pq_connection.cc @ 12718:1af86934c14e octave-forge

Make compatible with Octaves new exception-based error handling. Retain compatibility with Octaves old error handling based on error_state. * src/error_helpers.[h,cc]: Added. * src/Makefile.in: Integrate error-helpers.[h,cc]. * src/config.h.in: Added. * configure.ac, src/config.h.in: Test presence of 'error_state' and presence of 'verror (octave_execution_exception&, const char *, va_list)'. * src/__pq_connect__.cc, src/command.cc, src/command.h, src/converters.cc, src/converters_arr_comp.cc, src/pq_connection.cc, src/pq_conninfo.cc, src/pq_exec.cc, src/pq_lo.cc, src/pq_update_types.cc: If necessary, include error-helpers.h, replace error() with c_verror(), set and check a different error indicator than error_state, use CHECK_ERROR or SET_ERR, explicitely check for errors instead of relying on Octave checking error_state when returning to the prompt.
author i7tiol
date Sat, 27 Feb 2016 11:11:04 +0000
parents 2257648e8ce1
children 52ca082757c2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 "pq_connection.h"
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
21 #include "command.h"
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
22 #include "error-helpers.h"
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
23
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
24 DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_pq_connection, "PGconn", "PGconn")
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
25
11460
9ef769abf53d Fix segfault reported by Richard <richard@mail.sheugh.com>, due to undefined order of initialization.
i7tiol
parents: 11429
diff changeset
26 std::string &pq_basetype_prefix (void)
9ef769abf53d Fix segfault reported by Richard <richard@mail.sheugh.com>, due to undefined order of initialization.
i7tiol
parents: 11429
diff changeset
27 {
9ef769abf53d Fix segfault reported by Richard <richard@mail.sheugh.com>, due to undefined order of initialization.
i7tiol
parents: 11429
diff changeset
28 static std::string prefix ("pg_catalog.");
9ef769abf53d Fix segfault reported by Richard <richard@mail.sheugh.com>, due to undefined order of initialization.
i7tiol
parents: 11429
diff changeset
29 return prefix;
9ef769abf53d Fix segfault reported by Richard <richard@mail.sheugh.com>, due to undefined order of initialization.
i7tiol
parents: 11429
diff changeset
30 }
9ef769abf53d Fix segfault reported by Richard <richard@mail.sheugh.com>, due to undefined order of initialization.
i7tiol
parents: 11429
diff changeset
31
9ef769abf53d Fix segfault reported by Richard <richard@mail.sheugh.com>, due to undefined order of initialization.
i7tiol
parents: 11429
diff changeset
32 const int pq_bpl = pq_basetype_prefix ().size ();
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
33
11645
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
34 static bool map_str_cmp (const char *c1, const char *c2)
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
35 {
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
36 if (strcmp (c1, c2) < 0)
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
37 return true;
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
38 else
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
39 return false;
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
40 }
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
41
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
42 static bool map_string_cmp (const std::string &s1, const std::string &s2)
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
43 {
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
44 if (s1.compare (s2) < 0)
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
45 return true;
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
46 else
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
47 return false;
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
48 }
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
49
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 12181
diff changeset
50 octave_pq_connection_rep::octave_pq_connection_rep (std::string &arg)
11645
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
51 : conv_map (), name_conv_map (&map_str_cmp), conn (NULL), postgres (0)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
52 {
11422
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
53 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
54 conn = PQconnectdb (arg.c_str ());
11422
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
55 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11394
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 if (! conn || PQstatus (conn) == CONNECTION_BAD)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
58 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
59 if (conn)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
60 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
61 c_verror ("%s", PQerrorMessage (conn));
11550
a7e6bec0e9bf Retrieve error message when failing to connect.
i7tiol
parents: 11480
diff changeset
62
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
63 PGconn *t_conn = conn;
11394
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 conn = NULL;
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
66
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
67 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
68 PQfinish (t_conn);
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
69 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11394
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
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
72 c_verror ("PQ connection attempt failed");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
73 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
74 else
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 // init name converter-map (kind of "bootstrapping")
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
77 for (int i = 0; i < OCT_PQ_NUM_CONVERTERS; i++)
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
78 {
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
79 name_conv_map[conv_ptrs[i]->name.c_str ()] = conv_ptrs[i];
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
80
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
81 // unqualified name, may be replaced later with user-defined type
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
82 name_conv_map[conv_ptrs[i]->name.c_str () + pq_bpl] = conv_ptrs[i];
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
83 }
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
84
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
85 if (octave_pq_get_postgres_oid () ||
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
86 octave_pq_fill_base_types () ||
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
87 octave_pq_get_composite_types () ||
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
88 octave_pq_get_enum_types ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
89 {
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
90 PGconn *t_conn = conn;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
91
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
92 conn = NULL;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
93
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
94 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
95 PQfinish (t_conn);
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
96 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
97
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
98 c_verror ("could not read types");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
99 }
11659
7575dc1c0b06 Obtain connection information 'integer_datetimes'.
i7tiol
parents: 11645
diff changeset
100 else
11698
b3cbebad8a26 Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents: 11659
diff changeset
101 {
b3cbebad8a26 Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents: 11659
diff changeset
102 if (strcmp (PQparameterStatus (conn, "integer_datetimes"), "on"))
b3cbebad8a26 Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents: 11659
diff changeset
103 integer_datetimes = false;
b3cbebad8a26 Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents: 11659
diff changeset
104 else
b3cbebad8a26 Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents: 11659
diff changeset
105 integer_datetimes = true;
b3cbebad8a26 Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents: 11659
diff changeset
106 }
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
107 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
108 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
109
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 12181
diff changeset
110 octave_pq_connection_rep::~octave_pq_connection_rep (void)
11394
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 if (conn)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
113 {
11422
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
114 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
115 PQfinish (conn);
11422
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
116 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
117
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
118 octave_pq_delete_non_constant_types ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
119 }
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
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 12181
diff changeset
122 void octave_pq_connection_rep::octave_pq_close (void)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
123 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
124 if (conn)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
125 {
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
126 PGconn *t_conn = conn;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
127
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
128 conn = NULL;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
129
11422
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
130 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
131 PQfinish (t_conn);
11422
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
132 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
133
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
134 octave_pq_delete_non_constant_types ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
135 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
136 else
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
137 // deliberately left the 'error' call here, since
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
138 // 'octave_pq_close()' is only called by 'pq_close' immediately
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
139 // before returning
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
140 error ("PGconn object not open");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
141 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
142
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 12181
diff changeset
143 void octave_pq_connection_rep::octave_pq_delete_non_constant_types (void)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
144 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
145 // In the first map, allocated types are usually referenced twice
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
146 // (by oid and aoid). Yet we need no refcount as long as we go
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
147 // through the name map as the last, since there (the same) types
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
148 // are only referenced once.
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
149
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
150 std::vector<oct_pq_conv_map_t::iterator> t_it_v;
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 for (oct_pq_conv_map_t::iterator it = conv_map.begin ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
153 it != conv_map.end ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
154 it++)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
155 if (it->second->is_not_constant)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
156 t_it_v.push_back (it);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
157
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
158 for (std::vector<oct_pq_conv_map_t::iterator>::iterator it = t_it_v.begin ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
159 it != t_it_v.end (); it++)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
160 conv_map.erase (*it);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
161
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
162 std::vector<oct_pq_name_conv_map_t::iterator> t_name_it_v;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
163
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
164 for (oct_pq_name_conv_map_t::iterator it = name_conv_map.begin ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
165 it != name_conv_map.end ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
166 it++)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
167 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
168 oct_pq_conv_t *conv = it->second;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
169
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
170 if (conv->is_not_constant)
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 t_name_it_v.push_back (it);
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 delete conv;
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 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
177
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
178 for (std::vector<oct_pq_name_conv_map_t::iterator>::iterator it =
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
179 t_name_it_v.begin ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
180 it != t_name_it_v.end (); it++)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
181 name_conv_map.erase (*it);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
182 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
183
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 12181
diff changeset
184 int octave_pq_connection_rep::octave_pq_get_postgres_oid (void)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
185 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
186 Cell p, pt, rt (1, 1);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
187
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
188 rt(0) = octave_value ("oid");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
189
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
190 std::string cmd ("select oid from pg_roles where rolname = 'postgres';"),
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
191 caller ("octave_pq_get_postgres_oid");
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 command c (*this, cmd, p, pt, rt, caller);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
194 if (! c.good ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
195 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
196 c_verror ("could not read pg_roles");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
197 return 1;
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
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
200 octave_value res = c.process_single_result ();
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
201 if (! c.good ())
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
202 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
203
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
204 bool err;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
205 SET_ERR (postgres = res.scalar_map_value ().contents ("data").cell_value ()(0).int_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
206 if (err)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
207 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
208
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
209 return 0;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
210 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
211
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 12181
diff changeset
212 int octave_pq_connection_rep::octave_pq_fill_base_types (void)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
213 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
214 // assert postgres oid had been determined
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
215 if (! postgres.int_value ()) return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
216
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
217 Cell p (1, 1), pt (1, 1), rt (3, 1);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
218 p(0) = postgres;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
219 pt(0) = octave_value ("oid");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
220 rt(0) = octave_value ("oid");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
221 rt(1) = octave_value ("name");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
222 rt(2) = octave_value ("oid");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
223
11698
b3cbebad8a26 Fix segfault after internal error. Add converter for type 'unknown'.
i7tiol
parents: 11659
diff changeset
224 std::string cmd ("select oid, typname, typarray from pg_type where (typowner = $1 AND typtype = 'b' AND typarray != 0) OR typname = 'record' OR typname = 'unknown';"),
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
225 caller ("octave_pq_fill_base_types");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
226
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
227 command c (*this, cmd, p, pt, rt, caller);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
228 if (! c.good ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
229 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
230 c_verror ("octave_pq_fill_base_types: could not read pg_type");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
231 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
232 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
233
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
234 octave_value res = c.process_single_result ();
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
235 if (! c.good ())
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
236 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
237
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
238 Cell tpls;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
239 bool err;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
240 SET_ERR (tpls = res.scalar_map_value ().contents ("data").cell_value (),
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
241 err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
242 if (err)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
243 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
244 c_verror
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
245 ("octave_pq_fill_base_types: could not convert result data to cell");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
246 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
247 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
248
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
249 // make a temporary map of server base types (cell row numbers) for searching
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
250 typedef std::map<std::string, int, bool (*) (const std::string &,
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
251 const std::string &)>
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
252 bt_map_t;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
253 bt_map_t bt_map (&map_string_cmp);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
254 for (int i = 0; i < tpls.rows (); i++)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
255 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
256 SET_ERR (bt_map[tpls(i, 1).string_value ()] = i, err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
257 if (err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
258 break;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
259 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
260 if (err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
261 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
262 c_verror ("octave_pq_fill_base_types: could not read returned result");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
263 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
264 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
265
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
266 for (int i = 0; i < OCT_PQ_NUM_CONVERTERS; i++)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
267 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
268 bt_map_t::iterator bt_it;
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
269 if ((bt_it = bt_map.find (conv_ptrs[i]->name.c_str () + pq_bpl)) ==
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
270 bt_map.end ())
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
271 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
272 c_verror ("octave_pq_fill_base_types: type %s not found in pg_type",
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
273 conv_ptrs[i]->name.c_str () + pq_bpl);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
274 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
275 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
276 // fill in oid and aoid into static records of converters
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
277 SET_ERR (conv_ptrs[i]->oid = tpls(bt_it->second, 0).int_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
278 if (! err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
279 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
280 SET_ERR (conv_ptrs[i]->aoid = tpls(bt_it->second, 2).int_value (),
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
281 err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
282 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
283 if (err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
284 break;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
285
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
286 // fill in map of converters over oid with oid and, if not zero,
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
287 // also with aoid
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
288 conv_map[conv_ptrs[i]->oid] = conv_ptrs[i];
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
289 if (conv_ptrs[i]->aoid != 0)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
290 conv_map[conv_ptrs[i]->aoid] = conv_ptrs[i];
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
291 }
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
292 if (err)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
293 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
294 c_verror ("octave_pq_fill_base_types: could not read returned result");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
295 return 1;
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 return 0;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
299 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
300
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 12181
diff changeset
301 int octave_pq_connection_rep::octave_pq_get_composite_types (void)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
302 {
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
303 Cell p, pt, rt;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
304
12181
73d73ef1c0bf Fix error due to typo in query in pq_connection.cc (bug #40707).
i7tiol
parents: 11698
diff changeset
305 std::string cmd ("select pg_type.oid, pg_type.typname, pg_type.typarray, pg_namespace.nspname, pg_type_is_visible(pg_type.oid) as visible, array_agg(pg_attribute.atttypid), array_agg(pg_attribute.attnum) from (pg_type join pg_namespace on pg_type.typnamespace = pg_namespace.oid) join pg_attribute on pg_type.typrelid = pg_attribute.attrelid where pg_type.typtype = 'c' and pg_attribute.attnum > 0 group by pg_type.oid, pg_type.typname, pg_type.typarray, pg_type.typrelid, pg_namespace.nspname, visible;"),
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
306 caller ("octave_pq_get_composite_types");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
307
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
308 command c (*this, cmd, p, pt, rt, caller);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
309 if (! c.good ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
310 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
311 c_verror ("octave_pq_get_composite_types: could not read pg_type");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
312 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
313 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
314
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
315 octave_value res = c.process_single_result ();
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
316 if (! c.good ())
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
317 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
318
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
319 Cell tpls;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
320 bool err;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
321 SET_ERR (tpls = res.scalar_map_value ().contents ("data").cell_value (),
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
322 err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
323 if (err)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
324 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
325 c_verror ("octave_pq_get_composite_types: could not convert result data to cell");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
326 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
327 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
328
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
329 for (int i = 0; i < tpls.rows (); i++)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
330 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
331 Oid oid;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
332 SET_ERR (oid = tpls(i, 0).uint_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
333 Oid aoid;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
334 if (! err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
335 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
336 SET_ERR (aoid = tpls(i, 2).uint_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
337 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
338 std::string name;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
339 if (! err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
340 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
341 SET_ERR (name = tpls(i, 1).string_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
342 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
343 std::string nspace;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
344 if (! err)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
345 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
346 SET_ERR (nspace = tpls(i, 3).string_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
347 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
348 bool visible;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
349 if (! err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
350 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
351 SET_ERR (visible = tpls(i, 4).bool_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
352 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
353 Cell r_el_oids;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
354 if (! err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
355 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
356 SET_ERR (r_el_oids = tpls(i, 5).scalar_map_value ()
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
357 .contents ("data").cell_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
358 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
359 Cell r_el_pos;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
360 if (! err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
361 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
362 SET_ERR (r_el_pos = tpls(i, 6).scalar_map_value ()
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
363 .contents ("data").cell_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
364 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
365 if (err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
366 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
367 c_verror ("octave_pq_get_composite_types: could not read returned result");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
368 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
369 }
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: 11460
diff changeset
370 octave_idx_type nel = r_el_oids.numel ();
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: 11460
diff changeset
371 if (nel != r_el_pos.numel ())
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: 11460
diff changeset
372 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
373 c_verror ("octave_pq_get_composite_types: internal error, inconsistent content of pg_attribute?");
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: 11460
diff changeset
374
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: 11460
diff changeset
375 return 1;
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: 11460
diff changeset
376 }
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: 11460
diff changeset
377 oct_pq_el_oids_t el_oids;
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: 11460
diff changeset
378 el_oids.resize (nel);
11480
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
379 oct_pq_conv_cache_t conv_cache;
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
380 conv_cache.resize (nel);
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: 11460
diff changeset
381 for (octave_idx_type i = 0; i < nel; 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: 11460
diff changeset
382 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
383 octave_idx_type pos;
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: 11460
diff changeset
384 // "column" number (attnum) is one-based, so subtract 1
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
385 SET_ERR (pos = r_el_pos(i).idx_type_value () - 1, err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
386 if (! err)
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: 11460
diff changeset
387 {
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: 11460
diff changeset
388 if (pos >= nel)
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: 11460
diff changeset
389 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
390 c_verror ("octave_pq_get_composite_types: internal error (?system catalog erroneous?): column position %i greater than ncols %i for type %s, namespace %s",
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: 11460
diff changeset
391 pos, nel, name.c_str (), nspace.c_str ());
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: 11460
diff changeset
392 return 1;
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: 11460
diff changeset
393 }
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: 11460
diff changeset
394
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
395 SET_ERR (el_oids[pos] = r_el_oids(i).uint_value (), err);
11480
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
396
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
397 conv_cache[pos] = NULL;
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: 11460
diff changeset
398 }
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
399 if (err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
400 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
401 c_verror ("octave_pq_get_composite_types: could not fill in element oids.");
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: 11460
diff changeset
402
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
403 return 1;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
404 }
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: 11460
diff changeset
405 }
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
406
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
407 // must be allocated and filled before creating the name map
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
408 // entry, to get a remaining location for the c-string used as
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
409 // key
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
410 oct_pq_conv_t *t_conv = new oct_pq_conv_t;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
411 t_conv->oid = oid;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
412 t_conv->aoid = aoid;
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: 11460
diff changeset
413 t_conv->el_oids = el_oids;
11480
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
414 t_conv->conv_cache = conv_cache;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
415 t_conv->is_composite = true;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
416 t_conv->is_enum = false;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
417 t_conv->is_not_constant = true;
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
418 t_conv->name = nspace.append (".").append (name);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
419 t_conv->to_octave_str = NULL;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
420 t_conv->to_octave_bin = NULL;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
421 t_conv->from_octave_str = NULL;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
422 t_conv->from_octave_bin = NULL;
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 oct_pq_conv_t *&by_oid = conv_map[oid],
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
425 *&by_name = name_conv_map[t_conv->name.c_str ()];
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
426 if (by_oid || by_name)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
427 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
428 c_verror ("octave_pq_get_composite_types: internal error, key already in typemap (by_oid: %u/%li, by name: %s/%li)",
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
429 oid, by_oid, t_conv->name.c_str (), by_name);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
430 if (! by_oid) conv_map.erase (oid);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
431 if (! by_name) name_conv_map.erase (t_conv->name.c_str ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
432 delete t_conv;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
433 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
434 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
435
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
436 by_oid = by_name = t_conv;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
437
11645
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
438 oct_pq_conv_t *t_conv_v = NULL; // silence inadequate warning by
bd5a8f1bdfb8 Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents: 11550
diff changeset
439 // initializing it here
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: 11460
diff changeset
440
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
441 if (visible)
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
442 {
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
443 t_conv_v = new oct_pq_conv_t (*t_conv);
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
444
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: 11460
diff changeset
445 t_conv_v->el_oids = el_oids;
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: 11460
diff changeset
446
11480
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
447 t_conv_v->conv_cache = conv_cache;
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
448
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
449 t_conv_v->name = name;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
450
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
451 name_conv_map[t_conv_v->name.c_str ()] = t_conv_v;;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
452 }
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
453
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
454 if (aoid)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
455 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
456 oct_pq_conv_t *&by_aoid = conv_map[aoid];
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
457 if (by_aoid)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
458 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
459 c_verror ("octave_pq_get_composite_types: internal error, aoid key %u already in typemap", aoid);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
460 conv_map.erase (oid);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
461 name_conv_map.erase (t_conv->name.c_str ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
462 delete t_conv;
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
463 if (visible)
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
464 {
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
465 name_conv_map.erase (t_conv_v->name.c_str ());
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
466 delete t_conv_v;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
467 }
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
468 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
469 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
470
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
471 by_aoid = by_oid;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
472 }
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 }
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 return 0;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
477 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
478
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 12181
diff changeset
479 int octave_pq_connection_rep::octave_pq_get_enum_types (void)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
480 {
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
481 Cell p, pt, rt;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
482
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
483 std::string cmd ("select pg_type.oid, pg_type.typname, pg_type.typarray, pg_namespace.nspname, pg_type_is_visible(pg_type.oid) from pg_type join pg_namespace on pg_type.typnamespace = pg_namespace.oid where pg_type.typtype = 'e';"),
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
484 caller ("octave_pq_get_enum_types");
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
485
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
486 command c (*this, cmd, p, pt, rt, caller);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
487 if (! c.good ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
488 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
489 c_verror ("octave_pq_get_enum_types: could not read pg_type");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
490 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
491 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
492
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
493 octave_value res = c.process_single_result ();
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
494 if (! c.good ())
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
495 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
496
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
497 Cell tpls;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
498 bool err;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
499 SET_ERR (tpls = res.scalar_map_value ().contents ("data").cell_value (),
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
500 err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
501 if (err)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
502 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
503 c_verror ("octave_pq_get_enum_types: could not convert result data to cell");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
504 return 1;
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
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
507 for (int i = 0; i < tpls.rows (); i++)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
508 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
509 Oid oid;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
510 SET_ERR (oid = tpls(i, 0).uint_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
511 Oid aoid;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
512 if (! err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
513 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
514 SET_ERR (aoid = tpls(i, 2).uint_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
515 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
516 std::string name;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
517 if (! err)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
518 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
519 SET_ERR (name = tpls(i, 1).string_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
520 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
521 std::string nspace;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
522 if (! err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
523 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
524 SET_ERR (nspace = tpls(i, 3).string_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
525 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
526 bool visible;
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
527 if (! err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
528 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
529 SET_ERR (visible = tpls(i, 4).bool_value (), err);
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
530 }
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
531 if (err)
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
532 {
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
533 c_verror ("octave_pq_get_enum_types: could not read returned result");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
534 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
535 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
536
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
537 // must be allocated and filled before creating the name map
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
538 // entry, to get a remaining location for the c-string used as
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
539 // key
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
540 oct_pq_conv_t *t_conv = new oct_pq_conv_t;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
541 t_conv->oid = oid;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
542 t_conv->aoid = aoid;
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: 11460
diff changeset
543 t_conv->el_oids = oct_pq_el_oids_t ();
11480
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
544 t_conv->conv_cache = oct_pq_conv_cache_t ();
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
545 t_conv->is_composite = false;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
546 t_conv->is_enum = true;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
547 t_conv->is_not_constant = true;
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
548 t_conv->name = nspace.append (".").append (name);
11410
c20550232685 Conversion of enum types implemented.
i7tiol
parents: 11394
diff changeset
549 t_conv->to_octave_str = &to_octave_str_text;
c20550232685 Conversion of enum types implemented.
i7tiol
parents: 11394
diff changeset
550 t_conv->to_octave_bin = &to_octave_bin_text;
c20550232685 Conversion of enum types implemented.
i7tiol
parents: 11394
diff changeset
551 t_conv->from_octave_str = &from_octave_str_text;
c20550232685 Conversion of enum types implemented.
i7tiol
parents: 11394
diff changeset
552 t_conv->from_octave_bin = &from_octave_bin_text;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
553
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
554 // we trust there is always an array type in the table
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
555 oct_pq_conv_t *&by_oid = conv_map[oid], *&by_aoid = conv_map[aoid],
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
556 *&by_name = name_conv_map[t_conv->name.c_str ()];
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
557 if (by_oid || by_aoid || by_name)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
558 {
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
559 c_verror ("octave_pq_get_enum_types: internal error, key already in typemap");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
560 if (! by_oid) conv_map.erase (oid);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
561 if (! by_aoid) conv_map.erase (aoid);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
562 if (! by_name) name_conv_map.erase (t_conv->name.c_str ());
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
563 delete t_conv;
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
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
567 by_oid = by_aoid = by_name = t_conv;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
568
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
569 if (visible)
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
570 {
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
571 oct_pq_conv_t *t_conv_v = new oct_pq_conv_t (*t_conv);
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
572
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: 11460
diff changeset
573 t_conv_v->el_oids = oct_pq_el_oids_t ();
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: 11460
diff changeset
574
11480
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
575 t_conv_v->conv_cache = oct_pq_conv_cache_t ();
d14a23884d9c Cache map lookups of converters for composite type elements.
i7tiol
parents: 11474
diff changeset
576
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
577 t_conv_v->name = name;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
578
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
579 name_conv_map[t_conv_v->name.c_str ()] = t_conv_v;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
580 }
11394
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 return 0;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
584 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
585
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 12181
diff changeset
586 int octave_pq_connection_rep::octave_pq_refresh_types (void)
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
587 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
588 octave_pq_delete_non_constant_types ();
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
589
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
590 // refresh unqualified base type names, may be replaced later with
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
591 // user-defined types
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
592 for (int i = 0; i < OCT_PQ_NUM_CONVERTERS; i++)
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
593 name_conv_map[conv_ptrs[i]->name.c_str () + pq_bpl] = conv_ptrs[i];
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
594
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
595 if (octave_pq_get_composite_types () || octave_pq_get_enum_types ())
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
596 {
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
597 PGconn *t_conn = conn;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
598
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
599 conn = NULL;
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
600
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
601 if (t_conn)
11422
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
602 {
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
603 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
11429
61ea672a060a Consider schemas in type specifications by name.
i7tiol
parents: 11422
diff changeset
604 PQfinish (t_conn);
11422
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
605 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
606 }
b1f26b72b61a Large object import/export also from/to pipes.
i7tiol
parents: 11410
diff changeset
607
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
608 c_verror ("octave_pq_refresh_types: could not read types");
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
609 return 1;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
610 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
611 else
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 }