static switch_bool_t directory_execute_sql_callback(switch_mutex_t *mutex, char *sql, switch_core_db_callback_func_t callback, void *pdata)
{
    switch_bool_t ret = SWITCH_FALSE;
    switch_core_db_t *db;
    char *errmsg = NULL;

    if (mutex) {
        switch_mutex_lock(mutex);
    }

    if (!(db = switch_core_db_open_file(globals.dbname))) {
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
        goto end;
    }

    switch_core_db_exec(db, sql, callback, pdata, &errmsg);

    if (errmsg) {
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR: [%s] %s\n", sql, errmsg);
        switch_core_db_free(errmsg);
    }

    if (db) {
        switch_core_db_close(db);
    }

end:
    if (mutex) {
        switch_mutex_unlock(mutex);
    }

    return ret;
}
SWITCH_DECLARE(switch_core_db_t *) switch_core_db_open_file(const char *filename)
{
	switch_core_db_t *db;
	char path[1024];
	int db_ret;

	db_pick_path(filename, path, sizeof(path));
	if ((db_ret = switch_core_db_open(path, &db)) != SQLITE_OK) {
		goto end;
	}
	if ((db_ret = switch_core_db_exec(db, "PRAGMA synchronous=OFF;", NULL, NULL, NULL) != SQLITE_OK)) {
		goto end;
	}
	if ((db_ret = switch_core_db_exec(db, "PRAGMA count_changes=OFF;", NULL, NULL, NULL) != SQLITE_OK)) {
		goto end;
	}
	if ((db_ret = switch_core_db_exec(db, "PRAGMA cache_size=8000;", NULL, NULL, NULL) != SQLITE_OK)) {
		goto end;
	}
	if ((db_ret = switch_core_db_exec(db, "PRAGMA temp_store=MEMORY;", NULL, NULL, NULL) != SQLITE_OK)) {
		goto end;
	}

end:
	if (db_ret != SQLITE_OK) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", switch_core_db_errmsg(db));
		switch_core_db_close(db);
		db = NULL;
	}
	return db;
}
Exemple #3
0
SWITCH_DECLARE(switch_core_db_t *) switch_core_db_open_file(const char *filename)
{
	switch_core_db_t *db;
	char path[1024];

	db_pick_path(filename, path, sizeof(path));
	if (switch_core_db_open(path, &db)) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SQL ERR [%s]\n", switch_core_db_errmsg(db));
		switch_core_db_close(db);
		db = NULL;
	}
	return db;
}
static switch_status_t directory_execute_sql(char *sql, switch_mutex_t *mutex)
{
	switch_core_db_t *db;
	switch_status_t status = SWITCH_STATUS_SUCCESS;

	if (mutex) {
		switch_mutex_lock(mutex);
	}

	if (!(db = switch_core_db_open_file(globals.dbname))) {
		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB %s\n", globals.dbname);
		status = SWITCH_STATUS_FALSE;
		goto end;
	}
	status = switch_core_db_persistant_execute(db, sql, 1);
	switch_core_db_close(db);

  end:
	if (mutex) {
		switch_mutex_unlock(mutex);
	}

	return status;
}