11659
|
1 /* |
|
2 |
|
3 Copyright (C) 2013 Olaf Till <i7tiol@t-online.de> |
|
4 |
|
5 This program is free software; you can redistribute it and/or modify |
|
6 it under the terms of the GNU General Public License as published by |
|
7 the Free Software Foundation; either version 3 of the License, or |
|
8 (at your option) any later version. |
|
9 |
|
10 This program is distributed in the hope that it will be useful, |
|
11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 GNU General Public License for more details. |
|
14 |
|
15 You should have received a copy of the GNU General Public License |
|
16 along with this program; If not, see <http://www.gnu.org/licenses/>. |
|
17 |
|
18 */ |
|
19 |
|
20 #include <octave/oct.h> |
|
21 |
|
22 #include "pq_connection.h" |
|
23 |
|
24 // PKG_ADD: autoload ("pq_conninfo", "pq_interface.oct"); |
|
25 |
|
26 DEFUN_DLD (pq_conninfo, args, , |
|
27 "-*- texinfo -*-\n\ |
|
28 @deftypefn {Loadable Function} {@var{val} =} pq_conninfo (@var{connection}, @var{label})\n\ |
|
29 Retrieves connection information for postgresql connection @var{connection}, specified by the string @var{label}, and returns the value of this information in @var{val}. The type of @var{val} depends on the requested information. Currently, the only recognized @var{label} is @code{'integer_datetimes'}; @var{val} is @code{true} if 8-byte date and time values are stored as integer in the server, and @code{false} if they are stored as @code{double} (which is depricated).\n\ |
|
30 @end deftypefn") |
|
31 { |
|
32 std::string fname ("pq_conninfo"); |
|
33 |
|
34 octave_value retval; |
|
35 |
|
36 if (args.length () != 2 || |
|
37 args(0).type_id () != octave_pq_connection::static_type_id ()) |
|
38 { |
|
39 print_usage (); |
|
40 |
|
41 return retval; |
|
42 } |
|
43 |
|
44 std::string label (args(1).string_value ()); |
|
45 |
|
46 if (error_state) |
|
47 { |
|
48 error ("%s: second argument can not be converted to a string", |
|
49 fname.c_str ()); |
|
50 |
|
51 return retval; |
|
52 } |
|
53 |
|
54 if (label.compare ("integer_datetimes")) |
|
55 { |
|
56 error ("%s: unrecognized label %s", fname.c_str (), label.c_str ()); |
|
57 |
|
58 return retval; |
|
59 } |
|
60 |
|
61 octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ()); |
|
62 |
|
63 octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep); |
|
64 |
|
65 PGconn *conn = oct_pq_conn.octave_pq_get_conn (); |
|
66 |
|
67 if (! conn) |
|
68 { |
|
69 error ("%s: connection not open", fname.c_str ()); |
|
70 |
|
71 return retval; |
|
72 } |
|
73 |
11667
|
74 return octave_value (oct_pq_conn.get_integer_datetimes ()); |
11659
|
75 } |