671{
672 PGresult *
result, *geocol_result;
673 GtkTreeIter iter, geocol_iter;
674 GtkListStore *dumper_geocol_combo_list;
675 char *connection_string, *sql_form, *query, *schema, *table, *geocol_query, *geocol_name=NULL;
676 int hasgeo, i, j;
677
678
681
682
683
684
685 query = "SELECT tableoids.oid, n.nspname, tableoids.relname, COALESCE((SELECT 1 from pg_attribute WHERE attrelid = tableoids.oid AND atttypid IN (SELECT oid FROM pg_type WHERE typname in ('geometry', 'geography')) LIMIT 1), 0) hasgeo FROM (SELECT c.oid, c.relname, c.relnamespace FROM pg_class c WHERE c.relkind IN ('r', 'v', 'm', 'f','p') AND c.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname NOT ILIKE 'pg_%' AND nspname <> 'information_schema')) tableoids, pg_namespace n WHERE tableoids.relnamespace = n.oid ORDER BY n.nspname, tableoids.relname";
686
688
689
691
692
693 for (i = 0; i < PQntuples(
result); i++)
694 {
695 size_t sz;
697
698
699
700
701 schema = PQgetvalue(
result, i, PQfnumber(
result,
"nspname"));
702 table = PQgetvalue(
result, i, PQfnumber(
result,
"relname"));
703
704 sql_form = "SELECT n.nspname, c.relname, a.attname FROM pg_class c, pg_namespace n, pg_attribute a WHERE c.relnamespace = n.oid AND n.nspname = '%s' AND c.relname = '%s' AND a.attrelid = c.oid AND a.atttypid IN (SELECT oid FROM pg_type WHERE typname in ('geometry', 'geography'))";
705
706 sz = strlen(sql_form) + strlen(schema) + strlen(table) + 1;
707 geocol_query =
malloc(sz);
708 snprintf(geocol_query, sz, sql_form, schema, table);
709
711
712
713
714
715
717
718 if (PQntuples(geocol_result) > 0)
719 {
720
721 for (j = 0; j < PQntuples(geocol_result); j++)
722 {
723 geocol_name = PQgetvalue(geocol_result, j, PQfnumber(geocol_result, "attname"));
724
726 gtk_list_store_set(dumper_geocol_combo_list, &geocol_iter,
728 -1);
729 }
730 }
731 else
732 {
733
734 geocol_name = NULL;
735
737 gtk_list_store_set(dumper_geocol_combo_list, &geocol_iter,
739 -1);
740 }
741
742
743 PQclear(geocol_result);
744
745
747
748
749 hasgeo = atoi(PQgetvalue(
result, i, PQfnumber(
result,
"hasgeo")));
756 -1);
757 }
758
759
761
762
765
766 return;
767}
char result[OUT_DOUBLE_BUFFER_SIZE]
char * ShpDumperGetConnectionStringFromConn(SHPCONNECTIONCONFIG *conn)
@ TABLECHOOSER_HASGEO_COLUMN
@ TABLECHOOSER_TABLE_COLUMN
@ TABLECHOOSER_SCHEMA_COLUMN
@ TABLECHOOSER_GEO_LISTSTORE_COLUMN
@ TABLECHOOSER_GEO_COLUMN
GtkListStore * chooser_table_list_store
static PGconn * pg_connection
@ TABLECHOOSER_GEOCOL_COMBO_TEXT
@ TABLECHOOSER_GEOCOL_COMBO_COLUMNS
static SHPCONNECTIONCONFIG * conn