MCPcopy Create free account
hub / github.com/MapServer/MapServer / msPostGISRetrievePK

Function msPostGISRetrievePK

mappostgis.c:1075–1216  ·  view source on GitHub ↗

** msPostGISRetrievePK() ** ** Find out that the primary key is for this layer. ** The layerinfo->fromsource must already be populated and ** must not be a subquery. */

Source from the content-addressed store, hash-verified

1073** must not be a subquery.
1074*/
1075static int
1076msPostGISRetrievePK(layerObj *layer) {
1077 PGresult *pgresult = NULL;
1078 char *sql = 0;
1079 size_t size;
1080 msPostGISLayerInfo *layerinfo = 0;
1081 int length;
1082 int pgVersion;
1083 char *pos_sep;
1084 char *schema = NULL;
1085 char *table = NULL;
1086
1087 if (layer->debug) {
1088 msDebug("msPostGISRetrievePK called.\n");
1089 }
1090
1091 layerinfo = (msPostGISLayerInfo *) layer->layerinfo;
1092
1093 /* Attempt to separate fromsource into schema.table */
1094 pos_sep = strstr(layerinfo->fromsource, ".");
1095 if (pos_sep) {
1096 length = strlen(layerinfo->fromsource) - strlen(pos_sep) + 1;
1097 schema = (char*)msSmallMalloc(length);
1098 strlcpy(schema, layerinfo->fromsource, length);
1099
1100 length = strlen(pos_sep);
1101 table = (char*)msSmallMalloc(length);
1102 strlcpy(table, pos_sep + 1, length);
1103
1104 if (layer->debug) {
1105 msDebug("msPostGISRetrievePK(): Found schema %s, table %s.\n", schema, table);
1106 }
1107 }
1108
1109 if (layerinfo->pgconn == NULL) {
1110 msSetError(MS_QUERYERR, "Layer does not have a postgis connection.", "msPostGISRetrievePK()");
1111 return MS_FAILURE;
1112 }
1113 pgVersion = msPostGISRetrievePgVersion(layerinfo->pgconn);
1114
1115 if (pgVersion < 70000) {
1116 if (layer->debug) {
1117 msDebug("msPostGISRetrievePK(): Major version below 7.\n");
1118 }
1119 return MS_FAILURE;
1120 }
1121 if (pgVersion < 70200) {
1122 if (layer->debug) {
1123 msDebug("msPostGISRetrievePK(): Version below 7.2.\n");
1124 }
1125 return MS_FAILURE;
1126 }
1127 if (pgVersion < 70300) {
1128 /*
1129 ** PostgreSQL v7.2 has a different representation of primary keys that
1130 ** later versions. This currently does not explicitly exclude
1131 ** multicolumn primary keys.
1132 */

Callers 1

msPostGISParseDataFunction · 0.85

Calls 6

msDebugFunction · 0.85
msSmallMallocFunction · 0.85
strlcpyFunction · 0.85
msSetErrorFunction · 0.85
strlcatFunction · 0.85

Tested by

no test coverage detected