changeset 11712:f4c52c68f744 octave-forge

Added converters for types uuid and xml.
author i7tiol
date Sun, 19 May 2013 18:47:32 +0000
parents c53226c6cd5c
children ee2b22964070
files main/database/DESCRIPTION main/database/NEWS main/database/doc/README-postgresql main/database/doc/dev-postgresql/conversions.tex main/database/inst/pq_exec_params.m main/database/src/converters.cc main/database/src/converters.h
diffstat 7 files changed, 144 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/main/database/DESCRIPTION	Sun May 19 16:18:11 2013 +0000
+++ b/main/database/DESCRIPTION	Sun May 19 18:47:32 2013 +0000
@@ -1,6 +1,6 @@
 Name: database
 Version: 2.1.1
-Date: 2013-05-18
+Date: 2013-05-19
 Author: Olaf Till <i7tiol@t-online.de>
 Maintainer: Olaf Till <i7tiol@t-online.de>
 Title: Database.
--- a/main/database/NEWS	Sun May 19 16:18:11 2013 +0000
+++ b/main/database/NEWS	Sun May 19 18:47:32 2013 +0000
@@ -1,15 +1,7 @@
  ** pq_exec_params: For queries, information on postgresql data types
     of columns is also returned.
 
- ** New converters for bit string types (bit, varbit).
-
- ** New converters for network types (cidr, inet, macaddr).
-
- ** New converters for geometric types (point, lseg, (line,) box,
-    circle, polygon, path).
-
- ** New converters for date/time types (timestamp, timestamptz, time,
-    timetz, date, interval).
+ ** Converters for all base types except text search types implemented.
 
  ** New function pq_conninfo.
 
--- a/main/database/doc/README-postgresql	Sun May 19 16:18:11 2013 +0000
+++ b/main/database/doc/README-postgresql	Sun May 19 18:47:32 2013 +0000
@@ -51,7 +51,7 @@
 fit into the framework, and select should be equivalent). The whole
 framework including conversion of composite and array types with the
 resulting possible recursion, enum types, and all base types except
-uuid, xml, and textsearch types are implemented. Large object import,
-export, and unlink works, also import/export from/to pipes.
+textsearch types are implemented. Large object import, export, and
+unlink works, also import/export from/to pipes.
 
 Please report bugs.
--- a/main/database/doc/dev-postgresql/conversions.tex	Sun May 19 16:18:11 2013 +0000
+++ b/main/database/doc/dev-postgresql/conversions.tex	Sun May 19 18:47:32 2013 +0000
@@ -290,8 +290,8 @@
 xml &
 142 &
 143 &
-Do not provide communication of this type with Octave. &
-&
+string &
+yes &
 \\
 
 array &
--- a/main/database/inst/pq_exec_params.m	Sun May 19 16:18:11 2013 +0000
+++ b/main/database/inst/pq_exec_params.m	Sun May 19 18:47:32 2013 +0000
@@ -86,7 +86,9 @@
 ## The last column indicates whether specification of type (see above)
 ## is necessary for conversion from Octave type to Postgresql type, i.e.
 ## if Postgresql type is not deduced from the type of the Octave
-## variable.
+## variable. As long as the Postgresql type is deduced correctly or is
+## user-specified, it is often sufficent to provide an Octave type that
+## can be converted to the Octave type given in the table.
 ##
 ## @multitable {Postgresql} {Octave type blah blah blah blah blah} {Spec.}
 ## @headitem Postgresql @tab Octave @tab Spec.
@@ -196,6 +198,12 @@
 ## @item varbit
 ## @tab as bit
 ## yes
+## @item uuid
+## @tab uint8 array of 16 elements
+## @tab yes
+## @item xml
+## @tab string
+## @tab yes
 ## @item any array
 ## @tab Structure with fields @code{data} (holding a cell-array with
 ## entries of a type corresponding to the Postgresql element type),
--- a/main/database/src/converters.cc	Sun May 19 16:18:11 2013 +0000
+++ b/main/database/src/converters.cc	Sun May 19 18:47:32 2013 +0000
@@ -356,7 +356,7 @@
 
   octave_idx_type nl = b.numel ();
 
-  for (int i = 0; i < nl; i++)
+  for (octave_idx_type i = 0; i < nl; i++)
     val.push_back (b(i).value ());
 
   return 0;
@@ -1994,6 +1994,130 @@
 
 /* end type varbit */
 
+/* type uuid */
+
+int to_octave_str_uuid (const octave_pq_connection &conn,
+                        const char *c, octave_value &ov, int nb)
+{
+  return 1;
+}
+
+int to_octave_bin_uuid (const octave_pq_connection &conn,
+                        const char *c, octave_value &ov, int nb)
+{
+  uint8NDArray m (dim_vector (16, 1));
+
+  uint8_t *p = (uint8_t *) m.fortran_vec ();
+  for (int i = 0; i < 16; i++, c++)
+    *(p++) = uint8_t (*c);
+
+  ov = octave_value (m);
+
+  return 0;
+}
+
+int from_octave_str_uuid (const octave_pq_connection &conn,
+                          const octave_value &ov, oct_pq_dynvec_t &val)
+{
+  return 1;
+}
+
+int from_octave_bin_uuid (const octave_pq_connection &conn,
+                          const octave_value &ov, oct_pq_dynvec_t &val)
+{
+  uint8NDArray b = ov.uint8_array_value ();
+
+  if (error_state)
+    {
+      error ("can not convert octave_value to uuid representation");
+      return 1;
+    }
+
+  if (b.numel () != 16)
+    {
+      error ("uuid representation must have 16 elements");
+      return 1;
+    }
+
+  for (int i = 0; i < 16; i++)
+    val.push_back (b(i).value ());
+
+  return 0;
+}
+
+oct_pq_conv_t conv_uuid = {0,
+                           0,
+                           oct_pq_el_oids_t (),
+                           oct_pq_conv_cache_t (),
+                           false,
+                           false,
+                           false,
+                           "uuid",
+                           &to_octave_str_uuid,
+                           &to_octave_bin_uuid,
+                           &from_octave_str_uuid,
+                           &from_octave_bin_uuid};
+
+/* end type uuid */
+
+/* type xml */
+
+int to_octave_str_xml (const octave_pq_connection &conn,
+                       const char *c, octave_value &ov, int nb)
+{
+  return 1;
+}
+
+int to_octave_bin_xml (const octave_pq_connection &conn,
+                       const char *c, octave_value &ov, int nb)
+{
+  std::string s (c, nb);
+
+  ov = octave_value (s);
+
+  return 0;
+}
+
+int from_octave_str_xml (const octave_pq_connection &conn,
+                         const octave_value &ov, oct_pq_dynvec_t &val)
+{
+  return 1;
+}
+
+int from_octave_bin_xml (const octave_pq_connection &conn,
+                         const octave_value &ov, oct_pq_dynvec_t &val)
+{
+  std::string s = ov.string_value ();
+
+  if (error_state)
+    {
+      error ("can not convert octave_value to string");
+      return 1;
+    }
+
+  octave_idx_type l = s.size ();
+
+  for (int i = 0; i < l; i++)
+    val.push_back (s[i]);
+
+  return 0;
+}
+
+oct_pq_conv_t conv_xml = {0,
+                          0,
+                          oct_pq_el_oids_t (),
+                          oct_pq_conv_cache_t (),
+                          false,
+                          false,
+                          false,
+                          "xml",
+                          &to_octave_str_text,
+                          &to_octave_bin_text,
+                          &from_octave_str_text,
+                          &from_octave_bin_text};
+
+/* end type xml */
+
 oct_pq_conv_t *t_conv_ptrs[OCT_PQ_NUM_CONVERTERS] = {&conv_bool,
                                                      &conv_oid,
                                                      &conv_float8,
@@ -2025,6 +2149,8 @@
                                                      &conv_inet,
                                                      &conv_macaddr,
                                                      &conv_bit,
-                                                     &conv_varbit};
+                                                     &conv_varbit,
+                                                     &conv_uuid,
+                                                     &conv_xml};
 
 oct_pq_conv_ptrs_t conv_ptrs (OCT_PQ_NUM_CONVERTERS, t_conv_ptrs);
--- a/main/database/src/converters.h	Sun May 19 16:18:11 2013 +0000
+++ b/main/database/src/converters.h	Sun May 19 18:47:32 2013 +0000
@@ -32,7 +32,7 @@
 
 #include "wrap_endian.h"
 
-#define OCT_PQ_NUM_CONVERTERS 32
+#define OCT_PQ_NUM_CONVERTERS 34
 
 typedef std::vector<char> oct_pq_dynvec_t;