Skip to content

Commit 81ef81c

Browse files
committed
Do not list non-existing tables
1 parent 54a4d8a commit 81ef81c

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

demo/tinyows_no_checkschema.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,11 @@
2828
name="geometry_less"
2929
title="Geometry less layer" />
3030

31+
<layer retrievable="1"
32+
writable="1"
33+
ns_prefix="tows"
34+
ns_uri="http://www.tinyows.org/"
35+
name="i_dont_exist"
36+
title="Should not appear in GetCapabilities" />
37+
3138
</tinyows>

src/ows/ows_storage.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,8 +518,30 @@ void ows_layers_storage_fill(ows * o)
518518
}
519519

520520
if (!filled) {
521-
ows_layer_storage_fill(o, ln->layer, false);
522-
if( o->exit ) break;
521+
PGresult* res_t;
522+
523+
sql = buffer_init();
524+
buffer_add_str(sql, "SELECT 1 FROM information_schema.tables WHERE table_schema='");
525+
buffer_copy(sql, ln->layer->storage->schema);
526+
buffer_add_str(sql,"' and table_name='");
527+
buffer_copy(sql, ln->layer->storage->table);
528+
buffer_add_str(sql,"'");
529+
res_t = ows_psql_exec(o, sql->buf);
530+
buffer_free(sql);
531+
if (PQresultStatus(res_t) == PGRES_TUPLES_OK && PQntuples(res_t) > 0) {
532+
filled = true;
533+
}
534+
PQclear(res_t);
535+
536+
if (filled) {
537+
ows_layer_storage_fill(o, ln->layer, false);
538+
if( o->exit ) break;
539+
}
540+
}
541+
542+
if (!filled) {
543+
if (ln->layer->storage) ows_layer_storage_free(ln->layer->storage);
544+
ln->layer->storage = NULL;
523545
}
524546
}
525547

0 commit comments

Comments
 (0)