65 res = PQexecParams(o->
pg, sql, 0, NULL, NULL, NULL, NULL, 0);
66 if (strlen(PQresultErrorMessage(res)))
67 ows_log(o, 1, PQresultErrorMessage(res));
153 if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1
154 && (
char) PQgetvalue(res, 0, 0)[0] ==
't') ret =
true;
220 buffer_add_str(sql,
"SELECT constraint_name FROM information_schema.constraint_column_usage WHERE table_name = '");
229 if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) {
231 return constraint_name;
237 return constraint_name;
258 assert(constraint_name);
262 buffer_add_str(sql,
"SELECT check_clause FROM information_schema.check_constraints WHERE constraint_name = '");
268 if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) {
278 for (i = 0; constraint_value->
buf[i] !=
'\0'; i++) {
279 if(constraint_value->
buf[i] ==
'\'') {
311 buffer_add_str(sql,
"SELECT a.attname FROM pg_class c, pg_attribute a, pg_type t WHERE c.relname ='");
313 buffer_add_str(sql,
"' AND a.attnum > 0 AND a.attrelid = c.oid AND a.atttypid = t.oid AND a.attnum = ");
319 if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) {
339 buffer *character_maximum_length;
349 buffer_add_str(sql,
"SELECT character_maximum_length FROM information_schema.columns WHERE table_name = '");
358 if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) {
360 return character_maximum_length;
366 return character_maximum_length;
399 res =
ows_psql_exec(o,
"SELECT substr(postgis_full_version(), 10, 5)");
400 if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) {
447 int gml_version = 311;
454 if (
buffer_case_cmp(type,
"geometry"))
return "gml:GeometryPropertyType";
455 if (
buffer_cmp(type,
"geography"))
return "gml:GeometryPropertyType";
459 if (
buffer_cmp(type,
"float4"))
return "float";
460 if (
buffer_cmp(type,
"float8"))
return "double";
461 if (
buffer_cmp(type,
"bool"))
return "boolean";
465 if (
buffer_ncmp(type,
"numeric", 7))
return "decimal";
466 if (
buffer_ncmp(type,
"timestamp", 9))
return "dateTime";
467 if (
buffer_cmp(type,
"POINT"))
return "gml:PointPropertyType";
468 if (
buffer_cmp(type,
"LINESTRING") && gml_version == 212)
return "gml:LineStringPropertyType";
469 if (
buffer_cmp(type,
"LINESTRING") && gml_version >= 311)
return "gml:CurvePropertyType";
470 if (
buffer_cmp(type,
"POLYGON") && gml_version == 212)
return "gml:PolygonPropertyType";
471 if (
buffer_cmp(type,
"POLYGON") && gml_version >= 311)
return "gml:SurfacePropertyType";
472 if (
buffer_cmp(type,
"TRIANGLE"))
return "gml:TrianglePropertyType";
473 if (
buffer_cmp(type,
"MULTIPOINT"))
return "gml:MultiPointPropertyType";
474 if (
buffer_cmp(type,
"MULTILINESTRING") && gml_version == 212)
return "gml:MultiLineStringPropertyType";
475 if (
buffer_cmp(type,
"MULTILINESTRING") && gml_version >= 311)
return "gml:MultiCurvePropertyType";
476 if (
buffer_cmp(type,
"MULTIPOLYGON") && gml_version == 212)
return "gml:MultiPolygonPropertyType";
477 if (
buffer_cmp(type,
"MULTIPOLYGON") && gml_version >= 311)
return "gml:MultiSurfacePropertyType";
478 if (
buffer_cmp(type,
"TIN"))
return "gml:TriangulatedSurfacePropertyType";
479 if (
buffer_cmp(type,
"POLYHEDRALSURFACE"))
return "gml:PolyhedralSurfacePropertyType";
480 if (
buffer_cmp(type,
"GEOMETRYCOLLECTION"))
return "gml:MultiGeometryPropertyType";
497 if (!time->
use)
return time;
568 if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1) {
589 if (PQresultStatus(res) == PGRES_TUPLES_OK && PQntuples(res) == 1) {
605 seed = malloc(
sizeof(
char) * (seed_len * 3 + 1));
610 fp = fopen(
"/dev/urandom",
"r");
612 for (i=0 ; i<seed_len ; i++) {
614 sprintf(szBuf,
"%03d", fgetc(fp));
630 srand((
int) (time(NULL) ^ rand() % 1000) + 42);
631 srand((rand() % 1000 ^ rand() % 1000) + 42);
655 if (from->
size != where->
size)
return nb;
658 for (ln_from = from->
first, ln_where = where->
first;
660 ln_from = ln_from->
next, ln_where = ln_where->
next) {
671 if (PQresultStatus(res) != PGRES_TUPLES_OK) {
675 nb = nb + atoi(PQgetvalue(res, 0, 0));
690 if (result)
return result;
693 for (; n ; n = n->next) {
695 if (n->type != XML_ELEMENT_NODE)
continue;
698 if ( strcmp(
"http://www.opengis.net/gml", (
char *) n->ns->href)
699 && strcmp(
"http://www.opengis.net/gml/3.2", (
char *) n->ns->href))
continue;
702 if ( !strcmp((
char *) n->name,
"Point")
703 || !strcmp((
char *) n->name,
"LineString")
704 || !strcmp((
char *) n->name,
"LinearRing")
705 || !strcmp((
char *) n->name,
"Curve")
706 || !strcmp((
char *) n->name,
"Polygon")
707 || !strcmp((
char *) n->name,
"Triangle")
708 || !strcmp((
char *) n->name,
"Surface")
709 || !strcmp((
char *) n->name,
"MultiPoint")
710 || !strcmp((
char *) n->name,
"MultiLineString")
711 || !strcmp((
char *) n->name,
"MultiCurve")
712 || !strcmp((
char *) n->name,
"MultiPolygon")
713 || !strcmp((
char *) n->name,
"MultiSurface")
714 || !strcmp((
char *) n->name,
"PolyhedralSurface")
715 || !strcmp((
char *) n->name,
"Tin")
716 || !strcmp((
char *) n->name,
"TriangulatedSurface")
717 || !strcmp((
char *) n->name,
"MultiGeometry"))
return n;
721 for (c = n->children ; c ; c = c->next)
738 buffer *result, *sql, *gml;
748 if (xmlHasProp(g, (xmlChar *)
"srsName")) {
749 xmlChar* attr = xmlGetProp(g, (xmlChar *)
"srsName");
767 if (srs_geom == NULL && parent_srs != NULL &&
777 (srs_geom != NULL || parent_srs != NULL)) {
785 if (srs_geom == NULL && parent_srs != NULL &&
798 if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) {
818 if ( PQresultStatus(res) != PGRES_TUPLES_OK
819 || PQntuples(res) != 1
820 || (
char) PQgetvalue(res, 0, 0)[0] !=
't') {
842 char *content_escaped;
849 content_escaped = malloc(strlen(content) * 2 + 1);
850 PQescapeStringConn(o->
pg, content_escaped, content, strlen(content), &error);
852 if (error != 0)
return NULL;
854 return content_escaped;
877 if (PQresultStatus(res) != PGRES_TUPLES_OK || PQntuples(res) != 1) srid = -1;
878 else srid = atoi((
char *) PQgetvalue(res, 0, 0));
void ows_log(ows *o, int log_level, const char *log)
void buffer_add(buffer *buf, char c)
int ows_version_get(ows_version *v)
void buffer_empty(buffer *buf)
void buffer_copy(buffer *dest, const buffer *src)
bool buffer_cmp(const buffer *buf, const char *str)
bool in_list(const list *l, const buffer *value)
void buffer_add_str(buffer *buf, const char *str)
bool buffer_case_cmp(const buffer *buf, const char *str)
bool ows_srs_set_from_srsname(ows *o, ows_srs *s, const char *srsname)
buffer * cgi_add_xml_into_buffer(buffer *element, xmlNodePtr n)
buffer * array_get(const array *a, const char *key)
bool buffer_ncmp(const buffer *buf, const char *str, size_t n)
void list_add(list *l, buffer *value)
ows_version * ows_version_init()
buffer * buffer_replace(buffer *buf, char *before, char *after)
buffer * buffer_from_str(const char *str)
void buffer_free(buffer *buf)
void buffer_add_int(buffer *buf, int i)
void ows_srs_free(ows_srs *c)
bool check_regexp(const char *str_request, const char *str_regex)
list * list_explode_str(char separator, const char *value)
list * ows_psql_not_null_properties(ows *o, buffer *layer_name)
int ows_psql_geometry_srid(ows *o, const char *geom)
buffer * ows_psql_column_name(ows *o, buffer *layer_name, int number)
ows_version * ows_psql_postgis_version(ows *o)
buffer * ows_psql_column_constraint_name(ows *o, buffer *column_name, buffer *table_name)
PGresult * ows_psql_exec(ows *o, const char *sql)
buffer * ows_psql_gml_to_sql(ows *o, xmlNodePtr n, const ows_srs *parent_srs)
buffer * ows_psql_column_character_maximum_length(ows *o, buffer *column_name, buffer *table_name)
list * ows_psql_geometry_column(ows *o, buffer *layer_name)
buffer * ows_psql_type(ows *o, buffer *layer_name, buffer *property)
bool ows_psql_is_geometry_valid(ows *o, buffer *geom)
char * ows_psql_escape_string(ows *o, const char *content)
buffer * ows_psql_id_column(ows *o, buffer *layer_name)
list * ows_psql_column_check_constraint(ows *o, buffer *constraint_name)
array * ows_psql_describe_table(ows *o, buffer *layer_name)
buffer * ows_psql_timestamp_to_xml_time(char *timestamp)
bool ows_psql_is_numeric(buffer *type)
char * ows_psql_to_xsd(buffer *type, enum wfs_format format)
static xmlNodePtr ows_psql_recursive_parse_gml(ows *o, xmlNodePtr n, xmlNodePtr result)
bool ows_psql_is_geometry_column(ows *o, buffer *layer_name, buffer *column)
buffer * ows_psql_generate_id(ows *o, buffer *layer_name)
int ows_psql_number_features(ows *o, list *from, list *where)
buffer * ows_psql_table_name(ows *o, buffer *layer_name)
buffer * ows_psql_schema_name(ows *o, buffer *layer_name)
struct List_node list_node
struct Ows_version ows_version
struct Ows_layer_node ows_layer_node
char * buf
size to next realloc
struct Ows_layer_node * next
ows_layer_storage * storage
bool honours_authority_axis_order
bool is_axis_order_gis_friendly
ows_version * postgis_version