Mercurial > forge
annotate main/database/src/command.cc @ 11713:ee2b22964070 octave-forge
Make some functions of class 'command' non-members.
author | i7tiol |
---|---|
date | Mon, 20 May 2013 06:06:37 +0000 |
parents | 95b91d8c9ee2 |
children | 2257648e8ce1 |
rev | line source |
---|---|
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
1 /* |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
2 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
3 Copyright (C) 2012, 2013 Olaf Till <i7tiol@t-online.de> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
4 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
5 This program is free software; you can redistribute it and/or modify |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
8 (at your option) any later version. |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
9 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
10 This program is distributed in the hope that it will be useful, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
13 GNU General Public License for more details. |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
14 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
15 You should have received a copy of the GNU General Public License |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
16 along with this program; If not, see <http://www.gnu.org/licenses/>. |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
17 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
18 */ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
19 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
20 #include <octave/oct.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
21 #include <octave/ov-struct.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
22 #include <octave/Cell.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
23 #include <octave/lo-ieee.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
24 |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
25 #include <iostream> |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
26 #include <fstream> |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
27 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
28 #include "command.h" |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
29 #include "converters.h" |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
30 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
31 #define COPY_HEADER_SIZE 19 |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
32 |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
33 #define COUT_RESIZE_STEP 1000 // resize result only after this number of rows |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
34 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
35 command::command (octave_pq_connection &connection, std::string &cmd, |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
36 Cell &rtypes,std::string &who) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
37 : res (NULL), all_fetched (0), valid (1), conn (connection), |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
38 rettypes (rtypes), caller (who) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
39 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
40 if (! (cptr = conn.octave_pq_get_conn ())) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
41 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
42 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
43 error ("%s: connection not open", caller.c_str ()); |
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 if (! PQsendQuery (cptr, cmd.c_str ())) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
47 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
48 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
49 error ("%s: could not dispatch command: %s", caller.c_str (), |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
50 PQerrorMessage (cptr)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
51 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
52 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
53 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
54 res = PQgetResult (cptr); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
55 check_first_result (); |
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 } |
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 command::command (octave_pq_connection &connection, std::string &cmd, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
60 Cell ¶ms, Cell &ptypes, Cell &rtypes, std::string &who) |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
61 : res (NULL), all_fetched (1), valid (1), conn (connection), |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
62 rettypes (rtypes), caller (who) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
63 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
64 if (! (cptr = conn.octave_pq_get_conn ())) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
65 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
66 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
67 error ("%s: connection not open", caller.c_str ()); |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
70 int npars = params.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
71 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
72 char *vals [npars]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
73 std::vector<oct_pq_dynvec_t> valsvec; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
74 valsvec.resize (npars); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
75 int pl [npars]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
76 int pf [npars]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
77 Oid oids [npars]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
78 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
79 for (int i = 0; i < npars; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
80 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
81 pf[i] = 1; // means binary format |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
82 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
83 if (params(i).is_real_scalar () && params(i).isna ().bool_value ()) |
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 vals[i] = NULL; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
86 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
87 oids[i] = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
88 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
89 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
90 { |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
91 pq_oct_type_t oct_type; |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
92 oct_pq_conv_t *conv; |
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 if (ptypes(i).is_empty ()) |
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 oct_type = simple; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
97 |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
98 if (! (conv = pgtype_from_octtype (conn, params(i)))) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
99 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
100 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
101 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
102 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
103 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
104 // array not possible here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
105 oids[i] = conv->oid; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
106 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
107 else |
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 std::string s = ptypes(i).string_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
110 if (error_state) |
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 error ("%s: parameter type specification no string", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
113 caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
114 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
115 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
116 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
117 |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
118 if (! (conv = pgtype_from_spec (conn, s, oct_type))) |
11394
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 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
121 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
122 } |
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 (oct_type == array) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
125 oids[i] = conv->aoid; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
126 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
127 oids[i] = conv->oid; |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
130 switch (oct_type) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
131 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
132 case simple: |
11657 | 133 if (conv->from_octave_bin (conn, params(i), valsvec[i])) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
134 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
135 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
136 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
137 case array: |
11657 | 138 if (from_octave_bin_array (conn, params(i), valsvec[i], conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
139 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
140 break; |
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 case composite: |
11657 | 143 if (from_octave_bin_composite (conn, params(i), valsvec[i], conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
144 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
145 break; |
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 default: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
148 // should not get here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
149 error ("%s: internal error, undefined type identifier", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
150 caller.c_str ()); |
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 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
153 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
154 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
155 if (! valid) break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
156 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
157 vals[i] = &(valsvec[i].front ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
158 pl[i] = valsvec[i].size (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
159 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
160 } |
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 if (valid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
163 { |
11422 | 164 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
165 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
166 res = PQexecParams (cptr, cmd.c_str (), npars, oids, vals, pl, pf, 1); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
167 |
11422 | 168 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
169 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
170 check_first_result (); |
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 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
173 |
11706
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
174 octave_map command::get_elements_typeinfo (oct_pq_conv_t *conv, bool &err) |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
175 { |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
176 int nel = conv->el_oids.size (); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
177 |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
178 octave_map ret (dim_vector (1, nel)); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
179 Cell types_name (1, nel); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
180 Cell types_array (1, nel); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
181 Cell types_composite (1, nel); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
182 Cell types_enum (1, nel); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
183 Cell types_elements (1, nel); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
184 |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
185 for (int i = 0; i < nel; i++) |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
186 { |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
187 oct_pq_conv_t *el_conv; |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
188 pq_oct_type_t oct_type; |
11706
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
189 |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
190 if (! (el_conv = pgtype_from_spec (conn, conv->el_oids[i], |
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
191 conv->conv_cache[i], oct_type))) |
11706
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
192 { |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
193 err = true; |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
194 return ret; |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
195 } |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
196 |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
197 types_name(i) = octave_value (el_conv->name); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
198 types_array(i) = octave_value (oct_type == array); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
199 types_enum(i) = octave_value (el_conv->is_enum); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
200 types_composite(i) = octave_value (el_conv->is_composite); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
201 if (el_conv->is_composite) |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
202 { |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
203 bool rec_err = false; |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
204 types_elements(i) = octave_value (get_elements_typeinfo (el_conv, |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
205 rec_err)); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
206 if (rec_err) |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
207 { |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
208 err = true; |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
209 return ret; |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
210 } |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
211 } |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
212 } |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
213 |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
214 ret.assign ("name", types_name); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
215 ret.assign ("is_array", types_array); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
216 ret.assign ("is_composite", types_composite); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
217 ret.assign ("is_enum", types_enum); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
218 ret.assign ("elements", types_elements); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
219 |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
220 return ret; |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
221 } |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
222 |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
223 octave_value command::process_single_result (const std::string &infile, |
11484 | 224 const std::string &outfile, |
225 const Cell &cdata, | |
226 const Cell &ctypes, | |
227 bool coids, | |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
228 bool cin_var) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
229 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
230 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
231 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
232 // first result is already fetched |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
233 if (! res && (res = PQgetResult (cptr))) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
234 state = PQresultStatus (res); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
235 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
236 if (! res) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
237 all_fetched = 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
238 else |
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 switch (state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
241 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
242 case PGRES_BAD_RESPONSE: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
243 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
244 error ("%s: server response not understood", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
245 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
246 case PGRES_FATAL_ERROR: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
247 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
248 error ("%s: fatal error: %s", caller.c_str (), |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
249 PQresultErrorMessage (res)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
250 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
251 case PGRES_COMMAND_OK: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
252 retval = command_ok_handler (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
253 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
254 case PGRES_TUPLES_OK: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
255 retval = tuples_ok_handler (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
256 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
257 case PGRES_COPY_OUT: |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
258 retval = copy_out_handler (outfile); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
259 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
260 case PGRES_COPY_IN: |
11484 | 261 retval = copy_in_handler (infile, cdata, ctypes, coids, cin_var); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
262 break; |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
263 case PGRES_NONFATAL_ERROR: |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
264 break; |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
265 default: |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
266 valid = 0; |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
267 error ("internal error, unexpected server response"); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
268 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
269 |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
270 if (res) // could have been changed by a handler |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
271 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
272 PQclear (res); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
273 res = NULL; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
274 } |
11394
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
277 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
278 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
279 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
280 octave_value command::tuples_ok_handler (void) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
281 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
282 octave_map ret; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
283 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
284 int nt = PQntuples (res); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
285 int nf = PQnfields (res); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
286 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
287 Cell data (nt, nf); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
288 Cell columns (1, nf); |
11699 | 289 Cell types_name (1, nf); |
290 Cell types_array (1, nf); | |
291 Cell types_composite (1, nf); | |
292 Cell types_enum (1, nf); | |
11706
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
293 Cell types_elements (1, nf); |
11699 | 294 octave_map types (dim_vector (1, nf)); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
295 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
296 bool rtypes_given; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
297 int l = rettypes.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
298 if (l > 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 if (l != nf) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
301 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
302 error ("%s: wrong number of given returned types", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
303 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
304 return octave_value_list (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
305 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
306 rtypes_given = true; |
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 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
309 rtypes_given = false; |
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 for (int j = 0; j < nf; j++) // j is column |
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 columns(j) = octave_value (PQfname (res, j)); |
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 int f = PQfformat (res, j); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
316 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
317 oct_pq_to_octave_fp_t simple_type_to_octave; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
318 to_octave_array_fp_t array_to_octave; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
319 to_octave_composite_fp_t composite_to_octave; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
320 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
321 oct_pq_conv_t *conv = NULL; // silence inadequate warning by |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
322 // initializing it here |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
323 pq_oct_type_t oct_type; |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
324 |
11699 | 325 if (rtypes_given) // for internal reading of system tables |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
326 { |
11699 | 327 std::string type = rettypes(j).string_value (); |
328 if (error_state) | |
329 error ("%s: could not convert given type to string", | |
330 caller.c_str ()); | |
331 else | |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
332 conv = pgtype_from_spec (conn, type, oct_type); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
333 |
11699 | 334 if (error_state) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
335 { |
11699 | 336 valid = 0; |
337 break; | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
338 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
339 } |
11699 | 340 else |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
341 if (! (conv = pgtype_from_spec (conn, PQftype (res, j), oct_type))) |
11699 | 342 { |
343 valid = 0; | |
344 break; | |
345 } | |
346 | |
347 if (f) | |
348 { | |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
349 array_to_octave = &to_octave_bin_array; |
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
350 composite_to_octave = &to_octave_bin_composite; |
11699 | 351 // will be NULL for non-simple converters |
352 simple_type_to_octave = conv->to_octave_bin; | |
353 } | |
354 else | |
355 { | |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
356 array_to_octave = &to_octave_str_array; |
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
357 composite_to_octave = &to_octave_str_composite; |
11699 | 358 // will be NULL for non-simple converters |
359 simple_type_to_octave = conv->to_octave_str; | |
360 } | |
361 | |
11706
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
362 // prepare type information |
11699 | 363 types_name(j) = octave_value (conv->name); |
364 types_array(j) = octave_value (oct_type == array); | |
11706
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
365 types_enum(j) = octave_value (conv->is_enum); |
11702 | 366 types_composite(j) = octave_value (conv->is_composite); |
11706
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
367 if (conv->is_composite) |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
368 { |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
369 // To implement here: recursively go through the elements |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
370 // and return respective recursive structures. This has the |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
371 // side effect that all converters necessary for this query |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
372 // will be looked up and cached (if they aren't already), so |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
373 // in the actual conversion of composite types only cache |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
374 // reads are performed, no map lookups. |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
375 |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
376 bool err = false; |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
377 |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
378 types_elements(j) = octave_value (get_elements_typeinfo (conv, err)); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
379 |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
380 if (err) |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
381 { |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
382 valid = 0; |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
383 break; |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
384 } |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
385 } |
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 for (int i = 0; i < nt; i++) // i is row |
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 if (PQgetisnull (res, i, j)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
390 data(i, j) = octave_value (octave_NA); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
391 else |
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 char *v = PQgetvalue (res, i, j); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
394 int nb = PQgetlength (res, i, j); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
395 octave_value ov; |
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 switch (oct_type) |
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 case simple: |
11657 | 400 if (simple_type_to_octave (conn, v, ov, nb)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
401 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
402 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
403 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
404 case array: |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
405 if (array_to_octave (conn, v, ov, nb, conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
406 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
407 break; |
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 case composite: |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
410 if (composite_to_octave (conn, v, ov, nb, conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
411 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
412 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
413 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
414 default: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
415 // should not get here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
416 error ("%s: internal error, undefined type identifier", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
417 caller.c_str ()); |
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 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
420 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
421 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
422 if (valid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
423 data(i, j) = ov; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
424 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
425 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
426 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
427 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
428 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
429 if (! valid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
430 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
431 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
432 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
433 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
434 return octave_value_list (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
435 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
436 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
437 ret.assign ("data", octave_value (data)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
438 ret.assign ("columns", octave_value (columns)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
439 |
11699 | 440 types.setfield ("name", types_name); |
441 types.setfield ("is_array", types_array); | |
442 types.setfield ("is_composite", types_composite); | |
443 types.setfield ("is_enum", types_enum); | |
11706
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11702
diff
changeset
|
444 types.setfield ("elements", types_elements); |
11699 | 445 ret.assign ("types", octave_value (types)); |
446 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
447 return octave_value (ret); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
448 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
449 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
450 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
451 octave_value command::copy_out_handler (const std::string &outfile) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
452 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
453 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
454 |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
455 if (! outfile.empty ()) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
456 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
457 // store unchecked output in file |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
458 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
459 if (outfile.empty ()) |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
460 { |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
461 error ("no output file given"); |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
462 |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
463 valid = 0; |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
464 |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
465 return retval; |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
466 } |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
467 |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
468 std::ofstream ostr (outfile.c_str (), std::ios_base::out); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
469 if (ostr.fail ()) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
470 error ("could not open output file %s", outfile.c_str ()); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
471 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
472 char *data; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
473 int nb; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
474 while ((nb = PQgetCopyData (cptr, &data, 0)) > 0) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
475 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
476 if (! (ostr.fail () || ostr.bad ())) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
477 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
478 ostr.write (data, nb); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
479 if (ostr.bad ()) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
480 error ("write to file failed"); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
481 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
482 PQfreemem (data); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
483 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
484 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
485 if (! error_state) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
486 ostr.close (); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
487 |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
488 if (nb == -2) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
489 error ("server error in copy-out: %s", PQerrorMessage (cptr)); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
490 else |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
491 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
492 PQclear (res); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
493 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
494 if ((res = PQgetResult (cptr))) |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
495 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
496 if ((state = PQresultStatus (res)) == PGRES_FATAL_ERROR) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
497 error ("server error in copy-out: %s", PQerrorMessage (cptr)); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
498 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
499 else |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
500 error ("unexpectedly got no result information"); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
501 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
502 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
503 else |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
504 error ("no output file given"); |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
505 |
11408
6c22f62f2b64
Resumed to and finished copy-in/-out only from/to files.
i7tiol
parents:
11407
diff
changeset
|
506 if (error_state) |
6c22f62f2b64
Resumed to and finished copy-in/-out only from/to files.
i7tiol
parents:
11407
diff
changeset
|
507 valid = 0; |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
508 |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
509 return octave_value (std::string ("copy out")); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
510 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
511 |
11484 | 512 octave_value command::copy_in_handler (const std::string &infile, |
513 const Cell &data, | |
514 const Cell &cin_types, | |
515 bool oids, | |
516 bool var) | |
11394
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 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
519 |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
520 #define OCT_PQ_READSIZE 4096 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
521 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
522 char buff [OCT_PQ_READSIZE]; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
523 |
11484 | 524 if (! var) |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
525 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
526 // read unchecked input from file |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
527 |
11484 | 528 if (infile.empty ()) |
529 { | |
530 error ("no input file given"); | |
531 | |
532 valid = 0; | |
533 | |
534 return retval; | |
535 } | |
536 | |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
537 std::ifstream istr (infile.c_str (), std::ios_base::in); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
538 if (istr.fail ()) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
539 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
540 error ("could not open input file %s", infile.c_str ()); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
541 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
542 PQputCopyEnd (cptr, "could not open input file"); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
543 |
11407 | 544 error ("server error: %s", PQerrorMessage (cptr)); |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
545 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
546 valid = 0; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
547 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
548 return retval; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
549 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
550 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
551 do |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
552 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
553 istr.read (buff, OCT_PQ_READSIZE); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
554 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
555 if (istr.bad ()) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
556 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
557 error ("could not read file %s", infile.c_str ()); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
558 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
559 break; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
560 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
561 else |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
562 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
563 int nb; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
564 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
565 if ((nb = istr.gcount ()) > 0) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
566 if (PQputCopyData (cptr, buff, nb) == -1) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
567 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
568 error ("%s", PQerrorMessage (cptr)); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
569 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
570 break; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
571 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
572 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
573 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
574 while (! istr.eof ()); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
575 |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
576 istr.close (); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
577 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
578 if (error_state) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
579 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
580 PQputCopyEnd (cptr, "copy-in interrupted"); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
581 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
582 error ("%s", PQerrorMessage (cptr)); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
583 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
584 else |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
585 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
586 if (PQputCopyEnd (cptr, NULL) == -1) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
587 error ("%s", PQerrorMessage (cptr)); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
588 else |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
589 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
590 PQclear (res); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
591 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
592 if ((res = PQgetResult (cptr))) |
11398
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
593 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
594 if ((state = PQresultStatus (res)) == PGRES_FATAL_ERROR) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
595 error ("server error in copy-in: %s", PQerrorMessage (cptr)); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
596 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
597 else |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
598 error ("unexpectedly got no result information"); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
599 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
600 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
601 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
602 else |
11484 | 603 { |
604 // copy in from octave variable | |
605 | |
606 dim_vector dv = data.dims (); | |
607 octave_idx_type r = dv(0); | |
608 octave_idx_type c = dv(1); | |
609 | |
610 octave_idx_type nf = PQnfields (res); | |
611 if (c != nf + oids) | |
612 { | |
613 error ("variable for copy-in has %i columns, but should have %i", | |
614 c, nf + oids); | |
615 | |
616 PQputCopyEnd | |
617 (cptr, "variable for copy-in has wrong number of columns"); | |
618 } | |
619 else if (! PQbinaryTuples (res)) | |
620 { | |
621 error ("copy-in from variable must use binary mode"); | |
622 | |
623 PQputCopyEnd (cptr, "copy-in from variable must use binary mode"); | |
624 } | |
625 else | |
626 { | |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
627 for (octave_idx_type j = 0; j < nf; j++) |
11484 | 628 if (! PQfformat (res, j)) |
629 { | |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
630 error ("copy-in from variable must use binary mode in all columns"); |
11484 | 631 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
632 PQputCopyEnd (cptr, "copy-in from variable must use binary mode in all columns"); |
11484 | 633 |
634 break; | |
635 } | |
636 } | |
637 | |
638 if (error_state) | |
639 { | |
640 error ("server error: %s", PQerrorMessage (cptr)); | |
641 | |
642 valid = 0; | |
643 | |
644 return retval; | |
645 } | |
646 | |
647 char header [COPY_HEADER_SIZE]; | |
648 memset (header, 0, COPY_HEADER_SIZE); | |
649 strcpy (header, "PGCOPY\n\377\r\n\0"); | |
11646 | 650 uint32_t tpu32 = htobe32 (uint32_t (oids) << 16); |
651 memcpy (&header[11], &tpu32, 4); | |
11484 | 652 |
653 char trailer [2]; | |
11646 | 654 int16_t tp16 = htobe16 (int16_t (-1)); |
655 memcpy (&trailer, &tp16, 2); | |
11484 | 656 |
657 if (PQputCopyData (cptr, header, COPY_HEADER_SIZE) == -1) | |
658 { | |
659 PQputCopyEnd (cptr, "could not send header"); | |
660 | |
661 error ("server error: %s", PQerrorMessage (cptr)); | |
662 } | |
663 else | |
664 { | |
665 oct_pq_conv_t *convs [c]; | |
666 memset (convs, 0, sizeof (convs)); | |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
667 pq_oct_type_t oct_types [c]; |
11484 | 668 |
669 for (octave_idx_type i = 0; i < r; i++) // i is row | |
670 { | |
671 int16_t fc = htobe16 (int16_t (nf)); | |
672 if (PQputCopyData (cptr, (char *) &fc, 2) == -1) | |
673 { | |
674 error ("%s", PQerrorMessage (cptr)); | |
675 | |
676 PQputCopyEnd (cptr, "error sending field count"); | |
677 | |
678 error ("server error: %s", PQerrorMessage (cptr)); | |
679 | |
680 break; | |
681 } | |
682 | |
683 // j is column of argument data | |
684 for (octave_idx_type j = 0; j < c; j++) | |
685 { | |
686 if (data(i, j).is_real_scalar () && | |
687 data(i, j).isna ().bool_value ()) | |
688 { | |
689 int32_t t = htobe32 (int32_t (-1)); | |
690 if (PQputCopyData (cptr, (char *) &t, 4) == -1) | |
691 { | |
692 error ("could not send NULL in copy-in"); | |
693 | |
694 break; | |
695 } | |
696 } | |
697 else | |
698 { | |
699 if (! convs [j]) | |
700 { | |
701 if ((j == 0) && oids) | |
702 { | |
703 std::string t ("oid"); | |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
704 convs[0] = pgtype_from_spec (conn, t, |
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
705 oct_types[0]); |
11484 | 706 } |
707 else | |
708 { | |
709 if (cin_types(j).is_empty ()) | |
710 { | |
711 oct_types[j] = simple; | |
712 | |
713 if (! (convs[j] = | |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
714 pgtype_from_octtype (conn, |
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
715 data(i, j)))) |
11484 | 716 { |
717 error ("could not determine type in column %i for copy-in", | |
718 j); | |
719 | |
720 break; | |
721 } | |
722 } | |
723 else | |
724 { | |
725 std::string s = cin_types(j).string_value (); | |
726 if (error_state) | |
727 { | |
728 error ("column type specification no string"); | |
729 | |
730 break; | |
731 } | |
732 | |
733 if (! (convs[j] = | |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
734 pgtype_from_spec (conn, s, |
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
735 oct_types[j]))) |
11484 | 736 { |
737 error ("invalid column type specification"); | |
738 | |
739 break; | |
740 } | |
741 } | |
742 } | |
743 } // ! convs [j] | |
744 | |
745 oct_pq_dynvec_t val; | |
746 | |
747 bool conversion_failed = false; | |
748 switch (oct_types[j]) | |
749 { | |
750 case simple: | |
11657 | 751 if (convs[j]->from_octave_bin (conn, data(i, j), val)) |
11484 | 752 conversion_failed = true; |
753 break; | |
754 | |
755 case array: | |
11657 | 756 if (from_octave_bin_array (conn, data(i, j), val, |
757 convs[j])) | |
11484 | 758 conversion_failed = true; |
759 break; | |
760 | |
761 case composite: | |
11657 | 762 if (from_octave_bin_composite (conn, data(i, j), val, |
11484 | 763 convs[j])) |
764 conversion_failed = true; | |
765 break; | |
766 | |
767 default: | |
768 // should not get here | |
769 error ("internal error, undefined type identifier"); | |
770 } | |
771 | |
772 if (conversion_failed) | |
773 error ("could not convert data(%i, %i) for copy-in", | |
774 i, j); | |
775 else | |
776 { | |
777 uint32_t t = htobe32 (uint32_t (val.size ())); | |
778 if (PQputCopyData (cptr, (char *) &t, 4) == -1) | |
779 error ("could not send data length in copy-in"); | |
780 else if (PQputCopyData (cptr, &(val.front ()), | |
781 val.size ()) == -1) | |
782 error ("could not send copy-in data"); | |
783 } | |
784 | |
785 if (error_state) break; | |
786 } | |
787 } // columns of argument data | |
788 | |
789 if (error_state) | |
790 { | |
791 PQputCopyEnd (cptr, "error sending copy-in data"); | |
792 | |
793 error ("server error: %s", PQerrorMessage (cptr)); | |
794 | |
795 break; | |
796 } | |
797 } // rows of argument data | |
798 } | |
799 | |
800 if (! error_state) | |
801 if (PQputCopyData (cptr, trailer, 2) == -1) | |
802 { | |
803 PQputCopyEnd (cptr, "could not send trailer"); | |
804 | |
805 error ("%s", PQerrorMessage (cptr)); | |
806 } | |
807 | |
808 if (! error_state) | |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
809 { |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
810 if (PQputCopyEnd (cptr, NULL) == -1) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
811 error ("%s", PQerrorMessage (cptr)); |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
812 else |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
813 { |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
814 PQclear (res); |
11484 | 815 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
816 if ((res = PQgetResult (cptr))) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
817 { |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
818 if ((state = PQresultStatus (res)) == PGRES_FATAL_ERROR) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
819 error ("server error in copy-in: %s", |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
820 PQerrorMessage (cptr)); |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
821 } |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
822 else |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
823 error ("unexpectedly got no result information"); |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
824 } |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
825 } |
11484 | 826 } // copy from variable |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
827 |
11407 | 828 if (error_state) |
829 valid = 0; | |
830 | |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
831 return octave_value (std::string ("copy in")); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
832 } |