annotate main/database/src/command.h @ 12720:52ca082757c2 octave-forge tip

Update copyright notices.
author i7tiol
date Sat, 27 Feb 2016 11:21:29 +0000
parents 1af86934c14e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
52ca082757c2 Update copyright notices.
i7tiol
parents: 12718
diff changeset
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 #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"
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
29 #include "error-helpers.h"
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
30
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
31 class
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
32 command
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 public:
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
35
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11715
diff changeset
36 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
37 std::string &who);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
38
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11715
diff changeset
39 command (octave_pq_connection_rep &connection, std::string &cmd, Cell &params,
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
40 Cell &ptypes, Cell &rtypes, std::string &who);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
41
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
42 ~command (void)
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 if (res) PQclear (res);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
45
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
46 if (! all_fetched)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
47 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
48 while ((res = PQgetResult (cptr)))
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
49 PQclear (res);
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 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
52
11713
ee2b22964070 Make some functions of class 'command' non-members.
i7tiol
parents: 11706
diff changeset
53 typedef int (*to_octave_array_fp_t)
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11715
diff changeset
54 (const octave_pq_connection_rep &, const char *, octave_value &,
11657
465192f682f0 Pass connection information to converters.
i7tiol
parents: 11499
diff changeset
55 int, oct_pq_conv_t *);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
56
11713
ee2b22964070 Make some functions of class 'command' non-members.
i7tiol
parents: 11706
diff changeset
57 typedef int (*to_octave_composite_fp_t)
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11715
diff changeset
58 (const octave_pq_connection_rep &, const char *, octave_value &,
11657
465192f682f0 Pass connection information to converters.
i7tiol
parents: 11499
diff changeset
59 int, oct_pq_conv_t *);
11394
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 int all_results_fetched (void)
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 return all_fetched;
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
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
66 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
67 {
913ac5491db1 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 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
69 // 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
70 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
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
913ac5491db1 Copy in/out from/to local file hacked in. Doc change waits till copy in/out from/to variable.
i7tiol
parents: 11394
diff changeset
73 octave_value process_single_result (const std::string &infile,
11484
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11480
diff changeset
74 const std::string &outfile,
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11480
diff changeset
75 const Cell &cin_data,
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11480
diff changeset
76 const Cell &cin_types,
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11480
diff changeset
77 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
78 bool cin_from_variable);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
79
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
80 int good (void) {return valid;}
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 private:
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
83
11706
95b91d8c9ee2 Make returned type information recursive over composite type elements.
i7tiol
parents: 11657
diff changeset
84 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
85
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
86 void check_first_result (void)
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
87 {
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
88 if (! res)
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 valid = 0;
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
91 c_verror ("%s: could not execute command: %s", caller.c_str (),
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
92 PQerrorMessage (cptr));
11394
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 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
95 else if ((state = PQresultStatus (res)) == PGRES_EMPTY_QUERY)
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 valid = 0;
12718
1af86934c14e Make compatible with Octaves new exception-based error handling.
i7tiol
parents: 12612
diff changeset
98 c_verror ("%s: empty command", caller.c_str ());
11394
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 octave_value command_ok_handler (void)
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 char *c = PQcmdTuples (res);
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 return octave_value (atoi (c));
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
107 }
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
108
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
109 octave_value tuples_ok_handler (void);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
110
11499
1176424db5df Finished copy in from Octave variable. Removed preparations for copy out to variable. New release.
i7tiol
parents: 11484
diff changeset
111 octave_value copy_out_handler (const std::string &);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
112
11484
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11480
diff changeset
113 octave_value copy_in_handler (const std::string &, const Cell &, const Cell &,
154bc776dfa8 Implemented copy in from Octave variable.
i7tiol
parents: 11480
diff changeset
114 bool, bool);
11394
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 PGresult *res;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
117 int all_fetched;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
118 int valid;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
119 ExecStatusType state;
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11715
diff changeset
120 octave_pq_connection_rep &conn;
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
121 PGconn *cptr;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
122 Cell &rettypes;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
123 std::string &caller;
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
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
127 #endif // __OCT_PQ_COMMAND__