Changeset 7575

Show
Ignore:
Timestamp:
05/12/08 11:19:48 (2 months ago)
Author:
pramsey
Message:

Fix PostGIS transaction behavior in fcgi situations (#2613)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/mapserver/HISTORY.TXT

    r7570 r7575  
    2626- Remove C++-style comments and most other warnings thrown by -pedantic (#2598) 
    2727 
    28 - Fix PostGIS transaction behavior in fcgi situations (#2497
     28- Fix PostGIS transaction behavior in fcgi situations (#2497, #2613
    2929 
    3030- Improve performance for large shape files (#2282) 
  • trunk/mapserver/mappostgis.c

    r7558 r7575  
    536536 
    537537    /* Allocate buffer to fit the largest query string */ 
    538     query_string_0_6 = (char *) malloc(113 + 42 + strlen(columns_wanted) + strlen(data_source) + (layer->filter.string ? strlen(layer->filter.string) : 0) + 2 * strlen(geom_column) + strlen(box3d) + strlen(f_table_name) + strlen(user_srid) + 1); 
     538    query_string_0_6 = (char *) malloc(113 + 42 + 7 + 12 + strlen(columns_wanted) + strlen(data_source) + (layer->filter.string ? strlen(layer->filter.string) : 0) + 2 * strlen(geom_column) + strlen(box3d) + strlen(f_table_name) + strlen(user_srid) + 1); 
    539539     
    540540    assert( layerinfo->cursor_name[0] == '\0' ); 
    541541    strcpy( layerinfo->cursor_name, "mycursor" ); 
    542542 
    543     if(!layer->filter.string) { 
     543    if( layer->maxfeatures > 0 ) { 
     544      if(!layer->filter.string) { 
    544545        if(!strlen(user_srid)) { 
    545             sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE %s && setSRID(%s, find_srid('','%s','%s') )", columns_wanted, data_source, geom_column, box3d, f_table_name, geom_column); 
     546          sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE %s && setSRID(%s, find_srid('','%s','%s') ) limit %d", columns_wanted, data_source, geom_column, box3d, f_table_name, geom_column, layer->maxfeatures); 
    546547        } else { 
    547             /* use the user specified version */ 
    548             sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE %s && setSRID(%s, %s )", columns_wanted, data_source, geom_column, box3d, user_srid); 
    549         } 
     548          /* use the user specified version */ 
     549          sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE %s && setSRID(%s, %s ) limit %d", columns_wanted, data_source, geom_column, box3d, user_srid, layer->maxfeatures); 
     550        } 
     551      } else { 
     552        if(!strlen(user_srid)) { 
     553          sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE (%s) and (%s && setSRID( %s,find_srid('','%s','%s') )) limit %d", columns_wanted, data_source, layer->filter.string, geom_column, box3d, f_table_name, geom_column, layer->maxfeatures); 
     554        } else { 
     555          sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE (%s) and (%s && setSRID( %s,%s) ) limit %d", columns_wanted, data_source, layer->filter.string, geom_column, box3d, user_srid, layer->maxfeatures); 
     556        } 
     557      } 
    550558    } else { 
     559      if(!layer->filter.string) { 
    551560        if(!strlen(user_srid)) { 
    552             sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE (%s) and (%s && setSRID( %s,find_srid('','%s','%s') ))", columns_wanted, data_source, layer->filter.string, geom_column, box3d, f_table_name, geom_column); 
     561          sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE %s && setSRID(%s, find_srid('','%s','%s') )", columns_wanted, data_source, geom_column, box3d, f_table_name, geom_column); 
    553562        } else { 
    554             sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE (%s) and (%s && setSRID( %s,%s) )", columns_wanted, data_source, layer->filter.string, geom_column, box3d, user_srid); 
    555         } 
     563          /* use the user specified version */ 
     564          sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE %s && setSRID(%s, %s )", columns_wanted, data_source, geom_column, box3d, user_srid); 
     565        } 
     566      } else { 
     567        if(!strlen(user_srid)) { 
     568          sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE (%s) and (%s && setSRID( %s,find_srid('','%s','%s') ))", columns_wanted, data_source, layer->filter.string, geom_column, box3d, f_table_name, geom_column); 
     569        } else { 
     570          sprintf(query_string_0_6, "DECLARE mycursor BINARY CURSOR FOR SELECT %s from %s WHERE (%s) and (%s && setSRID( %s,%s) )", columns_wanted, data_source, layer->filter.string, geom_column, box3d, user_srid); 
     571        } 
     572      } 
    556573    } 
    557574 
     
    701718            if(query_result) { 
    702719                PQclear(query_result); 
    703             } 
     720            } else { 
     721              if (msPOSTGISSanitizeConnection(layerinfo->conn) != MS_SUCCESS) 
     722              { 
     723                return MS_FAILURE; 
     724              } 
     725            } 
    704726 
    705727            layerinfo->cursor_name[0] = '\0'; 
     
    14351457        if(query_result) { 
    14361458            PQclear(query_result); 
    1437         } 
     1459        } else { 
     1460            msPOSTGISSanitizeConnection(layerinfo->conn); 
     1461        } 
    14381462 
    14391463        free(sql); 
     
    16131637        } 
    16141638        free(tmp2); 
     1639        msPOSTGISSanitizeConnection(layerinfo->conn); 
    16151640        return(MS_FAILURE); 
    16161641 
     
    17601785      free(tmp2); 
    17611786      free(sql); 
     1787      msPOSTGISSanitizeConnection(layerinfo->conn); 
    17621788      return(MS_FAILURE); 
    17631789