Mercurial > forge
annotate main/database/src/pq_connection.h @ 12720:52ca082757c2 octave-forge tip
Update copyright notices.
author | i7tiol |
---|---|
date | Sat, 27 Feb 2016 11:21:29 +0000 |
parents | fc325d64210b |
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 #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 | 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 | 35 octave_pq_connection_rep (std::string &); |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
36 |
12612 | 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 | 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 | 73 // server configuration |
74 bool integer_datetimes; | |
12612 | 75 }; |
76 | |
77 class | |
78 octave_pq_connection : public octave_base_value | |
79 { | |
80 public: | |
81 | |
82 octave_pq_connection (std::string &arg) | |
83 : rep (new octave_pq_connection_rep (arg)) | |
84 { | |
85 static bool type_registered = false; | |
86 | |
12665 | 87 if (! type_registered) |
88 { | |
89 register_type (); | |
90 | |
91 type_registered = true; | |
92 } | |
12612 | 93 } |
94 | |
95 ~octave_pq_connection (void) { delete rep; } | |
96 | |
97 octave_pq_connection_rep *get_rep (void) const { return rep; } | |
98 | |
99 | |
100 // Octave internal stuff | |
101 | |
102 bool is_constant (void) const { return true; } | |
103 | |
104 bool is_defined (void) const { return true; } | |
105 | |
106 bool is_true (void) const { return rep->octave_pq_get_conn () != 0; } | |
107 | |
108 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const | |
109 { | |
110 indent (os); | |
111 os << "<PGconn object>"; | |
112 newline (os); | |
113 } | |
114 | |
115 void print (std::ostream& os, bool pr_as_read_syntax = false) const | |
116 { | |
117 print_raw (os); | |
118 } | |
12666
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
119 // Octave changeset bcd71a2531d3 (Jan 31st 2014) made |
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
120 // octave_base_value::print() non-const, after that this virtual |
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
121 // function is not re-defined by the above print() function. Having |
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
122 // both const and non-const print() here seems to work both with |
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
123 // Octave < and >= bcd71a2531d3 (print() is only called over the |
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
124 // parent class virtual function). |
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
125 void print (std::ostream& os, bool pr_as_read_syntax = false) |
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
126 { |
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
127 print_raw (os); |
fc325d64210b
pq_connection.h: Additional non-const octave_pq_connection::print ().
i7tiol
parents:
12665
diff
changeset
|
128 } |
12612 | 129 |
130 bool print_as_scalar (void) const { return true; } | |
131 | |
132 private: | |
133 | |
134 // needed by Octave for register_type() | |
135 octave_pq_connection (void) : rep (NULL) { } | |
136 | |
137 octave_pq_connection_rep *rep; | |
11667 | 138 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
139 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
140 }; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
141 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
142 #endif // __OCT_PQ_CONNECTION__ |