changeset 12612:2257648e8ce1 octave-forge

avoid using const_cast, new release 2.3.2 * pq_connection.h/cc: octave_pq_connection now contains pointer to object of new class octave_pq_connection_rep, containing the pq-specific members formerly in octave_pq_connection. * pq_exec.cc, pq_close.cc, pq_update_types.cc, pq_conninfo.cc, pq_lo.cc: Remove const_cast, use octave_pq_connection_rep object instead. * __pq_connect__.cc, converters.h/cc, converters_arr_comp.cc, command.h/cc: Use octave_pq_connection_rep instead of octave_pq_connection.
author i7tiol
date Tue, 05 May 2015 07:31:33 +0000
parents 4f35a79fa79a
children 9cb56e0cd09b
files main/database/DESCRIPTION main/database/NEWS main/database/src/__pq_connect__.cc main/database/src/command.cc main/database/src/command.h main/database/src/converters.cc main/database/src/converters.h main/database/src/converters_arr_comp.cc main/database/src/pq_close.cc main/database/src/pq_connection.cc main/database/src/pq_connection.h main/database/src/pq_conninfo.cc main/database/src/pq_exec.cc main/database/src/pq_lo.cc main/database/src/pq_update_types.cc
diffstat 15 files changed, 266 insertions(+), 235 deletions(-) [+]
line wrap: on
line diff
--- a/main/database/DESCRIPTION	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/DESCRIPTION	Tue May 05 07:31:33 2015 +0000
@@ -1,6 +1,6 @@
 Name: database
-Version: 2.3.1
-Date: 2015-02-24
+Version: 2.3.2
+Date: 2015-05-05
 Author: Olaf Till <i7tiol@t-online.de>
 Maintainer: Olaf Till <i7tiol@t-online.de>
 Title: Database.
--- a/main/database/NEWS	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/NEWS	Tue May 05 07:31:33 2015 +0000
@@ -1,3 +1,8 @@
+database 2.3.2
+--------------
+
+ ** Fix a potential source of internal bugs.
+
  ** Incompatible versions of postgresql (< 8.3) are rejected at
     configure time.
 
--- a/main/database/src/__pq_connect__.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/__pq_connect__.cc	Tue May 05 07:31:33 2015 +0000
@@ -52,8 +52,8 @@
   octave_value retval (new octave_pq_connection (opt_string));
 
   // We spare checking
-  // bool(octave_pq_connection::octave_pq_get_conn()), since in case
-  // of false there was an error thrown, so destruction of the
+  // bool(octave_pq_connection_rep::octave_pq_get_conn()), since in
+  // case of false there was an error thrown, so destruction of the
   // octave_pq_connection object will be caused by Octaves reference
   // counting scheme.
   return retval;
--- a/main/database/src/command.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/command.cc	Tue May 05 07:31:33 2015 +0000
@@ -32,7 +32,7 @@
 
 #define COUT_RESIZE_STEP 1000 // resize result only after this number of rows
 
-command::command (octave_pq_connection &connection, std::string &cmd,
+command::command (octave_pq_connection_rep &connection, std::string &cmd,
                   Cell &rtypes,std::string &who)
   : res (NULL), all_fetched (0), valid (1), conn (connection),
     rettypes (rtypes), caller (who)
@@ -56,7 +56,7 @@
     }
 }
 
-command::command (octave_pq_connection &connection, std::string &cmd,
+command::command (octave_pq_connection_rep &connection, std::string &cmd,
                   Cell &params, Cell &ptypes, Cell &rtypes, std::string &who)
   : res (NULL), all_fetched (1), valid (1), conn (connection),
     rettypes (rtypes), caller (who)
--- a/main/database/src/command.h	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/command.h	Tue May 05 07:31:33 2015 +0000
@@ -32,10 +32,10 @@
 {
 public:
 
-  command (octave_pq_connection &connection, std::string &cmd, Cell &rtypes,
+  command (octave_pq_connection_rep &connection, std::string &cmd, Cell &rtypes,
            std::string &who);
 
-  command (octave_pq_connection &connection, std::string &cmd, Cell &params,
+  command (octave_pq_connection_rep &connection, std::string &cmd, Cell &params,
            Cell &ptypes, Cell &rtypes, std::string &who);
 
   ~command (void)
@@ -50,11 +50,11 @@
   }
 
   typedef int (*to_octave_array_fp_t)
-    (const octave_pq_connection &, const char *, octave_value &,
+    (const octave_pq_connection_rep &, const char *, octave_value &,
      int, oct_pq_conv_t *);
 
   typedef int (*to_octave_composite_fp_t)
-    (const octave_pq_connection &, const char *, octave_value &,
+    (const octave_pq_connection_rep &, const char *, octave_value &,
      int, oct_pq_conv_t *);
 
   int all_results_fetched (void)
@@ -116,7 +116,7 @@
   int all_fetched;
   int valid;
   ExecStatusType state;
-  octave_pq_connection &conn;
+  octave_pq_connection_rep &conn;
   PGconn *cptr;
   Cell &rettypes;
   std::string &caller;
--- a/main/database/src/converters.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/converters.cc	Tue May 05 07:31:33 2015 +0000
@@ -54,7 +54,7 @@
 
 /* type bool */
 
-int to_octave_str_bool (const octave_pq_connection &conn,
+int to_octave_str_bool (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   bool tp = (*c == 't' ? true : false);
@@ -64,7 +64,7 @@
   return 0;
 }
 
-int to_octave_bin_bool (const octave_pq_connection &conn,
+int to_octave_bin_bool (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   ov = octave_value (bool (*c));
@@ -72,7 +72,7 @@
   return 0;
 }
 
-int from_octave_str_bool (const octave_pq_connection &conn,
+int from_octave_str_bool (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   bool b = ov.bool_value ();
@@ -89,7 +89,7 @@
   return 0;
 }
 
-int from_octave_bin_bool (const octave_pq_connection &conn,
+int from_octave_bin_bool (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   bool b = ov.bool_value ();
@@ -122,13 +122,13 @@
 
 /* type oid */
 
-int to_octave_str_oid (const octave_pq_connection &conn,
+int to_octave_str_oid (const octave_pq_connection_rep &conn,
                        const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_oid (const octave_pq_connection &conn,
+int to_octave_bin_oid (const octave_pq_connection_rep &conn,
                        const char *c, octave_value &ov, int nb)
 {
   ov = octave_value (octave_uint32 (be32toh (*((uint32_t *) c))));
@@ -136,13 +136,13 @@
   return 0;
 }
 
-int from_octave_str_oid (const octave_pq_connection &conn,
+int from_octave_str_oid (const octave_pq_connection_rep &conn,
                          const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_oid (const octave_pq_connection &conn,
+int from_octave_bin_oid (const octave_pq_connection_rep &conn,
                          const octave_value &ov, oct_pq_dynvec_t &val)
 {
   uint32_t oid = ov.uint_value ();
@@ -175,7 +175,7 @@
 
 /* type float8 */
 
-int to_octave_str_float8 (const octave_pq_connection &conn,
+int to_octave_str_float8 (const octave_pq_connection_rep &conn,
                           const char *c, octave_value &ov, int nb)
 {
   // not implemented
@@ -183,7 +183,7 @@
   return 1;
 }
 
-int to_octave_bin_float8 (const octave_pq_connection &conn,
+int to_octave_bin_float8 (const octave_pq_connection_rep &conn,
                           const char *c, octave_value &ov, int nb)
 {
   union
@@ -200,7 +200,7 @@
   return 0;
 }
 
-int from_octave_str_float8 (const octave_pq_connection &conn,
+int from_octave_str_float8 (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   // not implemented
@@ -208,7 +208,7 @@
   return 1;
 }
 
-int from_octave_bin_float8 (const octave_pq_connection &conn,
+int from_octave_bin_float8 (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   union
@@ -248,7 +248,7 @@
 
 /* type float4 */
 
-int to_octave_str_float4 (const octave_pq_connection &conn,
+int to_octave_str_float4 (const octave_pq_connection_rep &conn,
                           const char *c, octave_value &ov, int nb)
 {
   // not implemented
@@ -256,7 +256,7 @@
   return 1;
 }
 
-int to_octave_bin_float4 (const octave_pq_connection &conn,
+int to_octave_bin_float4 (const octave_pq_connection_rep &conn,
                           const char *c, octave_value &ov, int nb)
 {
   union
@@ -273,7 +273,7 @@
   return 0;
 }
 
-int from_octave_str_float4 (const octave_pq_connection &conn,
+int from_octave_str_float4 (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   // not implemented
@@ -281,7 +281,7 @@
   return 1;
 }
 
-int from_octave_bin_float4 (const octave_pq_connection &conn,
+int from_octave_bin_float4 (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   union
@@ -321,13 +321,13 @@
 
 /* type bytea */
 
-int to_octave_str_bytea (const octave_pq_connection &conn,
+int to_octave_str_bytea (const octave_pq_connection_rep &conn,
                          const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_bytea (const octave_pq_connection &conn,
+int to_octave_bin_bytea (const octave_pq_connection_rep &conn,
                          const char *c, octave_value &ov, int nb)
 {
   uint8NDArray m (dim_vector (nb, 1));
@@ -341,13 +341,13 @@
   return 0;
 }
 
-int from_octave_str_bytea (const octave_pq_connection &conn,
+int from_octave_str_bytea (const octave_pq_connection_rep &conn,
                            const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_bytea (const octave_pq_connection &conn,
+int from_octave_bin_bytea (const octave_pq_connection_rep &conn,
                            const octave_value &ov, oct_pq_dynvec_t &val)
 {
   uint8NDArray b = ov.uint8_array_value ();
@@ -383,13 +383,13 @@
 
 /* type text */
 
-int to_octave_str_text (const octave_pq_connection &conn,
+int to_octave_str_text (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_text (const octave_pq_connection &conn,
+int to_octave_bin_text (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   std::string s (c, nb);
@@ -399,13 +399,13 @@
   return 0;
 }
 
-int from_octave_str_text (const octave_pq_connection &conn,
+int from_octave_str_text (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_text (const octave_pq_connection &conn,
+int from_octave_bin_text (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   std::string s = ov.string_value ();
@@ -492,13 +492,13 @@
 
 /* type int2 */
 
-int to_octave_str_int2 (const octave_pq_connection &conn,
+int to_octave_str_int2 (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_int2 (const octave_pq_connection &conn,
+int to_octave_bin_int2 (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   ov = octave_value (octave_int16 (int16_t (be16toh (*((int16_t *) c)))));
@@ -506,13 +506,13 @@
   return 0;
 }
 
-int from_octave_str_int2 (const octave_pq_connection &conn,
+int from_octave_str_int2 (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_int2 (const octave_pq_connection &conn,
+int from_octave_bin_int2 (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   int16_t i2 = ov.int_value ();
@@ -546,13 +546,13 @@
 
 /* type int4 */
 
-int to_octave_str_int4 (const octave_pq_connection &conn,
+int to_octave_str_int4 (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_int4 (const octave_pq_connection &conn,
+int to_octave_bin_int4 (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   ov = octave_value (octave_int32 (int32_t (be32toh (*((int32_t *) c)))));
@@ -560,13 +560,13 @@
   return 0;
 }
 
-int from_octave_str_int4 (const octave_pq_connection &conn,
+int from_octave_str_int4 (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_int4 (const octave_pq_connection &conn,
+int from_octave_bin_int4 (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   int32_t i4 = ov.int_value ();
@@ -600,13 +600,13 @@
 
 /* type int8 */
 
-int to_octave_str_int8 (const octave_pq_connection &conn,
+int to_octave_str_int8 (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_int8 (const octave_pq_connection &conn,
+int to_octave_bin_int8 (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   ov = octave_value (octave_int64 (int64_t (be64toh (*((int64_t *) c)))));
@@ -614,13 +614,13 @@
   return 0;
 }
 
-int from_octave_str_int8 (const octave_pq_connection &conn,
+int from_octave_str_int8 (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_int8 (const octave_pq_connection &conn,
+int from_octave_bin_int8 (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   int64_t i8 = ov.int64_scalar_value ();
@@ -752,13 +752,13 @@
 
 /* type timestamp */
 
-int to_octave_str_timestamp (const octave_pq_connection &conn,
+int to_octave_str_timestamp (const octave_pq_connection_rep &conn,
                              const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_timestamp (const octave_pq_connection &conn,
+int to_octave_bin_timestamp (const octave_pq_connection_rep &conn,
                              const char *c, octave_value &ov, int nb)
 {
   ov = time_8byte_to_octave (c, conn.get_integer_datetimes ());
@@ -766,13 +766,13 @@
   return 0;
 }
 
-int from_octave_str_timestamp (const octave_pq_connection &conn,
+int from_octave_str_timestamp (const octave_pq_connection_rep &conn,
                                const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_timestamp (const octave_pq_connection &conn,
+int from_octave_bin_timestamp (const octave_pq_connection_rep &conn,
                                const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return (time_8byte_from_octave (ov, val, conn.get_integer_datetimes ()));
@@ -812,13 +812,13 @@
 
 /* type interval */
 
-int to_octave_str_interval (const octave_pq_connection &conn,
+int to_octave_str_interval (const octave_pq_connection_rep &conn,
                             const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_interval (const octave_pq_connection &conn,
+int to_octave_bin_interval (const octave_pq_connection_rep &conn,
                             const char *c, octave_value &ov, int nb)
 {
   Cell tp (dim_vector (3, 1));
@@ -838,13 +838,13 @@
   return 0;
 }
 
-int from_octave_str_interval (const octave_pq_connection &conn,
+int from_octave_str_interval (const octave_pq_connection_rep &conn,
                               const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_interval (const octave_pq_connection &conn,
+int from_octave_bin_interval (const octave_pq_connection_rep &conn,
                               const octave_value &ov, oct_pq_dynvec_t &val)
 {
   Cell iv = ov.cell_value ();
@@ -890,13 +890,13 @@
 
 /* type time */
 
-int to_octave_str_time (const octave_pq_connection &conn,
+int to_octave_str_time (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_time (const octave_pq_connection &conn,
+int to_octave_bin_time (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   ov = time_8byte_to_octave (c, conn.get_integer_datetimes ());
@@ -904,13 +904,13 @@
   return 0;
 }
 
-int from_octave_str_time (const octave_pq_connection &conn,
+int from_octave_str_time (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_time (const octave_pq_connection &conn,
+int from_octave_bin_time (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return (time_8byte_from_octave (ov, val, conn.get_integer_datetimes ()));
@@ -933,13 +933,13 @@
 
 /* type timetz */
 
-int to_octave_str_timetz (const octave_pq_connection &conn,
+int to_octave_str_timetz (const octave_pq_connection_rep &conn,
                           const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_timetz (const octave_pq_connection &conn,
+int to_octave_bin_timetz (const octave_pq_connection_rep &conn,
                           const char *c, octave_value &ov, int nb)
 {
   Cell tp (dim_vector (2, 1));
@@ -955,13 +955,13 @@
   return 0;
 }
 
-int from_octave_str_timetz (const octave_pq_connection &conn,
+int from_octave_str_timetz (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_timetz (const octave_pq_connection &conn,
+int from_octave_bin_timetz (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   Cell iv = ov.cell_value ();
@@ -1004,13 +1004,13 @@
 
 /* type date */
 
-int to_octave_str_date (const octave_pq_connection &conn,
+int to_octave_str_date (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_date (const octave_pq_connection &conn,
+int to_octave_bin_date (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   ov = octave_value (octave_int32 (int32_t (be32toh (*((int32_t *) c)))));
@@ -1018,13 +1018,13 @@
   return 0;
 }
 
-int from_octave_str_date (const octave_pq_connection &conn,
+int from_octave_str_date (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_date (const octave_pq_connection &conn,
+int from_octave_bin_date (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   int32_t i4 = ov.int_value ();
@@ -1057,13 +1057,13 @@
 
 /* type point */
 
-int to_octave_str_point (const octave_pq_connection &conn,
+int to_octave_str_point (const octave_pq_connection_rep &conn,
                          const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_point (const octave_pq_connection &conn,
+int to_octave_bin_point (const octave_pq_connection_rep &conn,
                          const char *c, octave_value &ov, int nb)
 {
   ColumnVector m (2);
@@ -1087,13 +1087,13 @@
   return 0;
 }
 
-int from_octave_str_point (const octave_pq_connection &conn,
+int from_octave_str_point (const octave_pq_connection_rep &conn,
                            const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_point (const octave_pq_connection &conn,
+int from_octave_bin_point (const octave_pq_connection_rep &conn,
                            const octave_value &ov, oct_pq_dynvec_t &val)
 {
   NDArray m = ov.array_value ();
@@ -1138,13 +1138,13 @@
 
 /* type lseg */
 
-int to_octave_str_lseg (const octave_pq_connection &conn,
+int to_octave_str_lseg (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_lseg (const octave_pq_connection &conn,
+int to_octave_bin_lseg (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   Matrix m (2, 2);
@@ -1168,13 +1168,13 @@
   return 0;
 }
 
-int from_octave_str_lseg (const octave_pq_connection &conn,
+int from_octave_str_lseg (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_lseg (const octave_pq_connection &conn,
+int from_octave_bin_lseg (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   NDArray m = ov.array_value ();
@@ -1253,13 +1253,13 @@
 
 /* type circle */
 
-int to_octave_str_circle (const octave_pq_connection &conn,
+int to_octave_str_circle (const octave_pq_connection_rep &conn,
                           const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_circle (const octave_pq_connection &conn,
+int to_octave_bin_circle (const octave_pq_connection_rep &conn,
                           const char *c, octave_value &ov, int nb)
 {
   ColumnVector m (3);
@@ -1283,13 +1283,13 @@
   return 0;
 }
 
-int from_octave_str_circle (const octave_pq_connection &conn,
+int from_octave_str_circle (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_circle (const octave_pq_connection &conn,
+int from_octave_bin_circle (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   NDArray m = ov.array_value ();
@@ -1334,13 +1334,13 @@
 
 /* type polygon */
 
-int to_octave_str_polygon (const octave_pq_connection &conn,
+int to_octave_str_polygon (const octave_pq_connection_rep &conn,
                            const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_polygon (const octave_pq_connection &conn,
+int to_octave_bin_polygon (const octave_pq_connection_rep &conn,
                            const char *c, octave_value &ov, int nb)
 {
   int32_t np = int32_t (be32toh (*((int32_t *) c)));
@@ -1368,13 +1368,13 @@
   return 0;
 }
 
-int from_octave_str_polygon (const octave_pq_connection &conn,
+int from_octave_str_polygon (const octave_pq_connection_rep &conn,
                              const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_polygon (const octave_pq_connection &conn,
+int from_octave_bin_polygon (const octave_pq_connection_rep &conn,
                              const octave_value &ov, oct_pq_dynvec_t &val)
 {
   octave_idx_type nel;
@@ -1425,13 +1425,13 @@
 
 /* type path */
 
-int to_octave_str_path (const octave_pq_connection &conn,
+int to_octave_str_path (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_path (const octave_pq_connection &conn,
+int to_octave_bin_path (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   bool closed = bool (*(c++));
@@ -1465,13 +1465,13 @@
   return 0;
 }
 
-int from_octave_str_path (const octave_pq_connection &conn,
+int from_octave_str_path (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_path (const octave_pq_connection &conn,
+int from_octave_bin_path (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   octave_scalar_map tp = ov.scalar_map_value ();
@@ -1539,7 +1539,7 @@
 // will not be called, but because a converter exists there won't be a
 // "no converter found" error thrown.
 
-int to_octave_str_unknown (const octave_pq_connection &conn,
+int to_octave_str_unknown (const octave_pq_connection_rep &conn,
                            const char *c, octave_value &ov, int nb)
 {
   error ("can not convert postgresql type 'unknown'");
@@ -1547,7 +1547,7 @@
   return 1;
 }
 
-int to_octave_bin_unknown (const octave_pq_connection &conn,
+int to_octave_bin_unknown (const octave_pq_connection_rep &conn,
                            const char *c, octave_value &ov, int nb)
 {
   error ("can not convert postgresql type 'unknown'");
@@ -1555,7 +1555,7 @@
   return 1;
 }
 
-int from_octave_str_unknown (const octave_pq_connection &conn,
+int from_octave_str_unknown (const octave_pq_connection_rep &conn,
                              const octave_value &ov, oct_pq_dynvec_t &val)
 {
   error ("can not convert postgresql type 'unknown'");
@@ -1563,7 +1563,7 @@
   return 1;
 }
 
-int from_octave_bin_unknown (const octave_pq_connection &conn,
+int from_octave_bin_unknown (const octave_pq_connection_rep &conn,
                              const octave_value &ov, oct_pq_dynvec_t &val)
 {
   error ("can not convert postgresql type 'unknown'");
@@ -1724,13 +1724,13 @@
 
 /* type cidr */
 
-int to_octave_str_cidr (const octave_pq_connection &conn,
+int to_octave_str_cidr (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_cidr (const octave_pq_connection &conn,
+int to_octave_bin_cidr (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   bool cidr = false;
@@ -1748,13 +1748,13 @@
   return 0;
 }
 
-int from_octave_str_cidr (const octave_pq_connection &conn,
+int from_octave_str_cidr (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_cidr (const octave_pq_connection &conn,
+int from_octave_bin_cidr (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return from_octave_bin_cidr_inet (ov, val, true);
@@ -1777,13 +1777,13 @@
 
 /* type inet */
 
-int to_octave_str_inet (const octave_pq_connection &conn,
+int to_octave_str_inet (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_inet (const octave_pq_connection &conn,
+int to_octave_bin_inet (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   bool cidr = false;
@@ -1801,13 +1801,13 @@
   return 0;
 }
 
-int from_octave_str_inet (const octave_pq_connection &conn,
+int from_octave_str_inet (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_inet (const octave_pq_connection &conn,
+int from_octave_bin_inet (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return from_octave_bin_cidr_inet (ov, val, false);
@@ -1830,13 +1830,13 @@
 
 /* type macaddr */
 
-int to_octave_str_macaddr (const octave_pq_connection &conn,
+int to_octave_str_macaddr (const octave_pq_connection_rep &conn,
                            const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_macaddr (const octave_pq_connection &conn,
+int to_octave_bin_macaddr (const octave_pq_connection_rep &conn,
                            const char *c, octave_value &ov, int nb)
 {
   uint8NDArray a (dim_vector (6, 1));
@@ -1849,13 +1849,13 @@
   return 0;
 }
 
-int from_octave_str_macaddr (const octave_pq_connection &conn,
+int from_octave_str_macaddr (const octave_pq_connection_rep &conn,
                              const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_macaddr (const octave_pq_connection &conn,
+int from_octave_bin_macaddr (const octave_pq_connection_rep &conn,
                              const octave_value &ov, oct_pq_dynvec_t &val)
 {
   uint8NDArray a = ov.uint8_array_value ();
@@ -1895,13 +1895,13 @@
 
 /* type bit */
 
-int to_octave_str_bit (const octave_pq_connection &conn,
+int to_octave_str_bit (const octave_pq_connection_rep &conn,
                        const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_bit (const octave_pq_connection &conn,
+int to_octave_bin_bit (const octave_pq_connection_rep &conn,
                        const char *c, octave_value &ov, int nb)
 {
   int32_t nbits = int32_t (be32toh (*((int32_t *) c)));
@@ -1924,13 +1924,13 @@
   return 0;
 }
 
-int from_octave_str_bit (const octave_pq_connection &conn,
+int from_octave_str_bit (const octave_pq_connection_rep &conn,
                          const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_bit (const octave_pq_connection &conn,
+int from_octave_bin_bit (const octave_pq_connection_rep &conn,
                          const octave_value &ov, oct_pq_dynvec_t &val)
 {
   octave_scalar_map tp = ov.scalar_map_value ();
@@ -2000,13 +2000,13 @@
 
 /* type uuid */
 
-int to_octave_str_uuid (const octave_pq_connection &conn,
+int to_octave_str_uuid (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_uuid (const octave_pq_connection &conn,
+int to_octave_bin_uuid (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb)
 {
   uint8NDArray m (dim_vector (16, 1));
@@ -2020,13 +2020,13 @@
   return 0;
 }
 
-int from_octave_str_uuid (const octave_pq_connection &conn,
+int from_octave_str_uuid (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_uuid (const octave_pq_connection &conn,
+int from_octave_bin_uuid (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val)
 {
   uint8NDArray b = ov.uint8_array_value ();
@@ -2066,13 +2066,13 @@
 
 /* type xml */
 
-int to_octave_str_xml (const octave_pq_connection &conn,
+int to_octave_str_xml (const octave_pq_connection_rep &conn,
                        const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_xml (const octave_pq_connection &conn,
+int to_octave_bin_xml (const octave_pq_connection_rep &conn,
                        const char *c, octave_value &ov, int nb)
 {
   std::string s (c, nb);
@@ -2082,13 +2082,13 @@
   return 0;
 }
 
-int from_octave_str_xml (const octave_pq_connection &conn,
+int from_octave_str_xml (const octave_pq_connection_rep &conn,
                          const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_xml (const octave_pq_connection &conn,
+int from_octave_bin_xml (const octave_pq_connection_rep &conn,
                          const octave_value &ov, oct_pq_dynvec_t &val)
 {
   std::string s = ov.string_value ();
@@ -2124,13 +2124,13 @@
 
 /* type record */
 
-int to_octave_str_record (const octave_pq_connection &conn,
+int to_octave_str_record (const octave_pq_connection_rep &conn,
                           const char *c, octave_value &ov, int nb)
 {
   return 1;
 }
 
-int to_octave_bin_record (const octave_pq_connection &conn,
+int to_octave_bin_record (const octave_pq_connection_rep &conn,
                           const char *v, octave_value &ov, int nb)
 {
   const char *p = v;
@@ -2195,13 +2195,13 @@
   return 0;
 }
 
-int from_octave_str_record (const octave_pq_connection &conn,
+int from_octave_str_record (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   return 1;
 }
 
-int from_octave_bin_record (const octave_pq_connection &conn,
+int from_octave_bin_record (const octave_pq_connection_rep &conn,
                             const octave_value &ov, oct_pq_dynvec_t &val)
 {
   error ("Type 'record' can't be sent to postgresql.");
--- a/main/database/src/converters.h	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/converters.h	Tue May 05 07:31:33 2015 +0000
@@ -45,12 +45,12 @@
 }
   oct_mo_count_state;
 
-class octave_pq_connection;
+class octave_pq_connection_rep;
 
-typedef int (*oct_pq_to_octave_fp_t) (const octave_pq_connection &,
+typedef int (*oct_pq_to_octave_fp_t) (const octave_pq_connection_rep &,
                                       const char *, octave_value &, int);
 
-typedef int (*oct_pq_from_octave_fp_t) (const octave_pq_connection &,
+typedef int (*oct_pq_from_octave_fp_t) (const octave_pq_connection_rep &,
                                         const octave_value &,
                                         oct_pq_dynvec_t &);
 
@@ -140,56 +140,56 @@
 
 // these prototypes are needed because pointers to these functions are
 // stored in the converter structures of each found enum type
-int to_octave_str_text (const octave_pq_connection &conn,
+int to_octave_str_text (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb);
-int to_octave_bin_text (const octave_pq_connection &conn,
+int to_octave_bin_text (const octave_pq_connection_rep &conn,
                         const char *c, octave_value &ov, int nb);
-int from_octave_str_text (const octave_pq_connection &conn,
+int from_octave_str_text (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val);
-int from_octave_bin_text (const octave_pq_connection &conn,
+int from_octave_bin_text (const octave_pq_connection_rep &conn,
                           const octave_value &ov, oct_pq_dynvec_t &val);
 
-oct_pq_conv_t *pgtype_from_octtype (const octave_pq_connection &conn,
+oct_pq_conv_t *pgtype_from_octtype (const octave_pq_connection_rep &conn,
                                     const octave_value &);
 
-oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection &, std::string &,
+oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection_rep &, std::string &,
                                  pq_oct_type_t &);
 
-oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection &, Oid,
+oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection_rep &, Oid,
                                  pq_oct_type_t &);
 
-oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection &, Oid,
+oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection_rep &, Oid,
                                  oct_pq_conv_t *&, pq_oct_type_t &);
 
 octave_idx_type count_row_major_order (dim_vector &, oct_mo_count_state &,
                                        bool);
 
-int from_octave_bin_array (const octave_pq_connection &conn,
+int from_octave_bin_array (const octave_pq_connection_rep &conn,
                            const octave_value &oct_arr, oct_pq_dynvec_t &val,
                            oct_pq_conv_t *);
 
-int from_octave_bin_composite (const octave_pq_connection &conn,
+int from_octave_bin_composite (const octave_pq_connection_rep &conn,
                                const octave_value &oct_comp,
                                oct_pq_dynvec_t &val, oct_pq_conv_t *);
 
-int from_octave_str_array (const octave_pq_connection &conn,
+int from_octave_str_array (const octave_pq_connection_rep &conn,
                            const octave_value &oct_arr, oct_pq_dynvec_t &val,
                            octave_value &type);
 
-int from_octave_str_composite (const octave_pq_connection &conn,
+int from_octave_str_composite (const octave_pq_connection_rep &conn,
                                const octave_value &oct_comp,
                                oct_pq_dynvec_t &val, octave_value &type);
 
-int to_octave_bin_array (const octave_pq_connection &conn,
+int to_octave_bin_array (const octave_pq_connection_rep &conn,
                          const char *, octave_value &, int, oct_pq_conv_t *);
 
-int to_octave_bin_composite (const octave_pq_connection &conn, const char *,
+int to_octave_bin_composite (const octave_pq_connection_rep &conn, const char *,
                              octave_value &, int, oct_pq_conv_t *);
 
-int to_octave_str_array (const octave_pq_connection &conn,
+int to_octave_str_array (const octave_pq_connection_rep &conn,
                          const char *, octave_value &, int, oct_pq_conv_t *);
 
-int to_octave_str_composite (const octave_pq_connection &conn, const char *,
+int to_octave_str_composite (const octave_pq_connection_rep &conn, const char *,
                              octave_value &, int, oct_pq_conv_t *);
 
 // append bytes of value 'val' of type 'type' to dynamic char vector 'dv'
--- a/main/database/src/converters_arr_comp.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/converters_arr_comp.cc	Tue May 05 07:31:33 2015 +0000
@@ -33,7 +33,7 @@
    return NULL;                                                         \
  }
 
-oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection &conn,
+oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection_rep &conn,
                                  std::string &name,
                                  pq_oct_type_t &oct_type)
 {
@@ -82,7 +82,7 @@
   return conv;
 }
 
-oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection &conn, Oid oid,
+oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection_rep &conn, Oid oid,
                                  pq_oct_type_t &oct_type)
 {
   // printf ("pgtype_from_spec(%u): ", oid);
@@ -111,7 +111,7 @@
   return conv;
 }
 
-oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection &conn, Oid oid,
+oct_pq_conv_t *pgtype_from_spec (const octave_pq_connection_rep &conn, Oid oid,
                                  oct_pq_conv_t *&c_conv,
                                  pq_oct_type_t &oct_type)
 {
@@ -130,7 +130,7 @@
   return c_conv;
 }
 
-oct_pq_conv_t *pgtype_from_octtype (const octave_pq_connection &conn,
+oct_pq_conv_t *pgtype_from_octtype (const octave_pq_connection_rep &conn,
                                     const octave_value &param)
 {
   // printf ("pgtype_from_octtype: ");
@@ -269,7 +269,7 @@
     }
 }
 
-int from_octave_bin_array (const octave_pq_connection &conn,
+int from_octave_bin_array (const octave_pq_connection_rep &conn,
                            const octave_value &oct_arr,
                            oct_pq_dynvec_t &val, oct_pq_conv_t *conv)
 {
@@ -377,7 +377,7 @@
   return 0;
 }
 
-int from_octave_bin_composite (const octave_pq_connection &conn,
+int from_octave_bin_composite (const octave_pq_connection_rep &conn,
                                const octave_value &oct_comp,
                                oct_pq_dynvec_t &val,
                                oct_pq_conv_t *conv)
@@ -453,7 +453,7 @@
   return 0;
 }
 
-int from_octave_str_array (const octave_pq_connection &conn,
+int from_octave_str_array (const octave_pq_connection_rep &conn,
                            const octave_value &oct_arr,
                            oct_pq_dynvec_t &val, octave_value &type)
 {
@@ -464,7 +464,7 @@
   return 0;
 }
 
-int from_octave_str_composite (const octave_pq_connection &conn,
+int from_octave_str_composite (const octave_pq_connection_rep &conn,
                                const octave_value &oct_comp,
                                oct_pq_dynvec_t &val,
                                octave_value &type)
@@ -476,7 +476,7 @@
   return 0;
 }
 
-int to_octave_bin_array (const octave_pq_connection &conn,
+int to_octave_bin_array (const octave_pq_connection_rep &conn,
                          const char *v, octave_value &ov, int nb,
                          oct_pq_conv_t *conv)
 {
@@ -561,7 +561,7 @@
   return 0;
 }
 
-int to_octave_bin_composite (const octave_pq_connection &conn,
+int to_octave_bin_composite (const octave_pq_connection_rep &conn,
                              const char *v, octave_value &ov, int nb,
                              oct_pq_conv_t *conv)
 {
@@ -629,7 +629,7 @@
 }
 
 
-int to_octave_str_array (const octave_pq_connection &conn,
+int to_octave_str_array (const octave_pq_connection_rep &conn,
                          const char *v, octave_value &ov, int nb,
                          oct_pq_conv_t *conv)
 {
@@ -640,7 +640,7 @@
   return 0;
 }
 
-int to_octave_str_composite (const octave_pq_connection &conn,
+int to_octave_str_composite (const octave_pq_connection_rep &conn,
                              const char *v, octave_value &ov, int nb,
                              oct_pq_conv_t *conv)
 {
--- a/main/database/src/pq_close.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/pq_close.cc	Tue May 05 07:31:33 2015 +0000
@@ -40,11 +40,12 @@
       return octave_value_list ();
     }
 
-  octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ());
+  const octave_base_value& rep = (args(0).get_rep ());
 
-  octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep);
+  const octave_pq_connection &oct_pq_conn =
+    dynamic_cast<const octave_pq_connection&> (rep);
 
-  oct_pq_conn.octave_pq_close ();
+  oct_pq_conn.get_rep ()->octave_pq_close ();
 
   return octave_value_list ();
 }
--- a/main/database/src/pq_connection.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/pq_connection.cc	Tue May 05 07:31:33 2015 +0000
@@ -46,13 +46,9 @@
     return false;
 }
 
-octave_pq_connection::octave_pq_connection (std::string arg)
+octave_pq_connection_rep::octave_pq_connection_rep (std::string &arg)
 : conv_map (), name_conv_map (&map_str_cmp), conn (NULL), postgres (0)
 {
-  static bool type_registered = false;
-
-  if (! type_registered) register_type ();
-
   BEGIN_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
   conn = PQconnectdb (arg.c_str ());
   END_INTERRUPT_IMMEDIATELY_IN_FOREIGN_CODE;
@@ -110,7 +106,7 @@
     }
 }
 
-octave_pq_connection::~octave_pq_connection (void)
+octave_pq_connection_rep::~octave_pq_connection_rep (void)
 {
   if (conn)
     {
@@ -122,7 +118,7 @@
     }
 }
 
-void octave_pq_connection::octave_pq_close (void)
+void octave_pq_connection_rep::octave_pq_close (void)
 {
   if (conn)
     {
@@ -140,7 +136,7 @@
     error ("PGconn object not open");
 }
 
-void octave_pq_connection::octave_pq_delete_non_constant_types (void)
+void octave_pq_connection_rep::octave_pq_delete_non_constant_types (void)
 {
   // In the first map, allocated types are usually referenced twice
   // (by oid and aoid). Yet we need no refcount as long as we go
@@ -181,7 +177,7 @@
     name_conv_map.erase (*it);
 }
 
-int octave_pq_connection::octave_pq_get_postgres_oid (void)
+int octave_pq_connection_rep::octave_pq_get_postgres_oid (void)
 {
   Cell p, pt, rt (1, 1);
 
@@ -209,7 +205,7 @@
   return 0;
 }
 
-int octave_pq_connection::octave_pq_fill_base_types (void)
+int octave_pq_connection_rep::octave_pq_fill_base_types (void)
 {
   // assert postgres oid had been determined
   if (! postgres.int_value ()) return 1;
@@ -285,7 +281,7 @@
   return 0;
 }
 
-int octave_pq_connection::octave_pq_get_composite_types (void)
+int octave_pq_connection_rep::octave_pq_get_composite_types (void)
 {
   Cell p, pt, rt;
 
@@ -434,7 +430,7 @@
   return 0;
 }
 
-int octave_pq_connection::octave_pq_get_enum_types (void)
+int octave_pq_connection_rep::octave_pq_get_enum_types (void)
 {
   Cell p, pt, rt;
 
@@ -521,7 +517,7 @@
   return 0;
 }
 
-int octave_pq_connection::octave_pq_refresh_types (void)
+int octave_pq_connection_rep::octave_pq_refresh_types (void)
 {
   octave_pq_delete_non_constant_types ();
 
--- a/main/database/src/pq_connection.h	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/pq_connection.h	Tue May 05 07:31:33 2015 +0000
@@ -28,13 +28,13 @@
 #include "converters.h"
 
 class
-octave_pq_connection : public octave_base_value
+octave_pq_connection_rep
 {
 public:
 
-  octave_pq_connection (std::string);
+  octave_pq_connection_rep (std::string &);
 
-  ~octave_pq_connection (void);
+  ~octave_pq_connection_rep (void);
 
   void octave_pq_close (void);
 
@@ -48,34 +48,8 @@
 
   const bool &get_integer_datetimes (void) const { return integer_datetimes; }
 
-
-  // Octave internal stuff
-
-  bool is_constant (void) const { return true; }
-
-  bool is_defined (void) const { return true; }
-
-  bool is_true (void) const { return conn != 0; }
-
-  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
-  {
-    indent (os);
-    os << "<PGconn object>";
-    newline (os);
-  }
-
-  void print (std::ostream& os, bool pr_as_read_syntax = false) const
-  {
-    print_raw (os);
-  }
-
-  bool print_as_scalar (void) const { return true; }
-
 private:
 
-  // needed by Octave for register_type()
-  octave_pq_connection (void) : conn (NULL) { }
-
   PGconn *conn;
 
   // Oid of postgres_user, needed to distinguish base types from
@@ -98,6 +72,54 @@
 
   // server configuration
   bool integer_datetimes;
+};
+
+class
+octave_pq_connection : public octave_base_value
+{
+public:
+
+  octave_pq_connection (std::string &arg)
+    : rep (new octave_pq_connection_rep (arg))
+  {
+    static bool type_registered = false;
+
+    if (! type_registered) register_type ();
+  }
+
+  ~octave_pq_connection (void) { delete rep; }
+
+  octave_pq_connection_rep *get_rep (void) const { return rep; }
+
+
+  // Octave internal stuff
+
+  bool is_constant (void) const { return true; }
+
+  bool is_defined (void) const { return true; }
+
+  bool is_true (void) const { return rep->octave_pq_get_conn () != 0; }
+
+  void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const
+  {
+    indent (os);
+    os << "<PGconn object>";
+    newline (os);
+  }
+
+  void print (std::ostream& os, bool pr_as_read_syntax = false) const
+  {
+    print_raw (os);
+  }
+
+  bool print_as_scalar (void) const { return true; }
+
+private:
+
+  // needed by Octave for register_type()
+  octave_pq_connection (void) : rep (NULL) { }
+
+  octave_pq_connection_rep *rep;
 
   DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
 };
--- a/main/database/src/pq_conninfo.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/pq_conninfo.cc	Tue May 05 07:31:33 2015 +0000
@@ -58,11 +58,12 @@
       return retval;
     }
 
-  octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ());
+  const octave_base_value& rep = (args(0).get_rep ());
 
-  octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep);
+  const octave_pq_connection &oct_pq_conn =
+    dynamic_cast<const octave_pq_connection&> (rep);
 
-  PGconn *conn = oct_pq_conn.octave_pq_get_conn ();
+  PGconn *conn = oct_pq_conn.get_rep ()->octave_pq_get_conn ();
 
   if (! conn)
     {
@@ -71,5 +72,5 @@
       return retval;
     }
 
-  return octave_value (oct_pq_conn.get_integer_datetimes ());
+  return octave_value (oct_pq_conn.get_rep ()->get_integer_datetimes ());
 }
--- a/main/database/src/pq_exec.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/pq_exec.cc	Tue May 05 07:31:33 2015 +0000
@@ -67,13 +67,14 @@
       return retval;
     }
 
-  octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ());
+  const octave_base_value& rep = (args(0).get_rep ());
 
-  octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep);
+  const octave_pq_connection &oct_pq_conn =
+    dynamic_cast<const octave_pq_connection&> (rep);
 
   Cell rettypes; // not implemented here
 
-  command c (oct_pq_conn, cmd, rettypes, fname);
+  command c (*(oct_pq_conn.get_rep ()), cmd, rettypes, fname);
 
   if (c.good ())
     {
@@ -128,15 +129,16 @@
       return retval;
     }
 
-  octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ());
+  const octave_base_value& rep = (args(0).get_rep ());
 
-  octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep);
+  const octave_pq_connection &oct_pq_conn =
+    dynamic_cast<const octave_pq_connection&> (rep);
 
 
   /*
   printf ("oid map:\n");
-  for (oct_pq_conv_map_t::iterator it = oct_pq_conn.conv_map.begin ();
-       it != oct_pq_conn.conv_map.end (); it++)
+  for (oct_pq_conv_map_t::iterator it = oct_pq_conn.get_rep ()->conv_map.begin ();
+       it != oct_pq_conn.get_rep ()->conv_map.end (); it++)
     {
       printf ("key: %u; ", it->first);
       print_conv (it->second);
@@ -144,8 +146,8 @@
   printf ("\n");
 
   printf ("name map:\n");
-  for (oct_pq_name_conv_map_t::iterator it = oct_pq_conn.name_conv_map.begin ();
-       it != oct_pq_conn.name_conv_map.end (); it++)
+  for (oct_pq_name_conv_map_t::iterator it = oct_pq_conn.get_rep ()->name_conv_map.begin ();
+       it != oct_pq_conn.get_rep ()->name_conv_map.end (); it++)
     {
       printf ("key: %s; ", it->first);
       print_conv (it->second);
@@ -334,7 +336,7 @@
 
   Cell rtypes;
 
-  command c (oct_pq_conn, cmd, params, ptypes, rtypes, fname);
+  command c (*(oct_pq_conn.get_rep ()), cmd, params, ptypes, rtypes, fname);
 
   if (c.good ())
     retval = c.process_single_result
--- a/main/database/src/pq_lo.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/pq_lo.cc	Tue May 05 07:31:33 2015 +0000
@@ -37,7 +37,7 @@
 {
 public:
 
-  pipe_to_lo (octave_pq_connection &, const char *, bool, std::string &);
+  pipe_to_lo (octave_pq_connection_rep &, const char *, bool, std::string &);
 
   ~pipe_to_lo (void);
 
@@ -49,7 +49,7 @@
 
 private:
 
-  octave_pq_connection &oct_pq_conn;
+  octave_pq_connection_rep &oct_pq_conn;
 
   PGconn *conn;
 
@@ -64,7 +64,7 @@
   bool commit;
 };
 
-pipe_to_lo::pipe_to_lo (octave_pq_connection &a_oct_pq_conn,
+pipe_to_lo::pipe_to_lo (octave_pq_connection_rep &a_oct_pq_conn,
                         const char *cmd, bool acommit, std::string &amsg)
   : msg (amsg), oct_pq_conn (a_oct_pq_conn),
     conn (a_oct_pq_conn.octave_pq_get_conn ()), oid (0), fp (NULL),
@@ -185,7 +185,7 @@
 {
 public:
 
-  lo_to_pipe (octave_pq_connection &, Oid, const char *, bool, std::string &);
+  lo_to_pipe (octave_pq_connection_rep &, Oid, const char *, bool, std::string &);
 
   ~lo_to_pipe (void);
 
@@ -195,7 +195,7 @@
 
 private:
 
-  octave_pq_connection &oct_pq_conn;
+  octave_pq_connection_rep &oct_pq_conn;
 
   PGconn *conn;
 
@@ -210,7 +210,7 @@
   bool commit;
 };
 
-lo_to_pipe::lo_to_pipe (octave_pq_connection &a_oct_pq_conn, Oid aoid,
+lo_to_pipe::lo_to_pipe (octave_pq_connection_rep &a_oct_pq_conn, Oid aoid,
                         const char *cmd, bool acommit, std::string &amsg) :
   msg (amsg), oct_pq_conn (a_oct_pq_conn),
   conn (a_oct_pq_conn.octave_pq_get_conn ()), oid (aoid), fp (NULL),
@@ -362,11 +362,12 @@
       from_pipe = true;
     }
 
-  octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ());
+  const octave_base_value& rep = (args(0).get_rep ());
 
-  octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep);
+  const octave_pq_connection &oct_pq_conn =
+    dynamic_cast<const octave_pq_connection&> (rep);
 
-  PGconn *conn = oct_pq_conn.octave_pq_get_conn ();
+  PGconn *conn = oct_pq_conn.get_rep ()->octave_pq_get_conn ();
 
   if (! conn)
     {
@@ -402,7 +403,7 @@
       Cell params;
       Cell ptypes (1, 0);
       Cell rtypes;
-      command c (oct_pq_conn, cmd, params, ptypes, rtypes, fname);
+      command c (*(oct_pq_conn.get_rep ()), cmd, params, ptypes, rtypes, fname);
 
       if (c.good ())
         c.process_single_result ();
@@ -421,7 +422,7 @@
 
   if (from_pipe)
     {
-      pipe_to_lo tp (oct_pq_conn, path.c_str (), make_tblock, msg);
+      pipe_to_lo tp (*(oct_pq_conn.get_rep ()), path.c_str (), make_tblock, msg);
 
       make_tblock = false; // commit handled by destructor of pipe_to_lo
 
@@ -445,7 +446,7 @@
       Cell params;
       Cell ptypes (1, 0);
       Cell rtypes;
-      command c (oct_pq_conn, cmd, params, ptypes, rtypes, fname);
+      command c (*(oct_pq_conn.get_rep ()), cmd, params, ptypes, rtypes, fname);
 
       if (c.good ())
         c.process_single_result ();
@@ -523,11 +524,12 @@
       return retval;
     }
 
-  octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ());
+  const octave_base_value& rep = (args(0).get_rep ());
 
-  octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep);
+  const octave_pq_connection &oct_pq_conn =
+    dynamic_cast<const octave_pq_connection&> (rep);
 
-  PGconn *conn = oct_pq_conn.octave_pq_get_conn ();
+  PGconn *conn = oct_pq_conn.get_rep ()->octave_pq_get_conn ();
 
   if (! conn)
     {
@@ -563,7 +565,7 @@
       Cell params;
       Cell ptypes (1, 0);
       Cell rtypes;
-      command c (oct_pq_conn, cmd, params, ptypes, rtypes, fname);
+      command c (*(oct_pq_conn.get_rep ()), cmd, params, ptypes, rtypes, fname);
 
       if (c.good ())
         c.process_single_result ();
@@ -580,7 +582,7 @@
 
   if (to_pipe)
     {
-      lo_to_pipe tp (oct_pq_conn, oid, path.c_str (), make_tblock, msg);
+      lo_to_pipe tp (*(oct_pq_conn.get_rep ()), oid, path.c_str (), make_tblock, msg);
 
       make_tblock = false; // commit handled by destructor of lo_to_pipe
 
@@ -602,7 +604,7 @@
       Cell params;
       Cell ptypes (1, 0);
       Cell rtypes;
-      command c (oct_pq_conn, cmd, params, ptypes, rtypes, fname);
+      command c (*(oct_pq_conn.get_rep ()), cmd, params, ptypes, rtypes, fname);
 
       if (c.good ())
         c.process_single_result ();
@@ -649,11 +651,12 @@
       return retval;
     }
 
-  octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ());
+  const octave_base_value& rep = (args(0).get_rep ());
 
-  octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep);
+  const octave_pq_connection &oct_pq_conn =
+    dynamic_cast<const octave_pq_connection&> (rep);
 
-  PGconn *conn = oct_pq_conn.octave_pq_get_conn ();
+  PGconn *conn = oct_pq_conn.get_rep ()->octave_pq_get_conn ();
 
   if (! conn)
     {
@@ -689,7 +692,7 @@
       Cell params;
       Cell ptypes (1, 0);
       Cell rtypes;
-      command c (oct_pq_conn, cmd, params, ptypes, rtypes, fname);
+      command c (*(oct_pq_conn.get_rep ()), cmd, params, ptypes, rtypes, fname);
 
       if (c.good ())
         c.process_single_result ();
@@ -718,7 +721,7 @@
       Cell params;
       Cell ptypes (1, 0);
       Cell rtypes;
-      command c (oct_pq_conn, cmd, params, ptypes, rtypes, fname);
+      command c (*(oct_pq_conn.get_rep ()), cmd, params, ptypes, rtypes, fname);
 
       if (c.good ())
         c.process_single_result ();
--- a/main/database/src/pq_update_types.cc	Tue May 05 05:29:10 2015 +0000
+++ b/main/database/src/pq_update_types.cc	Tue May 05 07:31:33 2015 +0000
@@ -42,11 +42,12 @@
       return retval;
     }
 
-  octave_base_value& rep = const_cast<octave_base_value&> (args(0).get_rep ());
+  const octave_base_value& rep = (args(0).get_rep ());
 
-  octave_pq_connection &oct_pq_conn = dynamic_cast<octave_pq_connection&> (rep);
+  const octave_pq_connection &oct_pq_conn =
+    dynamic_cast<const octave_pq_connection&> (rep);
 
-  oct_pq_conn.octave_pq_refresh_types ();
+  oct_pq_conn.get_rep ()->octave_pq_refresh_types ();
 
   return retval;
 }