Пример #1
0
void CppSQLite3DB::open(const char* szFile)
{
	//----------------------------------------------        
	//modified by robet.li
	int nRet = sqlite3_open(szFile, &mpDB);
	if(HasChineseChar(szFile))
	{
		char szFileNameUtf8[MAX_PATH*4] = {0};
		_bstr_t bstrFileName = szFile;
		AtlUnicodeToUTF8(bstrFileName,bstrFileName.length(),szFileNameUtf8,sizeof(szFileNameUtf8));
		nRet = sqlite3_open(szFileNameUtf8, &mpDB);
	}
	else
	{
		nRet = sqlite3_open(szFile, &mpDB);
	}


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


	setBusyTimeout(mnBusyTimeoutMs);
}
Пример #2
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);
}
Пример #3
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();
}
Пример #4
0
void CppSQLite3DB::open(const char* szFile)
{
	int nRet = sqlite3_open(szFile, &mpDB);
	if (nRet != SQLITE_OK)
	{
		const char* szError = sqlite3_errmsg(mpDB);
		throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
	}
	setBusyTimeout(mnBusyTimeoutMs);
}
Пример #5
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);
}
Пример #6
0
void CSQLite3Link::open(CDBUrl &objDBUrl)
{
    int iRtn =  0;

    iRtn = sqlite3_open(objDBUrl.getDB().c_str(), &m_pDB);
    if (iRtn != SQLITE_OK)
    {
        Q_EXCEPTION(sqlite3_errcode(m_pDB), "%s", sqlite3_errmsg(m_pDB));
    }

    setBusyTimeout(m_iBusyTimeoutMs);
}
Пример #7
0
void CppSQLite3DB::open(const char* szFile)
{
	int nRet = sqlite3_open(szFile, &mpDB);

	if (nRet != SQLITE_OK)
	{
		const char* szError = sqlite3_errmsg(mpDB);

		IwError((szError));
	}

	setBusyTimeout(mnBusyTimeoutMs);
}
Пример #8
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

}
Пример #9
0
SqlDatabase::SqlDatabase(const char* szFile, bool useExclusiveWAL /* = true */) {
	mpDB = 0;
	mnBusyTimeoutMs = 60000; // 60 seconds
	assert(sqlite3_libversion_number()==SQLITE_VERSION_NUMBER);

	if (sqlite3_open(szFile, &mpDB) != SQLITE_OK)
		throw SqlDatabaseException("Unable to open/create database file.");
	setBusyTimeout(mnBusyTimeoutMs);
	if (useExclusiveWAL) {
		// Set the database to use Write-Ahead Logging and the EXCLUSIVE locking mode
		// for performance improvements:
		sqlExecute("PRAGMA locking_mode = EXCLUSIVE; PRAGMA journal_mode=WAL;");
	}
}
Пример #10
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);
}
Пример #11
0
void CppSQLite3DB::open(const char* szFile)
{
	int nRet = sqlite3_open(szFile, &mpDB);

	if (nRet != SQLITE_OK)
	{
		const char* szError = sqlite3_errmsg(mpDB);
		throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);
	}
    
    //Load extension library.
    sqlite3_enable_load_extension(mpDB,1);
    sqlite3_load_extension(mpDB,getFullPath(extension_library_filename).c_str(),0,0);

	setBusyTimeout(mnBusyTimeoutMs);
}
Пример #12
0
void CppSQLite3DB::open(const char* szFile)
{
    wchar_t wcFilename[512];
    char *utf;    int len;  
	// convert to utf to allow for chinese characters    
	MultiByteToWideChar(CP_ACP, 0, szFile, strlen(szFile)+1, wcFilename,  512);	    
	utf = new char[wcslen(wcFilename)*3+1];    
	len = WideCharToMultiByte(CP_UTF8, 0, wcFilename, wcslen(wcFilename),utf,wcslen(wcFilename)*3,0,NULL);    
	utf[len] = '\0';    
	int nRet = sqlite3_open(utf, &mpDB);    
	delete[] utf;
	
	if (nRet != SQLITE_OK) {        
		const char* szError = sqlite3_errmsg(mpDB);        
		throw CppSQLite3Exception(nRet, (char*)szError, DONT_DELETE_MSG);    
	}    
	setBusyTimeout(mnBusyTimeoutMs);    
}
Пример #13
0
// Open the provided database UTF-8 filename with SQLITE_OPEN_xxx provided flags.
Database::Database ( const char* apFilename,
                     const int   aFlags         /* = SQLITE_OPEN_READONLY*/,
                     const int   aBusyTimeoutMs /* = 0 */,
                     const char* apVfs          /* = NULL*/ ) :
    mpSQLite ( NULL ),
    mFilename ( apFilename )
{
    const int ret = sqlite3_open_v2 ( apFilename, &mpSQLite, aFlags, apVfs );
    if ( SQLITE_OK != ret ) {
        const SQLite::Exception exception ( mpSQLite, ret ); // must create before closing
        sqlite3_close ( mpSQLite ); // close is required even in case of error on opening
        throw exception;
    }

    if ( aBusyTimeoutMs > 0 ) {
        setBusyTimeout ( aBusyTimeoutMs );
    }
}
Пример #14
0
// Open the provided database UTF-8 filename with SQLITE_OPEN_xxx provided flags.
Database::Database ( const std::string& aFilename,
                     const int          aFlags         /* = SQLITE_OPEN_READONLY*/,
                     const int          aBusyTimeoutMs /* = 0 */,
                     const std::string& aVfs           /* = "" */ ) :
    mpSQLite ( NULL ),
    mFilename ( aFilename )
{
    const int ret = sqlite3_open_v2 ( aFilename.c_str(), &mpSQLite, aFlags, aVfs.empty() ? NULL : aVfs.c_str() );
    if ( SQLITE_OK != ret ) {
        const SQLite::Exception exception ( mpSQLite, ret ); // must create before closing
        sqlite3_close ( mpSQLite ); // close is required even in case of error on opening
        throw exception;
    }

    if ( aBusyTimeoutMs > 0 ) {
        setBusyTimeout ( aBusyTimeoutMs );
    }
}
Пример #15
0
// Open the provided database UTF-8 filename with SQLITE_OPEN_xxx provided flags.
Database::Database(const char* apFilename,
                   const int   aFlags         /* = SQLITE_OPEN_READONLY*/,
                   const int   aBusyTimeoutMs /* = 0 */,
                   const char* apVfs          /* = NULL*/) :
    mpSQLite(NULL),
    mFilename(apFilename)
{
    const int ret = sqlite3_open_v2(apFilename, &mpSQLite, aFlags, apVfs);
    if (SQLITE_OK != ret)
    {
        std::string strerr = sqlite3_errmsg(mpSQLite);
        sqlite3_close(mpSQLite); // close is required even in case of error on opening
        throw SQLite::Exception(strerr);
    }

    if (aBusyTimeoutMs > 0)
    {
        setBusyTimeout(aBusyTimeoutMs);
    }
}
Пример #16
0
void CppSQLite3DB::open(const char* szFile)
{
	char *pPath;   
	WCHAR *wcPath;   
	wcPath = mbcsToUnicode(szFile);   
	pPath = unicodeToUtf8(wcPath);  

	int nRet = sqlite3_open(pPath, &mpDB);
	
	free(wcPath);
	free(pPath);

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

	setBusyTimeout(mnBusyTimeoutMs);
}
Пример #17
0
void CppSQLite3DB::open(const char* szFile)
{
#ifdef WIN32
    string pathStr = CConverter::G2U(szFile);
    const char* pPath = pathStr.c_str();
    int nRet = sqlite3_open(pPath, &mpDB);
#else
    int nRet = sqlite3_open(szFile, &mpDB);
#endif



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

    setBusyTimeout(mnBusyTimeoutMs);

}