Skip to content

Commit

Permalink
Add "pkey_sequence" attribute (in addition to "pkey") to layer config.
Browse files Browse the repository at this point in the history
In order to insert new feature into layer based on PostgreSQL view,
"pkey" attribute is not enough: one should be able to deduce sequence
name using pg_get_serial_sequence() function, which returns empty row
for views. Fix this by adding "pkey_sequence" attribute.
  • Loading branch information
Timur Sufiev committed Nov 20, 2012
1 parent 14d75ad commit c23f990
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/ows/ows_config.c
Expand Up @@ -567,6 +567,16 @@ static void ows_parse_config_layer(ows * o, xmlTextReaderPtr r)
buffer_copy(layer->pkey, layer->parent->pkey);
}

a = xmlTextReaderGetAttribute(r, (xmlChar *) "pkey_sequence");
if (a) {
layer->pkey_sequence = buffer_init();
buffer_add_str(layer->pkey_sequence, (char *) a);
xmlFree(a);
} else if (layer->parent && layer->parent->pkey_sequence) {
layer->pkey_sequence = buffer_init();
buffer_copy(layer->pkey_sequence, layer->parent->pkey_sequence);
}

if (layer->name && layer->ns_uri) {
buffer_add_head(layer->name, ':');
buffer_add_head_str(layer->name, layer->ns_uri->buf);
Expand Down
2 changes: 2 additions & 0 deletions src/ows/ows_layer.c
Expand Up @@ -534,6 +534,7 @@ ows_layer *ows_layer_init()
l->exclude_items = NULL;
l->include_items = NULL;
l->pkey = NULL;
l->pkey_sequence = NULL;
l->ns_prefix = buffer_init();
l->ns_uri = buffer_init();
l->storage = ows_layer_storage_init();
Expand Down Expand Up @@ -564,6 +565,7 @@ void ows_layer_free(ows_layer * l)
if (l->exclude_items) list_free(l->exclude_items);
if (l->include_items) list_free(l->include_items);
if (l->pkey) buffer_free(l->pkey);
if (l->pkey_sequence) buffer_free(l->pkey_sequence);

free(l);
l = NULL;
Expand Down
8 changes: 6 additions & 2 deletions src/ows/ows_storage.c
Expand Up @@ -268,9 +268,13 @@ static void ows_storage_fill_pkey(ows * o, ows_layer * l)
/* Even if no sequence found, this function return an empty row
* so we must check that result string returned > 0 char
*/
if (PQntuples(res) == 1 && strlen((char *) PQgetvalue(res, 0, 0)) > 0) {
if ( l->pkey_sequence ||
(PQntuples(res) == 1 && strlen((char *) PQgetvalue(res, 0, 0)) > 0) ) {
l->storage->pkey_sequence = buffer_init();
buffer_add_str(l->storage->pkey_sequence, PQgetvalue(res, 0, 0));
if ( l->pkey_sequence )
buffer_copy(l->storage->pkey_sequence, l->pkey_sequence);
else
buffer_add_str(l->storage->pkey_sequence, PQgetvalue(res, 0, 0));
}

buffer_empty(sql);
Expand Down
1 change: 1 addition & 0 deletions src/ows_struct.h
Expand Up @@ -179,6 +179,7 @@ typedef struct Ows_layer {
list * exclude_items;
list * include_items;
buffer * pkey;
buffer * pkey_sequence;
list * gml_ns;
buffer * ns_prefix;
buffer * ns_uri;
Expand Down

1 comment on commit c23f990

@ocourtin
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Timur,

Thanks for this report and this code add !

To be perfect on this subject, aim is also to have the same config enhancement in mapfile code
and to display pkey_sequence in layer_flush

Could you provide such a thing as a pull request too ?

Please sign in to comment.