Ejemplo n.º 1
0
/*
** Add or remove the fault-simulation layer using sqlite3_config(). If
** the argument is non-zero, the 
*/
static int faultsimInstall(int install){
  static struct sqlite3_mem_methods m = {
    faultsimMalloc,                   /* xMalloc */
    faultsimFree,                     /* xFree */
    faultsimRealloc,                  /* xRealloc */
    faultsimSize,                     /* xSize */
    faultsimRoundup,                  /* xRoundup */
    faultsimInit,                     /* xInit */
    faultsimShutdown,                 /* xShutdown */
    0                                 /* pAppData */
  };
  int rc;

  install = (install ? 1 : 0);
  assert(memfault.isInstalled==1 || memfault.isInstalled==0);

  if( install==memfault.isInstalled ){
    return SQLITE_ERROR;
  }

  if( install ){
    rc = sqlite3_config(SQLITE_CONFIG_GETMALLOC, &memfault.m);
    assert(memfault.m.xMalloc);
    if( rc==SQLITE_OK ){
      rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &m);
    }
    sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS, 
        faultsimBeginBenign, faultsimEndBenign
    );
  }else{
    sqlite3_mem_methods m2;
    assert(memfault.m.xMalloc);

    /* One should be able to reset the default memory allocator by storing
    ** a zeroed allocator then calling GETMALLOC. */
    memset(&m2, 0, sizeof(m2));
    sqlite3_config(SQLITE_CONFIG_MALLOC, &m2);
    sqlite3_config(SQLITE_CONFIG_GETMALLOC, &m2);
    assert( memcmp(&m2, &memfault.m, sizeof(m2))==0 );

    rc = sqlite3_config(SQLITE_CONFIG_MALLOC, &memfault.m);
    sqlite3_test_control(SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS,
        (void*)0, (void*)0);
  }

  if( rc==SQLITE_OK ){
    memfault.isInstalled = 1;
  }
  return rc;
}
Ejemplo n.º 2
0
/* Don't call this function directly!  Use svn_atomic__init_once(). */
static svn_error_t *
init_sqlite(void *baton, apr_pool_t *pool)
{
  if (sqlite3_libversion_number() < SQLITE_VERSION_NUMBER) {
    return svn_error_createf(SVN_ERR_SQLITE_ERROR, NULL,
                             _("SQLite compiled for %s, but running with %s"),
                             SQLITE_VERSION, sqlite3_libversion());
  }

#if APR_HAS_THREADS
#if SQLITE_VERSION_AT_LEAST(3,5,0)
  /* SQLite 3.5 allows verification of its thread-safety at runtime.
     Older versions are simply expected to have been configured with
     --enable-threadsafe, which compiles with -DSQLITE_THREADSAFE=1
     (or -DTHREADSAFE, for older versions). */
  if (! sqlite3_threadsafe())
    return svn_error_create(SVN_ERR_SQLITE_ERROR, NULL,
                            _("SQLite is required to be compiled and run in "
                              "thread-safe mode"));
#endif
#if SQLITE_VERSION_AT_LEAST(3,6,0)
  /* If SQLite has been already initialized, sqlite3_config() returns
     SQLITE_MISUSE. */
  {
    int err = sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
    if (err != SQLITE_OK && err != SQLITE_MISUSE)
      return svn_error_create(SQLITE_ERROR_CODE(err), NULL,
                              "Could not configure SQLite");
  }
  SQLITE_ERR_MSG(sqlite3_initialize(), "Could not initialize SQLite");
#endif
#endif /* APR_HAS_THRADS */

  return SVN_NO_ERROR;
}
Ejemplo n.º 3
0
void init_sqlite_memory() {
  fprintf(stdout, "Initializing sqlite memory configuration!\n");
  if (sqlite3_config(SQLITE_CONFIG_MALLOC, &my_mem) != SQLITE_OK) {
    fprintf(stdout, "Failed to set custom sqlite memory allocator!\n");
  }
  fprintf(stdout, "Success!\n");
}
Ejemplo n.º 4
0
Sqlite::Sqlite() {
	dbHandle = NULL;
	int out;
	sqlite3_config(SQLITE_CONFIG_URI, 1);
	std::string sqlString;
	std::string dbFile;
	dbFile = "file:";
	dbFile.append(getenv("HOME"));
	dbFile.append("/files.db");
	out = sqlite3_open_v2(dbFile.c_str(), &dbHandle, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX, NULL);
	if (out != SQLITE_OK || dbHandle == NULL) {
		std::cerr << "(" << __FILE__ << ":" << __LINE__ << ") " << out << dbFile.c_str() << " - " << sqlite3_errmsg(dbHandle) << std::endl;
	}
	initialiseDatabase();

	sqlString = "INSERT INTO gpsdata (time,latitude,longitude,altitude,heading) "
			"VALUES (?,?,?,?,?);";
	out = sqlite3_prepare_v2(dbHandle, sqlString.c_str(), sqlString.length(), &insert, NULL);
	if (out != SQLITE_OK) {
		std::cerr << "(" << __FILE__ << ":" << __LINE__ << ") " << out << " - " << sqlite3_errmsg(dbHandle) << std::endl;
	}
	sqlString = "SELECT * FROM gpsdata "
			"WHERE pkey IS ?;";
	out = sqlite3_prepare_v2(dbHandle, sqlString.c_str(), sqlString.length(), &query, NULL);
	if (out != SQLITE_OK) {
		std::cerr << "(" << __FILE__ << ":" << __LINE__ << ") " << out << " - " << sqlite3_errmsg(dbHandle) << std::endl;
	}
	// TODO Auto-generated constructor stub

}
Ejemplo n.º 5
0
// initialize SQLite3
void database_init ( void )
{
  // local variables
  database_state_t *state = database_getState ( );
  int status;

  // use thread safe serialized mode
  status = sqlite3_config ( SQLITE_CONFIG_SERIALIZED );
  if ( SQLITE_OK != status )
  {
    fatalError ( "Thread-safe SQLite3 not supported!", 1 );
  }

  // initialize SQLite3
  status = sqlite3_initialize ( );
  if ( SQLITE_OK != status )
  {
    fatalError ( "Failed to initialize SQLite3!", 1 );
  }

  // open database
  status = sqlite3_open( DATABASE_FILE, &state->database );
  if ( SQLITE_OK != status )
  {
    fatalError ( "Failed to open SQLite3 database!", 1 );
  }

  // initialize database
  database_loadFile ( state, DATABASE_SQL );

  // prepare statements
  database_initStatements ( state );
}
Ejemplo n.º 6
0
OCStackResult PDMInit(const char *path)
{
    int rc;
    const char *dbPath = NULL;
    if (SQLITE_OK !=  sqlite3_config(SQLITE_CONFIG_LOG, errLogCallback, NULL))
    {
        OC_LOG(INFO, TAG, "Unable to enable debug log of sqlite");
    }

    if (NULL == path || !*path)
    {
        dbPath = DB_FILE;
    }
    else
    {
        dbPath = path;
    }
    rc = sqlite3_open_v2(dbPath, &g_db, SQLITE_OPEN_READWRITE, NULL);
    if (SQLITE_OK != rc)
    {
        OC_LOG_V(INFO, TAG, "ERROR: Can't open database: %s", sqlite3_errmsg(g_db));
        return createDB(dbPath);
    }
    gInit = true;
    return OC_STACK_OK;
}
Ejemplo n.º 7
0
void
svn_sqlite__dbg_enable_errorlog(void)
{
#if defined(SVN_DEBUG) && defined(SQLITE_CONFIG_LOG)
  sqlite3_config(SQLITE_CONFIG_LOG, sqlite_error_log, (void*)NULL /* baton */);
#endif
}
Ejemplo n.º 8
0
//---------------------------------------------------------------------------
bool CFS_Sqlite::Initialize(void* pEngine)
{
	int ret=0;

	CON(MSG_INFO, _W("Database filesystem sqlite %s:"), _A2W(sqlite3_version) );

	if (!sqlite3_threadsafe())
	{
		CON(MSG_ERR, _W("... not compiled thread-safe - will not be used!"));
		return false;
	}

	CON(MSG_INFO, _W("... setting multithread configuration"));
	sqlite3_config(SQLITE_CONFIG_MULTITHREAD);

	ret = sqlite3_initialize();
	if (ret == SQLITE_OK)
		CON(MSG_INFO, _W("... successfuly initialized"));
	else
	{
		CON(MSG_ERR, _W("... error code %d returned - will not be used!"), ret);
		return false;
	}

	return true;
}
Ejemplo n.º 9
0
// Initialize library.
// To be called once during the lifetime of the app.
// $package: The folder where the package data resides.
// $webroot: The document root folder for the web server.
void bibledit_initialize_library (const char * package, const char * webroot)
{
  // Must initialize libcurl before any threads are started.
#ifdef HAVE_CLIENT
#else
  curl_global_init (CURL_GLOBAL_ALL);
#endif
  
  // Thread locking.
  thread_setup ();
  
  // Initialize SQLite: Full thread safety: https://www.sqlite.org/c3ref/threadsafe.html.
  // This is supported to prevent "database locked" errors.
  if (!sqlite3_threadsafe ()) {
    cerr << "SQLite is not threadsafe" << endl;
  }
  sqlite3_config (SQLITE_CONFIG_SERIALIZED);

  // Binary file mode on Windows.
#ifdef HAVE_WINDOWS
  _set_fmode (_O_BINARY);
#endif

  // Set the web root folder.
  config_globals_document_root = webroot;
  
  // Initialize SSL/TLS (after webroot has been set).
  filter_url_ssl_tls_initialize ();
  
#ifndef HAVE_CLIENT
  // Cloud initializes OpenLDAP server access settings (after webroot has been set).
  ldap_logic_initialize ();
#endif

#ifdef HAVE_CLIENT
  // Set local timezone offset in the library.
#ifdef HAVE_WINDOWS
  TIME_ZONE_INFORMATION tzi;
  DWORD dwRet = GetTimeZoneInformation (&tzi);
  (void)dwRet;
  int offset = 0 - (tzi.Bias / 60);
  bibledit_set_timezone_hours_offset_utc (offset);
#else
  time_t t = time (NULL);
  struct tm lt = {};
  localtime_r (&t, &lt);
  int offset = round (lt.tm_gmtoff / 3600);
  bibledit_set_timezone_hours_offset_utc (offset);
#endif
  
#endif

  // Initialize data in a thread.
  thread setup_thread = thread (setup_conditionally, package);
  setup_thread.detach ();
  
  // Multiple start/stop guard.
  bibledit_started = false;
}
// Sets the global SQLite configuration.
// This must be called before any other SQLite functions are called.
static void sqliteInitialize() {
    // Enable multi-threaded mode.  In this mode, SQLite is safe to use by multiple
    // threads as long as no two threads use the same database connection at the same
    // time (which we guarantee in the SQLite database wrappers).
    sqlite3_config(SQLITE_CONFIG_MULTITHREAD);

    // Redirect SQLite log messages to the Android log.
    bool verboseLog = android_util_Log_isVerboseLogEnabled(SQLITE_LOG_TAG);
    sqlite3_config(SQLITE_CONFIG_LOG, &sqliteLogCallback, verboseLog ? (void*)1 : NULL);

    // The soft heap limit prevents the page cache allocations from growing
    // beyond the given limit, no matter what the max page cache sizes are
    // set to. The limit does not, as of 3.5.0, affect any other allocations.
    sqlite3_soft_heap_limit(SOFT_HEAP_LIMIT);

    // Initialize SQLite.
    sqlite3_initialize();
}
Ejemplo n.º 11
0
int main()
{
	std::ifstream in("data/data.json");
	sqlite3* db;

//	std::remove("data.sqlite3");

	sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);

	int rc;
	rc = sqlite3_open("data.sqlite3", &db);
	assert(rc == SQLITE_OK);

	rc = sqlite3_exec(db, schema, NULL, NULL, NULL);
	assert(rc == SQLITE_OK);

	sqlite3_stmt* insert;
	rc = sqlite3_prepare_v2(db, insert_stmt, -1, &insert, NULL);
	while (!in.eof())
	{
		Json::Value root;
		char comment[512000];
		in.getline(comment, 512000);
		size_t clen = std::strlen(comment);
		//comment[clen++] = '}';
		//comment[clen] = 0;
		char* cstart = comment;
		while (cstart != comment + clen && *cstart != '{') ++cstart;
		if (cstart == comment + clen) continue;
		//std::cout << cstart << std::endl;
		std::stringstream cstream(cstart);
		cstream >> root;
		assert(root.type() == Json::ValueType::objectValue);
		bind_text(insert, 1, root, "name", Json::nullValue);
		bind_text(insert, 2, root, "link_id");
		bind_text(insert, 3, root, "created_utc");
		sqlite3_bind_int64(insert, 4, root.get("ups", 0).asInt64());
		sqlite3_bind_int64(insert, 5, root.get("downs", 0).asInt64());
		sqlite3_bind_int64(insert, 6, root.get("gilded", 0).asInt64());
		bind_text(insert, 7, root, "author");
		sqlite3_bind_int64(insert, 8, root.get("score", 0).asInt64());
		bind_text(insert, 9, root, "subreddit");
		bind_text(insert, 10, root, "subreddit_id");
		bind_text(insert, 11, root, "parent_id", Json::nullValue);
		bind_text(insert, 12, root, "author_flair_text", Json::nullValue);
		bind_text(insert, 13, root, "body");
		rc = sqlite3_step(insert);
		assert(rc == SQLITE_DONE);
		sqlite3_reset(insert);
	}

	sqlite3_finalize(insert);

	sqlite3_close(db);
}
Ejemplo n.º 12
0
NMBLSEXPORT void handleLoadLibrary(boost::asio::io_service &, std::string root, bool debug)
{
    docroot = root;

    worker_thread.create_thread(sqliteworker);

    std::cout << "Hi form handle load lib" << std::endl;

    is_running_as_debug = debug;
    sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
}
Ejemplo n.º 13
0
sqlite3 *db_sqlite_init(char *filename) {
	sqlite3_config(SQLITE_CONFIG_SERIALIZED);
	
	if(sqlite3_open(filename, &db) != SQLITE_OK) {
		fprintf(stderr, "[-] sqlite: cannot open sqlite databse: <%s>\n", sqlite3_errmsg(db));
		return NULL;
	}
	
	sqlite3_busy_timeout(db, 30000);
	
	return db;
}
static void installInitWrappers(void){
  sqlite3_mutex_methods mutexmethods = {
    wrMutexInit,  wrMutexEnd,   wrMutexAlloc,
    wrMutexFree,  wrMutexEnter, wrMutexTry,
    wrMutexLeave, wrMutexHeld,  wrMutexNotheld
  };
  sqlite3_pcache_methods pcachemethods = {
    0,
    wrPCacheInit,      wrPCacheShutdown,  wrPCacheCreate, 
    wrPCacheCachesize, wrPCachePagecount, wrPCacheFetch,
    wrPCacheUnpin,     wrPCacheRekey,     wrPCacheTruncate,  
    wrPCacheDestroy
  };
  sqlite3_mem_methods memmethods = {
    wrMemMalloc,   wrMemFree,    wrMemRealloc,
    wrMemSize,     wrMemRoundup, wrMemInit,
    wrMemShutdown,
    0
  };

  memset(&wrapped, 0, sizeof(wrapped));

  sqlite3_shutdown();
  sqlite3_config(SQLITE_CONFIG_GETMUTEX, &wrapped.mutex);
  sqlite3_config(SQLITE_CONFIG_GETMALLOC, &wrapped.mem);
  sqlite3_config(SQLITE_CONFIG_GETPCACHE, &wrapped.pcache);
  sqlite3_config(SQLITE_CONFIG_MUTEX, &mutexmethods);
  sqlite3_config(SQLITE_CONFIG_MALLOC, &memmethods);
  sqlite3_config(SQLITE_CONFIG_PCACHE, &pcachemethods);
}
Ejemplo n.º 15
0
/*
** This routine is the only routine in this file with external linkage.
**
** Populate the low-level memory allocation function pointers in
** sqlite3GlobalConfig.m with pointers to the routines in this file.
*/
void sqlite3MemSetDefault(void){
  static const sqlite3_mem_methods defaultMethods = {
     sqlite3MemMalloc,
     sqlite3MemFree,
     sqlite3MemRealloc,
     sqlite3MemSize,
     sqlite3MemRoundup,
     sqlite3MemInit,
     sqlite3MemShutdown,
     0
  };
  sqlite3_config(SQLITE_CONFIG_MALLOC, &defaultMethods);
}
Ejemplo n.º 16
0
RmSwapTable *rm_swap_table_open(gboolean in_memory, GError **error) {
    RmSwapTable *self = NULL;

    char *path = NULL;

    if(in_memory) {
        path = g_strdup(":memory:");
    } else {
        char pid[20] = {0};
        memset(pid, 0, sizeof(pid));

        g_snprintf(pid, sizeof(pid), "%d", getpid());
        path = g_build_filename(g_get_user_cache_dir(), "rmlint", pid, NULL);

        /* Make sure that path actually exists */
        rm_swap_table_create_cachedir(error);
    }

    /* Might happen if no tmp file could be created */
    if(error && *error) {
        goto cleanup;
    }

    /* We do locking ourselves */
    sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);

    sqlite3 *handle = NULL;
    if(sqlite3_open(path, &handle) != SQLITE_OK) {
        SET_ERROR("Cannot open swap table db");
        goto cleanup;
    }

    /* Finetune sqlite (quite slow without these) */
    sqlite3_extended_result_codes(handle, TRUE);
    sqlite3_exec(handle, "PRAGMA cache_size = 8000;", 0, 0, 0);
    sqlite3_exec(handle, "PRAGMA synchronous = OFF;", 0, 0, 0);
    sqlite3_exec(handle, "PRAGMA journal_mode = MEMORY;", 0, 0, 0);
    sqlite3_enable_shared_cache(TRUE);

    size_t path_len = strlen(path) + 1;
    self = g_malloc(sizeof(RmSwapTable) + path_len);
    self->cache = handle;
    self->attrs = g_ptr_array_new();
    self->transaction_running = FALSE;
    strncpy(self->path, path, path_len);
    g_mutex_init(&self->mtx);

cleanup:
    g_free(path);
    return self;
}
Ejemplo n.º 17
0
static OCStackResult initializeDatabase(const char *path)
{
    if (SQLITE_OK == sqlite3_config(SQLITE_CONFIG_LOG, errorCallback))
    {
        OIC_LOG_V(INFO, TAG, "SQLite debugging log initialized.");
    }

    sqlite3_open_v2(!path ? RD_PATH : path, &gRDDB, SQLITE_OPEN_READONLY, NULL);
    if (!gRDDB)
    {
        return OC_STACK_ERROR;
    }
    return OC_STACK_OK;
}
// register the logging func on sqlite. needs to be done BEFORE any sqlite3 func is called.
static void registerLoggingFunc(const char *path) {
    static bool loggingFuncSet = false;
    if (loggingFuncSet) {
        return;
    }

    LOGV("Registering sqlite logging func \n");
    int err = sqlite3_config(SQLITE_CONFIG_LOG, &sqlLogger, (void *)createStr(path));
    if (err != SQLITE_OK) {
        LOGE("sqlite_config failed error_code = %d. THIS SHOULD NEVER occur.\n", err);
        return;
    }
    loggingFuncSet = true;
}
Ejemplo n.º 19
0
void SqliteInitialize(TPerfTestMode aMode)
	{
	if(aMode == EPerfTestSqliteSqlMode)
		{
		const TInt KSqliteLookAsideCellSize = 128;
		const TInt KSqliteLookAsideCellCount = 512;
		int err;
		err = sqlite3_config(SQLITE_CONFIG_LOOKASIDE, KSqliteLookAsideCellSize, KSqliteLookAsideCellCount);
		TEST2(err, SQLITE_OK);
		sqlite3_soft_heap_limit(1024 * 1024);
		err = sqlite3_enable_shared_cache(1);
		TEST2(err, SQLITE_OK);
		}
	}
// register the logging func on sqlite. needs to be done BEFORE any sqlite3 func is called.
static void registerLoggingFunc(const char *path) {
    static bool loggingFuncSet = false;
    if (loggingFuncSet) {
        return;
    }

    LOGV("Registering sqlite logging func \n");
    int err = sqlite3_config(SQLITE_CONFIG_LOG, &sqlLogger, (void *)createStr(path, 0));
    if (err != SQLITE_OK) {
        LOGW("sqlite returned error = %d when trying to register logging func.\n", err);
        return;
    }
    loggingFuncSet = true;
}
Ejemplo n.º 21
0
int main(int argc, char **argv)
{
    struct tm tm;

   // pid = getpid();


    init_abt_log(NULL, LOG_NOTICE);




    if (sqlite3_config(SQLITE_CONFIG_MULTITHREAD) != SQLITE_OK) {       //多线程模式防止并发锁
        log_error(LOG_ERROR, "mutile thread error");
    }

    if (init_ds3231() < 0) {
        log_error(LOG_EMERG, "init_ds3231");
        return -1;
    }
    getTime(&tm);

    if (cache_init() < 0) {

        log_error(LOG_EMERG, "cache_init");
        return -1;
    }

    if (init_at24c02b() < 0) {
        log_error(LOG_NOTICE, "init_at24c02b");
    }
    g_dev_version = zigdev_version();

    if (zigdev_init() < 0) {
        log_error(LOG_NOTICE, "zigdev_init");
        return -1;
    }

    signal_propose();
    zigdev_test();
    //zigadd_dev(0x256833, 1, 1, 0, 1);
    tcp_server(NULL);


    cache_destroy();

    close_abt_log();
    return 0;
}
Ejemplo n.º 22
0
int main(void) {
    /* Determina l'opzione di configurazione relativa al multithreading, che
    non necessita peraltro di ulteriore argomento */
    sqlite3_config(SQLITE_CONFIG_MULTITHREAD);

    // Inizializzazione della libreria
    if (sqlite3_initialize() == SQLITE_OK)
        printf("Library: \'%s\' initialized\n", sqlite3_libversion());

    // Rilascio delle risorse
    if (sqlite3_shutdown() == SQLITE_OK)
        printf("Library: freed\n");

    return(EXIT_SUCCESS);
}
Ejemplo n.º 23
0
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);
  dcache = (mapcache_cache_sqlite*) cache;
  if ((cur_node = ezxml_child(node, "base")) != NULL) {
    ctx->set_error(ctx, 500, "sqlite config <base> not supported anymore, use <dbfile>");
    return;
  }
  if ((cur_node = ezxml_child(node, "dbname_template")) != NULL) {
    ctx->set_error(ctx, 500, "sqlite config <dbname_template> not supported anymore, use <dbfile>");
    return;
  }
  if ((cur_node = ezxml_child(node, "dbfile")) != NULL) {
    dcache->dbfile = apr_pstrdup(ctx->pool, cur_node->txt);
  }
  
  dcache->detect_blank = 0;
  if ((cur_node = ezxml_child(node, "detect_blank")) != NULL) {
    if(!strcasecmp(cur_node->txt,"true")) {
      dcache->detect_blank = 1;
    }
  }

  if ((cur_node = ezxml_child(node, "hitstats")) != NULL) {
    if (!strcasecmp(cur_node->txt, "true")) {
      ctx->set_error(ctx, 500, "sqlite config <hitstats> not supported anymore");
    }
  }
  if ((cur_node = ezxml_child(node, "pragma")) != NULL) {
    dcache->pragmas = apr_table_make(ctx->pool,1);
    while(cur_node) {
      char *name = (char*)ezxml_attr(cur_node,"name");
      if(!name || !cur_node->txt || !strlen(cur_node->txt)) {
        ctx->set_error(ctx,500,"<pragma> missing name attribute");
        return;
      }
      apr_table_set(dcache->pragmas,name,cur_node->txt);
      cur_node = cur_node->next;
    }
  }
  if (!dcache->dbfile) {
    ctx->set_error(ctx, 500, "sqlite cache \"%s\" is missing <dbfile> entry", cache->name);
    return;
  }
}
Ejemplo n.º 24
0
bool Utility::setThreadMode(int mode)
{
#if (SQLITE_THREADSAFE != 0)
	if (SQLITE_OK == sqlite3_shutdown())
	{
		if (SQLITE_OK == sqlite3_config(mode))
		{
			_threadMode = mode;
			if (SQLITE_OK == sqlite3_initialize())
				return true;
		}
		sqlite3_initialize();
	}
#endif
	return false;
}
Ejemplo n.º 25
0
Archivo: kvdb.c Proyecto: fingon/kvdb
bool kvdb_init()
{
#ifdef DEBUG
  int rc;

  KVASSERT(!_initialized, "kvdb_init called more than once");
  _initialized = true;
  rc = sqlite3_config(SQLITE_CONFIG_LOG, _sqlite_log, _sqlite_log);
  if (rc)
    {
      KVDEBUG("got %d when setting up log", rc);
      return false;
    }
#endif /* DEBUG */
  return true;
}
Ejemplo n.º 26
0
/*
** This function is called during initialization (sqlite3_initialize()) to
** install the default pluggable cache module, assuming the user has not
** already provided an alternative.
*/
void sqlite3PCacheSetDefault(void){
  static sqlite3_pcache_methods defaultMethods = {
    0,                       /* pArg */
    pcache1Init,             /* xInit */
    pcache1Shutdown,         /* xShutdown */
    pcache1Create,           /* xCreate */
    pcache1Cachesize,        /* xCachesize */
    pcache1Pagecount,        /* xPagecount */
    pcache1Fetch,            /* xFetch */
    pcache1Unpin,            /* xUnpin */
    pcache1Rekey,            /* xRekey */
    pcache1Truncate,         /* xTruncate */
    pcache1Destroy           /* xDestroy */
  };
  sqlite3_config(SQLITE_CONFIG_PCACHE, &defaultMethods);
}
Ejemplo n.º 27
0
int
mansearch_setup(int start)
{
	static void	*pagecache;
	int		 c;

#define	PC_PAGESIZE	1280
#define	PC_NUMPAGES	256

	if (start) {
		if (NULL != pagecache) {
			fprintf(stderr, "pagecache already enabled\n");
			return((int)MANDOCLEVEL_BADARG);
		}

		pagecache = mmap(NULL, PC_PAGESIZE * PC_NUMPAGES,
		    PROT_READ | PROT_WRITE,
		    MAP_SHARED | MAP_ANON, -1, 0);

		if (MAP_FAILED == pagecache) {
			perror("mmap");
			pagecache = NULL;
			return((int)MANDOCLEVEL_SYSERR);
		}

		c = sqlite3_config(SQLITE_CONFIG_PAGECACHE,
		    pagecache, PC_PAGESIZE, PC_NUMPAGES);

		if (SQLITE_OK == c)
			return((int)MANDOCLEVEL_OK);

		fprintf(stderr, "pagecache: %s\n", sqlite3_errstr(c));

	} else if (NULL == pagecache) {
		fprintf(stderr, "pagecache missing\n");
		return((int)MANDOCLEVEL_BADARG);
	}

	if (-1 == munmap(pagecache, PC_PAGESIZE * PC_NUMPAGES)) {
		perror("munmap");
		pagecache = NULL;
		return((int)MANDOCLEVEL_SYSERR);
	}

	pagecache = NULL;
	return((int)MANDOCLEVEL_OK);
}
Ejemplo n.º 28
0
StorageHandler::StorageHandler(
    const string &directory,
    const string &dataBaseName,
    Logger &logger):

    mDirectory(directory),
    mDataBaseName(dataBaseName),
    mTrustLineHandler(connection(dataBaseName, directory), kTrustLineTableName, logger),
    mPaymentOperationStateHandler(connection(dataBaseName, directory), kPaymentOperationStateTableName, logger),
    mTransactionHandler(connection(dataBaseName, directory), kTransactionTableName, logger),
    mHistoryStorage(connection(dataBaseName, directory), kHistoryMainTableName, kHistoryAdditionalTableName, logger),
    mBlackListHandler(connection(dataBaseName, directory), kBlackListTableName, logger),
    mNodeFeaturesHandler(connection(dataBaseName, directory), kNodeFeaturesTableName, logger),
    mLog(logger)
{
    sqlite3_config(SQLITE_CONFIG_SINGLETHREAD);
}
Ejemplo n.º 29
0
int SQL_init(struct SQLiteSession * sqlserver , const char * dbFilename)
{
    if (sqlite3_config(SQLITE_CONFIG_SERIALIZED)!=SQLITE_OK)
    {
        fprintf(stderr,"Cannot set SQLite to serialized mode , cannot continue we are not going to be thread safe..!");
        return 0;
    }

    sqlserver->rc = sqlite3_open(dbFilename, &sqlserver->db);
    if (sqlserver->rc != SQLITE_OK)
    {
        fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(sqlserver->db));
        sqlite3_close(sqlserver->db);
        return 0;
    }

    return 1;
}
Ejemplo n.º 30
0
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);
   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);
   }
   if ((cur_node = ezxml_child(node,"dbname_template")) != NULL) {
      dcache->dbname_template = apr_pstrdup(ctx->pool,cur_node->txt);
   }
   if ((cur_node = ezxml_child(node,"hitstats")) != NULL) {
      if(!strcasecmp(cur_node->txt,"true")) {
         dcache->hitstats = 1;
      }
   }
   if(!dcache->dbname_template) {
      ctx->set_error(ctx,500,"sqlite cache \"%s\" is missing <dbname_template> entry",cache->name);
      return;
   }
}