79 fprintf(output,
"schema: ");
81 fprintf(output,
"\n");
85 fprintf(output,
"table: ");
87 fprintf(output,
"\n");
91 fprintf(output,
"geom_columns: ");
93 fprintf(output,
"\n");
96 fprintf(output,
"srid: %i\n", storage->
srid);
97 fprintf(output,
"is_geographic: %i\n", storage->
is_geographic?1:0);
100 fprintf(output,
"pkey: ");
102 fprintf(output,
"\n");
106 fprintf(output,
"pkey_sequence: ");
108 fprintf(output,
"\n");
112 fprintf(output,
"pkey_default: ");
114 fprintf(output,
"\n");
118 fprintf(output,
"attributes: ");
120 fprintf(output,
"\n");
124 fprintf(output,
"not_null_columns: ");
126 fprintf(output,
"\n");
147 buffer_add_str(sql,
"SELECT a.attname AS field FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n ");
152 buffer_add_str(sql,
"' AND c.relnamespace = n.oid AND a.attnum > 0 AND a.attrelid = c.oid ");
153 buffer_add_str(sql,
"AND a.atttypid = t.oid AND a.attnotnull = 't'");
158 if (PQresultStatus(res) != PGRES_TUPLES_OK) {
164 nb_result = PQntuples(res);
166 for (i = 0 ; i < nb_result ; i++) {
191 buffer_add_str(sql,
"SELECT c.column_name FROM information_schema.constraint_column_usage c, pg_namespace n ");
192 buffer_add_str(sql,
"WHERE c.table_schema=n.nspname AND n.nspname = '");
198 buffer_add_str(sql,
"SELECT c.conname FROM pg_class r, pg_constraint c, pg_namespace n ");
201 buffer_add_str(sql,
"' AND r.relnamespace = n.oid AND n.nspname = '");
206 if (PQresultStatus(res) != PGRES_TUPLES_OK) {
214 if (l->
pkey || PQntuples(res) == 1) {
235 if (PQresultStatus(res) != PGRES_TUPLES_OK) {
237 snprintf(message,
sizeof(message),
238 "Unable to use pg_get_serial_sequence(%s, %s, %s).",
245 message,
"pkey_sequence retrieve");
253 (PQntuples(res) == 1 && strlen((
char *) PQgetvalue(res, 0, 0)) > 0) ) {
264 buffer_add_str(sql,
"SELECT column_default FROM information_schema.columns WHERE table_schema = '");
273 if (PQresultStatus(res) != PGRES_TUPLES_OK) {
277 "Unable to SELECT column_default FROM information_schema.columns.",
278 "pkey_default retrieve");
285 if (PQntuples(res) == 1 && strlen((
char *) PQgetvalue(res, 0, 0)) > 0) {
313 buffer_add_str(sql,
"SELECT a.attname AS field, t.typname AS type ");
314 buffer_add_str(sql,
"FROM pg_class c, pg_attribute a, pg_type t, pg_namespace n WHERE n.nspname = '");
318 buffer_add_str(sql,
"' AND c.relnamespace = n.oid AND a.attrelid = c.oid AND a.atttypid = t.oid");
340 if (PQresultStatus(res) != PGRES_TUPLES_OK) {
346 for (i = 0, end = PQntuples(res); i < end; i++) {
356 buffer_add_str(geom_sql,
"SELECT type from geometry_columns where f_table_schema='");
367 if (PQresultStatus(geom_res) != PGRES_TUPLES_OK || PQntuples(geom_res) == 0) {
371 "Unable to access geometry_columns table, try Populate_Geometry_Columns()",
"fill_attributes");
398 if (is_geom)
buffer_add_str(sql,
"SELECT srid, f_geometry_column FROM geometry_columns");
399 else buffer_add_str(sql,
"SELECT srid, f_geography_column FROM geography_columns");
407 buffer_add_str(sql, is_geom?
" AND f_geometry_column IN ('":
" AND f_geography_column IN ('");
412 buffer_add_str(sql, is_geom?
" AND f_geometry_column NOT IN ('":
" AND f_geography_column NOT IN ('");
421 if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) > 0) {
425 for (i = 0, end = PQntuples(res); i < end; i++)
437 if (PQntuples(res) != 1)
446 if( o->
exit )
return;
448 if( o->
exit )
return;
465 fprintf(output,
" - %s.%s (%i) -> %s [",
473 fprintf(output,
"]\n");
481 PGresult *res, *res_g;
491 buffer_add_str(sql,
"SELECT DISTINCT f_table_schema, f_table_name FROM geometry_columns");
495 buffer_add_str(sql,
"SELECT DISTINCT f_table_schema, f_table_name FROM geography_columns");
502 for (i = 0, end = PQntuples(res); i < end; i++) {
511 for (i = 0, end = PQntuples(res_g); i < end; i++) {
524 buffer_add_str(sql,
"SELECT 1 FROM information_schema.tables WHERE table_schema='");
531 if (PQresultStatus(res_t) == PGRES_TUPLES_OK && PQntuples(res_t) > 0) {
void buffer_empty(buffer *buf)
PGresult * ows_psql_exec(ows *o, const char *sql)
void list_implode(buffer *buf, const char *separator, const list *l)
void buffer_copy(buffer *dest, const buffer *src)
bool buffer_cmp(const buffer *buf, const char *str)
void buffer_add_str(buffer *buf, const char *str)
void list_flush(const list *l, FILE *output)
void ows_layer_storage_flush(ows_layer_storage *storage, FILE *output)
void buffer_flush(buffer *buf, FILE *output)
void ows_error(ows *o, enum ows_error_code code, char *message, char *locator)
void array_free(array *a)
void list_add(list *l, buffer *value)
void list_add_str(list *l, char *value)
void array_flush(const array *a, FILE *output)
void buffer_free(buffer *buf)
void array_add(array *a, buffer *key, buffer *value)
static void ows_storage_fill_attributes(ows *o, ows_layer *l)
static void ows_storage_fill_not_null(ows *o, ows_layer *l)
ows_layer_storage * ows_layer_storage_init()
static void ows_layer_storage_fill(ows *o, ows_layer *l, bool is_geom)
static void ows_storage_fill_pkey(ows *o, ows_layer *l)
void ows_layers_storage_flush(ows *o, FILE *output)
void ows_layer_storage_free(ows_layer_storage *storage)
void ows_layers_storage_fill(ows *o)
@ OWS_ERROR_REQUEST_SQL_FAILED
char * buf
size to next realloc
struct Ows_layer_node * next
ows_layer_storage * storage