MCPcopy Index your code
hub / github.com/MapServer/MapServer / msPOSTGRESQLJoinNext

Function msPOSTGRESQLJoinNext

mappostgresql.c:279–380  ·  view source on GitHub ↗

/ msPOSTGRESQLJoinNext() */ / The goal here is to populate join->values with the detail of the */ join against the previously prepared shapeObj. This will be called */ only once for a one-to-one join, with msPOSTGRESQLJoinPrepare() */ being called before each. It will be called repeatedly for */ one-to-many joins, until in returns MS_DONE. To accomodat

Source from the content-addressed store, hash-verified

277/* process the next tuple on each call. */
278/************************************************************************/
279int msPOSTGRESQLJoinNext(joinObj *join) {
280 msPOSTGRESQLJoinInfo *joininfo = join->joininfo;
281 int i, length, row_count;
282 char *sql, *columns;
283
284 /* We need a connection, and a join value. */
285 if(!joininfo || !joininfo->conn) {
286 msSetError(MS_JOINERR, "Join has not been connected.\n",
287 "msPOSTGRESQLJoinNext()");
288 return MS_FAILURE;
289 }
290
291 if(!joininfo->from_value) {
292 msSetError(MS_JOINERR, "Join has not been prepared.\n",
293 "msPOSTGRESQLJoinNext()");
294 return MS_FAILURE;
295 }
296
297 /* Free the previous results. */
298 if(join->values) {
299 msFreeCharArray(join->values, join->numitems);
300 join->values = NULL;
301 }
302
303 /* We only need to execute the query if no results exist. */
304 if(!joininfo->query_result) {
305 /* Write the list of column names. */
306 length = 0;
307 for(i = 0; i < join->numitems; i++) {
308 length += 8 + strlen(join->items[i]) + 2;
309 }
310
311 columns = (char *)malloc(length);
312 if(!columns) {
313 msSetError(MS_MEMERR, "Failure to malloc.\n",
314 "msPOSTGRESQLJoinNext()");
315 return MS_FAILURE;
316 }
317
318 strcpy(columns, "");
319 for(i = 0; i < join->numitems; i++) {
320 strcat(columns, "\"");
321 strcat(columns, join->items[i]);
322 strcat(columns, "\"::text");
323 if(i != join->numitems - 1) {
324 strcat(columns, ", ");
325 }
326 }
327
328 /* Create the query string. */
329 sql = (char *)malloc(26 + strlen(columns) + strlen(join->table) +
330 strlen(join->to) + strlen(joininfo->from_value));
331 if(!sql) {
332 msSetError(MS_MEMERR, "Failure to malloc.\n",
333 "msPOSTGRESQLJoinNext()");
334 return MS_FAILURE;
335 }
336 sprintf(sql, "SELECT %s FROM %s WHERE %s = '%s'", columns, join->table, join->to, joininfo->from_value);

Callers 1

msJoinNextFunction · 0.85

Calls 4

msSetErrorFunction · 0.85
msFreeCharArrayFunction · 0.85
msDebugFunction · 0.85
msStrdupFunction · 0.85

Tested by

no test coverage detected