** msPostGISLayerGetItems() ** ** Registered vtable->LayerGetItems function. Query the database for ** column information about the requested layer. Rather than look in ** system tables, we just run a zero-cost query and read out of the ** result header. */
| 2827 | ** result header. |
| 2828 | */ |
| 2829 | int msPostGISLayerGetItems(layerObj *layer) { |
| 2830 | #ifdef USE_POSTGIS |
| 2831 | msPostGISLayerInfo *layerinfo = NULL; |
| 2832 | static char *strSQLTemplate = "select * from %s where false limit 0"; |
| 2833 | PGresult *pgresult = NULL; |
| 2834 | char *col = NULL; |
| 2835 | char *sql = NULL; |
| 2836 | char *strFrom = NULL; |
| 2837 | char found_geom = 0; |
| 2838 | const char *value; |
| 2839 | int t, item_num; |
| 2840 | rectObj rect; |
| 2841 | |
| 2842 | /* A useless rectangle for our useless query */ |
| 2843 | rect.minx = rect.miny = rect.maxx = rect.maxy = 0.0; |
| 2844 | |
| 2845 | assert(layer != NULL); |
| 2846 | assert(layer->layerinfo != NULL); |
| 2847 | |
| 2848 | layerinfo = (msPostGISLayerInfo*) layer->layerinfo; |
| 2849 | |
| 2850 | assert(layerinfo->pgconn); |
| 2851 | |
| 2852 | if (layer->debug) { |
| 2853 | msDebug("msPostGISLayerGetItems called.\n"); |
| 2854 | } |
| 2855 | |
| 2856 | /* Fill out layerinfo with our current DATA state. */ |
| 2857 | if ( msPostGISParseData(layer) != MS_SUCCESS) { |
| 2858 | return MS_FAILURE; |
| 2859 | } |
| 2860 | |
| 2861 | layerinfo = (msPostGISLayerInfo*) layer->layerinfo; |
| 2862 | |
| 2863 | /* This allocates a fresh string, so remember to free it... */ |
| 2864 | strFrom = msPostGISReplaceBoxToken(layer, &rect, layerinfo->fromsource); |
| 2865 | |
| 2866 | /* |
| 2867 | ** Both the "table" and "(select ...) as sub" cases can be handled with the |
| 2868 | ** same SQL. |
| 2869 | */ |
| 2870 | sql = (char*) msSmallMalloc(strlen(strSQLTemplate) + strlen(strFrom)); |
| 2871 | sprintf(sql, strSQLTemplate, strFrom); |
| 2872 | free(strFrom); |
| 2873 | |
| 2874 | if (layer->debug) { |
| 2875 | msDebug("msPostGISLayerGetItems executing SQL: %s\n", sql); |
| 2876 | } |
| 2877 | |
| 2878 | pgresult = PQexecParams(layerinfo->pgconn, sql,0, NULL, NULL, NULL, NULL, 0); |
| 2879 | |
| 2880 | if ( (!pgresult) || (PQresultStatus(pgresult) != PGRES_TUPLES_OK) ) { |
| 2881 | if ( layer->debug ) { |
| 2882 | msDebug("Error (%s) executing SQL: %s", "msPostGISLayerGetItems()\n", PQerrorMessage(layerinfo->pgconn), sql); |
| 2883 | } |
| 2884 | msSetError(MS_QUERYERR, "Error executing SQL: %s", "msPostGISLayerGetItems()", PQerrorMessage(layerinfo->pgconn)); |
| 2885 | if (pgresult) { |
| 2886 | PQclear(pgresult); |
nothing calls this directly
no test coverage detected