[mapserver-commits] r10159 - trunk/mapserver

svn at osgeo.org svn at osgeo.org
Sat May 15 01:01:27 EDT 2010


Author: sdlime
Date: 2010-05-15 01:01:25 -0400 (Sat, 15 May 2010)
New Revision: 10159

Modified:
   trunk/mapserver/mapquery.c
   trunk/mapserver/mapserver.h
Log:
Added back functions to save/load query results in 5.4 and earlier fashion. Not sure if we'll keep them in the current format or not.

Modified: trunk/mapserver/mapquery.c
===================================================================
--- trunk/mapserver/mapquery.c	2010-05-14 18:17:27 UTC (rev 10158)
+++ trunk/mapserver/mapquery.c	2010-05-15 05:01:25 UTC (rev 10159)
@@ -161,6 +161,98 @@
   return(MS_SUCCESS);
 }
 
+/*
+** Serialize a query result set to disk.
+*/
+int msSaveQueryResults(mapObj *map, char *filename) {
+  FILE *stream;
+  int i, j, n=0;
+
+  if(!filename) {
+    msSetError(MS_MISCERR, "No filename provided to save query results to.", "msSaveQueryResults()");
+    return(MS_FAILURE);
+  }
+
+  stream = fopen(filename, "wb");
+  if(!stream) {
+    msSetError(MS_IOERR, "(%s)", "msSaveQueryResults()", filename);
+    return(MS_FAILURE);
+  }
+
+  /* count the number of layers with results */
+  for(i=0; i<map->numlayers; i++)
+    if(GET_LAYER(map, i)->resultcache) n++;
+  fwrite(&n, sizeof(int), 1, stream);
+
+  /* now write the result set for each layer */
+  for(i=0; i<map->numlayers; i++) {
+    if(GET_LAYER(map, i)->resultcache) {
+      fwrite(&i, sizeof(int), 1, stream); /* layer index */
+      fwrite(&(GET_LAYER(map, i)->resultcache->numresults), sizeof(int), 1, stream); /* number of results */
+      fwrite(&(GET_LAYER(map, i)->resultcache->bounds), sizeof(rectObj), 1, stream); /* bounding box */
+      for(j=0; j<GET_LAYER(map, i)->resultcache->numresults; j++)
+	fwrite(&(GET_LAYER(map, i)->resultcache->results[j]), sizeof(resultCacheMemberObj), 1, stream); /* each result */
+    }
+  }
+
+  fclose(stream);
+  return(MS_SUCCESS);
+}
+
+int msLoadQueryResults(mapObj *map, char *filename) {
+  FILE *stream;
+  int i, j, k, n=0;
+
+  if(!filename) {
+    msSetError(MS_MISCERR, "No filename provided to load query from.", "msLoadQueryResults()");
+    return(MS_FAILURE);
+  }
+
+  /*                                                                                                                                               
+  ** Make sure the file at least has the right extension.                                                         
+  */
+  if(msEvalRegex("\\.qy$", filename) != MS_TRUE) return MS_FAILURE;
+
+  stream = fopen(filename, "rb");
+  if(!stream) {
+    msSetError(MS_IOERR, "(%s)", "msLoadQueryResults()", filename);
+    return(MS_FAILURE);
+  }
+
+  fread(&n, sizeof(int), 1, stream);
+
+  /* now load the result set for each layer found in the query file */
+  for(i=0; i<n; i++) {
+    fread(&j, sizeof(int), 1, stream); /* layer index */
+
+    if(j<0 || j>map->numlayers) {
+      msSetError(MS_MISCERR, "Invalid layer index loaded from query file.", "msLoadQueryResults()");
+      return(MS_FAILURE);
+    }
+
+    /* inialize the results for this layer */
+    GET_LAYER(map, j)->resultcache = (resultCacheObj *)malloc(sizeof(resultCacheObj)); /* allocate and initialize the result cache */
+
+    fread(&(GET_LAYER(map, j)->resultcache->numresults), sizeof(int), 1, stream); /* number of results    */
+    GET_LAYER(map, j)->resultcache->cachesize = GET_LAYER(map, j)->resultcache->numresults;
+
+    fread(&(GET_LAYER(map, j)->resultcache->bounds), sizeof(rectObj), 1, stream); /* bounding box */
+
+    GET_LAYER(map, j)->resultcache->results = (resultCacheMemberObj *) malloc(sizeof(resultCacheMemberObj)*GET_LAYER(map, j)->resultcache->numresults);
+
+    for(k=0; k<GET_LAYER(map, j)->resultcache->numresults; k++) {
+      fread(&(GET_LAYER(map, j)->resultcache->results[k]), sizeof(resultCacheMemberObj), 1, stream); /* each result */
+      if(!GET_LAYER(map, j)->tileindex) GET_LAYER(map, j)->resultcache->results[k].tileindex = -1; /* reset the tile index for non-tiled layers */
+    }
+  }
+
+  fclose(stream);
+  return(MS_SUCCESS);
+}
+
+/*
+** Serialize the values necessary to duplicate a query to disk.
+*/
 int msSaveQuery(mapObj *map, char *filename) {
   FILE *stream;
 

Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h	2010-05-14 18:17:27 UTC (rev 10158)
+++ trunk/mapserver/mapserver.h	2010-05-15 05:01:25 UTC (rev 10159)
@@ -1759,6 +1759,8 @@
 
 MS_DLL_EXPORT int msInitQuery(queryObj *query); /* in mapquery.c */
 MS_DLL_EXPORT void msFreeQuery(queryObj *query);
+MS_DLL_EXPORT int msSaveQueryResults(mapObj *map, char *filename);
+MS_DLL_EXPORT int msLoadQueryResults(mapObj *map, char *filename);
 MS_DLL_EXPORT int msSaveQuery(mapObj *map, char *filename);
 MS_DLL_EXPORT int msLoadQuery(mapObj *map, char *filename);
 MS_DLL_EXPORT int msExecuteQuery(mapObj *map);



More information about the mapserver-commits mailing list