Mercurial > forge
annotate main/database/src/command.h @ 12612:2257648e8ce1 octave-forge
avoid using const_cast, new release 2.3.2
* pq_connection.h/cc: octave_pq_connection now contains pointer to object
of new class octave_pq_connection_rep, containing the pq-specific members
formerly in octave_pq_connection.
* pq_exec.cc, pq_close.cc, pq_update_types.cc, pq_conninfo.cc, pq_lo.cc:
Remove const_cast, use octave_pq_connection_rep object instead.
* __pq_connect__.cc, converters.h/cc, converters_arr_comp.cc, command.h/cc:
Use octave_pq_connection_rep instead of octave_pq_connection.
author | i7tiol |
---|---|
date | Tue, 05 May 2015 07:31:33 +0000 |
parents | ed5361361a0f |
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 #ifndef __OCT_PQ_COMMAND__ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
21 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
22 #define __OCT_PQ_COMMAND__ |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
23 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
24 #include <octave/oct.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
25 #include <octave/ov-struct.h> |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
26 #include <octave/Cell.h> |
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 #include "pq_connection.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 class |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
31 command |
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 public: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
34 |
12612 | 35 command (octave_pq_connection_rep &connection, std::string &cmd, Cell &rtypes, |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
36 std::string &who); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
37 |
12612 | 38 command (octave_pq_connection_rep &connection, std::string &cmd, Cell ¶ms, |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
39 Cell &ptypes, Cell &rtypes, std::string &who); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
40 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
41 ~command (void) |
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 if (res) PQclear (res); |
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 (! all_fetched) |
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 while ((res = PQgetResult (cptr))) |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
48 PQclear (res); |
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 |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
52 typedef int (*to_octave_array_fp_t) |
12612 | 53 (const octave_pq_connection_rep &, const char *, octave_value &, |
11657 | 54 int, oct_pq_conv_t *); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
55 |
11713
ee2b22964070
Make some functions of class 'command' non-members.
i7tiol
parents:
11706
diff
changeset
|
56 typedef int (*to_octave_composite_fp_t) |
12612 | 57 (const octave_pq_connection_rep &, const char *, octave_value &, |
11657 | 58 int, oct_pq_conv_t *); |
11394
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 int all_results_fetched (void) |
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 return all_fetched; |
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 |
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
|
65 octave_value process_single_result (void) |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
66 { |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
67 Cell c; |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
68 // inlining should prevent the additional copy |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
69 return process_single_result ("", "", c, c, false, false); |
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
|
70 } |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
71 |
913ac5491db1
Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents:
11394
diff
changeset
|
72 octave_value process_single_result (const std::string &infile, |
11484 | 73 const std::string &outfile, |
74 const Cell &cin_data, | |
75 const Cell &cin_types, | |
76 bool 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
|
77 bool cin_from_variable); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
78 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
79 int good (void) {return valid;} |
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 private: |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
82 |
11706
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11657
diff
changeset
|
83 octave_map get_elements_typeinfo (oct_pq_conv_t *conv, bool &err); |
95b91d8c9ee2
Make returned type information recursive over composite type elements.
i7tiol
parents:
11657
diff
changeset
|
84 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
85 void check_first_result (void) |
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 if (! res) |
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 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
90 error ("%s: could not execute command: %s", caller.c_str (), |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
91 PQerrorMessage (cptr)); |
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 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
94 else if ((state = PQresultStatus (res)) == PGRES_EMPTY_QUERY) |
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 valid = 0; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
97 error ("%s: empty command", caller.c_str ()); |
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 octave_value command_ok_handler (void) |
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 char *c = PQcmdTuples (res); |
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 return octave_value (atoi (c)); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
106 } |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
107 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
108 octave_value tuples_ok_handler (void); |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
109 |
11499
1176424db5df
Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents:
11484
diff
changeset
|
110 octave_value copy_out_handler (const std::string &); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
111 |
11484 | 112 octave_value copy_in_handler (const std::string &, const Cell &, const Cell &, |
113 bool, bool); | |
11394
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 PGresult *res; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
116 int all_fetched; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
117 int valid; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
118 ExecStatusType state; |
12612 | 119 octave_pq_connection_rep &conn; |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
120 PGconn *cptr; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
121 Cell &rettypes; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
122 std::string &caller; |
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 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
126 #endif // __OCT_PQ_COMMAND__ |