Permalink
Browse files

Merge pull request #48 from tsufiev/master

support inserts into views via pkey_sequence attr
  • Loading branch information...
2 parents 8fa80a5 + dc1a819 commit 38510100f539a80b26f707dcc0c458982050f9a6 @ocourtin ocourtin committed Nov 20, 2012
Showing with 31 additions and 2 deletions.
  1. +10 −0 src/ows/ows_config.c
  2. +14 −0 src/ows/ows_layer.c
  3. +6 −2 src/ows/ows_storage.c
  4. +1 −0 src/ows_struct.h
View
10 src/ows/ows_config.c
@@ -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);
View
14 src/ows/ows_layer.c
@@ -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();
@@ -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;
@@ -667,5 +669,17 @@ void ows_layer_flush(ows_layer * l, FILE * output)
list_flush(l->include_items, output);
fprintf(output, "\n");
}
+
+ if(l->pkey) {
+ fprintf(output, "pkey: ");
+ list_flush(l->pkey, output);
+ fprintf(output, "\n");
+ }
+
+ if(l->pkey_sequence) {
+ fprintf(output, "pkey_sequence: ");
+ list_flush(l->pkey_sequence, output);
+ fprintf(output, "\n");
+ }
}
#endif
View
8 src/ows/ows_storage.c
@@ -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);
View
1 src/ows_struct.h
@@ -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;

0 comments on commit 3851010

Please sign in to comment.