Mercurial > forge
annotate main/database/src/pq_exec.cc @ 12720:52ca082757c2 octave-forge tip
Update copyright notices.
author | i7tiol |
---|---|
date | Sat, 27 Feb 2016 11:21:29 +0000 |
parents | 1af86934c14e |
children |
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 |
12720 | 3 Copyright (C) 2012-2016 Olaf Till <i7tiol@t-online.de> |
11394
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" |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
26 #include "error-helpers.h" |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
27 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
28 // PKG_disabled_ADD: autoload ("pq_exec", "pq_interface.oct"); |
12613 | 29 // 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
|
30 // PKG_ADD: autoload ("__pq_exec_params__", "pq_interface.oct"); |
12613 | 31 // PKG_DEL: autoload ("__pq_exec_params__", "pq_interface.oct", "remove"); |
11394
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
34 #if 0 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
35 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
36 // I left this here because of its (formerly working) functionality of |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
37 // 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
|
38 // 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
|
39 // 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
|
40 // 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
|
41 // 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
|
42 // probably wait till someone expresses such a need. |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
43 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
44 DEFUN_DLD (pq_exec, args, , |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
45 "-*- texinfo -*-\n\ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
46 @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
|
47 @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
|
48 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
|
49 \n\ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
50 @end deftypefn") |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
51 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
52 std::string fname ("pq_exec"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
53 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
54 octave_value_list retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
55 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
56 if (args.length () < 2 || args.length () > 3 || |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
57 args(0).type_id () != octave_pq_connection::static_type_id ()) |
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 print_usage (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
60 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
61 return retval; |
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 std::string cmd (args(1).string_value ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
65 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
66 if (error_state) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
67 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
68 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
|
69 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
70 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
71 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
72 |
12612 | 73 const octave_base_value& rep = (args(0).get_rep ()); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
74 |
12612 | 75 const octave_pq_connection &oct_pq_conn = |
76 dynamic_cast<const octave_pq_connection&> (rep); | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
77 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
78 Cell rettypes; // not implemented here |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
79 |
12612 | 80 command c (*(oct_pq_conn.get_rep ()), cmd, rettypes, fname); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
81 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
82 if (c.good ()) |
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 while (true) |
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 octave_value val; |
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 val = c.process_single_result (); |
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 if (! c.good () || c.all_results_fetched ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
91 break; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
92 else |
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 int l = retval.length (); |
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 retval.resize (l + 1); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
97 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
98 retval (l) = val; |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
103 return retval; |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
106 #endif // code disabled |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
107 |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
108 DEFUN_DLD (__pq_exec_params__, args, nargout, |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
109 "-*- texinfo -*-\n\ |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
110 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
|
111 { |
11551
7c0dae992c31
Work around path problem in package initialization. Fixes part of bug #38491.
i7tiol
parents:
11499
diff
changeset
|
112 std::string fname ("__pq_exec_params__"); |
11394
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 octave_value retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
115 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
116 int nargs = args.length (); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
117 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
118 if (nargs < 2 || nargs > 4 || |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
119 args(0).type_id () != octave_pq_connection::static_type_id ()) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
120 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
121 print_usage (); |
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 return retval; |
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 |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
126 std::string cmd; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
127 CHECK_ERROR (cmd = args(1).string_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
128 "%s: second argument can not be converted to a string", |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
129 fname.c_str ()); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
130 |
12665 | 131 const octave_base_value &rep = args(0).get_rep (); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
132 |
12612 | 133 const octave_pq_connection &oct_pq_conn = |
134 dynamic_cast<const octave_pq_connection&> (rep); | |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
135 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
136 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
137 /* |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
138 printf ("oid map:\n"); |
12612 | 139 for (oct_pq_conv_map_t::iterator it = oct_pq_conn.get_rep ()->conv_map.begin (); |
140 it != oct_pq_conn.get_rep ()->conv_map.end (); it++) | |
11394
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 printf ("key: %u; ", it->first); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
143 print_conv (it->second); |
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 ("\n"); |
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 printf ("name map:\n"); |
12612 | 148 for (oct_pq_name_conv_map_t::iterator it = oct_pq_conn.get_rep ()->name_conv_map.begin (); |
149 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
|
150 { |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
151 printf ("key: %s; ", it->first); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
152 print_conv (it->second); |
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 ("\n"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
155 */ |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
158 Cell params; |
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 octave_scalar_map settings; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
161 |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
162 bool err; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
163 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
164 if (nargs == 3) |
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 if (args(2).is_cell ()) |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
167 { |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
168 SET_ERR (params = args(2).cell_value (), err); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
169 } |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
170 else |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
171 { |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
172 SET_ERR (settings = args(2).scalar_map_value (), err); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
173 } |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
174 |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
175 if (err) |
11394
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 error ("%s: third argument neither cell-array nor scalar structure", |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
178 fname.c_str ()); |
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 return retval; |
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 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
183 else if (nargs == 4) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
184 { |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
185 CHECK_ERROR (params = args(2).cell_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
186 "%s: could not convert third argument to cell-array", |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
187 fname.c_str ()); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
188 CHECK_ERROR (settings = args(3).scalar_map_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
189 "%s: could not convert fourth argument to scalar structure"); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
190 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
191 |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
192 int nparams = params.numel (); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
193 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
194 dim_vector pdims = params.dims (); |
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 if (pdims.length () > 2 || (pdims(0) > 1 && pdims(1) > 1)) |
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 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
|
199 fname.c_str ()); |
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 return retval; |
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 |
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
|
204 // 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
|
205 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
206 octave_value_list f_args (3); |
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 octave_value_list f_ret; |
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 f_args(0) = octave_value (settings); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
211 f_args(1) = octave_value ("param_types"); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
212 f_args(2) = octave_value (Cell (1, nparams)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
213 |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
214 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
215 "%s: error calling getdbopts", |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
216 fname.c_str ()); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
217 Cell ptypes; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
218 CHECK_ERROR (ptypes = f_ret(0).cell_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
219 "%s: could not convert param_types to cell", fname.c_str ()); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
220 |
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
|
221 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
|
222 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
|
223 |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
224 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
225 "%s: error calling getdbopts", fname.c_str ()); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
226 std::string cin_path; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
227 CHECK_ERROR (cin_path = f_ret(0).string_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
228 "%s: could not convert copy_in_path to string", 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
|
229 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
230 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
|
231 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
|
232 |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
233 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
234 "%s: error calling getdbopts", fname.c_str ()); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
235 std::string cout_path; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
236 CHECK_ERROR (cout_path = f_ret(0).string_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
237 "%s: could not convert copy_out_path to string", fname.c_str ()); |
11484 | 238 |
239 f_args(1) = octave_value ("copy_in_data"); | |
240 f_args(2) = octave_value (Cell ()); | |
241 | |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
242 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
243 "%s: error calling getdbopts", fname.c_str ()); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
244 Cell cin_data; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
245 CHECK_ERROR (cin_data = f_ret(0).cell_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
246 "%s: could not convert copy_in_data to cell", fname.c_str ()); |
11484 | 247 |
248 f_args(1) = octave_value ("copy_in_with_oids"); | |
249 f_args(2) = octave_value (false); | |
250 | |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
251 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
252 "%s: error calling getdbopts", fname.c_str ()); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
253 bool cin_with_oids; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
254 CHECK_ERROR (cin_with_oids = f_ret(0).bool_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
255 "%s: could not convert copy_in_with_oids to bool", |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
256 fname.c_str ()); |
11484 | 257 |
258 f_args(1) = octave_value ("copy_in_types"); | |
259 f_args(2) = octave_value (Cell ()); | |
260 | |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
261 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
262 "%s: error calling getdbopts", fname.c_str ()); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
263 Cell cin_types; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
264 CHECK_ERROR (cin_types = f_ret(0).cell_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
265 "%s: could not convert copy_in_types to cell", fname.c_str ()); |
11484 | 266 |
267 f_args(1) = octave_value ("copy_in_from_variable"); | |
268 f_args(2) = octave_value (false); | |
269 | |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
270 CHECK_ERROR (f_ret = feval ("getdbopts", f_args, 1), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
271 "%s: error calling getdbopts", fname.c_str ()); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
272 bool cin_from_variable; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
273 CHECK_ERROR (cin_from_variable = f_ret(0).bool_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
274 "%s: could not convert copy_in_from_variable to bool", |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
275 fname.c_str ()); |
11484 | 276 |
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
|
277 // 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
|
278 |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
279 if (ptypes.numel () != nparams) |
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 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
|
282 fname.c_str ()); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
283 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
284 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
285 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
286 |
11484 | 287 dim_vector cind_dv = cin_data.dims (); |
288 if (cind_dv.length () > 2) | |
289 { | |
290 error ("%s: copy-in data must not be more than two-dimensional", | |
291 fname.c_str ()); | |
292 | |
293 return retval; | |
294 } | |
295 | |
296 if (cin_types.is_empty ()) | |
297 cin_types.resize (dim_vector (1, cind_dv(1))); | |
298 if (cin_types.numel () != cind_dv(1)) | |
299 { | |
300 error ("%s: copy_in_types has wrong number of elements"); | |
301 | |
302 return retval; | |
303 } | |
304 | |
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
|
305 // |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
306 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
307 Cell rtypes; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
308 |
12612 | 309 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
|
310 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
311 if (c.good ()) |
11484 | 312 retval = c.process_single_result |
313 (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
|
314 cin_from_variable); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
315 |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
316 if (! c.good ()) |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
317 error ("%s: error processing result", fname.c_str ()); |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12665
diff
changeset
|
318 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
319 return retval; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
320 } |