예제 #1
0
int main(int argc, char **argv)
{
	struct arguments arguments;

	argp_parse(&argp, argc, argv, 0, 0, &arguments);

        char *file = arguments.args[0];
        sqlite3 *db;
        int rc = 0;

        sqlite3_initialize();
        rc = sqlite3_open(file, &db);

        if(rc) {
                fprintf(stderr, "Can't open database: %s\n",
                                sqlite3_errmsg(db));
                exit(0);
        } else {
                fprintf(stderr, "Opened database successfully\n");
        }

	int wk = atoi(arguments.args[1]);
	print_score(db, wk);

        sqlite3_close(db);

        exit(0);
}
예제 #2
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    m_log = new Log(this);
    m_pragmaDialog = new PragmaDialog(this);
    m_memoryDialog = new MemoryDialog(this);

    m_dbWidget = new DatabaseWidget();
    connect(m_dbWidget, SIGNAL(logMsg(QString)), m_log, SLOT(addMsg(QString)));
    connect(m_dbWidget, SIGNAL(active(QSharedPointer<SQLite>)), m_pragmaDialog, SLOT(active(QSharedPointer<SQLite>)));
    connect(m_dbWidget, SIGNAL(inactive()), m_pragmaDialog, SLOT(inactive()));

    connect(m_dbWidget, SIGNAL(active(QSharedPointer<SQLite>)), m_memoryDialog, SLOT(active(QSharedPointer<SQLite>)));
    connect(m_dbWidget, SIGNAL(inactive()), m_memoryDialog, SLOT(inactive()));

    setCentralWidget(m_dbWidget);

    createActions();
    createMenus();
    createToolBars();

    statusBar();

    QSettings settings("Research In Motion", "sbuilder");
    restoreGeometry(settings.value("geometry").toByteArray());
    m_recentFiles = settings.value("recentFiles").toStringList();
    updateRecentFileActions();

    sqlite3_initialize();
}
예제 #3
0
	bool Database::Open(const std::string &Path)
	{
		if (Inner != nullptr)
			Close();

		int Err;
		if ((Err = sqlite3_initialize()) != SQLITE_OK)
			return LogError(sqlite3_errstr(Err), false);

		if (Err = sqlite3_open_v2(Path.c_str(), &Inner, SQLITE_OPEN_READWRITE, nullptr) != SQLITE_OK)
		{
			if (Err = sqlite3_open_v2(Path.c_str(), &Inner, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr) != SQLITE_OK)
				return LogError(sqlite3_errstr(Err), false);

			std::vector<std::string> TableStrings;
			TableStrings.push_back(User::CreationString);
			TableStrings.push_back(Server::CreationString);
			TableStrings.push_back(Chatroom::CreationString);

			for (unsigned int x = 0; x < TableStrings.size(); x++)
			{
				Statement s;
				if (!s.Prepare(Inner, TableStrings[x]))
					return false;
				if (!s.Execute())
					return false;
			}
		}
		return true;
	}
예제 #4
0
void Init_sqlite3_native()
{
  /*
   * SQLite3 is a wrapper around the popular database
   * sqlite[http://sqlite.org].
   *
   * For an example of usage, see SQLite3::Database.
   */
  mSqlite3     = rb_define_module("SQLite3");

  /* A class for differentiating between strings and blobs, when binding them
   * into statements.
   */
  cSqlite3Blob = rb_define_class_under(mSqlite3, "Blob", rb_cString);

  /* Initialize the sqlite3 library */
#ifdef HAVE_SQLITE3_INITIALIZE
  sqlite3_initialize();
#endif

  init_sqlite3_database();
  init_sqlite3_statement();
#ifdef HAVE_SQLITE3_BACKUP_INIT
  init_sqlite3_backup();
#endif

  rb_define_singleton_method(mSqlite3, "libversion", libversion, 0);
  rb_define_const(mSqlite3, "SQLITE_VERSION", rb_str_new2(SQLITE_VERSION));
  rb_define_const(mSqlite3, "SQLITE_VERSION_NUMBER", INT2FIX(SQLITE_VERSION_NUMBER));
}
예제 #5
0
void CreateDatabase() {
sqlite3_initialize();
sqlite3* DB;
sqlite3_open_v2(DBName.c_str(), &DB, SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, 0);
sqlite3_exec(DB, "create table audiobooks(title varchar(255) not null, lastposition int not null);", 0, 0, 0);
sqlite3_close(DB);
}
예제 #6
0
/*
 ** Register a statically linked extension that is automatically
 ** loaded by every new database connection.
 */
SQLITE_API int sqlite3_auto_extension(void (*xInit)(void)){
    int rc = SQLITE_OK;
#ifndef SQLITE_OMIT_AUTOINIT
    rc = sqlite3_initialize();
    if( rc ){
        return rc;
    }else
#endif
    {
        int i;
#if SQLITE_THREADSAFE
        sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
        wsdAutoextInit;
        sqlite3_mutex_enter(mutex);
        for(i=0; i<wsdAutoext.nExt; i++){
            if( wsdAutoext.aExt[i]==xInit ) break;
        }
        if( i==wsdAutoext.nExt ){
            int nByte = (wsdAutoext.nExt+1)*sizeof(wsdAutoext.aExt[0]);
            void (**aNew)(void);
            aNew = sqlite3_realloc(wsdAutoext.aExt, nByte);
            if( aNew==0 ){
                rc = SQLITE_NOMEM;
            }else{
                wsdAutoext.aExt = aNew;
                wsdAutoext.aExt[wsdAutoext.nExt] = xInit;
                wsdAutoext.nExt++;
            }
        }
        sqlite3_mutex_leave(mutex);
        assert( (rc&0xff)==rc );
        return rc;
    }
}
예제 #7
0
static int init(void)
{
    int i;

    /* initialize sqlite3 */
    if (SQLITE_OK != sqlite3_initialize()) {
        return OPAL_ERR_UNREACH;
    }

    /* check if sqlite was built thread-safe - if not, we won't
     * use worker threads for thruput
     */
    if (0 == mca_db_sqlite_component.num_worker_threads || 0 != sqlite3_threadsafe()) {
        nthreads = 1;
    } else {
        nthreads = mca_db_sqlite_component.num_worker_threads;
    }

    /* get the required number of database handles */
    dbhandles = (sqlite3**)malloc(nthreads * sizeof(sqlite3*));

    /* open the database - this will create the database file if
     * it doesn't already exist
     */
    for (i=0; i < nthreads; i++) {
        if (SQLITE_OK != sqlite3_open(mca_db_sqlite_component.db_file, &dbhandles[i])) {
            opal_show_help("help-db-sqlite.txt", "cannot-create-sqlite", true, mca_db_sqlite_component.db_file);
            return OPAL_ERR_FILE_OPEN_FAILURE;
        }
    }

    return OPAL_SUCCESS;
}
예제 #8
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 );
}
예제 #9
0
int main( int argc, char **argv )
{
    char            *file = ""; /* default to temp db */
    const char      *data = NULL;
    sqlite3         *db = NULL;
    sqlite3_stmt    *stmt = NULL;
    int             rc = 0;

    if ( argc > 1 )
        file = argv[1];

    sqlite3_initialize( );
    rc = sqlite3_open_v2( file, &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL );
    if ( rc != SQLITE_OK) {
        sqlite3_close( db );
        exit( -1 );
    }


    rc = sqlite3_prepare_v2( db, "SELECT str FROM tbl ORDER BY 1", -1, &stmt, NULL );
    if ( rc != SQLITE_OK) exit( -1 );

    while( sqlite3_step( stmt ) == SQLITE_ROW ) {
        data = (const char*)sqlite3_column_text( stmt, 0 );
        printf( "%s\n", data ? data : "[NULL]" );
    }
    
    sqlite3_finalize( stmt );



    sqlite3_close( db );
    sqlite3_shutdown( );
}
예제 #10
0
/*
** The public interface to sqlite3Realloc.  Make sure that the memory
** subsystem is initialized prior to invoking sqliteRealloc.
*/
void *sqlite3_realloc(void *pOld, int n){
#ifndef SQLITE_OMIT_AUTOINIT
  if( sqlite3_initialize() ) return 0;
#endif
  if( n<0 ) n = 0;  /* IMP: R-26507-47431 */
  return sqlite3Realloc(pOld, n);
}
예제 #11
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;
}
예제 #12
0
int main(int argc, char *argv[]) {
    sqlite3 *db = NULL;
    int res = 0;

    if (argc != 2) {
        fprintf(stderr, "Usage: %s <database name>\n", argv[0]);
        exit(EXIT_FAILURE);
    }

    // Inizializzazione della libreria
    if (sqlite3_initialize() != SQLITE_OK) {
        fprintf(stderr, "Err. Unable to initialize the library\n");
        exit(EXIT_FAILURE);
    }

    // Creazione della connessione al database
    res = sqlite3_open(argv[1], &db);

    if (res != SQLITE_OK) {
        fprintf(stderr, "Err. can't create database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        exit(EXIT_FAILURE);
    }

    printf("Library \'%s\' successfully initialized..\n", sqlite3_libversion());
    printf("Database \'%s\' successfully created.\n", argv[1]);

    // Close database connection
    if (sqlite3_close(db) == SQLITE_OK)
        puts("Closed database connection");

    sqlite3_shutdown();

    return(EXIT_SUCCESS);
}
예제 #13
0
파일: main.cpp 프로젝트: Pastor/videotools
int WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    HWND                    hMainWnd;
    MSG                     msg;

    sqlite3_initialize();
    gLogger = new Logger("tagsconverter.log");
    gProp = new Properties();
    gProp->load("settings.properties");
    gLogger->printf(TEXT("Запуск"));
    InitCommonControls();
    CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
    hMainWnd = CreateDialogParam(hInstance, TEXT("MAINDIALOG"), nullptr, MainDialog, reinterpret_cast<LPARAM>(hInstance));
    ShowWindow(hMainWnd, SW_SHOW);
    is_running = true;
    do {
        if (PeekMessage(&msg, hMainWnd, 0, 0, PM_REMOVE)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    } while (msg.message != WM_QUIT && is_running);
    DestroyWindow(hMainWnd);
    gProp->save("settings.properties");
    delete gProp;
    gLogger->printf(TEXT("Остановка"));
    delete gLogger;
    return EXIT_SUCCESS;
}
예제 #14
0
파일: sqlite.c 프로젝트: aosm/subversion
/* 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;
}
예제 #15
0
파일: ev_record.c 프로젝트: kadoma/fms
// open db and create tables.
int ras_event_opendb()
{
	int rc;
	sqlite3 *db;

	printf("Calling %s()\n", __FUNCTION__);

	priv = calloc(1, sizeof(*priv));
	if (!priv)
		return -1;
    
	rc = sqlite3_initialize();
	if (rc != SQLITE_OK) {
		wr_log("", WR_LOG_ERROR,
		    "cpu: Failed to initialize sqlite: error = %d\n",
		     rc);
		return -1;
	}

	do {
		rc = sqlite3_open_v2(SQLITE_RAS_DB, &db,
				     SQLITE_OPEN_FULLMUTEX |
				     SQLITE_OPEN_READWRITE |
				     SQLITE_OPEN_CREATE, NULL);
		if (rc == SQLITE_BUSY)
			usleep(10000);
	} while (rc == SQLITE_BUSY);

	priv->db = db;
    
	if (rc != SQLITE_OK) {
		wr_log("", WR_LOG_ERROR,
		    "cpu: Failed to connect to %s: error = %d\n",
		    SQLITE_RAS_DB, rc);
		return -1;
	}
    
	rc = rasdb_create_table(&cpu_event_tab);
	if (rc == SQLITE_OK)
		rc = ras_prepare_stmt(&priv->stmt_cpu_event, &cpu_event_tab);

	rc = rasdb_create_table(&mem_event_tab);
	if (rc == SQLITE_OK)
		rc = ras_prepare_stmt(&priv->stmt_mem_event, &mem_event_tab);

	rc = rasdb_create_table(&disk_event_tab);
	if (rc == SQLITE_OK)
		rc = ras_prepare_stmt(&priv->stmt_disk_event, &disk_event_tab);

    /* create repaired and not repaired events */
	rc = rasdb_create_table(&rep_record_tab);
	if (rc == SQLITE_OK)
		rc = ras_prepare_stmt(&priv->stmt_rep_record, &rep_record_tab);

	rc = rasdb_create_table(&norep_record_tab);
	if (rc == SQLITE_OK)
		rc = ras_prepare_stmt(&priv->stmt_norep_record, &norep_record_tab);

	return 0;
}
예제 #16
0
파일: Utility.cpp 프로젝트: HanWenfang/poco
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;
}
예제 #17
0
TeSQLite::TeSQLite() 
: TeDatabase()
, _conn(0)
, _transactionCounter(0)
{
	sqlite3_initialize();
	dbmsName_ = "SQLite";
}
예제 #18
0
파일: Sqlite+NNT.cpp 프로젝트: imace/nnt
void init()
{
    d_owner->readonly = true;
    d_owner->creatable = false;
    
    sqlite3_initialize();
    db = NULL;
    mtx = sqlite3_mutex_alloc(SQLITE_MUTEX_FAST);
}
예제 #19
0
파일: Database.cpp 프로젝트: noriter/nit
	Initializer()
	{
		int err = sqlite3_initialize();

		if (err)
		{
			NIT_THROW_FMT(EX_DATABASE, "can't initialize sqlite3: %d\n", err);
		}
	}
예제 #20
0
파일: sqldb.c 프로젝트: brong/cyrus-imapd
EXPORTED int sqldb_init(void)
{
    if (!sqldb_active++) {
        sqlite3_initialize();
        assert(!open_sqldbs);
    }

    return 0;
}
예제 #21
0
bool Cache::initSqlite() {
    int retVal = sqlite3_initialize();
    if(SQLITE_OK != retVal) {
        std::cerr << "Can't initialize sqlite3: " << sqlite3_errstr(retVal) << std::endl;
        return false;
    }

    return true;
}
예제 #22
0
DBManager::DBManager(std::string name):
    database(NULL)
{
   int ret = 0;
    // initialize engine
   if (SQLITE_OK != (ret = sqlite3_initialize())) {
       std::cout << "Failed to initialize library: " << ret;
   }
}
SWIGEXPORT jint JNICALL Java_com_almworks_sqlite4java__1SQLiteSwiggedJNI_sqlite3_1initialize(JNIEnv *jenv, jclass jcls) {
  jint jresult = 0 ;
  int result;
  
  (void)jenv;
  (void)jcls;
  result = (int)sqlite3_initialize();
  jresult = (jint)result; 
  return jresult;
}
예제 #24
0
파일: pkgdb_repo.c 프로젝트: jillest/pkg
int
pkgdb_repo_open(const char *repodb, bool force, sqlite3 **sqlite,
	bool *incremental)
{
	bool db_not_open;
	int reposcver;
	int retcode = EPKG_OK;

	if (access(repodb, R_OK) == 0)
		*incremental = true;
	else
		*incremental = false;

	sqlite3_initialize();
	db_not_open = true;
	while (db_not_open) {
		if (sqlite3_open(repodb, sqlite) != SQLITE_OK) {
			sqlite3_shutdown();
			return (EPKG_FATAL);
		}

		db_not_open = false;

		/* If the schema is too old, or we're forcing a full
			   update, then we cannot do an incremental update.
			   Delete the existing repo, and promote this to a
			   full update */
		if (!*incremental)
			continue;
		retcode = get_repo_user_version(*sqlite, "main", &reposcver);
		if (retcode != EPKG_OK)
			return (EPKG_FATAL);
		if (force || reposcver != REPO_SCHEMA_VERSION) {
			if (reposcver != REPO_SCHEMA_VERSION)
				pkg_emit_error("re-creating repo to upgrade schema version "
						"from %d to %d", reposcver,
						REPO_SCHEMA_VERSION);
			sqlite3_close(*sqlite);
			unlink(repodb);
			*incremental = false;
			db_not_open = true;
		}
	}

	sqlite3_create_function(*sqlite, "file_exists", 2, SQLITE_ANY, NULL,
	    file_exists, NULL, NULL);

	if (!*incremental) {
		retcode = sql_exec(*sqlite, initsql, REPO_SCHEMA_VERSION);
		if (retcode != EPKG_OK)
			return (retcode);
	}

	return (EPKG_OK);
}
예제 #25
0
파일: core.c 프로젝트: AmericoBalboa/core
static void hb_sqlt3dd_init( void * cargo )
{
   HB_SYMBOL_UNUSED( cargo );

#if SQLITE_VERSION_NUMBER >= 3006000
   sqlite3_initialize();
#endif

   if( ! hb_sddRegister( &s_sqlt3dd ) )
      hb_errInternal( HB_EI_RDDINVALID, NULL, NULL, NULL );
}
예제 #26
0
static bool component_avail(void)
{
    /* initialize sqlite3 */
    if (SQLITE_OK != sqlite3_initialize()) {
        return false;
    }
    /* check if sqlite was built thread-safe - if not, we won't
     * use worker threads for thruput
     */
    thread_safe = sqlite3_threadsafe();

    return true;
}
예제 #27
0
파일: sqlite3.c 프로젝트: ljx0305/tbox
/* //////////////////////////////////////////////////////////////////////////////////////
 * library implementation
 */
static tb_handle_t tb_database_sqlite3_library_init(tb_cpointer_t* ppriv)
{
    // init it
    tb_int_t ok = SQLITE_OK;
    if ((ok = sqlite3_initialize()) != SQLITE_OK)
    {
        // trace
        tb_trace_e("init: sqlite3 library failed, error: %d", ok);
        return tb_null;
    }

    // ok
    return ppriv;
}
예제 #28
0
FskErr KprDBNew(KprDB* it, char* path, Boolean rw)
{
	FskErr err = kFskErrNone;
	KprDB self = NULL;
	if (!gDBCount)
		bailIfError(sqlite3_initialize());
	bailIfError(KprMemPtrNewClear(sizeof(KprDBRecord), it));
	self = *it;
	FskInstrumentedItemNew(self, NULL, &KprDBInstrumentation);
	bailIfError(sqlite3_open_v2(path, &self->data, rw ? SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE : SQLITE_OPEN_READONLY, NULL));
	gDBCount++;
bail:
	return err;
}
예제 #29
0
int main(int argc, char* argv[])
{
  argc -= handleOpts(argc, argv);
  if (argc < 2){
    fprintf(stderr, usage, argv[0]);
    exit(1);
  }
  optClientno = atoi(argv[optind+1]);

  ConfigParser cp(argv[optind]);
  cp.Parse();
  bool load_complete = false;
  for (auto& section : cp._section_names){
    if (section.find("Workload") != std::string::npos){
      std::string workload = section;

      Config cfg(&cp, workload);
      // SYSTEM-SPECIFIC
      std::string system_conf = cfg.get<std::string>("yesql", "");

      std::string dir = cfg.get<std::string>("logdir", ".");
      LOG("Got %s as logdir", dir.c_str());
      if (dir.back() != '/')
        dir.append("/");
      dir.append("client-");
      dir.append(std::to_string(optClientno));
      dir.append("-");
      dir.append(workload);
      dir.append(".txt");
      LOG("Setting log as %s\n", dir.c_str());
      SetLog(dir.c_str());
      LOG("About to initialize\n");
      if (!load_complete){
        sqlite3_initialize();
// FIXME        SetDebugLevel(0);
      } else {
// FIXME        SetDebugLevel(0);
      }
      int nthreads = cfg.get<int>("threads", 1);
      bool do_load = false;
      if (!load_complete)
        do_load = cfg.get<bool>("load", true);
      LOG("About to do a yesql experiment with %d threads\n", nthreads);
      do_experiment(nthreads, system_conf.c_str(), &cfg, do_load);
      load_complete = true;
    }
  }
  return 0;
}
예제 #30
0
/*
** Reset the automatic extension loading mechanism.
*/
void sqlite3_reset_auto_extension(void){
#ifndef SQLITE_OMIT_AUTOINIT
  if( sqlite3_initialize()==SQLITE_OK )
#endif
  {
#ifndef SQLITE_MUTEX_NOOP
    sqlite3_mutex *mutex = sqlite3MutexAlloc(SQLITE_MUTEX_STATIC_MASTER);
#endif
    sqlite3_mutex_enter(mutex);
    sqlite3_free(autoext.aExt);
    autoext.aExt = 0;
    autoext.nExt = 0;
    sqlite3_mutex_leave(mutex);
  }
}