Mercurial > forge
annotate main/database/src/pq_connection.h @ 12665:393b940d7ee2 octave-forge
pq_connection.h: Call register_type() only once.
author | i7tiol |
---|---|
date | Wed, 08 Jul 2015 13:54:27 +0000 |
parents | 2257648e8ce1 |
children | fc325d64210b |
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 | 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 } | |
119 | |
120 bool print_as_scalar (void) const { return true; } | |
121 | |
122 private: | |
123 | |
124 // needed by Octave for register_type() | |
125 octave_pq_connection (void) : rep (NULL) { } | |
126 | |
127 octave_pq_connection_rep *rep; | |
11667 | 128 |
11394
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
129 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
130 }; |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
131 |
9aee227e296c
Populated new database package with initial postgresql interface.
i7tiol
parents:
diff
changeset
|
132 #endif // __OCT_PQ_CONNECTION__ |