Mercurial > forge
annotate main/database/src/command.cc @ 11702:dc5cbdce490b octave-forge
Mark returned type as composite even when array.
author | i7tiol |
---|---|
date | Wed, 15 May 2013 17:48:17 +0000 |
parents | dafee4563c36 |
children | 95b91d8c9ee2 |
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" |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
29 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
30 #define ERROR_RETURN_NO_PG_TYPE \ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
31 { \ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
32 error ("could not determine postgresql type for Octave parameter"); \ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
33 return NULL; \ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
34 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
35 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
36 #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
|
37 |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
38 #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
|
39 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
40 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
|
41 Cell &rtypes,std::string &who) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
42 : res (NULL), all_fetched (0), valid (1), conn (connection), |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
43 rettypes (rtypes), caller (who) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
44 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
45 if (! (cptr = conn.octave_pq_get_conn ())) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
46 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
47 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
48 error ("%s: connection not open", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
49 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
50 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
51 if (! PQsendQuery (cptr, cmd.c_str ())) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
52 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
53 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
54 error ("%s: could not dispatch command: %s", caller.c_str (), |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
55 PQerrorMessage (cptr)); |
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 else |
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 res = PQgetResult (cptr); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
60 check_first_result (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
61 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
62 } |
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 command::command (octave_pq_connection &connection, std::string &cmd, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
65 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
|
66 : res (NULL), all_fetched (1), valid (1), conn (connection), |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
67 rettypes (rtypes), caller (who) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
68 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
69 if (! (cptr = conn.octave_pq_get_conn ())) |
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 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
72 error ("%s: connection not open", caller.c_str ()); |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
75 int npars = params.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
76 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
77 char *vals [npars]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
78 std::vector<oct_pq_dynvec_t> valsvec; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
79 valsvec.resize (npars); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
80 int pl [npars]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
81 int pf [npars]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
82 Oid oids [npars]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
83 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
84 for (int i = 0; i < npars; i++) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
85 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
86 pf[i] = 1; // means binary format |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
87 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
88 if (params(i).is_real_scalar () && params(i).isna ().bool_value ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
89 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
90 vals[i] = NULL; |
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 oids[i] = 0; |
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 else |
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_t oct_type; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
97 oct_pq_conv_t *conv; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
98 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
99 if (ptypes(i).is_empty ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
100 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
101 oct_type = simple; |
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 if (! (conv = pgtype_from_octtype (params(i)))) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
104 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
105 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
106 break; |
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 // array not possible here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
110 oids[i] = conv->oid; |
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 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
113 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
114 std::string s = ptypes(i).string_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
115 if (error_state) |
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 error ("%s: parameter type specification no string", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
118 caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
119 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
120 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
121 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
122 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
123 if (! (conv = pgtype_from_spec (s, oct_type))) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
124 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
125 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
126 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
127 } |
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 if (oct_type == array) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
130 oids[i] = conv->aoid; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
131 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
132 oids[i] = conv->oid; |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
135 switch (oct_type) |
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 simple: |
11657 | 138 if (conv->from_octave_bin (conn, params(i), valsvec[i])) |
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 array: |
11657 | 143 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
|
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 case composite: |
11657 | 148 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
|
149 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
150 break; |
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 default: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
153 // should not get here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
154 error ("%s: internal error, undefined type identifier", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
155 caller.c_str ()); |
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 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
158 } |
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 if (! valid) break; |
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 vals[i] = &(valsvec[i].front ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
163 pl[i] = valsvec[i].size (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
164 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
165 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
166 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
167 if (valid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
168 { |
11422 | 169 BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
170 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
171 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
|
172 |
11422 | 173 END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE; |
174 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
175 check_first_result (); |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
179 oct_pq_conv_t *command::pgtype_from_spec (std::string &name, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
180 oct_type_t &oct_type) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
181 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
182 oct_pq_conv_t *conv = NULL; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
183 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
184 // printf ("pgtype_from_spec(%s): simple ", name.c_str ()); |
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 oct_type = simple; // default |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
187 int l; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
188 while (name.size () >= 2 && ! name.compare (l = name.size () - 2, 2, "[]")) |
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 name.erase (l, 2); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
191 oct_type = array; |
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 // printf ("array "); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
194 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
195 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
196 oct_pq_name_conv_map_t::iterator iter; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
197 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
198 if ((iter = conn.name_conv_map.find (name.c_str ())) == |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
199 conn.name_conv_map.end ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
200 error ("%s: no converter found for type %s", caller.c_str (), |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
201 name.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
202 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
203 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
204 // printf ("(looked up in name map) "); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
205 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
206 conv = iter->second; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
207 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
208 if (oct_type == array && ! conv->aoid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
209 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
210 error ("%s: internal error, type %s, specified as array, has no array type in system catalog", name.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
211 return conv; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
212 } |
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 if (! (oct_type == array) && conv->is_composite) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
215 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
216 oct_type = composite; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
217 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
218 // printf ("composite "); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
219 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
220 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
221 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
222 // printf ("\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
223 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
224 return conv; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
225 } |
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 oct_pq_conv_t *command::pgtype_from_spec (Oid oid, oct_type_t &oct_type) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
228 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
229 // printf ("pgtype_from_spec(%u): ", oid); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
230 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
231 oct_pq_conv_t *conv = NULL; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
232 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
233 oct_pq_conv_map_t::iterator iter; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
234 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
235 if ((iter = conn.conv_map.find (oid)) == conn.conv_map.end ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
236 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
237 error ("%s: no converter found for element oid %u", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
238 caller.c_str (), oid); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
239 return conv; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
240 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
241 conv = iter->second; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
242 // printf ("(looked up %s in oid map) ", conv->name.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
243 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
244 if (conv->aoid == oid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
245 oct_type = array; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
246 else if (conv->is_composite) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
247 oct_type = composite; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
248 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
249 oct_type = simple; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
250 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
251 // printf ("oct_type: %i\n", oct_type); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
252 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
253 return conv; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
254 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
255 |
11480
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
256 oct_pq_conv_t *command::pgtype_from_spec (Oid oid, oct_pq_conv_t *&c_conv, |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
257 oct_type_t &oct_type) |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
258 { |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
259 if (c_conv) |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
260 { |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
261 if (c_conv->aoid == oid) |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
262 oct_type = array; |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
263 else if (c_conv->is_composite) |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
264 oct_type = composite; |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
265 else |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
266 oct_type = simple; |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
267 } |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
268 else |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
269 c_conv = pgtype_from_spec (oid, oct_type); |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
270 |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
271 return c_conv; |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
272 } |
d14a23884d9c
Cache map lookups of converters for composite type elements.
i7tiol
parents:
11422
diff
changeset
|
273 |
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
|
274 octave_value command::process_single_result (const std::string &infile, |
11484 | 275 const std::string &outfile, |
276 const Cell &cdata, | |
277 const Cell &ctypes, | |
278 bool coids, | |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
279 bool cin_var) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
280 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
281 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
282 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
283 // first result is already fetched |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
284 if (! res && (res = PQgetResult (cptr))) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
285 state = PQresultStatus (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 if (! res) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
288 all_fetched = 1; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
289 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
290 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
291 switch (state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
292 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
293 case PGRES_BAD_RESPONSE: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
294 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
295 error ("%s: server response not understood", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
296 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
297 case PGRES_FATAL_ERROR: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
298 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
299 error ("%s: fatal error: %s", caller.c_str (), |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
300 PQresultErrorMessage (res)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
301 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
302 case PGRES_COMMAND_OK: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
303 retval = command_ok_handler (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
304 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
305 case PGRES_TUPLES_OK: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
306 retval = tuples_ok_handler (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
307 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
308 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
|
309 retval = copy_out_handler (outfile); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
310 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
311 case PGRES_COPY_IN: |
11484 | 312 retval = copy_in_handler (infile, cdata, ctypes, coids, cin_var); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
313 break; |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
314 case PGRES_NONFATAL_ERROR: |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
315 break; |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
316 default: |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
317 valid = 0; |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
318 error ("internal error, unexpected server response"); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
319 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
320 |
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
|
321 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
|
322 { |
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
|
323 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
|
324 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
|
325 } |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
326 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
327 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
328 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
329 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
330 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
331 octave_value command::tuples_ok_handler (void) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
332 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
333 octave_map ret; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
334 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
335 int nt = PQntuples (res); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
336 int nf = PQnfields (res); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
337 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
338 Cell data (nt, nf); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
339 Cell columns (1, nf); |
11699 | 340 Cell types_name (1, nf); |
341 Cell types_array (1, nf); | |
342 Cell types_composite (1, nf); | |
343 Cell types_enum (1, nf); | |
344 octave_map types (dim_vector (1, nf)); | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
345 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
346 bool rtypes_given; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
347 int l = rettypes.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
348 if (l > 0) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
349 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
350 if (l != nf) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
351 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
352 error ("%s: wrong number of given returned types", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
353 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
354 return octave_value_list (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
355 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
356 rtypes_given = true; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
357 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
358 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
359 rtypes_given = false; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
360 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
361 for (int j = 0; j < nf; j++) // j is column |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
362 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
363 columns(j) = octave_value (PQfname (res, j)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
364 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
365 int f = PQfformat (res, j); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
366 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
367 oct_pq_to_octave_fp_t simple_type_to_octave; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
368 to_octave_array_fp_t array_to_octave; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
369 to_octave_composite_fp_t composite_to_octave; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
370 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
371 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
|
372 // initializing it here |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
373 oct_type_t oct_type; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
374 |
11699 | 375 if (rtypes_given) // for internal reading of system tables |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
376 { |
11699 | 377 std::string type = rettypes(j).string_value (); |
378 if (error_state) | |
379 error ("%s: could not convert given type to string", | |
380 caller.c_str ()); | |
381 else | |
382 conv = pgtype_from_spec (type, oct_type); | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
383 |
11699 | 384 if (error_state) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
385 { |
11699 | 386 valid = 0; |
387 break; | |
11394
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 } |
11699 | 390 else |
391 if (! (conv = pgtype_from_spec (PQftype (res, j), oct_type))) | |
392 { | |
393 valid = 0; | |
394 break; | |
395 } | |
396 | |
397 if (f) | |
398 { | |
399 array_to_octave = &command::to_octave_bin_array; | |
400 composite_to_octave = &command::to_octave_bin_composite; | |
401 // will be NULL for non-simple converters | |
402 simple_type_to_octave = conv->to_octave_bin; | |
403 } | |
404 else | |
405 { | |
406 array_to_octave = &command::to_octave_str_array; | |
407 composite_to_octave = &command::to_octave_str_composite; | |
408 // will be NULL for non-simple converters | |
409 simple_type_to_octave = conv->to_octave_str; | |
410 } | |
411 | |
412 types_name(j) = octave_value (conv->name); | |
413 types_array(j) = octave_value (oct_type == array); | |
11702 | 414 types_composite(j) = octave_value (conv->is_composite); |
11699 | 415 types_enum(j) = octave_value (conv->is_enum); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
416 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
417 for (int i = 0; i < nt; i++) // i is row |
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 if (PQgetisnull (res, i, j)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
420 data(i, j) = octave_value (octave_NA); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
421 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
422 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
423 char *v = PQgetvalue (res, i, j); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
424 int nb = PQgetlength (res, i, j); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
425 octave_value ov; |
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 switch (oct_type) |
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 case simple: |
11657 | 430 if (simple_type_to_octave (conn, v, ov, nb)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
431 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
432 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
433 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
434 case array: |
11657 | 435 if ((this->*array_to_octave) (conn, v, ov, nb, conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
436 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
437 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
438 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
439 case composite: |
11657 | 440 if ((this->*composite_to_octave) (conn, v, ov, nb, conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
441 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
442 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
443 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
444 default: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
445 // should not get here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
446 error ("%s: internal error, undefined type identifier", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
447 caller.c_str ()); |
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 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
450 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
451 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
452 if (valid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
453 data(i, j) = ov; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
454 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
455 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
456 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
457 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
458 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
459 if (! valid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
460 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
461 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
462 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
463 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
464 return octave_value_list (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
465 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
466 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
467 ret.assign ("data", octave_value (data)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
468 ret.assign ("columns", octave_value (columns)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
469 |
11699 | 470 types.setfield ("name", types_name); |
471 types.setfield ("is_array", types_array); | |
472 types.setfield ("is_composite", types_composite); | |
473 types.setfield ("is_enum", types_enum); | |
474 ret.assign ("types", octave_value (types)); | |
475 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
476 return octave_value (ret); |
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 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
479 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
480 octave_value command::copy_out_handler (const std::string &outfile) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
481 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
482 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
483 |
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
|
484 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
|
485 { |
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 // 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
|
487 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
488 if (outfile.empty ()) |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
489 { |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
490 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
|
491 |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
492 valid = 0; |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
493 |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
494 return retval; |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
495 } |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
496 |
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
|
497 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
|
498 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
|
499 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
|
500 |
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 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
|
502 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
|
503 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
|
504 { |
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 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
|
506 { |
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
|
507 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
|
508 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
|
509 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
|
510 } |
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
|
511 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
|
512 } |
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
|
513 |
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
|
514 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
|
515 ostr.close (); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
516 |
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
|
517 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
|
518 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
|
519 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
|
520 { |
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 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
|
522 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
523 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
|
524 { |
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 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
|
526 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
|
527 } |
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
|
528 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
|
529 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
|
530 } |
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
|
531 } |
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
|
532 else |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
533 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
|
534 |
11408
6c22f62f2b64
Resumed to and finished copy-in/-out only from/to files.
i7tiol
parents:
11407
diff
changeset
|
535 if (error_state) |
6c22f62f2b64
Resumed to and finished copy-in/-out only from/to files.
i7tiol
parents:
11407
diff
changeset
|
536 valid = 0; |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
537 |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
538 return octave_value (std::string ("copy out")); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
539 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
540 |
11484 | 541 octave_value command::copy_in_handler (const std::string &infile, |
542 const Cell &data, | |
543 const Cell &cin_types, | |
544 bool oids, | |
545 bool var) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
546 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
547 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
548 |
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
|
549 #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
|
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 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
|
552 |
11484 | 553 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
|
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 // 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
|
556 |
11484 | 557 if (infile.empty ()) |
558 { | |
559 error ("no input file given"); | |
560 | |
561 valid = 0; | |
562 | |
563 return retval; | |
564 } | |
565 | |
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
|
566 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
|
567 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
|
568 { |
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 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
|
570 |
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 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
|
572 |
11407 | 573 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
|
574 |
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
|
575 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
|
576 |
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 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
|
578 } |
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 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
|
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 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
|
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 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
|
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 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
|
587 |
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 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
|
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 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
|
591 { |
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
|
592 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
|
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 ((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
|
595 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
|
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 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
|
598 |
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 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
|
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 } |
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
|
603 while (! istr.eof ()); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
604 |
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
|
605 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
|
606 |
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
|
607 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
|
608 { |
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
|
609 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
|
610 |
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
|
611 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
|
612 } |
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
|
613 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
|
614 { |
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
|
615 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
|
616 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
|
617 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
|
618 { |
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
|
619 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
|
620 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
621 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
|
622 { |
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
|
623 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
|
624 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
|
625 } |
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
|
626 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
|
627 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
|
628 } |
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
|
629 } |
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
|
630 } |
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
|
631 else |
11484 | 632 { |
633 // copy in from octave variable | |
634 | |
635 dim_vector dv = data.dims (); | |
636 octave_idx_type r = dv(0); | |
637 octave_idx_type c = dv(1); | |
638 | |
639 octave_idx_type nf = PQnfields (res); | |
640 if (c != nf + oids) | |
641 { | |
642 error ("variable for copy-in has %i columns, but should have %i", | |
643 c, nf + oids); | |
644 | |
645 PQputCopyEnd | |
646 (cptr, "variable for copy-in has wrong number of columns"); | |
647 } | |
648 else if (! PQbinaryTuples (res)) | |
649 { | |
650 error ("copy-in from variable must use binary mode"); | |
651 | |
652 PQputCopyEnd (cptr, "copy-in from variable must use binary mode"); | |
653 } | |
654 else | |
655 { | |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
656 for (octave_idx_type j = 0; j < nf; j++) |
11484 | 657 if (! PQfformat (res, j)) |
658 { | |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
659 error ("copy-in from variable must use binary mode in all columns"); |
11484 | 660 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
661 PQputCopyEnd (cptr, "copy-in from variable must use binary mode in all columns"); |
11484 | 662 |
663 break; | |
664 } | |
665 } | |
666 | |
667 if (error_state) | |
668 { | |
669 error ("server error: %s", PQerrorMessage (cptr)); | |
670 | |
671 valid = 0; | |
672 | |
673 return retval; | |
674 } | |
675 | |
676 char header [COPY_HEADER_SIZE]; | |
677 memset (header, 0, COPY_HEADER_SIZE); | |
678 strcpy (header, "PGCOPY\n\377\r\n\0"); | |
11646 | 679 uint32_t tpu32 = htobe32 (uint32_t (oids) << 16); |
680 memcpy (&header[11], &tpu32, 4); | |
11484 | 681 |
682 char trailer [2]; | |
11646 | 683 int16_t tp16 = htobe16 (int16_t (-1)); |
684 memcpy (&trailer, &tp16, 2); | |
11484 | 685 |
686 if (PQputCopyData (cptr, header, COPY_HEADER_SIZE) == -1) | |
687 { | |
688 PQputCopyEnd (cptr, "could not send header"); | |
689 | |
690 error ("server error: %s", PQerrorMessage (cptr)); | |
691 } | |
692 else | |
693 { | |
694 oct_pq_conv_t *convs [c]; | |
695 memset (convs, 0, sizeof (convs)); | |
696 oct_type_t oct_types [c]; | |
697 | |
698 for (octave_idx_type i = 0; i < r; i++) // i is row | |
699 { | |
700 int16_t fc = htobe16 (int16_t (nf)); | |
701 if (PQputCopyData (cptr, (char *) &fc, 2) == -1) | |
702 { | |
703 error ("%s", PQerrorMessage (cptr)); | |
704 | |
705 PQputCopyEnd (cptr, "error sending field count"); | |
706 | |
707 error ("server error: %s", PQerrorMessage (cptr)); | |
708 | |
709 break; | |
710 } | |
711 | |
712 // j is column of argument data | |
713 for (octave_idx_type j = 0; j < c; j++) | |
714 { | |
715 if (data(i, j).is_real_scalar () && | |
716 data(i, j).isna ().bool_value ()) | |
717 { | |
718 int32_t t = htobe32 (int32_t (-1)); | |
719 if (PQputCopyData (cptr, (char *) &t, 4) == -1) | |
720 { | |
721 error ("could not send NULL in copy-in"); | |
722 | |
723 break; | |
724 } | |
725 } | |
726 else | |
727 { | |
728 if (! convs [j]) | |
729 { | |
730 if ((j == 0) && oids) | |
731 { | |
732 std::string t ("oid"); | |
733 convs[0] = pgtype_from_spec (t, oct_types[0]); | |
734 } | |
735 else | |
736 { | |
737 if (cin_types(j).is_empty ()) | |
738 { | |
739 oct_types[j] = simple; | |
740 | |
741 if (! (convs[j] = | |
742 pgtype_from_octtype (data(i, j)))) | |
743 { | |
744 error ("could not determine type in column %i for copy-in", | |
745 j); | |
746 | |
747 break; | |
748 } | |
749 } | |
750 else | |
751 { | |
752 std::string s = cin_types(j).string_value (); | |
753 if (error_state) | |
754 { | |
755 error ("column type specification no string"); | |
756 | |
757 break; | |
758 } | |
759 | |
760 if (! (convs[j] = | |
761 pgtype_from_spec (s, oct_types[j]))) | |
762 { | |
763 error ("invalid column type specification"); | |
764 | |
765 break; | |
766 } | |
767 } | |
768 } | |
769 } // ! convs [j] | |
770 | |
771 oct_pq_dynvec_t val; | |
772 | |
773 bool conversion_failed = false; | |
774 switch (oct_types[j]) | |
775 { | |
776 case simple: | |
11657 | 777 if (convs[j]->from_octave_bin (conn, data(i, j), val)) |
11484 | 778 conversion_failed = true; |
779 break; | |
780 | |
781 case array: | |
11657 | 782 if (from_octave_bin_array (conn, data(i, j), val, |
783 convs[j])) | |
11484 | 784 conversion_failed = true; |
785 break; | |
786 | |
787 case composite: | |
11657 | 788 if (from_octave_bin_composite (conn, data(i, j), val, |
11484 | 789 convs[j])) |
790 conversion_failed = true; | |
791 break; | |
792 | |
793 default: | |
794 // should not get here | |
795 error ("internal error, undefined type identifier"); | |
796 } | |
797 | |
798 if (conversion_failed) | |
799 error ("could not convert data(%i, %i) for copy-in", | |
800 i, j); | |
801 else | |
802 { | |
803 uint32_t t = htobe32 (uint32_t (val.size ())); | |
804 if (PQputCopyData (cptr, (char *) &t, 4) == -1) | |
805 error ("could not send data length in copy-in"); | |
806 else if (PQputCopyData (cptr, &(val.front ()), | |
807 val.size ()) == -1) | |
808 error ("could not send copy-in data"); | |
809 } | |
810 | |
811 if (error_state) break; | |
812 } | |
813 } // columns of argument data | |
814 | |
815 if (error_state) | |
816 { | |
817 PQputCopyEnd (cptr, "error sending copy-in data"); | |
818 | |
819 error ("server error: %s", PQerrorMessage (cptr)); | |
820 | |
821 break; | |
822 } | |
823 } // rows of argument data | |
824 } | |
825 | |
826 if (! error_state) | |
827 if (PQputCopyData (cptr, trailer, 2) == -1) | |
828 { | |
829 PQputCopyEnd (cptr, "could not send trailer"); | |
830 | |
831 error ("%s", PQerrorMessage (cptr)); | |
832 } | |
833 | |
834 if (! error_state) | |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
835 { |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
836 if (PQputCopyEnd (cptr, NULL) == -1) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
837 error ("%s", PQerrorMessage (cptr)); |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
838 else |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
839 { |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
840 PQclear (res); |
11484 | 841 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
842 if ((res = PQgetResult (cptr))) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
843 { |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
844 if ((state = PQresultStatus (res)) == PGRES_FATAL_ERROR) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
845 error ("server error in copy-in: %s", |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
846 PQerrorMessage (cptr)); |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
847 } |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
848 else |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
849 error ("unexpectedly got no result information"); |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
850 } |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
851 } |
11484 | 852 } // copy from variable |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
853 |
11407 | 854 if (error_state) |
855 valid = 0; | |
856 | |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
857 return octave_value (std::string ("copy in")); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
858 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
859 |
11407 | 860 oct_pq_conv_t *command::pgtype_from_octtype (const octave_value ¶m) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
861 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
862 // printf ("pgtype_from_octtype: "); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
863 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
864 if (param.is_bool_scalar ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
865 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
866 // printf ("bool\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
867 return conn.name_conv_map["bool"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
868 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
869 else if (param.is_real_scalar ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
870 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
871 if (param.is_double_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
872 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
873 // printf ("float8\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
874 return conn.name_conv_map["float8"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
875 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
876 else if (param.is_single_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
877 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
878 // printf ("float4\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
879 return conn.name_conv_map["float4"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
880 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
881 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
882 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
883 if (param.is_scalar_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
884 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
885 if (param.is_int16_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
886 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
887 // printf ("int2\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
888 return conn.name_conv_map["int2"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
889 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
890 else if (param.is_int32_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
891 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
892 // printf ("int4\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
893 return conn.name_conv_map["int4"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
894 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
895 else if (param.is_int64_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
896 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
897 // printf ("int8\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
898 return conn.name_conv_map["int8"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
899 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
900 else if (param.is_uint32_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
901 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
902 // printf ("oid\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
903 return conn.name_conv_map["oid"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
904 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
905 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
906 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
907 if (param.is_uint8_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
908 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
909 // printf ("bytea\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
910 return conn.name_conv_map["bytea"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
911 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
912 else if (param.is_string ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
913 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
914 // printf ("text\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
915 return conn.name_conv_map["text"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
916 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
917 |
11697 | 918 // is_real_type() is true for strings, so is_numeric_type() would |
919 // still be needed if strings were not recognized above | |
920 if (param.is_real_type ()) | |
921 { | |
922 switch (param.numel ()) | |
923 { | |
924 case 2: | |
925 // printf ("point\n"); | |
926 return conn.name_conv_map["point"]; | |
927 case 3: | |
928 // printf ("circle\n"); | |
929 return conn.name_conv_map["circle"]; | |
930 case 4: | |
931 // printf ("lseg\n"); | |
932 return conn.name_conv_map["lseg"]; | |
933 } | |
934 } | |
935 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
936 ERROR_RETURN_NO_PG_TYPE |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
937 } |