Mercurial > forge
annotate main/database/src/pq_exec.cc @ 12665:393b940d7ee2 octave-forge
pq_connection.h: Call register_type() only once.
author | i7tiol |
---|---|
date | Wed, 08 Jul 2015 13:54:27 +0000 |
parents | 9cb56e0cd09b |
children | 1af86934c14e |
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/parse.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
22 #include <octave/ov-struct.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
23 #include <octave/Cell.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
24 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
25 #include "command.h" |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
26 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
27 // PKG_disabled_ADD: autoload ("pq_exec", "pq_interface.oct"); |
12613 | 28 // PKG_disabled_DEL: autoload ("pq_exec", "pq_interface.oct", "remove"); |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
29 // PKG_ADD: autoload ("__pq_exec_params__", "pq_interface.oct"); |
12613 | 30 // PKG_DEL: autoload ("__pq_exec_params__", "pq_interface.oct", "remove"); |
11394
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
33 #if 0 |
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 // I left this here because of its (formerly working) functionality of |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
36 // reading more than one result. But the code (and the helptext, too) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
37 // has not been adapted to general changes and is not working, and it |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
38 // would need converters for text mode to be useful. Anyway I don't |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
39 // see why one should need to execute many commands with one line, |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
40 // except if one wants to use some unchanged external SQL code. I'll |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
41 // probably wait till someone expresses such a need. |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
42 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
43 DEFUN_DLD (pq_exec, args, , |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
44 "-*- texinfo -*-\n\ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
45 @deftypefn {Loadable Function} {@var{id}} pq_exec (@var{connection}, @var{command})\n\ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
46 @deftypefnx {Loadable Function} {@var{id}} pq_exec (@var{connection}, @var{command}, @var{copydata}, @dots{})\n\ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
47 Sends the string @var{command}, which should contain one or more SQL commands, over the connection @var{connection} and returns multiple output values, one for each command. For queries (commands potentially returning data), the output will be a structure with fields @code{data} (containing a cell array with the data) and @code{columns} (containing the column headers). For other commands, the output will be the number of affected rows in the database. For each command in @var{command} containing a @code{COPY FROM STDIN}, an additional argument @var{copydata} must be supplied which is either a cell-array with suitable data or a handle for a function which will return parts of this cell-array successively, one for each call, and @code{0} when ready.\n\ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
48 \n\ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
49 @end deftypefn") |
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 std::string fname ("pq_exec"); |
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 octave_value_list retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
54 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
55 if (args.length () < 2 || args.length () > 3 || |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
56 args(0).type_id () != octave_pq_connection::static_type_id ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
57 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
58 print_usage (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
59 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
60 return retval; |
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 std::string cmd (args(1).string_value ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
64 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
65 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
66 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
67 error ("%s: second argument can not be converted to a string", fname.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
68 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
69 return retval; |
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 |
12612 | 72 const octave_base_value& rep = (args(0).get_rep ()); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
73 |
12612 | 74 const octave_pq_connection &oct_pq_conn = |
75 dynamic_cast<const octave_pq_connection&> (rep); | |
11394
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 Cell rettypes; // not implemented here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
78 |
12612 | 79 command c (*(oct_pq_conn.get_rep ()), cmd, rettypes, fname); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
80 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
81 if (c.good ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
82 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
83 while (true) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
84 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
85 octave_value val; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
86 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
87 val = c.process_single_result (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
88 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
89 if (! c.good () || c.all_results_fetched ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
90 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
91 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
92 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
93 int l = retval.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
94 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
95 retval.resize (l + 1); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
96 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
97 retval (l) = val; |
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 } |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
102 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
103 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
104 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
105 #endif // code disabled |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
106 |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
107 DEFUN_DLD (__pq_exec_params__, args, nargout, |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
108 "-*- texinfo -*-\n\ |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
109 undifined internal function, meant to be called by @code{pq_exec_params}") |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
110 { |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
111 std::string fname ("__pq_exec_params__"); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
112 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
113 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
114 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
115 int nargs = args.length (); |
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 if (nargs < 2 || nargs > 4 || |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
118 args(0).type_id () != octave_pq_connection::static_type_id ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
119 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
120 print_usage (); |
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 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
123 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
124 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
125 std::string cmd (args(1).string_value ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
126 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
127 if (error_state) |
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 error ("%s: second argument can not be converted to a string", fname.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
130 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
131 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
132 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
133 |
12665 | 134 const octave_base_value &rep = args(0).get_rep (); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
135 |
12612 | 136 const octave_pq_connection &oct_pq_conn = |
137 dynamic_cast<const octave_pq_connection&> (rep); | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
138 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
139 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
140 /* |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
141 printf ("oid map:\n"); |
12612 | 142 for (oct_pq_conv_map_t::iterator it = oct_pq_conn.get_rep ()->conv_map.begin (); |
143 it != oct_pq_conn.get_rep ()->conv_map.end (); it++) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
144 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
145 printf ("key: %u; ", it->first); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
146 print_conv (it->second); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
147 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
148 printf ("\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
149 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
150 printf ("name map:\n"); |
12612 | 151 for (oct_pq_name_conv_map_t::iterator it = oct_pq_conn.get_rep ()->name_conv_map.begin (); |
152 it != oct_pq_conn.get_rep ()->name_conv_map.end (); it++) | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
153 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
154 printf ("key: %s; ", it->first); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
155 print_conv (it->second); |
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 printf ("\n"); |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
161 Cell params; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
162 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
163 octave_scalar_map settings; |
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 if (nargs == 3) |
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 (args(2).is_cell ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
168 params = args(2).cell_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
169 else |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
170 settings = args(2).scalar_map_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
171 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
172 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
173 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
174 error ("%s: third argument neither cell-array nor scalar structure", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
175 fname.c_str ()); |
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 return retval; |
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 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
180 else if (nargs == 4) |
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 params = args(2).cell_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
183 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
184 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
185 error ("%s: could not convert third argument to cell-array", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
186 fname.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
187 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
188 return retval; |
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 settings = args(3).scalar_map_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
191 if (error_state) |
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 error ("%s: could not convert fourth argument to scalar structure"); |
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 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
196 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
197 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
198 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
199 int nparams = params.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
200 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
201 dim_vector pdims = params.dims (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
202 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
203 if (pdims.length () > 2 || (pdims(0) > 1 && pdims(1) > 1)) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
204 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
205 error ("%s: cell-array of parameters must not be more than one-dimensional", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
206 fname.c_str ()); |
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 return retval; |
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 |
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
|
211 // get option settings |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
212 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
213 octave_value_list f_args (3); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
214 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
215 octave_value_list f_ret; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
216 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
217 f_args(0) = octave_value (settings); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
218 f_args(1) = octave_value ("param_types"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
219 f_args(2) = octave_value (Cell (1, nparams)); |
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 f_ret = feval ("getdbopts", f_args, 1); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
222 Cell ptypes = f_ret(0).cell_value (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
223 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
224 { |
11484 | 225 error ("%s: could not convert param_types to cell", |
226 fname.c_str ()); | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
227 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
228 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
229 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
230 |
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
|
231 f_args(1) = octave_value ("copy_in_path"); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
232 f_args(2) = octave_value (""); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
233 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
234 f_ret = feval ("getdbopts", f_args, 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
|
235 std::string cin_path = f_ret(0).string_value (); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
236 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
|
237 { |
11484 | 238 error ("%s: could not convert copy_in_path to string", |
239 fname.c_str ()); | |
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
|
240 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
241 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
|
242 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
243 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
244 f_args(1) = octave_value ("copy_out_path"); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
245 f_args(2) = octave_value (""); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
246 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
247 f_ret = feval ("getdbopts", f_args, 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
|
248 std::string cout_path = f_ret(0).string_value (); |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
249 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
|
250 { |
11484 | 251 error ("%s: could not convert copy_out_path to string", |
252 fname.c_str ()); | |
253 | |
254 return retval; | |
255 } | |
256 | |
257 f_args(1) = octave_value ("copy_in_data"); | |
258 f_args(2) = octave_value (Cell ()); | |
259 | |
260 f_ret = feval ("getdbopts", f_args, 1); | |
261 Cell cin_data = f_ret(0).cell_value (); | |
262 if (error_state) | |
263 { | |
264 error ("%s: could not convert copy_in_data to cell", | |
265 fname.c_str ()); | |
266 | |
267 return retval; | |
268 } | |
269 | |
270 f_args(1) = octave_value ("copy_in_with_oids"); | |
271 f_args(2) = octave_value (false); | |
272 | |
273 f_ret = feval ("getdbopts", f_args, 1); | |
274 bool cin_with_oids = f_ret(0).bool_value (); | |
275 if (error_state) | |
276 { | |
277 error ("%s: could not convert copy_in_with_oids to bool", | |
278 fname.c_str ()); | |
279 | |
280 return retval; | |
281 } | |
282 | |
283 f_args(1) = octave_value ("copy_in_types"); | |
284 f_args(2) = octave_value (Cell ()); | |
285 | |
286 f_ret = feval ("getdbopts", f_args, 1); | |
287 Cell cin_types = f_ret(0).cell_value (); | |
288 if (error_state) | |
289 { | |
290 error ("%s: could not convert copy_in_types to cell", | |
291 fname.c_str ()); | |
292 | |
293 return retval; | |
294 } | |
295 | |
296 f_args(1) = octave_value ("copy_in_from_variable"); | |
297 f_args(2) = octave_value (false); | |
298 | |
299 f_ret = feval ("getdbopts", f_args, 1); | |
300 bool cin_from_variable = f_ret(0).bool_value (); | |
301 if (error_state) | |
302 { | |
303 error ("%s: could not convert copy_in_from_variable to bool", | |
304 fname.c_str ()); | |
305 | |
306 return retval; | |
307 } | |
308 | |
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
|
309 // check option settings |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
310 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
311 if (ptypes.length () != nparams) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
312 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
313 error ("%s: if given, cell-array of parameter types must have same length as cell-array of parameters", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
314 fname.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
315 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
316 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
317 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
318 |
11484 | 319 dim_vector cind_dv = cin_data.dims (); |
320 if (cind_dv.length () > 2) | |
321 { | |
322 error ("%s: copy-in data must not be more than two-dimensional", | |
323 fname.c_str ()); | |
324 | |
325 return retval; | |
326 } | |
327 | |
328 if (cin_types.is_empty ()) | |
329 cin_types.resize (dim_vector (1, cind_dv(1))); | |
330 if (cin_types.numel () != cind_dv(1)) | |
331 { | |
332 error ("%s: copy_in_types has wrong number of elements"); | |
333 | |
334 return retval; | |
335 } | |
336 | |
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
|
337 // |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
338 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
339 Cell rtypes; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
340 |
12612 | 341 command c (*(oct_pq_conn.get_rep ()), cmd, params, ptypes, rtypes, fname); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
342 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
343 if (c.good ()) |
11484 | 344 retval = c.process_single_result |
345 (cin_path, cout_path, cin_data, cin_types, cin_with_oids, | |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
346 cin_from_variable); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
347 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
348 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
349 } |