Mercurial > forge
annotate main/database/src/command.cc @ 11697:9e624fa135a1 octave-forge
Added converters for geometric types.
author | i7tiol |
---|---|
date | Sun, 12 May 2013 10:19:34 +0000 |
parents | 465192f682f0 |
children | dafee4563c36 |
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); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
340 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
341 bool rtypes_given; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
342 int l = rettypes.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
343 if (l > 0) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
344 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
345 if (l != nf) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
346 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
347 error ("%s: wrong number of given returned types", caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
348 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
349 return octave_value_list (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
350 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
351 rtypes_given = true; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
352 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
353 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
354 rtypes_given = false; |
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 for (int j = 0; j < nf; j++) // j is column |
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 columns(j) = octave_value (PQfname (res, j)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
359 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
360 int f = PQfformat (res, j); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
361 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
362 oct_pq_to_octave_fp_t simple_type_to_octave; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
363 to_octave_array_fp_t array_to_octave; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
364 to_octave_composite_fp_t composite_to_octave; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
365 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
366 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
|
367 // initializing it here |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
368 oct_type_t oct_type; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
369 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
370 // perform next block only if there are any rows, since |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
371 // otherwise no converter will be needed and we can spare a |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
372 // possible error of not finding a suitable one |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
373 if (nt > 0) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
374 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
375 if (rtypes_given) // for internal reading of system tables |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
376 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
377 std::string type = rettypes(j).string_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
378 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
379 error ("%s: could not convert given type to string", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
380 caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
381 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
382 conv = pgtype_from_spec (type, oct_type); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
383 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
384 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
385 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
386 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
387 break; |
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 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
390 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
391 if (! (conv = pgtype_from_spec (PQftype (res, j), oct_type))) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
392 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
393 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
394 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
395 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
396 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
397 if (f) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
398 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
399 array_to_octave = &command::to_octave_bin_array; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
400 composite_to_octave = &command::to_octave_bin_composite; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
401 // will be NULL for non-simple converters |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
402 simple_type_to_octave = conv->to_octave_bin; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
403 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
404 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
405 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
406 array_to_octave = &command::to_octave_str_array; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
407 composite_to_octave = &command::to_octave_str_composite; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
408 // will be NULL for non-simple converters |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
409 simple_type_to_octave = conv->to_octave_str; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
410 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
411 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
412 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
413 for (int i = 0; i < nt; i++) // i is row |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
414 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
415 if (PQgetisnull (res, i, j)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
416 data(i, j) = octave_value (octave_NA); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
417 else |
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 char *v = PQgetvalue (res, i, j); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
420 int nb = PQgetlength (res, i, j); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
421 octave_value ov; |
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 switch (oct_type) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
424 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
425 case simple: |
11657 | 426 if (simple_type_to_octave (conn, v, ov, nb)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
427 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
428 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
429 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
430 case array: |
11657 | 431 if ((this->*array_to_octave) (conn, v, ov, nb, conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
432 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
433 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
434 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
435 case composite: |
11657 | 436 if ((this->*composite_to_octave) (conn, v, ov, nb, conv)) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
437 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
438 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
439 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
440 default: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
441 // should not get here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
442 error ("%s: internal error, undefined type identifier", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
443 caller.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
444 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
445 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
446 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
447 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
448 if (valid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
449 data(i, j) = ov; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
450 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
451 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
452 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
453 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
454 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
455 if (! valid) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
456 break; |
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 (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
460 return octave_value_list (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
461 else |
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 ret.assign ("data", octave_value (data)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
464 ret.assign ("columns", octave_value (columns)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
465 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
466 return octave_value (ret); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
467 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
468 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
469 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
470 octave_value command::copy_out_handler (const std::string &outfile) |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
471 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
472 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
473 |
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
|
474 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
|
475 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
476 // 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
|
477 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
478 if (outfile.empty ()) |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
479 { |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
480 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
|
481 |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
482 valid = 0; |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
483 |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
484 return retval; |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
485 } |
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
486 |
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
|
487 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
|
488 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
|
489 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
|
490 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
491 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
|
492 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
|
493 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
|
494 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
495 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
|
496 { |
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 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
|
498 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
|
499 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
|
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 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
|
502 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
503 |
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 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
|
505 ostr.close (); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
506 |
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
|
507 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
|
508 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
|
509 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
|
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 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
|
512 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
513 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
|
514 { |
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 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
|
516 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
|
517 } |
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 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
|
519 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
|
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 } |
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 else |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
523 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
|
524 |
11408
6c22f62f2b64
Resumed to and finished copy-in/-out only from/to files.
i7tiol
parents:
11407
diff
changeset
|
525 if (error_state) |
6c22f62f2b64
Resumed to and finished copy-in/-out only from/to files.
i7tiol
parents:
11407
diff
changeset
|
526 valid = 0; |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
527 |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
528 return octave_value (std::string ("copy out")); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
529 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
530 |
11484 | 531 octave_value command::copy_in_handler (const std::string &infile, |
532 const Cell &data, | |
533 const Cell &cin_types, | |
534 bool oids, | |
535 bool var) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
536 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
537 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
538 |
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
|
539 #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
|
540 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
541 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
|
542 |
11484 | 543 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
|
544 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
545 // 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
|
546 |
11484 | 547 if (infile.empty ()) |
548 { | |
549 error ("no input file given"); | |
550 | |
551 valid = 0; | |
552 | |
553 return retval; | |
554 } | |
555 | |
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
|
556 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
|
557 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
|
558 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
559 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
|
560 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
561 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
|
562 |
11407 | 563 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
|
564 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
565 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
|
566 |
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 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
|
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 |
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 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
|
571 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
572 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
|
573 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
574 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
|
575 { |
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 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
|
577 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
578 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
|
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 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
|
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 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
|
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 ((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
|
585 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
|
586 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
587 error ("%s", PQerrorMessage (cptr)); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
588 |
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 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
|
590 } |
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 } |
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 while (! istr.eof ()); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
594 |
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
|
595 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
|
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 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
|
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 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
|
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 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
|
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 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
|
604 { |
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 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
|
606 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
|
607 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
|
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 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
|
610 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
611 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
|
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 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
|
614 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
|
615 } |
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 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
|
617 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
|
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 } |
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 } |
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
|
621 else |
11484 | 622 { |
623 // copy in from octave variable | |
624 | |
625 dim_vector dv = data.dims (); | |
626 octave_idx_type r = dv(0); | |
627 octave_idx_type c = dv(1); | |
628 | |
629 octave_idx_type nf = PQnfields (res); | |
630 if (c != nf + oids) | |
631 { | |
632 error ("variable for copy-in has %i columns, but should have %i", | |
633 c, nf + oids); | |
634 | |
635 PQputCopyEnd | |
636 (cptr, "variable for copy-in has wrong number of columns"); | |
637 } | |
638 else if (! PQbinaryTuples (res)) | |
639 { | |
640 error ("copy-in from variable must use binary mode"); | |
641 | |
642 PQputCopyEnd (cptr, "copy-in from variable must use binary mode"); | |
643 } | |
644 else | |
645 { | |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
646 for (octave_idx_type j = 0; j < nf; j++) |
11484 | 647 if (! PQfformat (res, j)) |
648 { | |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
649 error ("copy-in from variable must use binary mode in all columns"); |
11484 | 650 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
651 PQputCopyEnd (cptr, "copy-in from variable must use binary mode in all columns"); |
11484 | 652 |
653 break; | |
654 } | |
655 } | |
656 | |
657 if (error_state) | |
658 { | |
659 error ("server error: %s", PQerrorMessage (cptr)); | |
660 | |
661 valid = 0; | |
662 | |
663 return retval; | |
664 } | |
665 | |
666 char header [COPY_HEADER_SIZE]; | |
667 memset (header, 0, COPY_HEADER_SIZE); | |
668 strcpy (header, "PGCOPY\n\377\r\n\0"); | |
11646 | 669 uint32_t tpu32 = htobe32 (uint32_t (oids) << 16); |
670 memcpy (&header[11], &tpu32, 4); | |
11484 | 671 |
672 char trailer [2]; | |
11646 | 673 int16_t tp16 = htobe16 (int16_t (-1)); |
674 memcpy (&trailer, &tp16, 2); | |
11484 | 675 |
676 if (PQputCopyData (cptr, header, COPY_HEADER_SIZE) == -1) | |
677 { | |
678 PQputCopyEnd (cptr, "could not send header"); | |
679 | |
680 error ("server error: %s", PQerrorMessage (cptr)); | |
681 } | |
682 else | |
683 { | |
684 oct_pq_conv_t *convs [c]; | |
685 memset (convs, 0, sizeof (convs)); | |
686 oct_type_t oct_types [c]; | |
687 | |
688 for (octave_idx_type i = 0; i < r; i++) // i is row | |
689 { | |
690 int16_t fc = htobe16 (int16_t (nf)); | |
691 if (PQputCopyData (cptr, (char *) &fc, 2) == -1) | |
692 { | |
693 error ("%s", PQerrorMessage (cptr)); | |
694 | |
695 PQputCopyEnd (cptr, "error sending field count"); | |
696 | |
697 error ("server error: %s", PQerrorMessage (cptr)); | |
698 | |
699 break; | |
700 } | |
701 | |
702 // j is column of argument data | |
703 for (octave_idx_type j = 0; j < c; j++) | |
704 { | |
705 if (data(i, j).is_real_scalar () && | |
706 data(i, j).isna ().bool_value ()) | |
707 { | |
708 int32_t t = htobe32 (int32_t (-1)); | |
709 if (PQputCopyData (cptr, (char *) &t, 4) == -1) | |
710 { | |
711 error ("could not send NULL in copy-in"); | |
712 | |
713 break; | |
714 } | |
715 } | |
716 else | |
717 { | |
718 if (! convs [j]) | |
719 { | |
720 if ((j == 0) && oids) | |
721 { | |
722 std::string t ("oid"); | |
723 convs[0] = pgtype_from_spec (t, oct_types[0]); | |
724 } | |
725 else | |
726 { | |
727 if (cin_types(j).is_empty ()) | |
728 { | |
729 oct_types[j] = simple; | |
730 | |
731 if (! (convs[j] = | |
732 pgtype_from_octtype (data(i, j)))) | |
733 { | |
734 error ("could not determine type in column %i for copy-in", | |
735 j); | |
736 | |
737 break; | |
738 } | |
739 } | |
740 else | |
741 { | |
742 std::string s = cin_types(j).string_value (); | |
743 if (error_state) | |
744 { | |
745 error ("column type specification no string"); | |
746 | |
747 break; | |
748 } | |
749 | |
750 if (! (convs[j] = | |
751 pgtype_from_spec (s, oct_types[j]))) | |
752 { | |
753 error ("invalid column type specification"); | |
754 | |
755 break; | |
756 } | |
757 } | |
758 } | |
759 } // ! convs [j] | |
760 | |
761 oct_pq_dynvec_t val; | |
762 | |
763 bool conversion_failed = false; | |
764 switch (oct_types[j]) | |
765 { | |
766 case simple: | |
11657 | 767 if (convs[j]->from_octave_bin (conn, data(i, j), val)) |
11484 | 768 conversion_failed = true; |
769 break; | |
770 | |
771 case array: | |
11657 | 772 if (from_octave_bin_array (conn, data(i, j), val, |
773 convs[j])) | |
11484 | 774 conversion_failed = true; |
775 break; | |
776 | |
777 case composite: | |
11657 | 778 if (from_octave_bin_composite (conn, data(i, j), val, |
11484 | 779 convs[j])) |
780 conversion_failed = true; | |
781 break; | |
782 | |
783 default: | |
784 // should not get here | |
785 error ("internal error, undefined type identifier"); | |
786 } | |
787 | |
788 if (conversion_failed) | |
789 error ("could not convert data(%i, %i) for copy-in", | |
790 i, j); | |
791 else | |
792 { | |
793 uint32_t t = htobe32 (uint32_t (val.size ())); | |
794 if (PQputCopyData (cptr, (char *) &t, 4) == -1) | |
795 error ("could not send data length in copy-in"); | |
796 else if (PQputCopyData (cptr, &(val.front ()), | |
797 val.size ()) == -1) | |
798 error ("could not send copy-in data"); | |
799 } | |
800 | |
801 if (error_state) break; | |
802 } | |
803 } // columns of argument data | |
804 | |
805 if (error_state) | |
806 { | |
807 PQputCopyEnd (cptr, "error sending copy-in data"); | |
808 | |
809 error ("server error: %s", PQerrorMessage (cptr)); | |
810 | |
811 break; | |
812 } | |
813 } // rows of argument data | |
814 } | |
815 | |
816 if (! error_state) | |
817 if (PQputCopyData (cptr, trailer, 2) == -1) | |
818 { | |
819 PQputCopyEnd (cptr, "could not send trailer"); | |
820 | |
821 error ("%s", PQerrorMessage (cptr)); | |
822 } | |
823 | |
824 if (! error_state) | |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
825 { |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
826 if (PQputCopyEnd (cptr, NULL) == -1) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
827 error ("%s", PQerrorMessage (cptr)); |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
828 else |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
829 { |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
830 PQclear (res); |
11484 | 831 |
11645
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
832 if ((res = PQgetResult (cptr))) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
833 { |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
834 if ((state = PQresultStatus (res)) == PGRES_FATAL_ERROR) |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
835 error ("server error in copy-in: %s", |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
836 PQerrorMessage (cptr)); |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
837 } |
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 error ("unexpectedly got no result information"); |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
840 } |
bd5a8f1bdfb8
Clean out harmless warnings and one unnecessarily returned column.
i7tiol
parents:
11551
diff
changeset
|
841 } |
11484 | 842 } // copy from variable |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
843 |
11407 | 844 if (error_state) |
845 valid = 0; | |
846 | |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
847 return octave_value (std::string ("copy in")); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
848 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
849 |
11407 | 850 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
|
851 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
852 // printf ("pgtype_from_octtype: "); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
853 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
854 if (param.is_bool_scalar ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
855 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
856 // printf ("bool\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
857 return conn.name_conv_map["bool"]; |
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 else if (param.is_real_scalar ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
860 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
861 if (param.is_double_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
862 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
863 // printf ("float8\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
864 return conn.name_conv_map["float8"]; |
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 else if (param.is_single_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
867 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
868 // printf ("float4\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
869 return conn.name_conv_map["float4"]; |
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 } |
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 if (param.is_scalar_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
874 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
875 if (param.is_int16_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
876 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
877 // printf ("int2\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
878 return conn.name_conv_map["int2"]; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
879 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
880 else if (param.is_int32_type ()) |
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 // printf ("int4\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
883 return conn.name_conv_map["int4"]; |
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 else if (param.is_int64_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 ("int8\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
888 return conn.name_conv_map["int8"]; |
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_uint32_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 ("oid\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
893 return conn.name_conv_map["oid"]; |
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 } |
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 if (param.is_uint8_type ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
898 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
899 // printf ("bytea\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
900 return conn.name_conv_map["bytea"]; |
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 else if (param.is_string ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
903 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
904 // printf ("text\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
905 return conn.name_conv_map["text"]; |
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 |
11697 | 908 // is_real_type() is true for strings, so is_numeric_type() would |
909 // still be needed if strings were not recognized above | |
910 if (param.is_real_type ()) | |
911 { | |
912 switch (param.numel ()) | |
913 { | |
914 case 2: | |
915 // printf ("point\n"); | |
916 return conn.name_conv_map["point"]; | |
917 case 3: | |
918 // printf ("circle\n"); | |
919 return conn.name_conv_map["circle"]; | |
920 case 4: | |
921 // printf ("lseg\n"); | |
922 return conn.name_conv_map["lseg"]; | |
923 } | |
924 } | |
925 | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
926 ERROR_RETURN_NO_PG_TYPE |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
927 } |