** msPostGISParseData() ** ** Parse the DATA string for geometry column name, table name, ** unique id column, srid, and SQL string. */
| 1223 | ** unique id column, srid, and SQL string. |
| 1224 | */ |
| 1225 | int msPostGISParseData(layerObj *layer) { |
| 1226 | char *pos_opt, *pos_scn, *tmp, *pos_srid, *pos_uid, *data; |
| 1227 | int slength; |
| 1228 | msPostGISLayerInfo *layerinfo; |
| 1229 | |
| 1230 | assert(layer != NULL); |
| 1231 | assert(layer->layerinfo != NULL); |
| 1232 | |
| 1233 | layerinfo = (msPostGISLayerInfo*)(layer->layerinfo); |
| 1234 | |
| 1235 | if (layer->debug) { |
| 1236 | msDebug("msPostGISParseData called.\n"); |
| 1237 | } |
| 1238 | |
| 1239 | if (!layer->data) { |
| 1240 | msSetError(MS_QUERYERR, "Missing DATA clause. DATA statement must contain 'geometry_column from table_name' or 'geometry_column from (sub-query) as sub'.", "msPostGISParseData()"); |
| 1241 | return MS_FAILURE; |
| 1242 | } |
| 1243 | data = layer->data; |
| 1244 | |
| 1245 | /* |
| 1246 | ** Clean up any existing strings first, as we will be populating these fields. |
| 1247 | */ |
| 1248 | if( layerinfo->srid ) { |
| 1249 | free(layerinfo->srid); |
| 1250 | layerinfo->srid = NULL; |
| 1251 | } |
| 1252 | if( layerinfo->uid ) { |
| 1253 | free(layerinfo->uid); |
| 1254 | layerinfo->uid = NULL; |
| 1255 | } |
| 1256 | if( layerinfo->geomcolumn ) { |
| 1257 | free(layerinfo->geomcolumn); |
| 1258 | layerinfo->geomcolumn = NULL; |
| 1259 | } |
| 1260 | if( layerinfo->fromsource ) { |
| 1261 | free(layerinfo->fromsource); |
| 1262 | layerinfo->fromsource = NULL; |
| 1263 | } |
| 1264 | |
| 1265 | /* |
| 1266 | ** Look for the optional ' using unique ID' string first. |
| 1267 | */ |
| 1268 | pos_uid = strcasestr(data, " using unique "); |
| 1269 | if (pos_uid) { |
| 1270 | /* Find the end of this case 'using unique ftab_id using srid=33' */ |
| 1271 | tmp = strstr(pos_uid + 14, " "); |
| 1272 | /* Find the end of this case 'using srid=33 using unique ftab_id' */ |
| 1273 | if (!tmp) { |
| 1274 | tmp = pos_uid + strlen(pos_uid); |
| 1275 | } |
| 1276 | layerinfo->uid = (char*) msSmallMalloc((tmp - (pos_uid + 14)) + 1); |
| 1277 | strlcpy(layerinfo->uid, pos_uid + 14, tmp - (pos_uid + 14)+1); |
| 1278 | msStringTrim(layerinfo->uid); |
| 1279 | } |
| 1280 | |
| 1281 | /* |
| 1282 | ** Look for the optional ' using srid=333 ' string next. |
no test coverage detected