lib/cache_sqlite.c
mapcache_cache* mapcache_cache_sqlite_create(mapcache_context *ctx)
{
  mapcache_cache_sqlite *cache = apr_pcalloc(ctx->pool, sizeof (mapcache_cache_sqlite));
  if (!cache) {
    ctx->set_error(ctx, 500, "failed to allocate sqlite cache");
    return NULL;
  }
  cache->cache.metadata = apr_table_make(ctx->pool, 3);
  cache->cache.type = MAPCACHE_CACHE_SQLITE;
  cache->cache.tile_delete = _mapcache_cache_sqlite_delete;
  cache->cache.tile_get = _mapcache_cache_sqlite_get;
  cache->cache.tile_exists = _mapcache_cache_sqlite_has_tile;
  cache->cache.tile_set = _mapcache_cache_sqlite_set;
  cache->cache.tile_multi_set = _mapcache_cache_sqlite_multi_set;
  cache->cache.configuration_post_config = _mapcache_cache_sqlite_configuration_post_config;
  cache->cache.configuration_parse_xml = _mapcache_cache_sqlite_configuration_parse_xml;
  cache->create_stmt.sql = apr_pstrdup(ctx->pool,
                                       "create table if not exists tiles(tileset text, grid text, x integer, y integer, z integer, data blob, dim text, ctime datetime, primary key(tileset,grid,x,y,z,dim))");
  cache->exists_stmt.sql = apr_pstrdup(ctx->pool,
                                       "select 1 from tiles where x=:x and y=:y and z=:z and dim=:dim and tileset=:tileset and grid=:grid");
  cache->get_stmt.sql = apr_pstrdup(ctx->pool,
                                    "select data,strftime(\"%s\",ctime) from tiles where tileset=:tileset and grid=:grid and x=:x and y=:y and z=:z and dim=:dim");
  cache->set_stmt.sql = apr_pstrdup(ctx->pool,
                                    "insert or replace into tiles(tileset,grid,x,y,z,data,dim,ctime) values (:tileset,:grid,:x,:y,:z,:data,:dim,datetime('now'))");
  cache->delete_stmt.sql = apr_pstrdup(ctx->pool,
                                       "delete from tiles where x=:x and y=:y and z=:z and dim=:dim and tileset=:tileset and grid=:grid");
  cache->n_prepared_statements = 4;
  cache->bind_stmt = _bind_sqlite_params;
  cache->detect_blank = 1;
  return (mapcache_cache*) cache;
}
/**
 * \brief creates and initializes a mapcache_sqlite_cache
 */
\brief creates and initializes a mapcache_sqlite_cache
\ brief creates and initializes a mapcache_sqlite_cache
mapcache_cache* mapcache_cache_sqlite_create(mapcache_context *ctx)
{
  mapcache_cache_sqlite *cache = apr_pcalloc(ctx->pool, sizeof (mapcache_cache_sqlite));
  if (!cache) {
    ctx->set_error(ctx, 500, "failed to allocate sqlite cache");
    return NULL;
  }
  cache->cache.metadata = apr_table_make(ctx->pool, 3);
  cache->cache.type = MAPCACHE_CACHE_SQLITE;
  cache->cache.tile_delete = _mapcache_cache_sqlite_delete;
  cache->cache.tile_get = _mapcache_cache_sqlite_get;
  cache->cache.tile_exists = _mapcache_cache_sqlite_has_tile;
  cache->cache.tile_set = _mapcache_cache_sqlite_set;
  cache->cache.tile_multi_set = _mapcache_cache_sqlite_multi_set;
  cache->cache.configuration_post_config = _mapcache_cache_sqlite_configuration_post_config;
  cache->cache.configuration_parse_xml = _mapcache_cache_sqlite_configuration_parse_xml;
  cache->create_stmt.sql = apr_pstrdup(ctx->pool,
                                       "create table if not exists tiles(tileset text, grid text, x integer, y integer, z integer, data blob, dim text, ctime datetime, primary key(tileset,grid,x,y,z,dim))");
  cache->exists_stmt.sql = apr_pstrdup(ctx->pool,
                                       "select 1 from tiles where x=:x and y=:y and z=:z and dim=:dim and tileset=:tileset and grid=:grid");
  cache->get_stmt.sql = apr_pstrdup(ctx->pool,
                                    "select data,strftime(\"%s\",ctime) from tiles where tileset=:tileset and grid=:grid and x=:x and y=:y and z=:z and dim=:dim");
  cache->set_stmt.sql = apr_pstrdup(ctx->pool,
                                    "insert or replace into tiles(tileset,grid,x,y,z,data,dim,ctime) values (:tileset,:grid,:x,:y,:z,:data,:dim,datetime('now'))");
  cache->delete_stmt.sql = apr_pstrdup(ctx->pool,
                                       "delete from tiles where x=:x and y=:y and z=:z and dim=:dim and tileset=:tileset and grid=:grid");
  cache->n_prepared_statements = 4;
  cache->bind_stmt = _bind_sqlite_params;
  cache->detect_blank = 1;
  return (mapcache_cache*) cache;
}
mapcache_cache * mapcache_cache_sqlite_create ( mapcache_context * ctx ) { mapcache_cache_sqlite * cache = apr_pcalloc ( ctx -> pool , sizeof ( mapcache_cache_sqlite ) ) ; if ( ! cache ) { ctx -> set_error ( ctx , 500 , " " ) ; return NULL ; } cache -> cache . metadata = apr_table_make ( ctx -> pool , 3 ) ; cache -> cache . type = MAPCACHE_CACHE_SQLITE ; cache -> cache . tile_delete = _mapcache_cache_sqlite_delete ; cache -> cache . tile_get = _mapcache_cache_sqlite_get ; cache -> cache . tile_exists = _mapcache_cache_sqlite_has_tile ; cache -> cache . tile_set = _mapcache_cache_sqlite_set ; cache -> cache . tile_multi_set = _mapcache_cache_sqlite_multi_set ; cache -> cache . configuration_post_config = _mapcache_cache_sqlite_configuration_post_config ; cache -> cache . configuration_parse_xml = _mapcache_cache_sqlite_configuration_parse_xml ; cache -> create_stmt . sql = apr_pstrdup ( ctx -> pool , " " ) ; cache -> exists_stmt . sql = apr_pstrdup ( ctx -> pool , " " ) ; cache -> get_stmt . sql = apr_pstrdup ( ctx -> pool , " \" \" " ) ; cache -> set_stmt . sql = apr_pstrdup ( ctx -> pool , " " ) ; cache -> delete_stmt . sql = apr_pstrdup ( ctx -> pool , " " ) ; cache -> n_prepared_statements = 4 ; cache -> bind_stmt = _bind_sqlite_params ; cache -> detect_blank = 1 ; return ( mapcache_cache * ) cache ; }
\brief creates and initializes a mapcache_sqlite_cache
\ brief creates and initializes a mapcache_sqlite_cache