changeset 11659:7575dc1c0b06 octave-forge

Obtain connection information 'integer_datetimes'. New function 'pq_conninfo' for querying connection information.
author i7tiol
date Sat, 27 Apr 2013 17:55:14 +0000
parents f9f1af45e49a
children cbff4e8a8af8
files main/database/INDEX main/database/NEWS main/database/src/Makefile.in main/database/src/pq_connection.cc main/database/src/pq_connection.h main/database/src/pq_conninfo.cc
diffstat 6 files changed, 86 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/main/database/INDEX	Sat Apr 27 09:40:51 2013 +0000
+++ b/main/database/INDEX	Sat Apr 27 17:55:14 2013 +0000
@@ -3,6 +3,7 @@
  pq_connect
  pq_close
  pq_update_types
+ pq_conninfo
 Postgresql command execution
  pq_exec_params
 Postgresql large objects
--- a/main/database/NEWS	Sat Apr 27 09:40:51 2013 +0000
+++ b/main/database/NEWS	Sat Apr 27 17:55:14 2013 +0000
@@ -1,3 +1,5 @@
+ ** New function pq_conninfo.
+
  ** Fix for includes on Apple.
 
 database 2.1.1:
--- a/main/database/src/Makefile.in	Sat Apr 27 09:40:51 2013 +0000
+++ b/main/database/src/Makefile.in	Sat Apr 27 17:55:14 2013 +0000
@@ -9,7 +9,7 @@
 
 OBJECTS := __pq_connect__.o pq_close.o pq_exec.o converters.o \
            converters_arr_comp.o pq_connection.o command.o \
-           pq_update_types.o pq_lo.o
+           pq_update_types.o pq_lo.o pq_conninfo.o
 
 pq_interface.oct: $(OBJECTS)
 	@MKOCTFILE@ -o pq_interface.oct -L`@PG_CONFIG@ --libdir` -lpq $(OBJECTS)
--- a/main/database/src/pq_connection.cc	Sat Apr 27 09:40:51 2013 +0000
+++ b/main/database/src/pq_connection.cc	Sat Apr 27 17:55:14 2013 +0000
@@ -100,6 +100,11 @@
 
           error ("could not read types");
         }
+
+      if (strcmp (PQparameterStatus (conn, "integer_datetimes"), "on"))
+        integer_datetimes = false;
+      else
+        integer_datetimes = true;
     }
 }
 
--- a/main/database/src/pq_connection.h	Sat Apr 27 09:40:51 2013 +0000
+++ b/main/database/src/pq_connection.h	Sat Apr 27 17:55:14 2013 +0000
@@ -51,6 +51,8 @@
 
   oct_pq_name_conv_map_t name_conv_map;
 
+  bool integer_datetimes;
+
 
   // Octave internal stuff
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main/database/src/pq_conninfo.cc	Sat Apr 27 17:55:14 2013 +0000
@@ -0,0 +1,75 @@
+/*
+
+Copyright (C) 2013 Olaf Till <i7tiol@t-online.de>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; If not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#include <octave/oct.h>
+
+#include "pq_connection.h"
+
+// PKG_ADD: autoload ("pq_conninfo", "pq_interface.oct");
+
+DEFUN_DLD (pq_conninfo, args, ,
+           "-*- texinfo -*-\n\
+@deftypefn {Loadable Function} {@var{val} =} pq_conninfo (@var{connection}, @var{label})\n\
+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\
+@end deftypefn")
+{
+  std::string fname ("pq_conninfo");
+
+  octave_value retval;
+
+  if (args.length () != 2 ||
+      args(0).type_id () != octave_pq_connection::static_type_id ())
+    {
+      print_usage ();
+
+      return retval;
+    }
+
+  std::string label (args(1).string_value ());
+
+  if (error_state)
+    {
+      error ("%s: second argument can not be converted to a string",
+             fname.c_str ());
+
+      return retval;
+    }
+
+  if (label.compare ("integer_datetimes"))
+    {
+      error ("%s: unrecognized label %s", fname.c_str (), label.c_str ());
+
+      return retval;
+    }
+
+  octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ());
+
+  octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep);
+
+  PGconn *conn = oct_pq_conn.octave_pq_get_conn ();
+
+  if (! conn)
+    {
+      error ("%s: connection not open", fname.c_str ());
+
+      return retval;
+    }
+
+  return octave_value (oct_pq_conn.integer_datetimes);
+}