Example #1
0
void CParamDB::InsertPKGParam(PARAM_ITEM param)
{
	CppSQLite3DB db;

	try
	{
		if (FileExists(_sFilePath) == true)
		{
			db.open(AnsiString(_sFilePath).c_str());

			String szSQL =
				" insert into RecipeParameter "
				" ( "
				" group_idx, recipe_idx, parameter_idx , value "
				" ) "
				" values "
				" ("
				" '" + IntToStr(param.nGroup_idx) + "', "
				" '" + IntToStr(param.nRecipe_idx) + "', "
				" '" + IntToStr(param.nParameter_idx) + "', "
				" '" + FloatToStr(param.dValue) + "') ";

			db.execDML( "begin transaction;" );
			db.execDML(AnsiString(szSQL).c_str());
			db.execDML( "commit transaction;" );

			db.close();
		}
	}
	catch (Exception &e)
	{
		db.close();
	}
}
Example #2
0
void CParamDB::UpdatePKGParam(PARAM_ITEM param)
{
	CppSQLite3DB db;

	try
	{
		if (FileExists(_sFilePath) == true)
		{
			db.open(AnsiString(_sFilePath).c_str());

			String szSQL = 	" update RecipeParameter "
							" set "
							" Value = '" + FloatToStr(param.dValue) + "'"
							" where group_idx = '" + IntToStr(param.nGroup_idx) + "'"
							" and recipe_idx = '" + IntToStr(param.nRecipe_idx) + "'"
							" and parameter_idx = '" + IntToStr(param.nParameter_idx) + "'";

			db.execDML( "begin transaction;" );
			db.execDML(AnsiString(szSQL).c_str());
			db.execDML( "commit transaction;" );

			db.close();
		}
	}
	catch (Exception &e)
	{
		db.close();
	}
}
Example #3
0
bool CParamDB::DeletePKGParam(int nGroup_no, int nRecipe_no)
{
	CppSQLite3DB db;
	bool bResult = false;

	try
	{
		if (FileExists(_sFilePath) == true)
		{
			db.open(AnsiString(_sFilePath).c_str());

			String szSQL =
				" delete from RecipeParameter "
				" where group_idx = '" + IntToStr(nGroup_no) + "'"
				" and recipe_idx = '" + IntToStr(nRecipe_no) + "'";

			db.execDML( "begin transaction;" );
			bResult = db.execDML(AnsiString(szSQL).c_str());
			db.execDML( "commit transaction;" );

			db.close();

			return bResult;
		}
	}
	catch (Exception &e)
	{
		db.close();
		return false;
	}
}
Example #4
0
//////////////////////////////////////////////////////////////////////////
//  [3/21/2011 DHKim]
//  그룹 테이블 생성 Table( GroupKey PrimaryKey, GroupName TEXT) 
//////////////////////////////////////////////////////////////////////////
int CDbMeter::db_Group_Create(const char* dbfilename)
{
	try
	{
		CppSQLite3DB db;

		db.open(dbfilename);
		db.execDML("CREATE TABLE IF NOT EXISTS groups (GroupKey INTEGER PRIMARY KEY, GroupName TEXT);");
		db.close();
	}
	catch ( CppSQLite3Exception& e )
	{
		return e.errorCode();
	}

	return SQLITE_OK;
	/*
	sqlite3* db = NULL;

	if(sqlite3_open(dbfilename, &db) != SQLITE_OK)
	{
		XDEBUG("SQLite open failed: %s\r\n", sqlite3_errmsg(db));
		return sqlite3_errcode(db);
	}
	if(sqlite3_exec(db, "CREATE TABLE IF NOT EXISTS groups (GroupKey) INTEGER PRIMARY KEY, GroupName TEXT", NULL, NULL, NULL) != SQLITE_OK)
	{
		XDEBUG("SQLite create failed: %s\r\n", sqlite3_errmsg(db));
		return sqlite3_errcode(db);
	}

	sqlite3_close(db);

	return sqlite3_errcode(db);
	*/
}
Example #5
0
void __fastcall TFrmAlarmDetailList::grdErrorDetailSelectCell(TObject *Sender, int ACol,
          int ARow, bool &CanSelect)
{

	TStringGrid* pGrid = ( TStringGrid* )Sender;

    MemoSolution->Clear();
    MemoCause->Clear();

	if(CanSelect = true)
	{
		if(pGrid->Cells[ 1 ][ ARow ] != "" &&
           pGrid->Cells[ 1 ][ ARow ] != "0" )
		{
            AnsiString szQuery = "SELECT * FROM " + g_szDBList[_nTableIndex];

            INT nErrCode = pGrid->Cells[ 1 ][ ARow ].ToInt();

            CppSQLite3DB dbMain;
            dbMain.open( AnsiString( g_MainDBPath ).c_str() );
			CppSQLite3Table tblAlarm = dbMain.getTable( szQuery.c_str() );
			tblAlarm.setRow( nErrCode-1 );

			const char* szCause = tblAlarm.getStringField( "cause", "" );
			const char* szSolution = tblAlarm.getStringField( "solution", "" );

            MemoCause->Lines->Add( szCause );
            MemoSolution->Lines->Add( szSolution );

            dbMain.close();

			pGrid->Refresh();
		}
	}        
}
Example #6
0
char* CreateInfoByid(int id)
{
	static char buffer[1024]={0};
	static char querybuf[1024]={0};
	char* str = "%s  体力%s 武力%s 智力%s 魅力%s 年龄%s 类型 %s";

	memset(querybuf,0,1024);
	try
	{	db.open("database/infodata.db");
		sprintf(querybuf,"select heroinfo.name,ti,wu,zhi,mei,age,herotype.name from "
			" heroinfo,herotype where heroinfo.id=%d and heroinfo.type=herotype.id;",id);
		CppSQLite3Query q = db.execQuery(querybuf);

		//nge_charsets_utf8_to_gbk((uint8*)str, (uint8*)querybuf, strlen(str), 1024);

		if (!q.eof())
	{
		sprintf(buffer,str, q.fieldValue(0),q.fieldValue(1),q.fieldValue(2),q.fieldValue(3),
				q.fieldValue(4),q.fieldValue(5),q.fieldValue(6));
	}
		db.close();
	}catch (CppSQLite3Exception& e){

	printf("%s\n",e.errorMessage());
	}

	return buffer;
}
Example #7
0
// ---------------------------------------------------------------------------
CppSQLite3Table CParamDB::LoadParameter(int nCategory)
{
	CppSQLite3DB db;
	CppSQLite3Table qryTable;

	try
	{
		if (FileExists(_sFilePath) == true)
		{
			db.open(AnsiString(_sFilePath).c_str());

			String szSQL = " select * from Parameter "
						   " where name <> ''"
//							" where category = '" + GetCategory(nCategory) + "'"
//							" or category = '3'"
							" order by idx ";

			qryTable = db.getTable(AnsiString(szSQL).c_str());
		}
	}
	catch (Exception &e)
	{

	}

	db.close();
	return qryTable;
}
Example #8
0
int CDbMeter::JoinTableAdd(const char* dbfilename, char* szID)
{
	try
	{
		CppSQLite3DB db;
		db.open(dbfilename);
		CppSQLite3Buffer bufSQL;
		CppSQLite3Table t;

		db.execDML("CREATE TABLE IF NOT EXISTS jointable (joinkey INTEGER PRIMARY KEY, EUI64ID CHAR(17), jointry INTEGER);");
		bufSQL.format("SELECT * FROM jointable WHERE EUI64ID=%Q", szID);
		t = db.getTable(bufSQL);
		if( t.numRows() == 0 )
		{
			bufSQL.clear();
			bufSQL.format("INSERT INTO jointable(EUI64ID, jointry) VALUES(%Q, %d);", szID, 0);
			db.execDML(bufSQL);
		}
		else
			XDEBUG("Jointable ID Duplicate!!\r\n");

		db.close();
	}
	catch( CppSQLite3Exception& e )
	{
		XDEBUG("%s\r\n",e.errorMessage());
		return e.errorCode();
	}
	return SQLITE_OK;
}
Example #9
0
bool CppSQLite3DB::repair(const CString& strDBFileName, const CString& strRetFileName)
{
	try
	{
		CString strTempFileName = ::WizGlobal()->GetTempPath() + WizIntToStr(GetTickCount()) + _T(".tmp");
		//
		CppSQLite3DB dbSrc;
        dbSrc.open(strDBFileName);
		//
		if (!dbSrc.dump(strTempFileName))
		{
			throw CppSQLite3Exception(-1, "Failed to dump database!");
		}
		//
		dbSrc.close();
		//
        if (PathFileExists(strRetFileName))
		{
            DeleteFile(strRetFileName);
		}
		//
		CppSQLite3DB dbDest;
        dbDest.open(strRetFileName);
		//
		if (!dbDest.read(strTempFileName))
		{
			throw CppSQLite3Exception(-1, "Failed to rebuild database form index!");
		}
		//
		dbDest.close();
		//
#ifdef Q_OS_WIN32
                _flushall();
#endif
		//
		return true;
	}
	catch (CppSQLite3Exception& e)
	{
                TOLOG(e.errorMessage());
		return false;
	}
	//
	return false;
}
Example #10
0
File: Space.cpp Project: GMIS/GMIS
CppSQLite3DB& GetWorldDB(const TCHAR* DB)
{
	static CppSQLite3DB  __World;
	if(DB){
		__World.close();
		tstring DBDir = DB;
		__World.open(DBDir);
	}
	return __World;
}
Example #11
0
int CDbMeter::GroupDelete(const char* dbfilename, int nGroupKey)
{
	try
	{
		CppSQLite3DB db;
		db.open(dbfilename);
		// 그룹테이블에 그룹이름이 있느지 확인
		CppSQLite3Buffer bufSQL;
		//CppSQLite3Query q;
		CppSQLite3Table t;

		bufSQL.format("SELECT GroupKey FROM groups WHERE GroupKey=%d;", nGroupKey);
		t = db.getTable(bufSQL);

		if( t.numRows() == 0 )
		{
			XDEBUG("ERROR: %d GroupKey doesn't exist in Groups Table!!\r\n", nGroupKey);
			return IF4ERR_GROUP_NAME_NOT_EXIST;
		}
		else
		{
			bufSQL.clear();
			bufSQL.format("DELETE FROM groups WHERE GroupKey=%d;", nGroupKey);
			db.execDML(bufSQL);

			XDEBUG("%d GroupKey deleted in Groups Table!!\r\n", nGroupKey);
			//bufSQL.format("SELECT Groups.GroupName FROM groupmember LEFT OUTER JOIN groups ON groupmember.GroupKey=groups.GroupKey LEFT OUTER JOIN member ON groupmember.EUI64ID=member.EUI64ID WHERE groups.GroupName = %s;", szGroupName);
		}

		bufSQL.clear();
		bufSQL.format("SELECT GroupKey FROM groupmember WHERE GroupKey=%d;", nGroupKey);
		t = db.getTable(bufSQL);

		if( t.numRows() == 0 )
		{
			XDEBUG("ERROR: %d GroupKey doesn't exist!! in Groupmember Table!!\r\n", nGroupKey);
			return IF4ERR_GROUP_NAME_NOT_EXIST;
		}
		else
		{
			bufSQL.clear();
			bufSQL.format("DELETE FROM groupmember WHERE GroupKey=%d;", nGroupKey);
			db.execQuery(bufSQL);
			XDEBUG("%d GroupKey deleted in Groupmember Table!!\r\n", nGroupKey);
		}
		db.close();
	}
	catch( CppSQLite3Exception& e )
	{
		XDEBUG("%s\r\n",e.errorMessage());
		return e.errorCode();
	}
	return SQLITE_OK;
}
Example #12
0
//////////////////////////////////////////////////////////////////////////
//  [3/23/2011 DHKim]
//  성공적으로 그룹테이블에 그룹이 추가되면 GroupKey를 리턴한다. 실패시 -1을 리턴
//////////////////////////////////////////////////////////////////////////
int CDbMeter::GroupAdd(const char* dbfilename, char* szGroupName)
{
	int nGroupKey = -1;
	try
	{
		CppSQLite3DB db;
		db.open(dbfilename);
		CppSQLite3Buffer bufSQL;
		CppSQLite3Table t;

		bufSQL.format("INSERT INTO groups(GroupName) VALUES(%Q);", szGroupName);
		db.execDML(bufSQL);
		XDEBUG("Success: INSERT Command!!\r\n");

		bufSQL.clear();
		bufSQL.format("SELECT GroupKey FROM groups WHERE GroupName=%Q;", szGroupName);
		//CppSQLite3Query q = db.execQuery(bufSQL);
		t = db.getTable(bufSQL);
		
		if( t.numRows() == 0 )
		{
			XDEBUG("Failure: SELECT Command!!\r\n");
			return nGroupKey;
		}
		else
		{
			// 동일 이름시 마지막에 추가된 그룹 키를 리턴한다.
			int nFinalRow = t.numRows() - 1;
			t.setRow(nFinalRow);
			if( !t.fieldIsNull(nFinalRow) )
				nGroupKey = atoi(t.fieldValue(nFinalRow));
			else
			{
				XDEBUG("Error: GroupKey is NULL!!\r\n");
				return nGroupKey;
			}
			XDEBUG("Success: SELECT Command!!\r\n");
		}

		//nGroupKey = q.getIntField("GroupKey", -1);
		
		db.close();
	}
	catch( CppSQLite3Exception& e )
	{
		XDEBUG("%s\r\n",e.errorMessage());
		return -1;
	}

	return nGroupKey;
}
Example #13
0
void	TfrmUseSkipViewer::LoadUseSkipNameFromDB()
{       
    CppSQLite3DB db;
	String szSelectQuery = "SELECT * FROM UseSkip";

	try
	{
		if( FileExists( g_MainDBPath ) == true )
		{
            db.open( AnsiString( g_MainDBPath ).c_str() );

            CppSQLite3Table table = db.getTable( AnsiString( szSelectQuery ).c_str() );

            if( table.numRows() != 0 )
            {
                for( int row = 0; row < table.numRows(); row++ )
                {
                    table.setRow( row );
                    String szName = table.getStringField( "name", "NULL" );
                    
                    if( szName == "NULL" || szName == "" )
                    {
                        szName = "UseSkip" + IntToStr( row );
                    }
                    
                    ComboBoxUseSkip->AddItem( szName, NULL );
                }
    		}
            db.close();
		}
	}
	catch(Exception &e)
	{
		db.close();
		ShowMessage("Use Skip DB select error! : " + e.Message);
	}       
}
Example #14
0
bool AppDelegate::applicationDidFinishLaunching() {
    // initialize director
    CCDirector* pDirector = CCDirector::sharedDirector();
    CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();

    pDirector->setOpenGLView(pEGLView);
	
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(960, 640, kResolutionShowAll);
    
    // turn on display FPS
    pDirector->setDisplayStats(false);

    // set FPS. the default value is 1.0/60 if you don't call this
    pDirector->setAnimationInterval(1.0 / 60);

    //将数据库复制到可写目录
    string dbSrc = CCFileUtils::sharedFileUtils()->fullPathForFilename(GAME_SYS_DB);
    string dbDes = CCFileUtils::sharedFileUtils()->getWritablePath();
    dbDes.append(GAME_SYS_DB);
    
    if(!OzgFileUtility::fileExists(dbDes))
        OzgFileUtility::copyFile(dbSrc.c_str(), dbDes.c_str());
    CCLog("%s", dbDes.c_str());
    
    //记录检查,如果没有记录则生成
    CppSQLite3DB db;
    db.open(dbDes.c_str());
    
    CppSQLite3Query query = db.execQuery("select count(id) from save_data");
    //    CCLog("%i", query.getIntField(0));
    if(query.getIntField(0) == 0)
        db.execDML(GAME_INIT_SQL);
    
    query.finalize();
    db.close();
    
    //初始化背景音乐和效果音的默认大小值
    SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(CCUserDefault::sharedUserDefault()->getFloatForKey(GAME_BG_AUDIO_VOLUME, 1.0));
    SimpleAudioEngine::sharedEngine()->setEffectsVolume(CCUserDefault::sharedUserDefault()->getFloatForKey(GAME_EFFECT_AUDIO_VOLUME, 1.0));
    
    // create a scene. it's an autorelease object
    CCScene *pScene = RPGStartSceneLayer::scene();

    // run
    pDirector->runWithScene(pScene);

    return true;
}
Example #15
0
int CDbMeter::GroupAddMember(const char* dbfilename, int nGroupKey, char* szMemberId)
{
	try
	{
		CppSQLite3DB db;
		db.open(dbfilename);
		CppSQLite3Buffer bufSQL;
		CppSQLite3Query q;
		CppSQLite3Table t;
		int nFindgroupkey = -1;

		bufSQL.format("SELECT EUI64ID FROM member WHERE EUI64ID=%Q;", szMemberId);
		t = db.getTable(bufSQL);
	
		if( t.numRows() == 0 )
		{
			bufSQL.clear();
			bufSQL.format("INSERT INTO member VALUES(%Q, 'Meter', 'none', '1.0.0', '1.0.0', 'Nomal', 'None');", szMemberId);
			db.execDML(bufSQL);
		}

		bufSQL.clear();
		bufSQL.format("SELECT * FROM groups WHERE GroupKey=%d;", nGroupKey);
		t = db.getTable(bufSQL);
		if( t.numRows() == 1)
			nFindgroupkey = atoi(t.fieldValue(0));
		else
			nFindgroupkey = -1;

		if( nFindgroupkey >= -1)
		{
			bufSQL.clear();
			bufSQL.format("INSERT INTO groupmember(EUI64ID, GroupKey) VALUES(%Q, %d);", szMemberId, nGroupKey);
			db.execDML(bufSQL);
		}

		db.close();
	}
	catch( CppSQLite3Exception& e )
	{
		XDEBUG("%s\r\n",e.errorMessage());
		return -1;
	}

	return SQLITE_OK;
}
Example #16
0
void CDlgEventList::ShowPage(int nPageIndex)
{
	CString str;
	int i = 0;
	int nStartIndex = 0;
	int nOffset = 0;

	CppSQLite3DB db;
	db.open(PATH_SQLITE_DB_808);	//打开数据库
	
	//查询记录总数量
	m_nRecordCount = db.execScalar("SELECT count(*) FROM event_info;");
	//计算总页数
	if(m_nRecordCount > 0)
		m_nPageCount = (m_nRecordCount-1)/elist_count+1;
	else
		m_nPageCount = 1;

	//在数据库中查询第nPageIndex页的elist_count条数据
	char szSqlBuffer[512];
	sprintf(szSqlBuffer, "SELECT * FROM event_info ORDER BY event_ID DESC LIMIT %d, %d;", nPageIndex*elist_count, elist_count);
	CppSQLite3Query q = db.execQuery(szSqlBuffer);

	for( i = 0; i < elist_count; i++ )
	{
		if ( !q.eof() )	//数据行
		{
			m_nEvent_ID[i]		= q.getIntField("event_ID");
			m_list[i].chChar	= q.fieldValue("event_content");
			m_list[i].nState	= BTN_STATE_NORMAL;
			q.nextRow();
		}
		else			//空白行
		{
			m_ItemState[i]		= 0;
			m_list[i].chChar	= _T("");
			m_list[i].nState	= BTN_STATE_DISABLE;
		}
	}
	//释放statement
	q.finalize();

	db.close();	//关闭数据库
	return;
}
Example #17
0
void CPhoneLog::OnBtnDelLogState(int state) 
{
	m_ObArrary = NULL;
	m_Pos = 0;
	m_CurPage = 1;
	m_TotalPage = 0;
	UINT Tag = 0;
	//PhoneLogMng::Instance().DelLPhoneLogState(state);
	CppSQLite3DB db;
	db.open(PATH_SQLITE_DB_808);	//打开数据库

	char szSqlBuffer[512];
	memset(szSqlBuffer, 0, sizeof(szSqlBuffer));
	
	switch(enLog)
	{
	case PLACEDCALL:
		{
			Tag = 1;
			sprintf(szSqlBuffer, "DELETE FROM phone_log WHERE flag = '%d';", Tag);
			db.execDML(szSqlBuffer);
		}
		break;
	case RECEIVEDCALL:
		{
			Tag = 2;
			sprintf(szSqlBuffer, "DELETE FROM phone_log WHERE flag = '%d';", Tag);
			db.execDML(szSqlBuffer);
		}
		break;
	case MISSEDCALL:
		{
			Tag = 3;
			sprintf(szSqlBuffer, "DELETE FROM phone_log WHERE flag = '%d';", Tag);
			db.execDML(szSqlBuffer);
		}
		break;
	default:
		break;
	}
	
	db.close();

	PostMessage(WM_ACTIVATE);
}
Example #18
0
int GetInfoCount()
{
	int count = 0;
	try
	{	db.open("database/infodata.db");
		CppSQLite3Query q = db.execQuery("select count(*) from heroinfo;");
		if (!q.eof())
	{
		 count = atoi(q.fieldValue(0));

	}
		db.close();
	}catch (CppSQLite3Exception& e){

	printf("%s\n",e.errorMessage());
	}
	return count;
}
Example #19
0
void Char::save(){
    Uint16 x,y,z;
    Location& loc = getPosition();
    loc.getXYZ(x,y,z);
    try{
        CppSQLite3DB accDb;
        accDb.open(DB_ACCOUNTS);
        std::string query = "UPDATE characters SET name=\""+getName() +"\", x_position="+ boost::lexical_cast< std::string >(x)+", y_position="+ boost::lexical_cast< std::string >(y)+", z_position="+ boost::lexical_cast< std::string >(z)+" WHERE id="+ boost::lexical_cast< std::string >(myId)+";";
        accDb.execQuery(query.c_str());
        accDb.close();
    }
    catch(CppSQLite3Exception e){
        std::string error = "Error saving 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);
    }
}
Example #20
0
void CDlgEventList::ChangeReadStatus()
{
	CppSQLite3DB db;
	db.open(PATH_SQLITE_DB_808);	//打开数据库
	int nUnReadSMS = 0;	//未读短信数量
	const char* pszSQL;
	//查询中心信息未读短信总数量
	pszSQL = "select count(*) from text_info where read_status = 0;";
	nUnReadSMS = db.execScalar(pszSQL);
	if(nUnReadSMS > 0)
	{
		//更新状态:未读->已读
		pszSQL = "update text_info set read_status = 1;";
        db.execDML(pszSQL);
	}
	db.close();
	m_bSMSCenter = FALSE;//将新信息提示关闭
}
Example #21
0
CppSQLite3Table CParamDB::LoadPKGParamList(int nGroup_no, int nRecipe_no,
	INT nCategory, int nParam_no, bool bFindCategory, bool bFindParameter)
{
	CppSQLite3DB db;
	CppSQLite3Table qryTable;

	try
	{
		if (FileExists(_sFilePath) == true)
		{
			db.open(AnsiString(_sFilePath).c_str());

			String szSQL =
				" select * from RecipeParameter rp "
				" left outer join Parameter p "
				" 	on rp.Parameter_idx = p.idx "
				" where group_idx = '" + IntToStr(nGroup_no) + "'"
				" and recipe_idx = '" + IntToStr(nRecipe_no) + "'";

//			if (bFindCategory == true)
//			{
//				szSQL = szSQL + " and (p.category = '" + GetCategory(nCategory)
//					+ "'" " or p.category = '3')";
//			}

			if (bFindParameter == true)
			{
				szSQL = szSQL + " and Parameter_idx = '" + IntToStr(nParam_no) + "'";
			}
			szSQL = szSQL + " order by rp.Parameter_idx";

			qryTable = db.getTable(AnsiString(szSQL).c_str());

		}
	}
	catch (Exception &e)
	{

	}

	db.close();
	return qryTable;
}
Example #22
0
BOOL PhoneLogMng::AddLog( CDialLog* pPhone)
{
	m_ObArr.InsertAt(0,pPhone);
	m_Cnt++;

	char szphonenum[200];
	memset(szphonenum,0,sizeof(szphonenum));
	WideCharToMultiByte(CP_ACP,NULL, pPhone->m_csNum, -1,szphonenum, sizeof(szphonenum), NULL,FALSE );

	char szSql[512];
	CppSQLite3DB db;
	db.open(PATH_SQLITE_DB_808);	//´ò¿ªÊý¾Ý¿â
	sprintf(szSql, "INSERT INTO phone_log(flag,phone_number) VALUES(%d, %s);", 
		pPhone->m_iLogFlag, szphonenum);

	db.execDML(szSql);
	db.close();

	return TRUE;
}
Example #23
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); 
	}
}
Example #24
0
int CDbMeter::GroupTableDelete(const char* dbfilename, char* szTablekind)
{
	try
	{
		CppSQLite3DB db;
		db.open(dbfilename);
		CppSQLite3Buffer bufSQL;
		CppSQLite3Table t;

		bufSQL.format("DELETE FROM %Q", szTablekind);

		/*
		switch(szTablekind)
		{
		case 1:
			bufSQL.format("DELETE FROM groups;");
			break;
		case 2:
			bufSQL.format("DELETE FROM member;");
			break;
		case 3:
			bufSQL.format("DELETE FROM groupmember;");
			break;
		case 4:
			bufSQL.format("DELETE FROM command;");
			break;
		}
		*/
		db.execDML(bufSQL);

		db.close();
	}
	catch( CppSQLite3Exception& e )
	{
		XDEBUG("%s\r\n",e.errorMessage());
		return e.errorCode();
	}
	return SQLITE_OK;
}
Example #25
0
int CDbMeter::db_Table_Check(const char* dbfilename)
{
	try
	{
		CppSQLite3DB db;

		db.open(dbfilename);
		// Group Tables
		db.execDML("CREATE TABLE IF NOT EXISTS groups (GroupKey INTEGER PRIMARY KEY, GroupName TEXT);");
		db.execDML("CREATE TABLE IF NOT EXISTS member(EUI64ID CHAR(16) PRIMARY KEY, Model TEXT, MeterSerial TEXT, HWver CHAR(10), SWver CHAR(10), SensorState CHAR(10), NetworkPathInfo TEXT);");
		db.execDML("CREATE TABLE IF NOT EXISTS groupmember(GroupKey INTEGER, EUI64ID CHAR(16), FOREIGN KEY(GroupKey) REFERENCES groups(GroupKey), FOREIGN KEY(EUI64ID) REFERENCES member(EUI64ID));");
		db.execDML("CREATE TABLE IF NOT EXISTS command(CommandKey INTEGER PRIMARY KEY, GroupKey INTEGER, EUI64ID CHAR(16), GroupName TEXT, CommandState INTEGER, Command TEXT, CommandCreateTime TEXT, CommandExecuteTime TEXT, ResultErrorCode INTEGER, ParamPathInfo TEXT, FOREIGN KEY(GroupKey) REFERENCES groups(GroupKey), FOREIGN KEY(EUI64ID) REFERENCES member(EUI64ID));");
		db.close();
	}
	catch ( CppSQLite3Exception& e )
	{
		XDEBUG("ERROR: %s\r\n",e.errorMessage());
		return e.errorCode();
	}

	return SQLITE_OK;
}
Example #26
0
void  CDlgAnswerList::OnBtnDelAll()
{
	CResString str;
	str.LoadString( RES_BUTTON_DELETE_ALL );
	
	CDlgConfirm::m_stTitle = str;
	CDlgConfirm dlg;
	dlg.DoModal();
	
	if( CDlgConfirm::s_bOk )
	{
		CppSQLite3DB db;
		db.open(PATH_SQLITE_DB_808);
		db.execDML( "DELETE FROM answer;" );
		db.close();

		m_nPageIndex	= 0;
		m_nPageCount	= 1;
		m_nRecordCount	= 0;

		ShowPage( m_nPageIndex );
	}
}
Example #27
0
int CDbMeter::GroupDeleteMember(const char* dbfilename, int nGroupKey, char* szMemberId)
{
	try
	{
		CppSQLite3DB db;
		db.open(dbfilename);
		CppSQLite3Buffer bufSQL;
		//CppSQLite3Query q;
		CppSQLite3Table t;

		bufSQL.format("SELECT * FROM groupmember WHERE GroupKey=%d AND EUI64ID=%Q;", nGroupKey, szMemberId);
		//q = db.execQuery(bufSQL);
		t = db.getTable(bufSQL);

		if( t.numRows() == 0 )
		{
			XDEBUG("ERROR: %s EUI64ID doesn't exist in %d Groupkey Table!!\r\n", szMemberId, nGroupKey);
			return IF4ERR_GROUP_NAME_NOT_EXIST;
		}
		else
		{
			bufSQL.clear();
			bufSQL.format("DELETE FROM groupmember WHERE GroupKey=%d AND EUI64ID=%Q;", nGroupKey, szMemberId);
			db.execQuery(bufSQL);
			XDEBUG("%s Groupmember of %d GroupKey deleted in Groupmember Table!!\r\n", szMemberId, nGroupKey);
		}
		db.close();
	}
	catch( CppSQLite3Exception& e )
	{
		XDEBUG("%s\r\n",e.errorMessage());
		return e.errorCode();
	}

	return SQLITE_OK;
}
Example #28
0
status_t
LoadRules(const char *path, BObjectList<FilerRule> *ruleList)
{
	BEntry entry("/boot/home/config/settings/FilerRules");
	if (!entry.Exists())
		return B_OK;
	
	CppSQLite3DB db;
	db.open("/boot/home/config/settings/FilerRules");
	
	// Because this particular build of sqlite3 does not support multithreading
	// because of lack of pthreads support, we need to do this in a slightly different order
	
	CppSQLite3Query query;
	query = DBQuery(db,"select name from RuleList order by ruleid;","PrefsWindow::LoadRules");
	
	BString command;
	while (!query.eof())
	{
		BString rulename = query.getStringField((int)0);
		
		FilerRule *rule = new FilerRule;
		rule->SetDescription(DeescapeIllegalCharacters(rulename.String()).String());
		
		ruleList->AddItem(rule);
		
		query.nextRow();
	}
	
	query.finalize();
	
	for (int32 i = 0; i < ruleList->CountItems(); i++)
	{
		FilerRule *rule = ruleList->ItemAt(i);
		
		if (!rule)
			continue;
		
		BString rulename(EscapeIllegalCharacters(rule->GetDescription()));
		
		// Now comes the fun(?) part: loading the tests and actions. Joy. :/
		command = "select * from ";
		command << rulename << " where entrytype = 'test';";
		query = DBQuery(db,command.String(),"PrefsWindow::LoadRules");
		
		while (!query.eof())
		{
			BString classname = DeescapeIllegalCharacters(query.getStringField(1));
			BMessage *test = new BMessage;
			
			test->AddString("name",classname);
			
			if (classname.ICompare("Attribute") == 0)
			{
				test->AddString("mimetype",DeescapeIllegalCharacters(query.getStringField(4)));
				test->AddString("typename",DeescapeIllegalCharacters(query.getStringField(5)));
				test->AddString("attrname",DeescapeIllegalCharacters(query.getStringField(6)));
			}
			
			test->AddString("mode",DeescapeIllegalCharacters(query.getStringField(2)).String());
			test->AddString("value",DeescapeIllegalCharacters(query.getStringField(3)).String());
			
			rule->AddTest(test);
			
			query.nextRow();
		}
		query.finalize();
		
		command = "select * from ";
		command << rulename << " where entrytype = 'action';";
		query = DBQuery(db,command.String(),"PrefsWindow::LoadRules");
		
		while (!query.eof())
		{
			BMessage *action = new BMessage;
			
			action->AddString("name",DeescapeIllegalCharacters(query.getStringField(1)));
			action->AddString("value",DeescapeIllegalCharacters(query.getStringField(3)));
			
			rule->AddAction(action);
			
			query.nextRow();
		}
		query.finalize();
		
	}
	
	db.close();
	return B_OK;
}
Example #29
0
void    CDlgAnswerList::ShowPage(int nPageIndex)
{
	CString str = _T("");
	int i = 0;
	int nStartIndex = 0;
	int nOffset = 0;
	
	CppSQLite3Table t;
	CppSQLite3Query q;
	CppSQLite3DB db;
	db.open(PATH_SQLITE_DB_808);	//打开数据库
	char szSqlBuffer[1024];
	memset(szSqlBuffer, 0, sizeof(szSqlBuffer));
	//查询记录总数量
// 	sprintf(szSqlBuffer, "SELECT COUNT(*) FROM answer \
// 						 WHERE UID IN (SELECT UID FROM question ORDER BY question_datatime DESC LIMIT %d, 1) \
// 						 ORDER BY answer_ID;", 
// 						 m_nQuestionIndex);
// 	m_nRecordCount = db.execScalar( szSqlBuffer );

	sprintf(szSqlBuffer, "SELECT * FROM answer where UID = '%d';", m_nQuestionIndex);
	t = db.getTable(szSqlBuffer);
	m_nRecordCount = t.numRows();
	
	//计算总页数
	if(m_nRecordCount > 0)
		m_nPageCount = (m_nRecordCount-1)/elist_count+1;
	else
		m_nPageCount = 1;

	memset(szSqlBuffer, 0, sizeof(szSqlBuffer));
	sprintf(szSqlBuffer, "SELECT * FROM question where UID = '%d';", m_nQuestionIndex);
	q = db.execQuery(szSqlBuffer);
	int nFlag = q.getIntField("flag");
	const char* ccText = q.fieldValue("question_content");
	str = ccText;

	//在数据库中查询第nPageIndex页的elist_count条数据
// 	sprintf(szSqlBuffer, "SELECT * FROM answer \
// 						 WHERE UID IN (SELECT UID FROM question ORDER BY question_datatime DESC LIMIT %d, 1) \
// 						 ORDER BY answer_ID LIMIT %d, %d;", 
// 						 m_nQuestionIndex, nPageIndex*elist_count, elist_count);
// 	q = db.execQuery(szSqlBuffer);

	memset(szSqlBuffer, 0, sizeof(szSqlBuffer));
	sprintf(szSqlBuffer, "SELECT * FROM answer where UID = '%d' LIMIT %d, %d;", 
				m_nQuestionIndex, (nPageIndex)*elist_count, elist_count);
	q = db.execQuery(szSqlBuffer);

	for( i = 0; i < elist_count; i++ )
	{
		if ( !q.eof() )	//数据行
		{
			m_nAnswerID[i]		= q.getIntField("answer_ID");
			m_list[i].chChar	= q.fieldValue("answer_content");
			m_list[i].nState	= BTN_STATE_NORMAL;
			q.nextRow();
		}
		else			//空白行
		{
			m_ItemState[i]		= 0;
			m_list[i].chChar	= _T("");
			m_list[i].nState	= BTN_STATE_DISABLE;
		}
	}
	//释放statement
	q.finalize();
	db.close();	//关闭数据库

	if(nFlag)
		TTSSpeaking( str );

	return;
}
void EventDataManager::readDB()
{
    string strFullPath = CCFileUtils::sharedFileUtils()->fullPathFromRelativePath("config/luckycat.sqlite");
    CppSQLite3DB db;
    db.open(strFullPath.c_str());
	if (!db.isOpen())
	{
		return;
	}
    
//    CppSQLite3Query result = db.execQuery("select * from dict_event;");
//    
//    std::vector<stEvent *> tEventVector;
//	while(!result.eof())
//	{
//        stEvent *tEvent = new stEvent();
//        tEvent->id = result.getIntField("id");
//        tEvent->type = (LEventType)result.getIntField("type");
//        tEvent->targetId = atoi(result.getStringField("target"));
//        std::string strBonus = result.getStringField("bonus");
//        std::vector<int> tmpBonusList = separateStringToNumberVector(strBonus, ",");
//        
//        if (tmpBonusList.size() > 0)
//            CCAssert( tmpBonusList[0]*2 == tmpBonusList.size()-1, "Something error in sql field\n");
//        for (int i = 1; tmpBonusList[0] != 0 && i+1 < tmpBonusList.size(); i+=2) {
//            stGood _good;
//            _good.id = tmpBonusList[i];
//            _good.count = tmpBonusList[i+1];
//            tEvent->bonus.push_back(_good);
//        }
//        
//        tEvent->bonusRepeat = result.getIntField("bonus_repeat");
//        tEvent->nextEventId = result.getIntField("next_event_id");
//        tEvent->box_id = result.getIntField("box_id");
//        
//        tEventVector.push_back(tEvent);
//        
//        result.nextRow();
//    }
//    
//    this->setEventMap(tEventVector);
    
    CppSQLite3Query result_1 = db.execQuery("select * from dict_npc_talk;");
    
    std::vector<stTalk *> tTalkVector;
	while(!result_1.eof())
	{
        stTalk *tTalk = new stTalk();
        tTalk->id = result_1.getIntField("id");
        tTalk->eventId = result_1.getIntField("event_id");
        std::string _dialog= result_1.getStringField("content");
        
        tTalk->dialogList = separateString(_dialog,"||");
        
        tTalk->npcId = result_1.getIntField("npc_id");
        tTalk->npcName = result_1.getStringField("npc_name");
        
        tTalkVector.push_back(tTalk);
        
        result_1.nextRow();
    }
    this->setTalkMap(tTalkVector);
    
    db.close();
}