** msPostGISLayerGetShape() ** ** Registered vtable->LayerGetShape function. For pulling from a prepared and ** undisposed result set. */
| 2560 | ** undisposed result set. |
| 2561 | */ |
| 2562 | int msPostGISLayerGetShape(layerObj *layer, shapeObj *shape, resultObj *record) { |
| 2563 | #ifdef USE_POSTGIS |
| 2564 | |
| 2565 | PGresult *pgresult = NULL; |
| 2566 | msPostGISLayerInfo *layerinfo = NULL; |
| 2567 | int result = MS_SUCCESS; |
| 2568 | |
| 2569 | long shapeindex = record->shapeindex; |
| 2570 | int resultindex = record->resultindex; |
| 2571 | |
| 2572 | assert(layer != NULL); |
| 2573 | assert(layer->layerinfo != NULL); |
| 2574 | |
| 2575 | if (layer->debug) { |
| 2576 | msDebug("msPostGISLayerGetShape called for record = %i\n", resultindex); |
| 2577 | } |
| 2578 | |
| 2579 | /* If resultindex is set, fetch the shape from the resultcache, otherwise fetch it from the DB */ |
| 2580 | if (resultindex >= 0) |
| 2581 | { |
| 2582 | int status; |
| 2583 | |
| 2584 | layerinfo = (msPostGISLayerInfo*) layer->layerinfo; |
| 2585 | |
| 2586 | /* Check the validity of the open result. */ |
| 2587 | pgresult = layerinfo->pgresult; |
| 2588 | if ( ! pgresult ) { |
| 2589 | msSetError( MS_MISCERR, |
| 2590 | "PostgreSQL result set is null.", |
| 2591 | "msPostGISLayerGetShape()"); |
| 2592 | return MS_FAILURE; |
| 2593 | } |
| 2594 | status = PQresultStatus(pgresult); |
| 2595 | if ( layer->debug > 1 ) { |
| 2596 | msDebug("msPostGISLayerGetShape query status: %s (%d)\n", PQresStatus(status), status); |
| 2597 | } |
| 2598 | if( ! ( status == PGRES_COMMAND_OK || status == PGRES_TUPLES_OK) ) { |
| 2599 | msSetError( MS_MISCERR, |
| 2600 | "PostgreSQL result set is not ready.", |
| 2601 | "msPostGISLayerGetShape()"); |
| 2602 | return MS_FAILURE; |
| 2603 | } |
| 2604 | |
| 2605 | /* Check the validity of the requested record number. */ |
| 2606 | if( resultindex >= PQntuples(pgresult) ) { |
| 2607 | msDebug("msPostGISLayerGetShape got request for (%d) but only has %d tuples.\n", resultindex, PQntuples(pgresult)); |
| 2608 | msSetError( MS_MISCERR, |
| 2609 | "Got request larger than result set.", |
| 2610 | "msPostGISLayerGetShape()"); |
| 2611 | return MS_FAILURE; |
| 2612 | } |
| 2613 | |
| 2614 | layerinfo->rownum = resultindex; /* Only return one result. */ |
| 2615 | |
| 2616 | /* We don't know the shape type until we read the geometry. */ |
| 2617 | shape->type = MS_SHAPE_NULL; |
| 2618 | |
| 2619 | /* Return the shape, cursor access mode. */ |
nothing calls this directly
no test coverage detected