[mapserver-commits] r12995 - in trunk/mapserver/mapcache: . lib

svn at osgeo.org svn at osgeo.org
Wed Jan 18 12:25:01 EST 2012


Author: aboudreault
Date: 2012-01-18 09:25:00 -0800 (Wed, 18 Jan 2012)
New Revision: 12995

Modified:
   trunk/mapserver/mapcache/lib/cache_sqlite.c
   trunk/mapserver/mapcache/nmake.opt
Log:
Added SQLITE support in MapCache on Windows

Modified: trunk/mapserver/mapcache/lib/cache_sqlite.c
===================================================================
--- trunk/mapserver/mapcache/lib/cache_sqlite.c	2012-01-18 15:27:07 UTC (rev 12994)
+++ trunk/mapserver/mapcache/lib/cache_sqlite.c	2012-01-18 17:25:00 UTC (rev 12995)
@@ -33,9 +33,12 @@
 #include <apr_strings.h>
 #include <string.h>
 #include <errno.h>
-#include <unistd.h>
 #include <time.h>
 
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
 #include <sqlite3.h>
 
 
@@ -75,14 +78,15 @@
 
 static sqlite3* _get_conn(mapcache_context *ctx, mapcache_tile* tile, int readonly) {
    sqlite3* handle;
-   int flags;
+   char *dbfile;
+   int flags, ret;
    if(readonly) {
       flags = SQLITE_OPEN_READONLY;
    } else {
       flags = SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE;
    }
-   char *dbfile = _get_dbname(ctx,tile->tileset, tile->grid_link->grid);
-   int ret = sqlite3_open_v2(dbfile,&handle,flags,NULL);
+   dbfile = _get_dbname(ctx,tile->tileset, tile->grid_link->grid);
+   ret = sqlite3_open_v2(dbfile,&handle,flags,NULL);
    if(ret != SQLITE_OK) {
       ctx->set_error(ctx,500,"failed to connect to sqlite db %s: %s",dbfile,sqlite3_errmsg(handle));
       return NULL;
@@ -144,15 +148,16 @@
 static int _mapcache_cache_sqlite_has_tile(mapcache_context *ctx, mapcache_tile *tile) {
    mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*)tile->tileset->cache;
    sqlite3* handle = _get_conn(ctx,tile,1);
+   sqlite3_stmt *stmt;
+   int ret;
    if(GC_HAS_ERROR(ctx)) {
       sqlite3_close(handle);
       return MAPCACHE_FALSE;
    }
 
-   sqlite3_stmt *stmt;
    sqlite3_prepare(handle,cache->exists_stmt.sql,-1,&stmt,NULL);
    _bind_sqlite_params(ctx,stmt,tile);
-   int ret = sqlite3_step(stmt);
+   ret = sqlite3_step(stmt);
    if(ret != SQLITE_DONE && ret != SQLITE_ROW) {
       ctx->set_error(ctx,500,"sqlite backend failed on has_tile: %s",sqlite3_errmsg(handle));
    }
@@ -169,11 +174,12 @@
 static void _mapcache_cache_sqlite_delete(mapcache_context *ctx, mapcache_tile *tile) {
    mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*)tile->tileset->cache;
    sqlite3* handle = _get_conn(ctx,tile,0);
+   sqlite3_stmt *stmt;
+   int ret;
    GC_CHECK_ERROR(ctx);
-   sqlite3_stmt *stmt;
    sqlite3_prepare(handle,cache->delete_stmt.sql,-1,&stmt,NULL);
    _bind_sqlite_params(ctx,stmt,tile);
-   int ret = sqlite3_step(stmt);
+   ret = sqlite3_step(stmt);
    if(ret != SQLITE_DONE && ret != SQLITE_ROW) {
       ctx->set_error(ctx,500,"sqlite backend failed on delete: %s",sqlite3_errmsg(handle));
    }
@@ -185,6 +191,8 @@
 static int _mapcache_cache_sqlite_get(mapcache_context *ctx, mapcache_tile *tile) {
    mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*)tile->tileset->cache;
    sqlite3 *handle;
+   sqlite3_stmt *stmt;
+   int ret;
    if(cache->hitstats) {
       handle = _get_conn(ctx,tile,0);
    } else {
@@ -194,10 +202,8 @@
       sqlite3_close(handle);
       return MAPCACHE_FAILURE;
    }
-   sqlite3_stmt *stmt;
    sqlite3_prepare(handle,cache->get_stmt.sql,-1,&stmt,NULL);
    _bind_sqlite_params(ctx,stmt,tile);
-   int ret;
    do {
       ret = sqlite3_step(stmt);
       if(ret!=SQLITE_DONE && ret != SQLITE_ROW && ret!=SQLITE_BUSY && ret !=SQLITE_LOCKED) {
@@ -240,11 +246,11 @@
 static void _mapcache_cache_sqlite_set(mapcache_context *ctx, mapcache_tile *tile) {
    mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*)tile->tileset->cache;
    sqlite3* handle = _get_conn(ctx,tile,0);
+   sqlite3_stmt *stmt;
+   int ret;
    GC_CHECK_ERROR(ctx);
-   sqlite3_stmt *stmt;
    sqlite3_prepare(handle,cache->set_stmt.sql,-1,&stmt,NULL);
    _bind_sqlite_params(ctx,stmt,tile);
-   int ret;
    do {
       ret = sqlite3_step(stmt);
       if(ret != SQLITE_DONE && ret != SQLITE_ROW && ret != SQLITE_BUSY && ret != SQLITE_LOCKED) {
@@ -262,9 +268,10 @@
 
 static void _mapcache_cache_sqlite_configuration_parse_xml(mapcache_context *ctx, ezxml_t node, mapcache_cache *cache, mapcache_cfg *config) {
    ezxml_t cur_node;
+   mapcache_cache_sqlite *dcache;
    sqlite3_initialize();
    sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
-   mapcache_cache_sqlite *dcache = (mapcache_cache_sqlite*)cache;
+   dcache = (mapcache_cache_sqlite*)cache;
    if ((cur_node = ezxml_child(node,"base")) != NULL) {
       dcache->dbname_template = apr_pstrcat(ctx->pool,cur_node->txt,"/{tileset}#{grid}.db",NULL);
    }

Modified: trunk/mapserver/mapcache/nmake.opt
===================================================================
--- trunk/mapserver/mapcache/nmake.opt	2012-01-18 15:27:07 UTC (rev 12994)
+++ trunk/mapserver/mapcache/nmake.opt	2012-01-18 17:25:00 UTC (rev 12995)
@@ -94,6 +94,12 @@
 JPEG_DIR=$(MAPCACHE_BASE)\..\..\jpeg-8c
 JPEG_INC = -I$(JPEG_DIR)
 
+#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# SQLite3 Support
+# ----------------------------------------------------------------------
+# Uncomment, and update accordingly.
+#SQLITE_DEF=-DUSE_SQLITE
+#SQLITE_DIR=$(MAPCACHE_BASE)\..\..\sqlite3
 
 #~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # FastCGI Support
@@ -142,6 +148,9 @@
 JPEG_LIB=$(JPEG_DIR)/libjpeg.lib
 !ENDIF
 
+SQLITE_LIB=$(SQLITE_DIR)\lib\sqlite3_i.lib
+SQLITE_INC=-I$(SQLITE_DIR)\include
+
 FCGI_LIB=$(FCGI_DIR)\libfcgi\Release\libfcgi.lib
 FCGI_INC=-I$(FCGI_DIR)\include
 
@@ -179,17 +188,17 @@
 ########################################################################
 
 !IFNDEF EXTERNAL_LIBS
-EXTERNAL_LIBS= $(PNG_LIB) $(CURL_LIB) $(JPEG_LIB) $(APR_LIB) $(APACHE_LIB) $(FRIBIDI_LIB) $(FCGI_LIB)
+EXTERNAL_LIBS= $(PNG_LIB) $(CURL_LIB) $(JPEG_LIB) $(APR_LIB) $(APACHE_LIB) $(FRIBIDI_LIB) $(SQLITE_LIB) $(FCGI_LIB)
 !ENDIF
 
 LIBS=$(MAPCACHE_LIB) $(EXTERNAL_LIBS)
 
 !IFNDEF INCLUDES
-INCLUDES=$(MAPCACHE_INC) $(APR_INC) $(APACHE_INC) $(REGEX_INC) $(PNG_INC) $(ZLIB_INC) $(CURL_INC) $(JPEG_INC) $(FCGI_INC)
+INCLUDES=$(MAPCACHE_INC) $(APR_INC) $(APACHE_INC) $(REGEX_INC) $(PNG_INC) $(ZLIB_INC) $(CURL_INC) $(JPEG_INC) $(SQLITE_INC) $(FCGI_INC)
 !ENDIF
 
 
-MAPCACHE_DEFS =$(REGEX_OPT) $(FCGI_DEF)
+MAPCACHE_DEFS =$(REGEX_OPT) $(SQLITE_DEF) $(FCGI_DEF)
 
 
 



More information about the mapserver-commits mailing list