Esempio n. 1
0
void CppSQLite3DB::open(LPCTSTR szFile)
{
    int nRet;

#if defined(_UNICODE) || defined(UNICODE)

	nRet = sqlite3_open16(szFile, &mpDB); // not tested under window 98 

#else // For Ansi Version
//*************-  Added by Begemot  szFile must be in unicode- 23/03/06 11:04 - ****
    OSVERSIONINFOEX osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    GetVersionEx ((OSVERSIONINFO *) &osvi);
   
	if ( osvi.dwMajorVersion == 5) 
    {
          WCHAR pMultiByteStr[MAX_PATH+1];
          MultiByteToWideChar( CP_ACP, 0, szFile,
		                    _tcslen(szFile)+1, pMultiByteStr,   
			                sizeof(pMultiByteStr)/sizeof(pMultiByteStr[0]) );
          nRet = sqlite3_open16(pMultiByteStr, &mpDB);
    }
    else
          nRet = sqlite3_open(szFile,&mpDB);
#endif
//*************************
	if (nRet != SQLITE_OK)
	{
		LPCTSTR szError = (LPCTSTR) _sqlite3_errmsg(mpDB);
		throw CppSQLite3Exception(nRet, (LPTSTR)szError, DONT_DELETE_MSG);
	}
	setBusyTimeout(mnBusyTimeoutMs);
}
Esempio n. 2
0
void CppSQLite3DB::open(LPCTSTR szFile)
{
    int nRet;

#ifndef IN_MEMORY_DB

#if defined(_UNICODE) || defined(UNICODE)

	nRet = sqlite3_open16(szFile, &mpDB); // not tested under window 98 

#else // For Ansi Version
//*************-  Added by Begemot  szFile must be in unicode- 23/03/06 11:04 - ****
    OSVERSIONINFOEX osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    GetVersionEx ((OSVERSIONINFO *) &osvi);
   
	if ( osvi.dwMajorVersion == 5) 
    {
          WCHAR pMultiByteStr[MAX_PATH+1];
          MultiByteToWideChar( CP_ACP, 0, szFile,
		                    _tcslen(szFile)+1, pMultiByteStr,   
			                sizeof(pMultiByteStr)/sizeof(pMultiByteStr[0]) );
          nRet = sqlite3_open16(pMultiByteStr, &mpDB);
    }
    else
          nRet = sqlite3_open(szFile,&mpDB);
#endif
//*************************
	if (nRet != SQLITE_OK)
	{
		LPCTSTR szError = (LPCTSTR) _sqlite3_errmsg(mpDB);
		throw CppSQLite3Exception(nRet, (LPTSTR)szError, DONT_DELETE_MSG);
	}

#else
	nRet = sqlite3_open16(":memory:", &mpDB);
	if (nRet != SQLITE_OK)
	{
		LPCTSTR szError = (LPCTSTR) _sqlite3_errmsg(mpDB);
		throw CppSQLite3Exception(nRet, (LPTSTR)szError, DONT_DELETE_MSG);
	}

	// Attach the backup to the in memory
    nRet = sqlite3_exec(mpDB, "ATTACH DATABASE 'H:\\Users\\tomy\\AppData\\Roaming\\Benubird\\Benubird.db' as Benubird", 
            NULL, NULL, NULL);
	if (nRet != SQLITE_OK)
	{
		LPCTSTR szError = (LPCTSTR) _sqlite3_errmsg(mpDB);
		throw CppSQLite3Exception(nRet, (LPTSTR)szError, DONT_DELETE_MSG);
	}

#endif
	setBusyTimeout(mnBusyTimeoutMs);

	//int lsave = sqlite3_threadsafe();
}
Esempio n. 3
0
/* call-seq: SQLite3::Database.new(file, options = {})
 *
 * Create a new Database object that opens the given file. If utf16
 * is +true+, the filename is interpreted as a UTF-16 encoded string.
 *
 * By default, the new database will return result rows as arrays
 * (#results_as_hash) and has type translation disabled (#type_translation=).
 */
static VALUE initialize(int argc, VALUE *argv, VALUE self)
{
  sqlite3RubyPtr ctx;
  VALUE file;
  VALUE opts;
  VALUE zvfs;
  int status;

  Data_Get_Struct(self, sqlite3Ruby, ctx);

  rb_scan_args(argc, argv, "12", &file, &opts, &zvfs);
  if(NIL_P(opts)) opts = rb_hash_new();

#ifdef HAVE_RUBY_ENCODING_H
  if(UTF16_LE_P(file)) {
    status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db);
  } else {
#endif

    if(Qtrue == rb_hash_aref(opts, sym_utf16)) {
      status = sqlite3_open16(utf16_string_value_ptr(file), &ctx->db);
    } else {

#ifdef HAVE_RUBY_ENCODING_H
      if(!UTF8_P(file)) {
        file = rb_str_export_to_enc(file, rb_utf8_encoding());
      }
#endif

      status = sqlite3_open_v2(
          StringValuePtr(file),
          &ctx->db,
          SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE,
          NIL_P(zvfs) ? NULL : StringValuePtr(zvfs)
      );
    }

#ifdef HAVE_RUBY_ENCODING_H
  }
#endif

  CHECK(ctx->db, status)

  rb_iv_set(self, "@tracefunc", Qnil);
  rb_iv_set(self, "@authorizer", Qnil);
  rb_iv_set(self, "@encoding", Qnil);
  rb_iv_set(self, "@busy_handler", Qnil);
  rb_iv_set(self, "@results_as_hash", rb_hash_aref(opts, sym_results_as_hash));
  rb_iv_set(self, "@type_translation", rb_hash_aref(opts, sym_type_translation));

  if(rb_block_given_p()) {
    rb_yield(self);
    rb_funcall(self, rb_intern("close"), 0);
  }

  return self;
}
Esempio n. 4
0
__declspec(dllexport) int WINAPI sqlite3_open16_interop(const void *filename, sqlite3 **ppdb)
{
  int ret = sqlite3_open16(filename, ppdb);
  if (ret == SQLITE_OK) InitializeDbMutex(*ppdb);

  return ret;
}
Esempio n. 5
0
static int _linphone_sqlite3_open(const char *db_file, sqlite3 **db) {
#if defined(ANDROID) || defined(__QNXNTO__)
	return sqlite3_open(db_file, db);
#elif defined(_WIN32)
	int ret;
	wchar_t db_file_utf16[MAX_PATH_SIZE];
	ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, db_file, -1, db_file_utf16, MAX_PATH_SIZE);
	if(ret == 0) db_file_utf16[0] = '\0';
	return sqlite3_open16(db_file_utf16, db);
#else
	char db_file_locale[MAX_PATH_SIZE] = {'\0'};
	char db_file_utf8[MAX_PATH_SIZE] = "";
	char *inbuf=db_file_locale, *outbuf=db_file_utf8;
	size_t inbyteleft = MAX_PATH_SIZE, outbyteleft = MAX_PATH_SIZE;
	iconv_t cb;

	strncpy(db_file_locale, db_file, MAX_PATH_SIZE-1);
	cb = iconv_open("UTF-8", nl_langinfo(CODESET));
	if(cb != (iconv_t)-1) {
		int ret;
		ret = iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft);
		if(ret == -1) db_file_utf8[0] = '\0';
		iconv_close(cb);
	}
	return sqlite3_open(db_file_utf8, db);
#endif
}
Esempio n. 6
0
/* 函数功能:打开数据库
* 参数说明:pszPath 待打开的数据库文件路径,路径要求大于7个字节
* 返回说明:返回NULL表示失败。此时可使用format_err_sqlite函数得到错误文本信息
* 注意事项:如果没有对应的库文件,则产生一个新的数据库
* 使用举例:1.if (open_sqlite("test_sqlite.db") == NULL) 
* printf("sqlite open err(%s)", format_sqlite_err());
* */
sqlite3 * open_sqlite(const char * pszPath)
{
	static sqlite3 * pSqlite3;
	pSqlite3 = NULL;
	if (pszPath == NULL || strlen(pszPath) <= 7) 
	{
		printf("null or path < 7\n");
		return NULL;
	}
	if (sqlite3_open(pszPath, &pSqlite3) != SQLITE_OK) {
		/* 如果 UTF-8 格式的数据库名打开失败,则再传入UTF-16 格式的数据库名 */
		if (sqlite3_open16(pszPath, &pSqlite3) != SQLITE_OK) 
		{
			printf("bit-16 is fail\n");
			return NULL;
		}
		else 
		{
			printf("bit-16 is ok\n");
			return pSqlite3;
		}

	}
	printf("open is normal\n");	
	printf("pathway is %s\n",pszPath);	
	return pSqlite3;
}
Esempio n. 7
0
bool
O2DatDB::
reindex(const char *target)
{
#if TRACE_SQL_EXEC_TIME
	stopwatch sw("reindex");
#endif

	sqlite3 *db = NULL;
	int err = sqlite3_open16(dbfilename.c_str(), &db);
	if (err != SQLITE_OK)
		goto error;

	char sql[64];
	sprintf_s(sql, 64, "reindex %s;", target);

	err = sqlite3_exec(db, sql, NULL, 0, 0);
	if (err != SQLITE_OK)
		goto error;

	err = sqlite3_close(db);
	if (err != SQLITE_OK)
		goto error;
	return true;

error:
	log(db);
	if (db) sqlite3_close(db);
	return false;
}
Esempio n. 8
0
bool
O2DatDB::
select(O2DatRec &out, const wchar_t *domain, const wchar_t *bbsname, const wchar_t *datname)
{
#if TRACE_SQL_EXEC_TIME
	stopwatch sw("select by domain bbsname datname");
#endif

	bool ret = true;
	sqlite3 *db = NULL;
	int err = sqlite3_open16(dbfilename.c_str(), &db);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_busy_timeout(db, 5000);

	wchar_t *sql =
		L"select"
		COLUMNS
		L" from dat"
		L" where domain = ?"
		L"   and bbsname = ?"
		L"   and datname = ?;";

	sqlite3_stmt *stmt = NULL;
	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
	if (err != SQLITE_OK)
		goto error;

	if (!bind(db, stmt, 1, domain))
		goto error;
	if (!bind(db, stmt, 2, bbsname))
		goto error;
	if (!bind(db, stmt, 3, datname))
		goto error;

	err = sqlite3_step(stmt);
	if (err != SQLITE_ROW && err != SQLITE_DONE)
		goto error;

	if (err == SQLITE_DONE)
		ret = false;
	if (err == SQLITE_ROW)
		get_columns(stmt, out);

	sqlite3_finalize(stmt);
	stmt = NULL;

	err = sqlite3_close(db);
	if (err != SQLITE_OK)
		goto error;

	return (ret);

error:
	log(db);
	if (stmt) sqlite3_finalize(stmt);
	if (db) sqlite3_close(db);
	return false;
}
Esempio n. 9
0
SQLite::SQLite(const void* filename) {
  handle = 0;
  int ret;
  if ((ret = sqlite3_open16(filename, &handle)) != SQLITE_OK || !handle) {
	Close();
	throw ret;
  }
}
Esempio n. 10
0
static JSVAL sqlite_open16(JSARGS args) {
    HandleScope scope;
    String::Utf8Value filename(args[0]->ToString());
    sqlite3 *db;
    if (sqlite3_open16(*filename, &db)) {
        return scope.Close(String::New(sqlite3_errmsg(db)));
    }
    return scope.Close(External::New(db));
}
Esempio n. 11
0
size_t
O2DatDB::
select(const wchar_t *sql, SQLResultList &out)
{
#if TRACE_SQL_EXEC_TIME
	stopwatch sw("select");
#endif
	wstrarray cols;

	sqlite3 *db = NULL;
	int err = sqlite3_open16(dbfilename.c_str(), &db);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_busy_timeout(db, 5000);

	sqlite3_stmt *stmt = NULL;
	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_reset(stmt);

	err = sqlite3_step(stmt);
	if (err != SQLITE_ROW && err != SQLITE_DONE)
		goto error;

	if (out.empty()) {
		//一行目
		cols.clear();
		get_column_names(stmt, cols);
		out.push_back(cols);
		cols.clear();
		get_columns(stmt, cols);
		out.push_back(cols);
	}
	while (sqlite3_step(stmt) == SQLITE_ROW) {
		//2行目以降
		cols.clear();
		get_columns(stmt, cols);
		out.push_back(cols);
	}

	sqlite3_finalize(stmt);
	stmt = NULL;

	err = sqlite3_close(db);
	if (err != SQLITE_OK)
		goto error;

	return (out.size());

error:
	log(db);
	if (stmt) sqlite3_finalize(stmt);
	if (db) sqlite3_close(db);
	return (0);
}
void DoSecurityTest2()
	{
	//It should not be possible to operate with the database file directly. Only through the passed file handles.		
	sqlite3* db = NULL;
	
	TInt err = sqlite3_open16(KTestDbName2, &db);
	TEST2(err, SQLITE_CANTOPEN);
	
	sqlite3_close(db);
	}
Esempio n. 13
0
bool
O2DatDB::
select(O2DatRecList &out, time_t publish_tt, size_t limit)
{
#if TRACE_SQL_EXEC_TIME
	stopwatch sw("select lastpublish");
#endif

	sqlite3 *db = NULL;
	sqlite3_stmt *stmt = NULL;
	O2DatRec rec;

	int err = sqlite3_open16(dbfilename.c_str(), &db);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_busy_timeout(db, 5000);

	wchar_t *sql =
		L"select"
		COLUMNS
		L" from dat"
		L" where lastpublish < ?"
		L" order by lastpublish"
		L" limit ?;";

	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
	if (err != SQLITE_OK)
		goto error;

	if (!bind(db, stmt, 1, time(NULL)-publish_tt))
		goto error;
	if (!bind(db, stmt, 2, limit))
		goto error;

	while (sqlite3_step(stmt) == SQLITE_ROW) {
		get_columns(stmt, rec);
		out.push_back(rec);
	}

	sqlite3_finalize(stmt);
	stmt = NULL;

	err = sqlite3_close(db);
	if (err != SQLITE_OK)
		goto error;

	return true;

error:
	log(db);
	if (stmt) sqlite3_finalize(stmt);
	if (db) sqlite3_close(db);
	return false;
}
Esempio n. 14
0
extern "C" HANDLE __stdcall OpenDatabase(WCHAR * szDatabase)
{
    DbHandle * dbh = new DbHandle();
    dbh->szLastError = NULL;

    wcscpy_s(dbh->szDBName, szDatabase);

    sqlite3_open16(dbh->szDBName, &(dbh->db));

    return (HANDLE)dbh;
}
Esempio n. 15
0
bool
O2DatDB::
select(O2DatRecList &out, const wchar_t *domain, const wchar_t *bbsname)
{
#if TRACE_SQL_EXEC_TIME
	stopwatch sw("select domain bbsname order by datname");
#endif

	sqlite3 *db = NULL;
	sqlite3_stmt *stmt = NULL;
	O2DatRec rec;

	int err = sqlite3_open16(dbfilename.c_str(), &db);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_busy_timeout(db, 5000);

	wchar_t *sql =
		L"select"
		COLUMNS
		L" from dat"
		L" where domain = ?"
		L"   and bbsname = ?"
		L" order by datname;";

	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
	if (err != SQLITE_OK)
		goto error;

	if (!bind(db, stmt, 1, domain))
		goto error;
	if (!bind(db, stmt, 2, bbsname))
		goto error;

	while (sqlite3_step(stmt) == SQLITE_ROW) {
		get_columns(stmt, rec);
		out.push_back(rec);
	}

	sqlite3_finalize(stmt);
	stmt = NULL;

	err = sqlite3_close(db);
	if (err != SQLITE_OK)
		goto error;
	return true;

error:
	log(db);
	if (stmt) sqlite3_finalize(stmt);
	if (db) sqlite3_close(db);
	return false;
}
Esempio n. 16
0
/**
	connect : filename:string -> 'db
	<doc>Open or create the database stored in the specified file.</doc>
**/
HL_PRIM sqlite_database *HL_NAME(connect)( vbyte *filename ) {
	sqlite_database *db;
	sqlite3 *sqlite;
	if( sqlite3_open16(filename, &sqlite) != SQLITE_OK ) {
		HL_NAME(error)(sqlite, true);
	}
	db = (sqlite_database*)hl_gc_alloc_finalizer(sizeof(sqlite_database));
	db->finalize = HL_NAME(finalize_database);
	db->db = sqlite;
	db->last = NULL;
	return db;
}
Esempio n. 17
0
void CppSQLite3DB::open(const CString& strFile)
{
    int nRet = sqlite3_open16(strFile.utf16(), &mpDB);

	if (nRet != SQLITE_OK)
	{
		const char* szError = sqlite3_errmsg(mpDB);
        throw CppSQLite3Exception(nRet, szError);
	}

	setBusyTimeout(mnBusyTimeoutMs);
}
Esempio n. 18
0
int SQLiteFileSystem::openDatabase(const String& fileName, sqlite3** database, bool)
{
    // SQLite expects a null terminator on its UTF-16 strings.
    String path = fileName;

#if OS(BLACKBERRY)
    if (! Olympia::Platform::prepareEncryptedFile(path.ascii().data()))
        return -1;
    
#endif

    return sqlite3_open16(path.charactersWithNullTermination(), database);
}
Esempio n. 19
0
bool
O2DatDB::
select(O2DatRec &out)
{
#if TRACE_SQL_EXEC_TIME
	stopwatch sw("select random 1");
#endif

	bool ret = true;
	sqlite3 *db = NULL;
	int err = sqlite3_open16(dbfilename.c_str(), &db);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_busy_timeout(db, 5000);

	wchar_t *sql =
		L"select"
		COLUMNS
		L" from dat"
		L" order by random() limit 1;";

	sqlite3_stmt *stmt = NULL;
	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_reset(stmt);

	err = sqlite3_step(stmt);
	if (err != SQLITE_ROW && err != SQLITE_DONE)
		goto error;

	if (err == SQLITE_DONE)
		ret = false;
	if (err == SQLITE_ROW)
		get_columns(stmt, out);

	sqlite3_finalize(stmt);
	stmt = NULL;

	err = sqlite3_close(db);
	if (err != SQLITE_OK)
		goto error;

	return (ret);

error:
	log(db);
	if (stmt) sqlite3_finalize(stmt);
	if (db) sqlite3_close(db);
	return false;
}
Esempio n. 20
0
void CppSQLite3DB::open(tstring& szFile){
#ifdef _UNICODE
	int nRet = sqlite3_open16((void*)szFile.c_str(), &mpDB);    

	if (nRet != SQLITE_OK) {        
		const char* szError = sqlite3_errmsg(mpDB);        
		throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);    
	}    
	setBusyTimeout(mnBusyTimeoutMs);    
#else
	open(szFile.c_str());
#endif

}
Esempio n. 21
0
uint64
O2DatDB::
select_datcount(wstrnummap &out)
{
#if TRACE_SQL_EXEC_TIME
	stopwatch sw("select datcount group by domain bbsname");
#endif

	sqlite3 *db = NULL;
	sqlite3_stmt *stmt = NULL;
	wstring domain_bbsname;
	uint64 total = 0;
	uint64 num;

	int err = sqlite3_open16(dbfilename.c_str(), &db);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_busy_timeout(db, 5000);

	wchar_t *sql =
		L"select domain, bbsname, count(*) from dat group by domain, bbsname;";

	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
	if (err != SQLITE_OK)
		goto error;

	while (sqlite3_step(stmt) == SQLITE_ROW) {
		domain_bbsname = (wchar_t*)sqlite3_column_text16(stmt, 0);
		domain_bbsname += L":";
		domain_bbsname += (wchar_t*)sqlite3_column_text16(stmt, 1);
		num = sqlite3_column_int64(stmt, 2);

		out.insert(wstrnummap::value_type(domain_bbsname, num));
		total += num;
	}

	sqlite3_finalize(stmt);
	stmt = NULL;

	err = sqlite3_close(db);
	if (err != SQLITE_OK)
		goto error;
	return (total);

error:
	log(db);
	if (stmt) sqlite3_finalize(stmt);
	if (db) sqlite3_close(db);
	return false;
}
	void sqlite3_connection::open(const wchar_t *db) {
		if(sqlite3_open16(db, &this->m_db)!=SQLITE_OK)
			throw database_error("unable to open database");
		try
		{
			this->on_open();
		}
		catch(...)
		{
			try { this->close(); }
			catch(...) { /* ignore */ }
			throw;
		}
	}
Esempio n. 23
0
/*
* Class:     com_sabo_sqlite_SQLiteDatabase
* Method:    nativeOpen
* Signature: (Ljava/lang/String;)J
*/
JNIEXPORT jlong JNICALL Java_com_sabo_sqlite_SQLiteDatabase_nativeOpen
(JNIEnv *env, jobject clazz, jstring path) {
	const jchar *zPath;
	sqlite3 *pDb;
	int rc;

	zPath = env->GetStringCritical(path, NULL);
	assert(zPath != NULL);
	rc = sqlite3_open16(zPath, &pDb);
	env->ReleaseStringCritical(path, zPath);
	if (rc != SQLITE_OK || pDb == NULL) return (jlong)0;

	return (jlong)pDb;
}
Esempio n. 24
0
bool DBBrowserDB::create ( const QString & db)
{
    bool ok=false;

    if (isOpen()) close();

    lastErrorMessage = QObject::tr("no error");

    // read encoding from settings and open with sqlite3_open for utf8
    // and sqlite3_open16 for utf16
    QSettings settings(QApplication::organizationName(), QApplication::organizationName());
    QString sEncoding = settings.value("/db/defaultencoding", "UTF-8").toString();

    int openresult = SQLITE_OK;

    if(sEncoding == "UTF-8" || sEncoding == "UTF8" || sEncoding == "Latin1")
        openresult = sqlite3_open(db.toUtf8(), &_db);
    else
        openresult = sqlite3_open16(db.utf16(), &_db);

    if( openresult != SQLITE_OK ){
        lastErrorMessage = QString::fromUtf8((const char*)sqlite3_errmsg(_db));
        sqlite3_close(_db);
        _db = 0;
        return false;
    }

    if (_db){
        if (SQLITE_OK==sqlite3_exec(_db,"PRAGMA empty_result_callbacks = ON;",
                                    NULL,NULL,NULL)){
            if (SQLITE_OK==sqlite3_exec(_db,"PRAGMA show_datatypes = ON;",
                                        NULL,NULL,NULL)){
                ok=true;
            }
            curDBFilename = db;
        }

        // Enable extension loading
        sqlite3_enable_load_extension(_db, 1);

        // force sqlite3 do write proper file header
        // if we don't create and drop the table we might end up
        // with a 0 byte file, if the user cancels the create table dialog
        sqlite3_exec(_db, "CREATE TABLE notempty (id integer primary key);", NULL, NULL, NULL);
        sqlite3_exec(_db, "DROP TABLE notempty", NULL, NULL, NULL);
        sqlite3_exec(_db, "COMMIT;", NULL, NULL, NULL);
    }

    return ok;
}
Esempio n. 25
0
		SPtr<sqlite_db>			sqlite_db::open(const wstring& filepath)
		{
			sqlite3* handle=NULL;
			sqlite3_open16(filepath.c_str(),&handle);
			if(!handle)
				return NULL;
			sqlite_db* db=new sqlite_db();
			db->_filepath=filepath;
			db->_handle=handle;

			db->query(L"pragma cache_size = 4096; pragma count_changes = 0; pragma temp_store = memory;");

			return db;
		}
Esempio n. 26
0
int _linphone_sqlite3_open(const char *db_file, sqlite3 **db) {
	char* errmsg = NULL;
	int ret;
#if defined(ANDROID) || defined(__QNXNTO__)
	ret = sqlite3_open(db_file, db);
#elif TARGET_OS_IPHONE
	/* the secured filesystem of the iPHone doesn't allow writing while the app is in background mode, which is problematic.
	 * We workaround by asking that the open is made with no protection*/
	ret = sqlite3_open_v2(db_file, db, SQLITE_OPEN_FILEPROTECTION_NONE|SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, NULL);
#elif defined(_WIN32)
	wchar_t db_file_utf16[MAX_PATH_SIZE];
	ret = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, db_file, -1, db_file_utf16, MAX_PATH_SIZE);
	if(ret == 0) db_file_utf16[0] = '\0';
	ret = sqlite3_open16(db_file_utf16, db);
#else
	char db_file_locale[MAX_PATH_SIZE] = {'\0'};
	char db_file_utf8[MAX_PATH_SIZE] = "";
	char *inbuf=db_file_locale, *outbuf=db_file_utf8;
	size_t inbyteleft = MAX_PATH_SIZE, outbyteleft = MAX_PATH_SIZE;
	iconv_t cb;

	strncpy(db_file_locale, db_file, MAX_PATH_SIZE-1);
	cb = iconv_open("UTF-8", nl_langinfo(CODESET));
	if(cb != (iconv_t)-1) {
		int ret;
		ret = iconv(cb, &inbuf, &inbyteleft, &outbuf, &outbyteleft);
		if(ret == -1) db_file_utf8[0] = '\0';
		iconv_close(cb);
	}
	ret = sqlite3_open(db_file_utf8, db);
#endif
	if (ret != SQLITE_OK) return ret;
	// Some platforms do not provide a way to create temporary files which are needed
	// for transactions... so we work in memory only
	// see http ://www.sqlite.org/compile.html#temp_store
	ret = sqlite3_exec(*db, "PRAGMA temp_store=MEMORY", NULL, NULL, &errmsg);
	if (ret != SQLITE_OK) {
		ms_error("Cannot set sqlite3 temporary store to memory: %s.", errmsg);
		sqlite3_free(errmsg);
	}
#if TARGET_OS_IPHONE
	ret = sqlite3_exec(*db, "PRAGMA journal_mode = OFF", NULL, NULL, &errmsg);
	if (ret != SQLITE_OK) {
		ms_error("Cannot set sqlite3 journal_mode to off: %s.", errmsg);
		sqlite3_free(errmsg);
	}
#endif
	return ret;
}
Esempio n. 27
0
void CppSQLite3DB::open(const TCHAR* szFile)
{
#ifdef _UNICODE
	int nRet = sqlite3_open16(szFile, &mpDB);
#else
	int nRet = sqlite3_open(szFile, &mpDB);
#endif

	if (nRet != SQLITE_OK)
	{
		SQLITE3_ERRMSG(mpDB);
		throw CppSQLite3Exception(nRet, (TCHAR*)szError, DONT_DELETE_MSG);
	}

	setBusyTimeout(mnBusyTimeoutMs);
}
Esempio n. 28
0
BOOL SQLite::Open(LPCTSTR lpDbFlie)
{
	if (lpDbFlie == NULL)
	{
		return FALSE;
	}
#ifdef  UNICODE 
	if (sqlite3_open16(lpDbFlie, &m_db) != SQLITE_OK)
#else
	if (sqlite3_open(lpDbFlie, &m_db) != SQLITE_OK)
#endif
	{
		return FALSE;
	}
	return TRUE;
}
Esempio n. 29
0
uint64
O2DatDB::
select_publishcount(time_t publish_tt)
{
#if TRACE_SQL_EXEC_TIME
	stopwatch sw("select datcount by lastpublish");
#endif

	sqlite3 *db = NULL;
	sqlite3_stmt *stmt = NULL;

	int err = sqlite3_open16(dbfilename.c_str(), &db);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_busy_timeout(db, 5000);

	wchar_t *sql = L"select count(*) from dat where lastpublish > ?;";

	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
	if (err != SQLITE_OK)
		goto error;

	if (!bind(db, stmt, 1, time(NULL)-publish_tt))
		goto error;

	err = sqlite3_step(stmt);
	if (err != SQLITE_ROW && err != SQLITE_DONE)
		goto error;

	uint64 count = sqlite3_column_int64(stmt,0);

	sqlite3_finalize(stmt);
	stmt = NULL;

	err = sqlite3_close(db);
	if (err != SQLITE_OK)
		goto error;

	return (count);

error:
	log(db);
	if (stmt) sqlite3_finalize(stmt);
	if (db) sqlite3_close(db);
	return (0);
}
Esempio n. 30
0
bool
O2DatDB::
select(O2DatRecList &out)
{
#if TRACE_SQL_EXEC_TIME
	stopwatch sw("select all");
#endif

	sqlite3 *db = NULL;
	sqlite3_stmt *stmt = NULL;
	O2DatRec rec;

	int err = sqlite3_open16(dbfilename.c_str(), &db);
	if (err != SQLITE_OK)
		goto error;
	sqlite3_busy_timeout(db, 5000);

	wchar_t *sql =
		L"select"
		COLUMNS
		L" from dat;";

	err = sqlite3_prepare16_v2(db, sql, wcslen(sql)*2, &stmt, NULL);
	if (err != SQLITE_OK)
		goto error;

	while (sqlite3_step(stmt) == SQLITE_ROW) {
		get_columns(stmt, rec);
		out.push_back(rec);
	}

	sqlite3_finalize(stmt);
	stmt = NULL;

	err = sqlite3_close(db);
	if (err != SQLITE_OK)
		goto error;
	return true;

error:
	log(db);
	if (stmt) sqlite3_finalize(stmt);
	if (db) sqlite3_close(db);
	return false;
}