Exemple #1
0
bool mtn_cms_page_builder::getcache(const std::string& page, mtn_cms_cache_item* cache_item)
{
  std::string _q = "SELECT * FROM `page_cache` WHERE page = \'" + page + "\';"; 
try
  {
  CppSQLite3Query q = _db->execQuery(_q.c_str());


  while (!q.eof())
    {
      int len;
      cache_item->data = q.getStringField("data");
      cache_item->created = q.getIntField("created");
      cache_item->ttl = q.getIntField("ttl");
      cache_item->valid = true;
      q.nextRow();
    } 
  }
 catch (CppSQLite3Exception ex)
   {
     cache_item->valid = false;
   }

  return cache_item->valid;
}
//private
void RPGMapItemsMenuLayer::loadItemsData()
{
    //道具数据
    this->m_itemsList->removeAllObjects();
    
    CppSQLite3Query query = this->m_db->execQuery(ITEMS_EXISTING_QUERY);
    while(!query.eof())
    {
        RPGExistingItems *itemsData = RPGExistingItems::create();
        itemsData->m_dataId = query.getIntField("id");
        itemsData->m_name = query.getStringField("name_cns");
        itemsData->m_buy = query.getIntField("buy");
        itemsData->m_sell = query.getIntField("sell");
        itemsData->m_type = query.getIntField("type");
        itemsData->m_attack = query.getFloatField("attack");
        itemsData->m_defense = query.getFloatField("defense");
        itemsData->m_speed = query.getFloatField("speed");
        itemsData->m_skillAttack = query.getFloatField("skill_attack");
        itemsData->m_skillDefense = query.getFloatField("skill_defense");
        itemsData->m_total = query.getIntField("total");
        this->m_itemsList->addObject(itemsData);
        
        query.nextRow();
    }
    query.finalize();
    
    CCTableView *tableView = (CCTableView*)this->getChildByTag(kRPGMapItemsMenuLayerTagItemListTable);
    tableView->reloadData();
}
void CTerminateNewLocationDialog::OnSelchangeLocationlist() 
{
    int iLocationID = m_ctlLocationList.GetItemData(m_ctlLocationList.GetCurSel());
    CString sSQL;
    sSQL.Format("SELECT Industries.id,Industries.name FROM Industries,Sidings WHERE Industries.Sidings_FK=Sidings.id AND Sidings.Locations_FK=%d",iLocationID);
    TRACE(sSQL);
    //
    CppSQLite3DB* pDB = &((CTrainOpsApp*)AfxGetApp())->m_pDB;
    CppSQLite3Query q = pDB->execQuery(sSQL);
    //
    while( m_ctlIndustryList.GetCount() > 0 )
        m_ctlIndustryList.DeleteString(0);
    //
    while (!q.eof())
    {
        int nIndex = m_ctlIndustryList.AddString(q.getStringField("name"));
        m_ctlIndustryList.SetItemData(nIndex,q.getIntField("id"));
        q.nextRow();
    }
    //
    sSQL.Format("SELECT id,name FROM Sidings WHERE Locations_FK=%d;",iLocationID);
    q = pDB->execQuery(sSQL);
    //
    while( m_ctlSidingList.GetCount() > 0 )
        m_ctlSidingList.DeleteString(0);
    //
    while (!q.eof())
    {
        int nIndex = m_ctlSidingList.AddString(q.getStringField("name"));
        m_ctlSidingList.SetItemData(nIndex,q.getIntField("id"));
        q.nextRow();
    }
    q.finalize();
}
BOOL CDBCmdHandler::OnCmdDBLoadCharReq( UINT16 wCommandID, UINT64 u64ConnID, CBufferHelper *pBufferHelper )
{
	StDBLoadCharInfoReq DBLoadCharInfoReq;
	pBufferHelper->Read(DBLoadCharInfoReq);


	StDBLoadCharInfoAck DBLoadCharInfoAck;
	DBLoadCharInfoAck.dwProxySvrID = DBLoadCharInfoReq.dwProxySvrID;

	CBufferHelper WriteHelper(TRUE, &m_WriteBuffer);
	WriteHelper.BeginWrite(CMD_DB_LOAD_CHAR_ACK, 0, DBLoadCharInfoReq.dwSceneID, DBLoadCharInfoReq.u64CharID);

	WriteHelper.Write(DBLoadCharInfoAck);

	CDBPlayerObject *pDBPlayer = m_DBPlayerMgr.GetPlayer(DBLoadCharInfoReq.u64CharID);
	if(pDBPlayer == NULL)
	{
		//读取一条记录,
		//读出成功
		pDBPlayer = m_DBPlayerMgr.InsertAlloc(DBLoadCharInfoReq.u64CharID);

		pDBPlayer->Init();

		pDBPlayer->m_u64ObjectID = DBLoadCharInfoReq.u64CharID;

		CHAR szSql[MAX_PATH];
		sprintf(szSql, "select * from t_charinfo where F_CharID = '%lld'", DBLoadCharInfoReq.u64CharID);

		CppSQLite3Query QueryRes = m_DBProcManager.m_DBConnection.execQuery(szSql);

		if(!QueryRes.eof())
		{
			pDBPlayer->m_dwFeature = QueryRes.getIntField("F_Feature", 0);
			strncpy(pDBPlayer->m_szObjectName, QueryRes.getStringField("F_Name", ""), 32);
			pDBPlayer->m_dwLevel = QueryRes.getIntField("F_Level", 0);
	
		}

		//if(!pDBPlayer->LoadFromDB())
		//{
		//	return TRUE;
		//}
	}

	pDBPlayer->WriteToPacket(&WriteHelper);

	WriteHelper.EndWrite();
	
	CGameService::GetInstancePtr()->SendCmdToConnection(DBLoadCharInfoReq.dwGameSvrID, &m_WriteBuffer);
	
	return TRUE;
}
Exemple #5
0
int CPersistencManager::LoadClientInfo(CI_VECTOR &client_list){
	if(m_useLevelDB)
	{
		return 0;
	}
	
	int ret = 0;
	
	int type = 0;
	CppSQLite3Query query = m_SQLite3DB.execQuery("select * from Client");

    while (!query.eof())
    {
        CClientInfo *pCI = new CClientInfo();
		if (!pCI){

			CLog::Log(LOG_LEVEL_ERROR,"Alloc object CClientInfo Error\n");
			return -1;
		}
		
		type = query.getIntField("type");
		if (type == COMPUTE_TYPE_CLIENT){

			((CCompClient*)pCI)->m_gputhreads = query.getIntField("gpu");
			((CCompClient*)pCI)->m_cputhreads = query.getIntField("cpu");
		}

		pCI->m_type = type;

		memset(pCI->m_ip,0,sizeof(pCI->m_ip));
		memset(pCI->m_guid,0,sizeof(pCI->m_guid));
		memset(pCI->m_hostname,0,sizeof(pCI->m_hostname));
		memset(pCI->m_osinfo,0,sizeof(pCI->m_osinfo));


		memcpy(pCI->m_ip,query.fieldValue("ip"),strlen(query.fieldValue("ip")));
		memcpy(pCI->m_hostname,query.fieldValue("hostname"),strlen(query.fieldValue("hostname")));
		memcpy(pCI->m_osinfo,query.fieldValue("osinfo"),strlen(query.fieldValue("osinfo")));


		//keeplive time and logintime 

		client_list.push_back(pCI);

        query.nextRow();
    }



	return ret;

}
bool RPGMapSceneLayer::init(float showObjectTime)
{
    if(RPGBaseSceneLayer::init())
    {        
        CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("joystick.plist");
        CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("main.plist");
        
        //加载语言文件
        string languageFile = CCFileUtils::sharedFileUtils()->fullPathForFilename("scene_map_cns.plist");
        this->m_stringList = CCDictionary::createWithContentsOfFileThreadSafe(languageFile.c_str());
        this->m_stringList->retain();
        
        //数据库部分,读取进度记录
        CppSQLite3Query query = this->m_db.execQuery(SAVEDATA_MAP_QUERY);
        this->m_mapData.mapId = query.getIntField("map_id");
        this->m_mapData.mapName = query.getStringField("map_name");
        this->m_mapData.hasEnemy = query.getIntField("has_enemy") == 1 ? true : false;
        this->m_mapData.bgAudio = query.getStringField("bg_audio");
        this->m_mapData.playerToX = query.getFloatField("player_to_x");
        this->m_mapData.playerToY = query.getFloatField("player_to_y");
        this->m_mapData.playerDirection = query.getStringField("player_direction");
        this->m_mapData.location = query.getStringField("location_cns");
        this->m_mapData.gold = query.getIntField("gold");
        query.finalize();
        
        CCTMXTiledMap *bgMap = CCTMXTiledMap::create(this->m_mapData.mapName.c_str());
        bgMap->setTag(kRPGMapSceneLayerTagBgMap);
        bgMap->setPosition(ccp((CCDirector::sharedDirector()->getWinSize().width - bgMap->getContentSize().width) / 2.0, (CCDirector::sharedDirector()->getWinSize().height - bgMap->getContentSize().height) / 2.0));
        this->addChild(bgMap);
        
        //背景音乐
        if(SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
        {
            SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(true);
            SimpleAudioEngine::sharedEngine()->playBackgroundMusic(this->m_mapData.bgAudio.c_str(), true);
        }
        
        this->m_playerMoveAct = NULL;
        this->m_playerMoveSpeed = GAME_PLAYER_MOVESPEED;
        this->m_touchedDialogNPC = NULL;
        this->m_dialogDirection = kRPGMapSceneLayerDialogDirectionNone;
        
        this->m_hasEnemy = this->m_mapData.hasEnemy; //是否会遇敌
        this->m_releaseTexture = false; //是否在释构方法里面释放占用纹理
        
        this->scheduleOnce(schedule_selector(RPGMapSceneLayer::startPlay), showObjectTime);
        
//        CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo();
        return true;
    }
    return false;
}
Exemple #7
0
EXPORT_C gint32 CContactDb::GetRecentContacts(GPtrArray ** pContacts)
	{
	char sql[64] = {0};
	char times[20] = {0};
//	time_t t;
	
//	time(&t); 
	*pContacts = NULL;
	*pContacts = g_ptr_array_new();
	if (*pContacts == NULL)
		{
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}
	
	OpenDatabase();
	strcpy(sql, "select * from recent_contact;");
	CppSQLite3Query query = m_dbBeluga.execQuery(sql);
	while (!query.eof())
		{
		stRecentContact * recentContact = (stRecentContact*)g_malloc0(sizeof(stRecentContact));
		if (recentContact == NULL)
			{
			CloseDatabase();
			return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
			}
		
		recentContact->nContactId = query.getIntField(1);
		recentContact->event = (EContactEvent)query.getIntField(2);
		strcpy(recentContact->eventCommInfo, query.getStringField(3));
		strcpy(times, query.getStringField(4));  /* exp: 2009-6-30 21:51:23 */
 		//recentContact->time = localtime(&t); 
		GetLocalTime(&recentContact->time);
		char * tmp = strrchr(times, '-');
		recentContact->time.tm_mon = atoi(tmp+1);
		tmp = strrchr(tmp, '-');
		recentContact->time.tm_mday = atoi(tmp+1);
		tmp = strrchr(tmp, ' ');
		recentContact->time.tm_hour = atoi(tmp+1);
		tmp = strrchr(tmp, ':');
		recentContact->time.tm_min = atoi(tmp+1);
		tmp = strrchr(tmp, ':');
		recentContact->time.tm_sec = atoi(tmp+1);
		
		g_ptr_array_add(*pContacts, recentContact);
		query.nextRow();
		}
	
	CloseDatabase();
	return 0;
	}
Exemple #8
0
BOOL CCP_MainApp::EnterGroupID(long lID)
{
	BOOL bResult = FALSE;

	if(m_GroupID == lID)
		return TRUE;

	// if we are switching to the parent, focus on the previous group
	if(m_GroupParentID == lID && m_GroupID > 0)
		m_FocusID = m_GroupID;

	switch(lID)
	{
	case -1:
		m_FocusID = -1;
		m_GroupID = -1;
		m_GroupParentID = -1;
		m_GroupText = "History";
		bResult = TRUE;
		break;
	default: // Normal Group
		try
		{
			CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lParentID, mText, bIsGroup FROM Main WHERE lID = %d"), lID);
			if(q.eof() == false)
			{
				if(q.getIntField(_T("bIsGroup")) > 0)
				{
					m_GroupID = lID;
					m_GroupParentID = q.getIntField(_T("lParentID"));
//					if( m_GroupParentID == 0 )
//				      m_GroupParentID = -1; // back out into "all top-level groups" list.
					m_GroupText = q.getStringField(_T("mText"));
					bResult = TRUE;
				}
			}
		}
		CATCH_SQLITE_EXCEPTION
		break;
	}

	if(bResult)
	{
		theApp.RefreshView();
		if(QPasteWnd())
			QPasteWnd()->UpdateStatus(true);
	}

	return bResult;
}
void BudgetWindow::RefreshCategories(void)
{
	fCategoryList->Clear();
	fIncomeRow = new BRow();
	fCategoryList->AddRow(fIncomeRow);
	fSpendingRow = new BRow();
	fCategoryList->AddRow(fSpendingRow);
	fIncomeRow->SetField(new BStringField(TRANSLATE("Income")),0);
	fSpendingRow->SetField(new BStringField(TRANSLATE("Spending")),0);

	CppSQLite3Query query = gDatabase.DBQuery("select category,amount,period,isexpense from "
											"budgetlist order by category",
											"BudgetWindow::RefreshCategories");
	float maxwidth=fCategoryList->StringWidth("Category");
	while(!query.eof())
	{
		BString cat = DeescapeIllegalCharacters(query.getStringField(0));
		Fixed amount;
		amount.SetPremultiplied(query.getInt64Field(1));
		BudgetPeriod period = (BudgetPeriod)query.getIntField(2);

		BRow *row = new BRow();

		if(query.getIntField(3)==0)
			fCategoryList->AddRow(row,fIncomeRow);
		else
			fCategoryList->AddRow(row,fSpendingRow);

		row->SetField(new BStringField(cat.String()),0);

		BString amountstr;
		gDefaultLocale.CurrencyToString(amount.AbsoluteValue(),amountstr);
		amountstr.Truncate(amountstr.FindFirst(gDefaultLocale.CurrencyDecimal()));
		amountstr.RemoveFirst(gDefaultLocale.CurrencySymbol());

		row->SetField(new BStringField(amountstr.String()),1);

		float tempwidth = fCategoryList->StringWidth(cat.String());
		maxwidth = MAX(tempwidth,maxwidth);

		row->SetField(new BStringField(BudgetPeriodToString(period).String()),2);

		query.nextRow();
	}
	fCategoryList->ColumnAt(0)->SetWidth(maxwidth+30);
	fCategoryList->ExpandOrCollapse(fIncomeRow,true);
	fCategoryList->ExpandOrCollapse(fSpendingRow,true);
}
Exemple #10
0
bool CDittoCopyBuffer::PastCopyBuffer(long lCopyBuffer)
{
	//Can't paste while another is still active
	if(WaitForSingleObject(m_Pasting, 1) == WAIT_TIMEOUT)
	{
		Log(_T("Copy Buffer pasted to fast"));
		return false;
	}

	m_RestoreTimer.ResetEvent();
	m_Pasting.ResetEvent();
	bool bRet = false;

	Log(StrF(_T("Start - PastCopyBuffer buffer = %d"), m_lCurrentDittoBuffer));

	try
	{
		CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT Main.lID FROM Main ")
													_T("INNER JOIN CopyBuffers ON CopyBuffers.lClipID = Main.lID ")
													_T("WHERE CopyBuffers.lCopyBuffer = %d"), lCopyBuffer);

		if(q.eof() == false)
		{
			m_pClipboard = new CClipboardSaveRestoreCopyBuffer;
			if(m_pClipboard)
			{
				//Save the clipboard, 
				//then put the new data on the clipboard
				//then send a paste
				//then wait a little and restore the original clipboard data
				if(m_pClipboard->Save())
				{
					CProcessPaste paste;
					paste.m_bSendPaste = true;
					paste.m_bActivateTarget = false;
					paste.GetClipIDs().Add(q.getIntField(_T("lID")));
					paste.DoPaste();

					m_pClipboard->m_lRestoreDelay = g_Opt.GetDittoRestoreClipboardDelay();

					Log(StrF(_T("PastCopyBuffer sent paste, starting thread to restore clipboard, Delay = %d"), m_pClipboard->m_lRestoreDelay));

					AfxBeginThread(CDittoCopyBuffer::DelayRestoreClipboard, (LPVOID)this, THREAD_PRIORITY_LOWEST);

					bRet = true;
				}
				else
				{
					Log(_T("PastCopyBuffer failed to save clipboard"));
				}
			}
		}
	}
	CATCH_SQLITE_EXCEPTION

	if(bRet == false)
		m_Pasting.SetEvent();

	return bRet;
}
Exemple #11
0
int CDBObject::getFirstFile(char* name)
{
	try
	{
		if(name != NULL)
		{
			char szSql[]= {"SELECT * from Record"};
			CppSQLite3DB database;
			database.open(g_szFile);
			CppSQLite3Query query = database.execQuery(szSql);
			if(!query.eof())
			{
				string path = query.getStringField(8);
				string file= query.getStringField(7);
				sprintf(name, "%s\\%s", UTF_82ASCII(path).c_str(), UTF_82ASCII(file).c_str());
				return query.getIntField(0);
			}
		}
	}
	catch(...)
	{
		g_pLog->WriteLog("数据库查询异常 getFirstFile\n");
	}
	return -1;
}
Exemple #12
0
bool CWizIndexBase::SQLToStyleDataArray(const CString& strSQL, CWizStyleDataArray& arrayStyle)
{
    try
    {
        CppSQLite3Query query = m_db.execQuery(strSQL);
        while (!query.eof())
        {
            WIZSTYLEDATA data;
            data.strKbGUID = kbGUID();
            data.strGUID = query.getStringField(styleSTYLE_GUID);
            data.strName = query.getStringField(styleSTYLE_NAME);
            data.strDescription = query.getStringField(styleSTYLE_DESCRIPTION);
            data.crTextColor = query.getColorField(styleSTYLE_TEXT_COLOR);
            data.crBackColor = query.getColorField(styleSTYLE_BACK_COLOR);
            data.bTextBold = query.getBoolField(styleSTYLE_TEXT_BOLD);
            data.nFlagIndex = query.getIntField(styleSTYLE_FLAG_INDEX);
            data.tModified = query.getTimeField(styleDT_MODIFIED);
            data.nVersion = query.getInt64Field(styleVersion);

            arrayStyle.push_back(data);
            query.nextRow();
        }

        std::sort(arrayStyle.begin(), arrayStyle.end());
        return true;
    }
    catch (const CppSQLite3Exception& e)
    {
        return LogSQLException(e, strSQL);
    }
}
Exemple #13
0
//void CDlgProjectNew::OnBnClickedButtonCancel()
//{
//	// TODO: 在此添加控件通知处理程序代码
//	m_bIsSave=false;
//	OnOK();
//}
bool CDlgProjectNew::IsExistProjectName(CString strProjectName)//该产品名称是否存在库存表中 true 存在 false 不存在
{

	CString strSQL;
	strSQL.Format(_T("select count(ProjectName) as COUNTProjectName from Project where ProjectName='%s';"),	strProjectName);
	int nCount=0;
	try
	{

		CppSQLite3DB db;
		db.open(CBoBoDingApp::g_strDatabasePath);
		CppSQLite3Query q = db.execQuery(strSQL);//销售单历史表

		if (!q.eof())
		{
			//nCount=q.fieldValue(_T("COUNTPinMingGuiGe"));
			nCount=q.getIntField(_T("COUNTProjectName"));
		}
	}
	catch (CppSQLite3Exception& e)
	{

		AfxMessageBox(e.errorMessage());
	}
	if(nCount>0) 
		return true;
	else
		return false;

}
//##ModelId=474D307602CF
bool CClip_ImportExport::ImportFromSqliteDB(CppSQLite3DB &db, bool bAddToDB, bool bPutOnClipboard)
{
	bool bRet = false;
	CStringA csCF_TEXT;
	CStringW csCF_UNICODETEXT;

	try
	{
		CppSQLite3Query q = db.execQuery(_T("Select * from Main"));
		while(q.eof() == false)
		{
			Clear();

			int nVersion = q.getIntField(_T("lVersion"));
			if(nVersion == 1)
			{
				if(ImportFromSqliteV1(db, q))
				{
					if(bAddToDB)
					{
						MakeLatestTime();
						AddToDB(true);
						bRet = true;
					}
					else if(bPutOnClipboard)
					{
						bRet = true;
					}
				}
			}

			m_lImportCount++;

			//If putting on the clipboard and there are multiple
			//then append cf_text and cf_unicodetext
			if(bPutOnClipboard)
			{
				Append_CF_TEXT_AND_CF_UNICODETEXT(csCF_TEXT, csCF_UNICODETEXT);
			}

			q.nextRow();
		}

		if(bRet && bAddToDB)
		{
			theApp.RefreshView();
		}
		else if(bRet && m_lImportCount == 1 && bPutOnClipboard)
		{
			PlaceFormatsOnclipboard();
		}
		else if(bRet && bPutOnClipboard)
		{
			PlaceCF_TEXT_AND_CF_UNICODETEXT_OnClipboard(csCF_TEXT, csCF_UNICODETEXT);
		}
	}
	CATCH_SQLITE_EXCEPTION_AND_RETURN(false)

	return bRet;
}
BOOL CCarTypesDetailDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

    if( m_iCarTypeFK != -1 )
    {
        CppSQLite3DB* pDB = &((CTrainOpsApp*)AfxGetApp())->m_pDB;
        CString sSQL;
        sSQL.Format("SELECT * FROM CarTypes WHERE id=%d",m_iCarTypeFK);
        CppSQLite3Query q = pDB->execQuery((LPCTSTR)sSQL);
        if( !q.eof() )
        {
            m_sCarTypeDescription = q.getStringField("description");
            m_sCarTypeID = q.getStringField("type_id");
            m_bPassenger = q.getIntField("passenger")==1?TRUE:FALSE;
        }
        q.finalize();
    }


    UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
BOOL FireFox3PlugIn::ExportFavoriteData( PFAVORITELINEDATA* ppData, int32& nDataNum )
{
	memset(ppData,0x0, nDataNum*sizeof(PFAVORITELINEDATA));

	if (ppData == NULL || *ppData == NULL || nDataNum == 0)
	{
		return FALSE;
	}

	string strSql = "select marks.* from moz_bookmarks as marks where marks.id in (2,3,4,5)";
	CppSQLite3Query Query = m_pSqliteDatabase->execQuery(strSql.c_str());

	// 当前插入的位置
	int nCurrentIndex = 0;
	while(!Query.eof())
	{
		int nId = Query.getIntField("id", 0);
		ExportFavoriteData(nId,ppData,nCurrentIndex);

		Query.nextRow();
	}

	nDataNum = nCurrentIndex;

	return TRUE;
}
Exemple #17
0
EXPORT_C gint32 CContactDb::GetEntityById(guint32 nId, CDbEntity** ppEntity)
	{
	char sql[128] = {0};
	*ppEntity = NULL;
	
	OpenDatabase();
	sprintf(sql, "select * from contact where cid = %d;", nId);
	CppSQLite3Query query = m_dbBeluga.execQuery(sql);
	
	if (query.eof())
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_Not_Exist);
		}
	
	if (ContactType_Phone == query.getIntField(ContactField_Type))
		*ppEntity = new CPhoneContact(this, FALSE);
	else
		*ppEntity = new CIMContact(this);
	if (NULL == *ppEntity)
		{
		CloseDatabase();
		return ERROR(ESide_Client, EModule_Db, ECode_No_Memory);
		}
	
	for (int i=0; i<query.numFields(); i++)
		{
		GString * fieldValue = g_string_new(query.fieldValue(i));
		(*ppEntity)->SetFieldValue(i, fieldValue);
		g_string_free(fieldValue, TRUE);
		}
		
	CloseDatabase();
	return 0;
	}
Exemple #18
0
//Método que monta as tab do Tab Control
void CRcGen::GetGrupos(WPARAM wParam, CStringArray& arrayGrp)
{
	CStringA sQuery;

	sQuery.Format("select distinct res.grupo, resgrupo.descricao from res, resgrupo where res.grupo = resgrupo.grupo and res.pagina between %d and %d", LOWORD(wParam), HIWORD(wParam));

	try
	{
		CppSQLite3Query q = CppSQLite3DB::getInstance()->execQuery(sQuery);

		if(!q.eof())
		{
			m_nGrupo = q.getIntField(0);
			m_nGrupoInicial = m_nGrupo;
		}

		while(!q.eof())
		{
			arrayGrp.Add(CString(q.getStringField(1)));
			q.nextRow();
		}
	}
	catch(CppSQLite3Exception e)
	{
	
	}
}
Exemple #19
0
void CatBrowser::SetupQuery(void)
{
	BString command, esccat = EscapeIllegalCharacters(fCategory.String());
	CppSQLite3Query query;
	
	command = "select count(number) from ";
	command << esccat << ";";
	query = DBQuery(command.String(), "CatBrowser::SetupQuery:get category count");
	
	fCategoryCount = (query.eof()) ? 0 : query.getIntField(0);
	
	for(int32 i = 0; i < fPageList.CountItems(); i++)
	{
		QueryPage *page = (QueryPage*)fPageList.ItemAt(i);
		page->MakeEmpty();
	}
	
	fPageCount = (fCategoryCount / BROWSE_MODE_RECIPE_COUNT);
	if( (fPageCount % BROWSE_MODE_RECIPE_COUNT) || fPageCount < BROWSE_MODE_RECIPE_COUNT)
		fPageCount++;
	if(fPageList.CountItems() < fPageCount)
	{
		for(int32 i = fPageList.CountItems(); i <= fPageCount; i++)
			fPageList.AddItem(new QueryPage());
	}
	
	fCurrentPage = -1;
}
Exemple #20
0
void CCP_MainApp::LoadGlobalClips()
{
	try
	{
		{
			CppSQLite3Query q = m_db.execQuery(_T("SELECT lID, lShortCut, mText FROM Main WHERE lShortCut > 0 AND globalShortCut = 1"));

			while(q.eof() == false)
			{
				int id = q.getIntField(_T("lID"));
				int shortcut = q.getIntField(_T("lShortCut"));
				CString desc = q.getStringField(_T("mText"));

				//Constructor will add to a global list and free
				CHotKey* globalHotKey = new CHotKey(desc, shortcut, true, CHotKey::PASTE_OPEN_CLIP);
				if(globalHotKey != NULL)
				{
					globalHotKey->m_clipId = id;
				}

				q.nextRow();
			}
		}

		{
			CppSQLite3Query q2 = m_db.execQuery(_T("SELECT lID, MoveToGroupShortCut, mText FROM Main WHERE MoveToGroupShortCut > 0 AND GlobalMoveToGroupShortCut = 1"));

			while(q2.eof() == false)
			{
				int id = q2.getIntField(_T("lID"));
				int shortcut = q2.getIntField(_T("MoveToGroupShortCut"));
				CString desc = q2.getStringField(_T("mText"));

				//Constructor will add to a global list and free
				CHotKey* globalHotKey = new CHotKey(desc, shortcut, true, CHotKey::MOVE_TO_GROUP);
				if(globalHotKey != NULL)
				{
					globalHotKey->m_clipId = id;
				}

				q2.nextRow();
			}
		}
	}
	CATCH_SQLITE_EXCEPTION
}
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;

}
Exemple #22
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();
	}
}
void CMainTableFunctions::LoadAcceleratorKeys(CAccels& accels, CppSQLite3DB &db)
{
	try
	{
		CppSQLite3Query q = db.execQuery(_T("SELECT lID, lShortCut FROM Main WHERE lShortCut > 0"));
		
		CAccel a;
		while(q.eof() == false)
		{
			a.Cmd = q.getIntField(_T("lID"));
			a.Key = q.getIntField(_T("lShortCut"));
			
			accels.AddAccel(a);

			q.nextRow();
		}
	}
	CATCH_SQLITE_EXCEPTION
}
int RPGResultsLogic::battleSkill(CppSQLite3DB* db, RPGBaseRole* srcObjData, int skillId, RPGBaseRole* targetObjData)
{
    RPGSkill *skill = NULL;
    
    CppSQLite3Query srcSkillQuery = db->execQuery(CCString::createWithFormat(SKILL_DETAIL_QUERY, skillId)->getCString());
    while(!srcSkillQuery.eof())
    {
        skill = RPGSkill::create();
        skill->m_dataId = srcSkillQuery.getIntField("id");
        skill->m_MP = srcSkillQuery.getIntField("mp");
        skill->m_name = srcSkillQuery.getStringField("name_cns");
        skill->m_skillAttack = srcSkillQuery.getFloatField("skill_attack");
        skill->m_attr = srcSkillQuery.getFloatField("attr");
        
        srcSkillQuery.nextRow();
    }
    srcSkillQuery.finalize();
    
    if(skill)
    {
        //扣减MP
        srcObjData->m_MP -= skill->m_MP;
        if(srcObjData->m_MP < 0)
            srcObjData->m_MP = 0;
        
        switch (skill->m_dataId)
        {
            case 2:
                //回复
                return RPGComputingResults::skillCureResults(srcObjData->m_skillAttack, skill->m_skillAttack);
                break;
                
            default:
            {
                //火焰
                int val = RPGComputingResults::skillAttackResults(srcObjData->m_skillAttack, skill->m_skillAttack, (RPGSkillAttr)skill->m_attr, targetObjData->m_skillDefense, kRPGSkillAttrNormal); //后面的参数暂定为普通属性
                return -val;
            }
                break;
        }
    }
    return 0;
}
Exemple #25
0
bool CSpace::Load(int64 ParentID,int64 ChildID){
	m_ID = ParentID;
	
	char     ParentName[30], ChildName[30]; 
	int64toa(ParentID,ParentName);
	int64toa(ChildID,ChildName);
	
	CppSQLite3Buffer SQL;
	SQL.format("select * from \"%s\" where %s = \"%s\" ",
		ParentName,
		ITEM_ID,
		ChildName  
	);

	CppSQLite3Query Result = GetWorldDB().execQuery(SQL);
	if(Result.eof()){
		return false;
	}
	assert(Size()>5);
	assert(GetDataType(0) == TYPE_INT);
	int64& OldID = *(int64*)GetData(0);
	OldID = ChildID;

	AnsiString AnsiName = Result.getStringField(1,"");	
	tstring Name = UTF8toWS(AnsiName);
	SetName(Name);

	SPACETYPE Type = (SPACETYPE)Result.getIntField(2);
	SetSpaceType(Type);

	AnsiString Fingerprint = Result.getStringField(3);
	tstring Fingerprint1 = UTF8toWS(Fingerprint);
    SetFingerprint(Fingerprint1);
	
	AnsiString AnsiProperty = Result.getStringField(4,"");     	
	ePipeline Property;
	uint32 pos =0;
	bool ret = Property.FromString(AnsiProperty,pos);
	if(!ret){
		return false;
	}
    SetProerty(Property);

	AnsiString AnsiOwner = Result.getStringField(5,"");
	ePipeline OwnerInfo;

	pos=0;
	ret = OwnerInfo.FromString(AnsiOwner,pos);
	if(!ret){
		return false;
	}  
	SetOwnerInfo(OwnerInfo);

	return true;
}
Exemple #26
0
int CppSQLite3DB::execScalar(const char* szSQL, int nNullValue/*=0*/)
{
	CppSQLite3Query q = execQuery(szSQL);

	if (q.eof() || q.numFields() < 1)
	{
		throw CppSQLite3Exception(CPPSQLITE_ERROR,"Invalid scalar query",DONT_DELETE_MSG);
	}

	return q.getIntField(0, nNullValue);
}
Exemple #27
0
//##ModelId=474D306600CC
void CGroupCombo::FillCombo(long lParentID, long lSpaces)
{
	try
	{			
		int nIndex;
		CString csSpaces;

		for(int i = 0; i < lSpaces; i++)
		{
			csSpaces += "---";
		}

		//First time through
		if(lSpaces > 0)
		{
			csSpaces += " ";
			//ResetContent();
		}

		lSpaces++;

		CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, mText FROM Main WHERE bIsGroup = 1 AND lParentID = %d"), lParentID);
			
		if(q.eof() == false)
		{
			while(!q.eof())
			{
				if(q.getIntField(_T("lID")) != m_lSkipGroupID)
				{
					nIndex = AddString(csSpaces + q.getStringField(_T("mText")));
					SetItemData(nIndex, q.getIntField(_T("lID")));

					FillCombo(q.getIntField(_T("lID")), lSpaces);
				}

				q.nextRow();
			}
		}
	}		
	CATCH_SQLITE_EXCEPTION	
}
Exemple #28
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();
	}
}
Exemple #29
0
Char::Char(Uint64 serial, Uint16 type, Uint32 dbId, Client& client)
    :IMoveableObject(serial, type),
    myId(dbId),
    myClient(client)
{
	if (dbId != 0) {// The account has a valid character attached.
		
		try{
			CppSQLite3DB accDb;
			accDb.open(DB_ACCOUNTS);

			std::string query = "SELECT * FROM characters WHERE id = \""+boost::lexical_cast< std::string >(myId)+"\";";
			CppSQLite3Query q = accDb.execQuery(query.c_str());

			if (!q.eof()){
				setName(q.fieldValue(2));
				setPosition(Location(q.getIntField(3),q.getIntField(4),q.getIntField(5)));
				mDestPos = mPos; // We set our destination to our actual location.
				// Since everything went fine we add the client to the list of active clients.
				(client.getServer()).addClient(&client); 
			}
			else{
				Logger::getInstance()->log("Error creating Character with ID "+boost::lexical_cast< std::string >(myId) +" no such character in DB!", LOGMODE_DB);
			}

    		accDb.close();
		}
		catch(CppSQLite3Exception e){
			std::string error = "Error creating Character with ID "+boost::lexical_cast< std::string >(myId)+
					", SQLite says: "+ e.errorMessage();
			Logger::getInstance()->log(error, LOGMODE_DB);
			(myClient.getServer()).getConsole().printMsg(error, CONSOLE_ERROR);
		}
	}
	else{ // Create a dummy char
		setName("Dummy");
		setPosition(Location(0,0,0));
		mDestPos = mPos;
		(client.getServer()).addClient(&client); 
	}
}
void BudgetWindow::RefreshBudgetGrid(void)
{
	fIncomeGrid.MakeEmpty();
	fSpendingGrid.MakeEmpty();

	CppSQLite3Query query = gDatabase.DBQuery("select category,amount,period from "
											"budgetlist order by category",
											"BudgetWindow::RefreshCategories");
	while(!query.eof())
	{
		BString cat = DeescapeIllegalCharacters(query.getStringField(0));
		Fixed amount;
		amount.SetPremultiplied(query.getInt64Field(1));
		BudgetPeriod period = (BudgetPeriod)query.getIntField(2);

		ReportGrid *grid = (amount.IsPositive()) ? &fIncomeGrid : &fSpendingGrid;

		int32 index = grid->CountItems();
		grid->AddItem();
		grid->SetRowTitle(index, cat.String());

		Fixed f(amount.AbsoluteValue());
		switch(period)
		{
			case BUDGET_QUARTERLY:
			{
				f /= 3;
				Fixed qamt(amount);
				qamt *= 4;
				grid->SetValue(12,index,qamt);
				break;
			}
			case BUDGET_ANNUALLY:
			{
				f /=12;
				grid->SetValue(12,index,amount);
				break;
			}
			default:
			{
				Fixed mamt(f);
				mamt *= 12;
				grid->SetValue(12,index,mamt);
				break;
			}
		}

		for(int32 i=0; i<12; i++)
			grid->SetValue(i,index,f);

		query.nextRow();
	}
}