Example #1
0
void CVoxSQLite::InsertMergedContact( const char* strContactUsername, const char* strUsername )
{
	//TODO: compile as a member var?
	std::string	strSql = "INSERT INTO [MergedContact] "
						 "( [parent_username], [username] ) "
						 "VALUES( ?, ? ); ";

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( strSql.c_str() );

		stmt.bind( 1, strContactUsername );
		stmt.bind( 2, strUsername );

		stmt.execDML();		//We expect a return value == 1 (Number of rows changed);
		stmt.reset();

		int nId = (int)m_db.lastRowId();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #2
0
void CVoxSQLite::GetGroups( const char* username, Groups& rList )
{
	CppSQLite3Buffer buf;
	buf.format( "SELECT * from [Group] WHERE [username] = %Q;", username );

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf );

		int				nContactId	= 0;
		std::string		type		= "";
		CppSQLite3Query q			= stmt.execQuery();
		Group			grp;

		//Process record set.
        while (!q.eof())
        {
			grp.setUsername( q.getStringField( 0 ) );
			grp.setName    ( q.getStringField( 1 ) );

			rList.Add( &grp );

			q.nextRow();
        }

		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #3
0
void   CBrainMemory::SetSystemItem(int64 Item,AnsiString Info){
	CppSQLite3Buffer SQL;
	CppSQLite3Query  Result;
	char a[30],b[30];
     int64toa(ROOM_SYSTEM,a);
	 int64toa(Item,b);

    SQL.format("select b from \"%s\" where a = \"%s\";",a,b);				
	Result = BrainDB.execQuery(SQL);
	bool Find = !Result.eof();
    Result.finalize();

	if(!Find){
		SQL.format("insert into \"%s\" values (\"%s\", ?)",
			a,
			b);
	}else{
		SQL.format("update \"%s\" set b = ? where a = \"%s\";",
			a,
			b
			);
	}

	CppSQLite3Statement State = BrainDB.compileStatement(SQL);
	State.bind(1,Info.c_str()); //替换第一个问号
	State.execDML();

}
BOOL DatabaseModule_Impl::sqlDeleteGroupInfoEntity(IN const std::string& groupId)
{
	try
	{
		CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(deleteGroupInfoSql.c_str());
		stmt.bind(1, groupId.c_str());
		stmt.execDML();
	}
	catch (CppSQLite3Exception& sqliteException)
	{
#ifdef _DEBUG
		MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
		CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
		LOG__(ERR, _T("delete failed,error msg:%s"), csErrMsg);
		return FALSE;
	}
	catch (...)
	{
		LOG__(ERR, _T("db unknown exception"));
		return FALSE;
	}

	return TRUE;
}
BOOL DatabaseModule_Impl::sqlInsertOrReplaceGroupInfoEntity(IN const module::GroupInfoEntity& groupInfo)
{
	try
	{
		CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(insertGroupInfoSql.c_str());
		stmt.bind(1, groupInfo.gId.c_str());
		stmt.bind(2, util::cStringToString(groupInfo.csName).c_str());
		stmt.bind(3, util::cStringToString(groupInfo.desc).c_str());
		stmt.bind(4, groupInfo.avatarUrl.c_str());
		stmt.bind(5, groupInfo.creatorId.c_str());
		stmt.bind(6, int(groupInfo.type));
		stmt.bind(7, int(groupInfo.version));
		stmt.bind(8, int(groupInfo.groupUpdated));
		stmt.bind(9, int(groupInfo.shieldStatus));
		std::string& strJson = _makeJsonForGroupMembers(groupInfo.groupMemeberList);
		stmt.bind(10, strJson.c_str());
		stmt.execDML();
	}
	catch (CppSQLite3Exception& sqliteException)
	{
#ifdef _DEBUG
		MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
		CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
		LOG__(ERR, _T("insert failed,error msg:%s"), csErrMsg);
		return FALSE;
	}
	catch (...)
	{
		LOG__(ERR, _T("db unknown exception"));
		return FALSE;
	}

	return TRUE;
}
Example #6
0
void CVoxSQLite::InsertContact( Contact& rContact )
{
	//TODO: compile as a member var?
	std::string	strSql = "INSERT INTO Contact "
						 "( [username], [nickname], [merged_parent_username]) "
						 "VALUES( ?, ?, ? ); ";

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( strSql.c_str() );

//		stmt.bind( 1, rContact.getName().c_str()	);
//		stmt.bind( 2, rContact.getNickname().c_str());
//		stmt.bind( 3, rContact.getMergedContact().c_str() );

		stmt.execDML();		//We expect a return value == 1 (Number of rows changed);
		stmt.reset();

		int nContactId = (int)m_db.lastRowId();

//		InsertGroups	    ( rContact.getName().c_str(), rContact.getGroups()			);
//		InsertMergedContacts( rContact.getName().c_str(), rContact.getMergedContacts()	);
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #7
0
void CVoxSQLite::InsertStreetAddress( int nId, StreetAddress& addr )
{
	std::string	strSql = "INSERT INTO StreetAddress "
		"( [profile_id], [type], [street], [locality], [region], [postcode], [country], [visibility] ) "
						 "VALUES( ?, ?, ?, ?, ?, ?, ?, ? ); ";

	try
	{
		//TODO: compile as a member var?
		CppSQLite3Statement stmt = m_db.compileStatement( strSql.c_str() );

		stmt.bind( 1, nId	);
		stmt.bind( 2, addr.getType().c_str()		);
		stmt.bind( 3, addr.getStreet1().c_str() 	);
		stmt.bind( 4, addr.getCity().c_str()		);
		stmt.bind( 5, addr.getStateProvince().c_str());
		stmt.bind( 6, addr.getPostalCode().c_str()	);
		stmt.bind( 7, addr.getCountry().c_str()		);
		stmt.bind( 8, (int) addr.getVisibility()	);

		stmt.execDML();		//We expect a return value == 1 (Number of rows changed);
		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #8
0
	void BaseDatabaseUnitImpl::runCreateStatements()
	{
		loadDatabaseInfo();

		if (database_)
		{
			try
			{
				uint32_t version = databaseInfo_->latest_.version_;
				for (auto it = databaseInfo_->latest_.tableList_.begin(); it != databaseInfo_->latest_.tableList_.end(); ++it)
				{
					CppSQLite3Statement statement = database_->compileStatement(it->statement_.c_str());
					runTransaction(statement);
				}

				CppSQLite3Statement statement = database_->compileStatement(SQL_VERSION_TABLE_CREATE);
				runTransaction(statement);

				statement = database_->compileStatement(SQL_VERSION_TABLE_SET_VERSION);
				statement.bind(1, VERSION_KEY);
				statement.bind(2, (int)version);
				runTransaction(statement);

				runUpdateStatements();
			}
			catch (CppSQLite3Exception e)
			{
				LOG_ERR_R(DATABASE_MANAGER_LOG_TAG, _T("Failed to run create statements, error: %u"), e.errorCode());
				LOG_ERR_D_A(DATABASE_MANAGER_LOG_TAG_A, "Message: %s", e.errorMessage());
			}
		}
	}
Example #9
0
void CVoxSQLite::GetMergedContacts( const char* parent_username, MergedContacts& rList )
{
	CppSQLite3Buffer buf;
	buf.format( "SELECT * from [MergedContact] WHERE [parent_username] = %Q;", parent_username );

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf );

		int				nContactId	= 0;
		std::string		type		= "";
		CppSQLite3Query q			= stmt.execQuery();
		MergedContact	mc;

		//Process record set.
        while (!q.eof())
        {
			mc.setParentUsername( q.getStringField( 0 ) );
			mc.setUsername      ( q.getStringField( 1 ) );

			rList.Add( &mc );

			q.nextRow();
        }

		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #10
0
void CVoxSQLite::InsertGroup( const char* username, Group& rGroup )
{
	//TODO: compile as a member var?
	std::string	strSql = "INSERT INTO [Group] "
						 "( [username], [name] ) "
						 "VALUES( ?, ? ); ";

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( strSql.c_str() );

		stmt.bind( 1, username );
		stmt.bind( 2, rGroup.getName() );

		stmt.execDML();		//We expect a return value == 1 (Number of rows changed);
		stmt.reset();

		int nId = (int)m_db.lastRowId();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #11
0
int CppSQLite3DB::insertBlob(const CString& szSQL, const unsigned char *data, int dataLength)
{
    CppSQLite3Statement statement = compileStatement(szSQL);

    statement.bind(1, data, dataLength);

    return statement.execDML();
}
Example #12
0
int CppSQLite3DB::updateBlob(const CString& szTableName, const CString& szFieldName, const unsigned char* data, int dataLength, const CString& szWhere)
{

    CString sql = CString("update ") + szTableName + " set " + szFieldName + "=? where " + szWhere;

    CppSQLite3Statement statement = compileStatement(sql);
    statement.bind(1, data, dataLength);

    return statement.execDML();
}
BOOL DatabaseModule_Impl::sqlUpdateRecentSessionInfoEntity(IN const module::SessionEntity& sessionInfo)
{
	try
	{
		CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(updateRecentSessionByIdSql.c_str());
		stmt.bind(1, sessionInfo.sessionID.c_str());
		stmt.bind(2, int(sessionInfo.sessionType));
		stmt.bind(3, int(sessionInfo.updatedTime));
		stmt.bind(4, int(sessionInfo.latestmsgId));
		stmt.bind(5, sessionInfo.latestMsgContent.c_str());
		stmt.bind(6, sessionInfo.latestMsgFromId.c_str());

		stmt.bind(7, sessionInfo.sessionID.c_str());
		int countUpdate = stmt.execDML();
		if (0 == countUpdate)
		{
			return FALSE;
		}
	}
	catch (CppSQLite3Exception& sqliteException)
	{
#ifdef _DEBUG
		MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
		CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
		LOG__(ERR, _T("db failed,error msg:%s"), csErrMsg);
		return FALSE;
	}
	catch (...)
	{
		LOG__(ERR, _T("db unknown exception"));
		return FALSE;
	}
	return TRUE;
}
BOOL DatabaseModule_Impl::sqlGetGroupInfoByGId(IN std::string& gId, OUT module::GroupInfoEntity& groupInfo)
{
	try
	{
		CppSQLite3Statement stmt;
		stmt = m_pSqliteDB->compileStatement(getGroupInfoByGIdSql.c_str());
		stmt.bind(1, gId.c_str());

		CppSQLite3Query query = stmt.execQuery();
		if (!query.eof())
		{
			groupInfo.gId = gId;
			groupInfo.csName = util::stringToCString(query.getStringField(2));
			groupInfo.desc = util::stringToCString(query.getStringField(3));
			groupInfo.avatarUrl = query.getStringField(4);
			groupInfo.creatorId = query.getStringField(5);
			groupInfo.type = query.getIntField(6);
			groupInfo.version = query.getIntField(7);
			groupInfo.groupUpdated = query.getIntField(8);
			groupInfo.shieldStatus = query.getIntField(9);
			_parseJsonForGroupMembers(query.getStringField(10), groupInfo.groupMemeberList);
		}
		else
		{
			return FALSE;
		}
	}
	catch (CppSQLite3Exception& sqliteException)
	{
#ifdef _DEBUG
		MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
		CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
		LOG__(ERR, _T("db failed,error msg:%s"),
			csErrMsg);
		return FALSE;
	}
	catch (...)
	{
		LOG__(ERR, _T("db unknown exception"));
		return FALSE;
	}

	return TRUE;

}
Example #15
0
	void BaseDatabaseUnitImpl::runUpdateStatements()
	{
		loadDatabaseInfo();

		if (database_)
		{
			uint32_t version = getDatabaseVersion();
			if (version > 0)
			{
				auto it = databaseInfo_->updateMap_.find(boost::lexical_cast<std::string>(version + 1));
				if (it != databaseInfo_->updateMap_.end())
				{
					try
					{
						for (it; it != databaseInfo_->updateMap_.end(); ++it)
						{
							for (auto it2 = it->second.tableList_.begin(); it2 != it->second.tableList_.end(); ++it2)
							{
								CppSQLite3Statement statement = database_->compileStatement(it2->statement_.c_str());
								runTransaction(statement);
							}

							try
							{
								version = boost::lexical_cast<uint32_t>(it->first);
							}
							catch (...)
							{
							}
						}

						CppSQLite3Statement statement = database_->compileStatement(SQL_VERSION_TABLE_SET_VERSION);
						statement.bind(1, VERSION_KEY);
						statement.bind(2, (int)version);
						runTransaction(statement);
					}
					catch (CppSQLite3Exception e)
					{
						LOG_ERR_R(DATABASE_MANAGER_LOG_TAG, _T("Failed to run update statements, error: %u"), e.errorCode());
						LOG_ERR_D_A(DATABASE_MANAGER_LOG_TAG_A, "Message: %s", e.errorMessage());
					}
				}
			}
		}
	}
Example #16
0
void CVoxSQLite::GetProfile( const char* username, Profile& rProfile )
{
	CppSQLite3Buffer buf;
	buf.format( "SELECT * from Profile WHERE username = %Q;", username );

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf );

		int	nProfileId	  = 0;
		CppSQLite3Query q = stmt.execQuery();

		//Process record set.
        while (!q.eof())
        {
			nProfileId = q.getIntField(0);

			rProfile.setFirstName	( q.getStringField(2) );
			rProfile.setLastName	( q.getStringField(3) );
			rProfile.setAlias		( q.getStringField(4) );
			rProfile.setSmsSignature( q.getStringField(5) );
			rProfile.setCompany		( q.getStringField(6) );
			rProfile.setSex			( (EnumSex::Sex)q.getIntField(7)	  );
			rProfile.setNotes		( q.getStringField(10) );
//			rProfile.setBirthday( q.getStringField(8) );
//			photo (filename)
//TODO		rProfile.setPhoto( q.getBlobField(9) );
			
			//Address, email, phone numbers, and URLs will be in separate tables to allow for easy
			GetStreetAddresses( nProfileId, rProfile.getStreetAddresses() );
			GetEmailAddresses ( nProfileId, rProfile.getEmailAddresses()  );
			GetTelephones	  ( nProfileId, rProfile.getTelephones()	  );
			GetUrls			  ( nProfileId, rProfile.getUrls()			  );

			q.nextRow();
        }

		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #17
0
void CVoxSQLite::InsertUrl ( int nId, const std::string& type, const std::string& url, EnumVisibility::Visibility vis )
{
	if ( IsValidUrl( url.c_str() ) )
	{
		std::string	strSql = "INSERT INTO Url "
			"( [profile_id], [type], [url], [visibility] ) "
							 "VALUES( ?, ?, ?, ? ); ";

		try
		{
			//TODO: compile as a member var?
			CppSQLite3Statement stmt = m_db.compileStatement( strSql.c_str() );

			stmt.bind( 1, nId			);
			stmt.bind( 2, type.c_str()	);
			stmt.bind( 3, url.c_str()   );
			stmt.bind( 4, (int)vis		);

			stmt.execDML();		//We expect a return value == 1 (Number of rows changed);
			stmt.reset();
		}

		catch (CppSQLite3Exception& e)
		{
			e.errorCode();
		}
	}
}
Example #18
0
void CVoxSQLite::GetStreetAddresses( int nProfileId, StreetAddresses& rAddrs )
{
	CppSQLite3Buffer buf;
	buf.format( "SELECT * from StreetAddress WHERE profile_id = %d;", nProfileId );

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf );

		int				nId		= 0;
		CppSQLite3Query q		= stmt.execQuery();

		StreetAddress	addr;

		//Process record set.
        while (!q.eof())
        {
//			"( [profile_id], [type], [street], [locality], [region], [postcode], [country], [visibility] ) "
			nId  = q.getIntField(0);			//Not part of Profile.

			addr.setType		 ( q.getStringField(1) );
			addr.setStreet1		 ( q.getStringField(2) );
			addr.setCity		 ( q.getStringField(3) );
			addr.setStateProvince( q.getStringField(4) );
			addr.setPostalCode	 ( q.getStringField(5) );
			addr.setCountry		 ( q.getStringField(6) );
			addr.setVisibility   ( (EnumVisibility::Visibility)q.getIntField(7) );

			rAddrs.Add( &addr );

			q.nextRow();
        }

		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #19
0
//##ModelId=474D30760272
bool CClip_ImportExport::ExportToSqliteDB(CppSQLite3DB &db)
{
	bool bRet = false;
	try
	{
		//Add to Main Table
		m_Desc.Replace(_T("'"), _T("''"));
		db.execDMLEx(_T("insert into Main values(NULL, %d, '%s');"), CURRENT_EXPORT_VERSION, m_Desc);
		long lId = (long)db.lastRowId();

		//Add to Data table
		CClipFormat* pCF;
		CppSQLite3Statement stmt = db.compileStatement(_T("insert into Data values (NULL, ?, ?, ?, ?);"));

		for(int i = m_Formats.GetSize()-1; i >= 0 ; i--)
		{
			pCF = & m_Formats.ElementAt(i);

			stmt.bind(1, lId);
			stmt.bind(2, GetFormatName(pCF->m_cfType));
			long lOriginalSize = GlobalSize(pCF->m_hgData);
			stmt.bind(3, lOriginalSize);

			const unsigned char *Data = (const unsigned char *)GlobalLock(pCF->m_hgData);
			if(Data)
			{
				//First compress the data
				long lZippedSize = compressBound(lOriginalSize);
				Bytef *pZipped = new Bytef[lZippedSize];
				if(pZipped)
				{				
					int nZipReturn = compress(pZipped, (uLongf *)&lZippedSize, (const Bytef *)Data, lOriginalSize);
					if(nZipReturn == Z_OK)
					{
						stmt.bind(4, pZipped, lZippedSize);
					}

					delete []pZipped;
					pZipped = NULL;
				}
			}
			GlobalUnlock(pCF->m_hgData);

			stmt.execDML();
			stmt.reset();

			m_Formats.RemoveAt(i);
		}

		bRet = true;
	}
	CATCH_SQLITE_EXCEPTION_AND_RETURN(false)

	return bRet;
}
BOOL DatabaseModule_Impl::sqlGetRecentSessionInfoByGId(IN std::string& sId, OUT module::SessionEntity& sessionInfo)
{
	try
	{
		CppSQLite3Statement stmt;
		stmt = m_pSqliteDB->compileStatement(getRecentSessionByIdSql.c_str());
		stmt.bind(1, sId.c_str());

		CppSQLite3Query query = stmt.execQuery();
		if (!query.eof())
		{
			sessionInfo.sessionID = sId;
			sessionInfo.sessionType = query.getIntField(2);
			sessionInfo.updatedTime = query.getIntField(3);
			sessionInfo.latestmsgId = query.getIntField(4);
			sessionInfo.latestMsgContent = query.getStringField(5);
			sessionInfo.latestMsgFromId = query.getStringField(6);
		}
		else
		{
			return FALSE;
		}
	}
	catch (CppSQLite3Exception& sqliteException)
	{
#ifdef _DEBUG
		MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
		CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
		LOG__(ERR, _T("db failed,error msg:%s"),
			csErrMsg);
		return FALSE;
	}
	catch (...)
	{
		LOG__(ERR, _T("db unknown exception"));
		return FALSE;
	}
	return TRUE;
}
BOOL DatabaseModule_Impl::sqlUpdateGroupInfoEntity(std::string& sId, IN const module::GroupInfoEntity& groupInfo)
{
	try
	{
		//"update groupinfo set name=?,desc=?,avatarUrl=?,creatorId=?,type=?,version=?,lastUpdateTime=?,shieldStatus=?,memberlist=? where groupId=?";
		CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(updateGroupInfoBySIdSql.c_str());
		stmt.bind(1, util::cStringToString(groupInfo.csName).c_str());
		stmt.bind(2, util::cStringToString(groupInfo.desc).c_str());
		stmt.bind(3, groupInfo.avatarUrl.c_str());
		stmt.bind(4, groupInfo.creatorId.c_str());
		stmt.bind(5, int(groupInfo.type));
		stmt.bind(6, int(groupInfo.version));
		stmt.bind(7, int(groupInfo.groupUpdated));
		stmt.bind(8, int(groupInfo.shieldStatus));
		std::string& strJson = _makeJsonForGroupMembers(groupInfo.groupMemeberList);
		stmt.bind(9, strJson.c_str());
		stmt.bind(9, groupInfo.gId.c_str());
		int countUpdate = stmt.execDML();
		if (0 == countUpdate)
		{
			LOG__(ERR, _T("db update failed:%s"), util::stringToCString(groupInfo.gId));
			return FALSE;
		}
	}
	catch (CppSQLite3Exception& sqliteException)
	{
#ifdef _DEBUG
		MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
		CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
		LOG__(ERR, _T("db failed,error msg:%s"), csErrMsg);
		return FALSE;
	}
	catch (...)
	{
		return FALSE;
	}

	return TRUE;
}
BOOL DatabaseModule_Impl::sqlGetFileTransferHistory(OUT std::vector<TransferFileEntity>& fileList)
{
    try
    {
        CppSQLite3Statement stmt;
        stmt = m_pSqliteDB->compileStatement(getFileTransferHistoryBySIdSql.c_str());
        stmt.bind(1, 20);

        CppSQLite3Query query = stmt.execQuery();
        while (!query.eof())
        {
            TransferFileEntity fileInfo;
            fileInfo.sTaskID = query.getStringField(1);
            fileInfo.sFromID = query.getStringField(2);
            fileInfo.sFileName = query.getStringField(3);
            CString strSavePath = util::stringToCString(query.getStringField(7));
            fileInfo.setSaveFilePath(strSavePath);
            fileInfo.nFileSize = query.getIntField(8);
            fileInfo.time = query.getIntField(9);
            fileList.push_back(fileInfo);
            query.nextRow();
        }
    }
    catch (CppSQLite3Exception& sqliteException)
    {
#ifdef _DEBUG
        MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
        CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
        LOG__(ERR, _T("db failed,error msg:%s"),
            csErrMsg);
        return FALSE;
    }
    catch (...)
    {
        return FALSE;
    }

    return TRUE;
}
BOOL DatabaseModule_Impl::sqlGetAllRecentSessionInfo(OUT std::vector<module::SessionEntity>& sessionList)
{
	try
	{
		CppSQLite3Statement stmt;
		stmt = m_pSqliteDB->compileStatement(getAllRecentSessionSql.c_str());

		CppSQLite3Query query = stmt.execQuery();
		while (!query.eof())
		{
			module::SessionEntity sessionInfo;
			sessionInfo.sessionID = query.getStringField(1);;
			sessionInfo.sessionType = query.getIntField(2);
			sessionInfo.updatedTime = query.getIntField(3);
			sessionInfo.latestmsgId = query.getIntField(4);
			sessionInfo.latestMsgContent = query.getStringField(5);
			sessionInfo.latestMsgFromId = query.getStringField(6);
			sessionList.push_back(sessionInfo);
			query.nextRow();
		}
	}
	catch (CppSQLite3Exception& sqliteException)
	{
#ifdef _DEBUG
		MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
		CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
		LOG__(ERR, _T("select failed,error msg:%s"),
			csErrMsg);
		return FALSE;
	}
	catch (...)
	{
		LOG__(ERR, _T("db unknown exception"));
		return FALSE;
	}

	return TRUE;
}
Example #24
0
void CVoxSQLite::InsertProfile( const char* username, Profile& rProfile )
{
	//TODO: compile as a member var?
	std::string	strSql = "INSERT INTO Profile "
						 "( [username], [first_name], [last_name], [alias], [sms_signature], [company], [notes], [sex] ) "
//						 "[birthday], [photo] ) "		//TODO
						 "VALUES( ?, ?, ?, ?, ?, ?, ?, ? ); ";

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( strSql.c_str() );

		stmt.bind( 1, username	);
		stmt.bind( 2, rProfile.getFirstName().c_str()	);
		stmt.bind( 3, rProfile.getLastName().c_str() 	);
		stmt.bind( 4, rProfile.getAlias().c_str()		);
		stmt.bind( 5, rProfile.getSmsSignature().c_str());
		stmt.bind( 6, rProfile.getCompany().c_str()		);
		stmt.bind( 7, rProfile.getNotes().c_str()		);
		stmt.bind( 8, rProfile.getSex()					);
//		stmt.bind( 10, rProfile.getBirthday()			);
//		stmt.bind( 11, rProfile.getPhoto()				);

		stmt.execDML();		//We expect a return value == 1 (Number of rows changed);
		stmt.reset();

		int nId = (int)m_db.lastRowId();

		InsertUrls			 ( nId, rProfile.getUrls()			  );
		InsertStreetAddresses( nId, rProfile.getStreetAddresses() );
		InsertEmailAddresses ( nId, rProfile.getEmailAddresses()  );
		InsertTelephones	 ( nId, rProfile.getTelephones()	  );
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #25
0
void CVoxSQLite::GetEmailAddresses( int nProfileId, EmailAddresses& rList )
{
	CppSQLite3Buffer buf;
	buf.format( "SELECT * from EmailAddress WHERE profile_id = %d;", nProfileId );

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf );

		int				nProfileId	= 0;
		std::string		type		= "";
		EmailAddress	addr;
		CppSQLite3Query q			= stmt.execQuery();

		//Process record set.
        while (!q.eof())
        {
//			"( [profile_id], [type], [email], [visiblity]
			nProfileId = q.getIntField(0);		//Not part of Profile.
			type = q.getStringField( 1 );		//Use to determine which address to update.

			addr.setType	  ( q.getStringField(1) );
			addr.setAddress	  ( q.getStringField(2) );
			addr.setVisibility( (EnumVisibility::Visibility) q.getIntField(3)	);

			rList.Add( &addr );

			q.nextRow();
        }

		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #26
0
	uint32_t BaseDatabaseUnitImpl::getDatabaseVersion()
	{
		if (database_)
		{
			try
			{
				CppSQLite3Statement statement = database_->compileStatement(SQL_VERSION_TABLE_GET_VERSION);
				statement.bind(1, VERSION_KEY);
				CppSQLite3Query result = statement.execQuery();

				if (!result.eof())
				{
					return (uint32_t)result.getIntField("version");
				}
			}
			catch (CppSQLite3Exception e)
			{
				LOG_ERR_R(DATABASE_MANAGER_LOG_TAG, _T("Failed to get database version, error: %u"), e.errorCode());
				LOG_ERR_D_A(DATABASE_MANAGER_LOG_TAG_A, "Message: %s", e.errorMessage());
			}
		}
		return 0;
	}
Example #27
0
void CVoxSQLite::GetUrls( int nProfileId, Urls& rList )
{
	CppSQLite3Buffer buf;
	buf.format( "SELECT * from Url WHERE profile_id = %d;", nProfileId );

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf );

		int				nProfileId	= 0;
		std::string		type		= "";
		CppSQLite3Query q			= stmt.execQuery();
		Url				url;

		//Process record set.
        while (!q.eof())
        {
//			"( [profile_id], [type], [address]
			nProfileId = q.getIntField(0);		//Not part of Profile.

			url.setType   ( q.getStringField( 1 ) );
			url.setUrl    ( q.getStringField( 2 ) );
			url.setVisibility( (EnumVisibility::Visibility)q.getIntField(3) );

			rList.Add( &url );

			q.nextRow();
        }

		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #28
0
void CVoxSQLite::GetContact( const char* username, Contact& c )
{
	CppSQLite3Buffer buf;
	buf.format( "SELECT * from Contact WHERE username = %Q;", username );

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf );

		int	nContactId = 0;
		CppSQLite3Query q = stmt.execQuery();

		//Process record set.
        while (!q.eof())
        {
			nContactId = q.getIntField(0);

//			c.setName		( q.getStringField(1) );
//			c.setNickname	( q.getStringField(2) );
//			c.setBirthday	( q.getStringField(3) );
//			c.setMergedContact( q.getStringField(3) );

			GetMergedContacts( username, c.getMergedContacts() );
			GetGroups		 ( username, c.getGroups() );
			GetProfile		 ( username, c );

			q.nextRow();
        }

		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
Example #29
0
void CVoxSQLite::GetTelephones( int nProfileId, Telephones& rList )
{
	CppSQLite3Buffer buf;
	buf.format( "SELECT * from Telephone WHERE profile_id = %d;", nProfileId );

	try
	{
		CppSQLite3Statement stmt = m_db.compileStatement( (const char*)buf );

		int				nProfileId	= 0;
		std::string		type		= "";
		CppSQLite3Query q			= stmt.execQuery();
		Telephone		tel;

		//Process record set.
        while (!q.eof())
        {
//			"( [profile_id], [type], [number]
			nProfileId = q.getIntField(0);		//Not part of Profile.

			tel.setType  ( q.getStringField( 1 ) );
			tel.setNumber( q.getStringField( 2 ) );

			rList.Add( &tel );

			q.nextRow();
        }

		stmt.reset();
	}

	catch (CppSQLite3Exception& e)
	{
		e.errorCode();
	}
}
BOOL DatabaseModule_Impl::sqlInsertFileTransferHistory(IN TransferFileEntity& fileInfo)
{
    if (fileInfo.nClientMode == IM::BaseDefine::ClientFileRole::CLIENT_OFFLINE_UPLOAD
        || fileInfo.nClientMode == IM::BaseDefine::ClientFileRole::CLIENT_REALTIME_SENDER)
    {
        LOG__(DEBG, _T("fileInfo.nClientMode not fixed"));
        return FALSE;
    }
    try
    {
        CppSQLite3Statement stmt = m_pSqliteDB->compileStatement(insertFileTransferHistorySql.c_str());
        stmt.bind(1, fileInfo.sTaskID.c_str());
        stmt.bind(2, fileInfo.sFromID.c_str());
        std::string filename = util::cStringToString(fileInfo.getRealFileName());
        stmt.bind(3, filename.c_str());
        std::string savePath = util::cStringToString(fileInfo.getSaveFilePath());
        stmt.bind(7, savePath.c_str());
        stmt.bind(8, (Int32)fileInfo.nFileSize);
        stmt.bind(9, time(0));
        stmt.execDML();
    }

    catch (CppSQLite3Exception& sqliteException)
    {
#ifdef _DEBUG
        MessageBoxA(0, sqliteException.errorMessage(), "BD ERROR", MB_OK | MB_ICONHAND);
#endif
        CString csErrMsg = util::stringToCString(sqliteException.errorMessage(), CP_UTF8);
        LOG__(ERR, _T("failed,error msg:%s"), csErrMsg);
        return FALSE;
    }
    catch (...)
    {
        LOG__(ERR, _T("unknown exception"));
        return FALSE;
    }

    return TRUE;
}