# HG changeset patch # User i7tiol # Date 1368549022 0 # Node ID dafee4563c36c6447d318ebb2c730ab6319fb3c7 # Parent b3cbebad8a26c5ffebb7bf83884f64f8e29ed7c5 Return information on column types. diff -r b3cbebad8a26 -r dafee4563c36 main/database/DESCRIPTION --- a/main/database/DESCRIPTION Sun May 12 18:12:31 2013 +0000 +++ b/main/database/DESCRIPTION Tue May 14 16:30:22 2013 +0000 @@ -1,6 +1,6 @@ Name: database Version: 2.1.1 -Date: 2013-05-12 +Date: 2013-05-14 Author: Olaf Till Maintainer: Olaf Till Title: Database. diff -r b3cbebad8a26 -r dafee4563c36 main/database/NEWS --- a/main/database/NEWS Sun May 12 18:12:31 2013 +0000 +++ b/main/database/NEWS Tue May 14 16:30:22 2013 +0000 @@ -1,3 +1,7 @@ + ** pq_exec_params: For queries, information on postgresql data types + of columns is also returned (but not recursively for elements of + composite types). + ** New converters for geometric types (point, lseg, (line,) box, circle, polygon, path). diff -r b3cbebad8a26 -r dafee4563c36 main/database/inst/pq_exec_params.m --- a/main/database/inst/pq_exec_params.m Sun May 12 18:12:31 2013 +0000 +++ b/main/database/inst/pq_exec_params.m Tue May 14 16:30:22 2013 +0000 @@ -71,10 +71,13 @@ ## For queries (commands potentially returning data), the output will be ## a structure with fields @code{data} (containing a cell array with the ## data, columns correspond to returned database columns, rows -## correspond to returned tuples) and @code{columns} (containing the -## column headers). For copy commands nothing is returned. For other -## commands, the output will be the number of affected rows in the -## database. +## correspond to returned tuples), @code{columns} (containing the column +## headers), and @code{types} (a structure-vector with the postgresql +## data types of the columns, subfields @code{name} (string with +## typename), @code{is_array} (boolean), @code{is_composite} (boolean), +## and @code{is_enum} (boolean)). For copy commands nothing is returned. +## For other commands, the output will be the number of affected rows in +## the database. ## ## Mapping of currently implemented Postgresql types to Octave types ## diff -r b3cbebad8a26 -r dafee4563c36 main/database/src/command.cc --- a/main/database/src/command.cc Sun May 12 18:12:31 2013 +0000 +++ b/main/database/src/command.cc Tue May 14 16:30:22 2013 +0000 @@ -337,6 +337,11 @@ Cell data (nt, nf); Cell columns (1, nf); + Cell types_name (1, nf); + Cell types_array (1, nf); + Cell types_composite (1, nf); + Cell types_enum (1, nf); + octave_map types (dim_vector (1, nf)); bool rtypes_given; int l = rettypes.length (); @@ -367,48 +372,47 @@ // initializing it here oct_type_t oct_type; - // perform next block only if there are any rows, since - // otherwise no converter will be needed and we can spare a - // possible error of not finding a suitable one - if (nt > 0) + if (rtypes_given) // for internal reading of system tables { - if (rtypes_given) // for internal reading of system tables - { - std::string type = rettypes(j).string_value (); - if (error_state) - error ("%s: could not convert given type to string", - caller.c_str ()); - else - conv = pgtype_from_spec (type, oct_type); + std::string type = rettypes(j).string_value (); + if (error_state) + error ("%s: could not convert given type to string", + caller.c_str ()); + else + conv = pgtype_from_spec (type, oct_type); - if (error_state) - { - valid = 0; - break; - } - } - else - if (! (conv = pgtype_from_spec (PQftype (res, j), oct_type))) - { - valid = 0; - break; - } - - if (f) + if (error_state) { - array_to_octave = &command::to_octave_bin_array; - composite_to_octave = &command::to_octave_bin_composite; - // will be NULL for non-simple converters - simple_type_to_octave = conv->to_octave_bin; - } - else - { - array_to_octave = &command::to_octave_str_array; - composite_to_octave = &command::to_octave_str_composite; - // will be NULL for non-simple converters - simple_type_to_octave = conv->to_octave_str; + valid = 0; + break; } } + else + if (! (conv = pgtype_from_spec (PQftype (res, j), oct_type))) + { + valid = 0; + break; + } + + if (f) + { + array_to_octave = &command::to_octave_bin_array; + composite_to_octave = &command::to_octave_bin_composite; + // will be NULL for non-simple converters + simple_type_to_octave = conv->to_octave_bin; + } + else + { + array_to_octave = &command::to_octave_str_array; + composite_to_octave = &command::to_octave_str_composite; + // will be NULL for non-simple converters + simple_type_to_octave = conv->to_octave_str; + } + + types_name(j) = octave_value (conv->name); + types_array(j) = octave_value (oct_type == array); + types_composite(j) = octave_value (oct_type == composite); + types_enum(j) = octave_value (conv->is_enum); for (int i = 0; i < nt; i++) // i is row { @@ -463,6 +467,12 @@ ret.assign ("data", octave_value (data)); ret.assign ("columns", octave_value (columns)); + types.setfield ("name", types_name); + types.setfield ("is_array", types_array); + types.setfield ("is_composite", types_composite); + types.setfield ("is_enum", types_enum); + ret.assign ("types", octave_value (types)); + return octave_value (ret); } }