Mercurial > forge
annotate main/database/src/pq_conninfo.cc @ 12720:52ca082757c2 octave-forge tip
Update copyright notices.
author | i7tiol |
---|---|
date | Sat, 27 Feb 2016 11:21:29 +0000 |
parents | 1af86934c14e |
children |
rev | line source |
---|---|
11659 | 1 /* |
2 | |
12720 | 3 Copyright (C) 2013-2016 Olaf Till <i7tiol@t-online.de> |
11659 | 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" | |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12613
diff
changeset
|
23 #include "error-helpers.h" |
11659 | 24 |
25 // PKG_ADD: autoload ("pq_conninfo", "pq_interface.oct"); | |
12613 | 26 // PKG_DEL: autoload ("pq_conninfo", "pq_interface.oct", "remove"); |
11659 | 27 |
28 DEFUN_DLD (pq_conninfo, args, , | |
29 "-*- texinfo -*-\n\ | |
30 @deftypefn {Loadable Function} {@var{val} =} pq_conninfo (@var{connection}, @var{label})\n\ | |
12611 | 31 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 deprecated).\n\ |
11659 | 32 @end deftypefn") |
33 { | |
34 std::string fname ("pq_conninfo"); | |
35 | |
36 octave_value retval; | |
37 | |
38 if (args.length () != 2 || | |
39 args(0).type_id () != octave_pq_connection::static_type_id ()) | |
40 { | |
41 print_usage (); | |
42 | |
43 return retval; | |
44 } | |
45 | |
12718
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12613
diff
changeset
|
46 std::string label; |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12613
diff
changeset
|
47 CHECK_ERROR (label = args(1).string_value (), retval, |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12613
diff
changeset
|
48 "%s: second argument can not be converted to a string", |
1af86934c14e
Make compatible with Octaves new exception-based error handling.
i7tiol
parents:
12613
diff
changeset
|
49 fname.c_str ()); |
11659 | 50 |
51 if (label.compare ("integer_datetimes")) | |
52 { | |
53 error ("%s: unrecognized label %s", fname.c_str (), label.c_str ()); | |
54 | |
55 return retval; | |
56 } | |
57 | |
12612 | 58 const octave_base_value& rep = (args(0).get_rep ()); |
11659 | 59 |
12612 | 60 const octave_pq_connection &oct_pq_conn = |
61 dynamic_cast<const octave_pq_connection&> (rep); | |
11659 | 62 |
12612 | 63 PGconn *conn = oct_pq_conn.get_rep ()->octave_pq_get_conn (); |
11659 | 64 |
65 if (! conn) | |
66 { | |
67 error ("%s: connection not open", fname.c_str ()); | |
68 | |
69 return retval; | |
70 } | |
71 | |
12612 | 72 return octave_value (oct_pq_conn.get_rep ()->get_integer_datetimes ()); |
11659 | 73 } |