Пример #1
0
static apr_status_t _sqlite_reslist_get_ro_connection(void **conn_, void *params, apr_pool_t *pool)
{
  int ret;
  int flags;  
  mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*) params;
  struct sqlite_conn *conn = apr_pcalloc(pool, sizeof (struct sqlite_conn));
  *conn_ = conn;
  flags = SQLITE_OPEN_READONLY | SQLITE_OPEN_NOMUTEX;
  ret = sqlite3_open_v2(cache->dbfile, &conn->handle, flags, NULL);
  
  if (ret != SQLITE_OK) {
    return APR_EGENERAL;
  }
  sqlite3_busy_timeout(conn->handle, 300000);
  conn->readonly = 1;

  ret = _sqlite_set_pragmas(pool,cache, conn);
  if (ret != MAPCACHE_SUCCESS) {
    sqlite3_close(conn->handle);
    return APR_EGENERAL;
  }
  conn->prepared_statements = calloc(cache->n_prepared_statements,sizeof(sqlite3_stmt*));
  conn->nstatements = cache->n_prepared_statements;
  return APR_SUCCESS;
}
Пример #2
0
void mapcache_sqlite_connection_constructor(mapcache_context *ctx, void **conn_, void *params, apr_pool_t *process_pool)
{
    int ret;
    int flags;
    struct sqlite_conn_params *sq_params = (struct sqlite_conn_params*)params;
    struct sqlite_conn *conn = calloc(1, sizeof (struct sqlite_conn));
    *conn_ = conn;
    if(sq_params->readonly) {
        flags = SQLITE_OPEN_READONLY | SQLITE_OPEN_NOMUTEX;
    } else {
        flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_CREATE;
    }
    ret = sqlite3_open_v2(sq_params->dbfile, &conn->handle, flags, NULL);
    if (ret != SQLITE_OK) {
        ctx->set_error(ctx,500,"sqlite backend failed to open db %s: %s", sq_params->dbfile, sqlite3_errmsg(conn->handle));
        return;
    }
    sqlite3_busy_timeout(conn->handle, 300000);
    do {
        ret = sqlite3_exec(conn->handle, sq_params->cache->create_stmt.sql, 0, 0, NULL);
        if (ret != SQLITE_OK && ret != SQLITE_BUSY && ret != SQLITE_LOCKED) {
            break;
        }
    } while (ret == SQLITE_BUSY || ret == SQLITE_LOCKED);
    if (ret != SQLITE_OK) {
        ctx->set_error(ctx,500, "sqlite backend failed to create db schema on %s: %s", sq_params->dbfile, sqlite3_errmsg(conn->handle));
        sqlite3_close(conn->handle);
        return;
    }
    _sqlite_set_pragmas(ctx, sq_params->cache, conn);
    if(GC_HAS_ERROR(ctx)) {
        sqlite3_close(conn->handle);
        return;
    }
    conn->prepared_statements = calloc(sq_params->cache->n_prepared_statements,sizeof(sqlite3_stmt*));
    conn->nstatements = sq_params->cache->n_prepared_statements;
}
Пример #3
0
static apr_status_t _sqlite_reslist_get_rw_connection(void **conn_, void *params, apr_pool_t *pool)
{
  int ret;
  int flags;  
  mapcache_cache_sqlite *cache = (mapcache_cache_sqlite*) params;
  struct sqlite_conn *conn = apr_pcalloc(pool, sizeof (struct sqlite_conn));
  *conn_ = conn;
  flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_NOMUTEX | SQLITE_OPEN_CREATE;
  ret = sqlite3_open_v2(cache->dbfile, &conn->handle, flags, NULL);
  if (ret != SQLITE_OK) {
    conn->errmsg = apr_psprintf(pool,"sqlite backend failed to open db %s: %s", cache->dbfile, sqlite3_errmsg(conn->handle));
    return APR_EGENERAL;
  }
  sqlite3_busy_timeout(conn->handle, 300000);
  do {
    ret = sqlite3_exec(conn->handle, cache->create_stmt.sql, 0, 0, NULL);
    if (ret != SQLITE_OK && ret != SQLITE_BUSY && ret != SQLITE_LOCKED) {
      break;
    }
  } while (ret == SQLITE_BUSY || ret == SQLITE_LOCKED);
  if (ret != SQLITE_OK) {
    conn->errmsg = apr_psprintf(pool, "sqlite backend failed to create db schema on %s: %s", cache->dbfile, sqlite3_errmsg(conn->handle));
    sqlite3_close(conn->handle);
    return APR_EGENERAL;
  }
  conn->readonly = 0;
  ret = _sqlite_set_pragmas(pool, cache, conn);
  if(ret != MAPCACHE_SUCCESS) {
    sqlite3_close(conn->handle);
    return APR_EGENERAL;
  }
  conn->prepared_statements = calloc(cache->n_prepared_statements,sizeof(sqlite3_stmt*));
  conn->nstatements = cache->n_prepared_statements;

  return APR_SUCCESS;
}