annotate main/database/src/pq_connection.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 ee2b22964070
children 393b940d7ee2
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
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_CONNECTION__
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_CONNECTION__
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
11553
35e9e4b6ab34 Fix configuration of postgresql include directories.
i7tiol
parents: 11474
diff changeset
26 #include <libpq-fe.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 #include "converters.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
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
31 octave_pq_connection_rep
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 public:
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
34
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
35 octave_pq_connection_rep (std::string &);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
36
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
37 ~octave_pq_connection_rep (void);
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
38
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
39 void octave_pq_close (void);
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 int octave_pq_refresh_types (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 PGconn *octave_pq_get_conn (void) { return conn; }
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 oct_pq_conv_map_t conv_map;
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 oct_pq_name_conv_map_t name_conv_map;
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
48
11667
2c21253d3341 Add converter for timestamptz.
i7tiol
parents: 11659
diff changeset
49 const bool &get_integer_datetimes (void) const { return integer_datetimes; }
11659
7575dc1c0b06 Obtain connection information 'integer_datetimes'.
i7tiol
parents: 11645
diff changeset
50
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
51 private:
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 PGconn *conn;
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 // Oid of postgres_user, needed to distinguish base types from
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
56 // others.
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
57 octave_value postgres;
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 void octave_pq_delete_non_constant_types (void);
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 // returns zero on success
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
62 int octave_pq_get_postgres_oid (void);
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 // returns zero on success
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
65 int octave_pq_fill_base_types (void);
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 // returns zero on success
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
68 int octave_pq_get_composite_types (void);
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 // returns zero on success
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
71 int octave_pq_get_enum_types (void);
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
72
11667
2c21253d3341 Add converter for timestamptz.
i7tiol
parents: 11659
diff changeset
73 // server configuration
2c21253d3341 Add converter for timestamptz.
i7tiol
parents: 11659
diff changeset
74 bool integer_datetimes;
12612
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
75 };
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
76
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
77 class
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
78 octave_pq_connection : public octave_base_value
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
79 {
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
80 public:
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
81
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
82 octave_pq_connection (std::string &arg)
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
83 : rep (new octave_pq_connection_rep (arg))
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
84 {
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
85 static bool type_registered = false;
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
86
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
87 if (! type_registered) register_type ();
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
88 }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
89
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
90 ~octave_pq_connection (void) { delete rep; }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
91
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
92 octave_pq_connection_rep *get_rep (void) const { return rep; }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
93
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
94
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
95 // Octave internal stuff
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
96
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
97 bool is_constant (void) const { return true; }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
98
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
99 bool is_defined (void) const { return true; }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
100
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
101 bool is_true (void) const { return rep->octave_pq_get_conn () != 0; }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
102
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
103 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
104 {
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
105 indent (os);
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
106 os << "<PGconn object>";
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
107 newline (os);
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
108 }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
109
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
110 void print (std::ostream& os, bool pr_as_read_syntax = false) const
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
111 {
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
112 print_raw (os);
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
113 }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
114
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
115 bool print_as_scalar (void) const { return true; }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
116
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
117 private:
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
118
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
119 // needed by Octave for register_type()
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
120 octave_pq_connection (void) : rep (NULL) { }
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
121
2257648e8ce1 avoid using const_cast, new release 2.3.2
i7tiol
parents: 11713
diff changeset
122 octave_pq_connection_rep *rep;
11667
2c21253d3341 Add converter for timestamptz.
i7tiol
parents: 11659
diff changeset
123
11394
9aee227e296c Populated new database package with initial postgresql interface.
i7tiol
parents:
diff changeset
124 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
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_CONNECTION__