Exemplo n.º 1
0
 virtual void* Main(void) {
     //for (int i = 0; i < 10; ++i) {
     for (;;) {
         try {
             CDatabase db("MSDEV");
             db.Connect();
             CQuery q = db.NewQuery("select serverproperty('servername')");
             q.Execute();
             LOG_POST("Thread " << m_Num << " connected to " << q.begin()[1].AsString());
             try {
                 q.SetSql("drop table #t");
                 q.Execute();
             }
             catch (CSDB_Exception&) {
                 //
             }
             q.SetSql("create table #t (tt varchar(100))");
             q.Execute();
             q.SetSql("insert into #t values (@tt)");
             for (int i = 0; i < 500; ++i) {
                 q.SetParameter("@tt", i, eSDB_String);
                 q.Execute();
             }
             SleepMilliSec(100);
         }
         catch (CSDB_Exception& ex) {
             LOG_POST("Error from SDBAPI in thread " << m_Num << ": " << ex);
         }
     }
     return NULL;
 }
void CAccountTimeLimitDBCtrl::Handler( LPDB_OVERLAPPED_PLUS pov, DWORD dwCompletionKey )
{
	CAr ar( pov->lpBuf, pov->uBufSize );

	switch( pov->nQueryMode )
	{
		case QUERY_TIMELIMIT_LOAD:
		{
			DWORD	dwPlayerId; 
			int		nPlayTime = -1;
			char	szAccount[MAX_ACCOUNT];

			ar >> dwPlayerId;
			ar.ReadString( szAccount, MAX_ACCOUNT );
			
			CQuery* pQuery = GetQueryObject();
			if( pQuery->Execute( "USP_AccountPlay_Select '%s'", szAccount ) )
			{
				if( pQuery->Fetch() )
				{
					nPlayTime = pQuery->GetInt( "PlayTime" ) * SEC( 1 );	// 초단위를 ms단위로 변환
					DWORD dwLastPlayDate	= static_cast<DWORD>( pQuery->GetInt( "PlayDate" ) );
					int nYear = dwLastPlayDate/10000;	dwLastPlayDate%=10000;
					int nMonth = dwLastPlayDate/100;	dwLastPlayDate%=100;
					int nDay = dwLastPlayDate;
					CTime time( nYear, nMonth, nDay+1, 0, 0, 0 );	// 하루를 더한 값이 더 작으면 초기화..
					if( time < CTime::GetCurrentTime() )
						nPlayTime = 0;
					
					if( !prj.m_EventLua.IsTimeLimit() )		// 루아이벤트 스크립트에 베트남 제한 여부 설정
						nPlayTime = 0;
				}
			}

			if( nPlayTime < 0 )
				Error( "PlayTime is wrong - PlayerId : %d, PlayTime : %d", dwPlayerId, nPlayTime );
			CDPTrans::GetInstance()->SendTimeLimitAck( dwPlayerId, nPlayTime, dwCompletionKey );
		}
		break;

		case QUERY_TIMELIMIT_UPDATE:
		{
			char	szAccount[MAX_ACCOUNT];
			int		nPlayTime;

			ar.ReadString( szAccount, MAX_ACCOUNT );
			ar >> nPlayTime;
			nPlayTime /= SEC( 1 );	// ms 단위를 초단위로 변환

			CTime time = CTime::GetCurrentTime();
			DWORD dwLastDate = (time.GetYear()*10000) + (time.GetMonth()*100) + time.GetDay();
			
			GetQueryObject()->Execute( "USP_AccountPlay_Update '%s', %d, %d", szAccount, dwLastDate, nPlayTime );
		}
		break;
	}
}
Exemplo n.º 3
0
BOOL CCoupleController::Restore()
{
	CQuery* pQuery	= CreateQuery();
	if( !pQuery )
		return FALSE;
	if( !pQuery->Execute( "uspRestoreCouple %d", g_appInfo.dwSys ) )
	{
		Error( "couldn't execute uspRestoreCouple" );
		return FALSE;
	}
	while( pQuery->Fetch() )
	{
		int nExperience	= pQuery->GetInt( "nExperience" );
		u_long idFirst	= pQuery->GetInt( "idFirst" );
		u_long idSecond	= pQuery->GetInt( "idSecond" );
		CCouple* pCouple	= new CCouple( idFirst, idSecond );
		m_pHelper->Couple( pCouple );
		pCouple->AddExperience( nExperience );
	}

	pQuery->Clear();
	if( !pQuery->Execute( "uspRestorePropose %d", g_appInfo.dwSys ) )
	{
		Error( "couldn't execute uspRestorePropose" );
		return FALSE;
	}
	while( pQuery->Fetch() )
	{
		u_long idProposer	= pQuery->GetInt( "idProposer" );
		time_t tPropose	= pQuery->GetInt( "tPropose" );
		bool bResult	= m_pHelper->AddPropose( idProposer, tPropose );
		ASSERT( bResult );
	}
	
	SAFE_DELETE( pQuery );
	return FALSE;
}
Exemplo n.º 4
0
void CHousingDBCtrl::LoadHousingInfo( DWORD dwPlayerId, DPID dpId )
{
    CHousing* pHousing = CHousingMng::GetInstance()->GetHousing( dwPlayerId );
    if( !pHousing )
    {
        pHousing = CHousingMng::GetInstance()->CreateHousing( dwPlayerId );
        if( !pHousing )	// 생성 실패시 그냥 리턴..
            return;

        // DB 로딩...
        CQuery* pQuery = GetQueryObject();
        if( pQuery->Execute( "usp_Housing_Load '%02d', '%07d'", g_appInfo.dwSys, dwPlayerId ) )
        {
            while( pQuery->Fetch() )
            {
                HOUSINGINFO housingInfo;
                housingInfo.dwItemId = static_cast<DWORD>( pQuery->GetInt( "ItemIndex" ) );
                housingInfo.tKeepTime = static_cast<time_t>( pQuery->GetInt64( "tKeepTime" ) );
                housingInfo.bSetup = static_cast<BOOL>( pQuery->GetInt( "bSetup" ) );
                housingInfo.vPos.x = pQuery->GetFloat( "x_Pos" );
                housingInfo.vPos.y = pQuery->GetFloat( "y_Pos" );
                housingInfo.vPos.z = pQuery->GetFloat( "z_Pos" );
                housingInfo.fAngle = pQuery->GetFloat( "fAngle" );

                ItemProp* pItemProp = prj.GetItemProp( housingInfo.dwItemId );
                if( pItemProp && pItemProp->dwItemKind1 == IK1_HOUSING )
                    pHousing->SetFurnitureList( housingInfo, TRUE );
            }

            if( pQuery->MoreResults() )
            {
                while( pQuery->Fetch() )
                    pHousing->SetVisitAllow( pQuery->GetInt( "f_idPlayer" ), TRUE );
            }
        }
    }

    // 하우징 정보를 월드서버에 전달...
    CDPTrans::GetInstance()->SendHousingLoadInfo( dwPlayerId, pHousing, dpId );
}
void CGuildHouseDBCtrl::CreateGuildHouse( CAr & ar, DPID dpId )
{
	DWORD dwPlayerId, dwGuildId;
	ar >> dwPlayerId >> dwGuildId;
	
	BOOL bResult = FALSE;
	CQuery* pQuery = GetQueryObject();

	BEFORESENDDUAL( arCreate, PACKETTYPE_GUILDHOUSE_BUY, DPID_UNKNOWN, DPID_UNKNOWN );
	{
		arCreate << dwPlayerId << dwGuildId;
		CGuildHouseBase* pGuildHouse = GuildHouseMng->MakeGuildHouse( dwGuildId, WI_GUILDHOUSE_SMALL );
		if( pGuildHouse )
		{
			pGuildHouse->SetUpkeeptime( time_null() + ( UPKEEP_DAY_TIME * 7 ) );	// 기본 유지기간을 제공한다.
			if( pQuery->Execute( "usp_GuildHouse_Insert '%02d', '%06d', %d, %d", g_appInfo.dwSys, dwGuildId, WI_GUILDHOUSE_SMALL, pGuildHouse->GetUpkeepTime() ) // DB에 추가 성공
				&& GuildHouseMng->AddGuildHouse( dwGuildId, pGuildHouse ) )
			{
				arCreate << TRUE;
				dpId = DPID_ALLPLAYERS;	// 모든 월드 서버로 전송한다.
				GH_Fntr_Info gfi( II_GHOU_FUR_NPC_TELEPORTER, TRUE, pGuildHouse->GetTeleporterPos(), 0.0f, ( UPKEEP_DAY_TIME * 7 ) );
				if( ExcuteQuery( dwGuildId, pGuildHouse, GUILDHOUSE_PCKTTYPE_LISTUP, gfi, NULL_ID ) )
					pGuildHouse->OnGuildHousePacket( GUILDHOUSE_PCKTTYPE_LISTUP, gfi, NULL_ID );
				pGuildHouse->SerializeAllInfo( arCreate );
			}
			else
			{
				arCreate << FALSE;
				SAFE_DELETE( pGuildHouse );
			}
		}
		else
			arCreate << FALSE;
	}
	SEND( arCreate, CDPTrans::GetInstance(), dpId );
}
Exemplo n.º 6
0
BEGIN_NCBI_SCOPE

///////////////////////////////////////////////////////////////////////////////
BOOST_AUTO_TEST_CASE(Test_DateTime)
{
    string sql;
    CQuery query = GetDatabase().NewQuery();
    CTime t;
    CTime dt_value;

    try {
        if (true) {
            // Initialization ...
            {
                sql =
                    "CREATE TABLE #test_datetime ( \n"
                    "   id INT, \n"
                    "   dt_field DATETIME NULL \n"
                    ") \n";

                query.SetSql( sql );
                query.Execute();
                query.RequireRowCount(0);
                BOOST_CHECK_NO_THROW(query.VerifyDone(CQuery::eAllResultSets));
            }

            {
                // Initialization ...
                {
                    sql = "INSERT INTO #test_datetime(id, dt_field) "
                          "VALUES(1, GETDATE() )";

                    query.SetSql( sql );
                    query.Execute();
                    query.RequireRowCount(0);
                    BOOST_CHECK_NO_THROW(query.VerifyDone(CQuery::eAllResultSets));
                }

                // Retrieve data ...
                {
                    sql = "SELECT * FROM #test_datetime";

                    query.SetSql( sql );
                    query.Execute();
                    query.RequireRowCount(1);
                    BOOST_CHECK( query.HasMoreResultSets() );
                    CQuery::iterator it = query.begin();
                    BOOST_CHECK( it != query.end() );
                    BOOST_CHECK( !it[2].IsNull());
                    dt_value = it[2].AsDateTime();
                    BOOST_CHECK( !dt_value.IsEmpty() );
                    BOOST_CHECK_NO_THROW(query.VerifyDone(CQuery::eAllResultSets));
                }

                // Insert data using parameters ...
                {
                    query.SetSql( "DELETE FROM #test_datetime" );
                    query.Execute();
                    query.RequireRowCount(0);
                    BOOST_CHECK_NO_THROW(query.VerifyDone(CQuery::eAllResultSets));

                    query.SetParameter( "@dt_val", dt_value );

                    sql = "INSERT INTO #test_datetime(id, dt_field) "
                          "VALUES(1, @dt_val)";

                    query.SetSql( sql );
                    query.Execute();
                    query.RequireRowCount(0);
                    BOOST_CHECK_NO_THROW(query.VerifyDone(CQuery::eAllResultSets));
                }

                // Retrieve data again ...
                {
                    sql = "SELECT * FROM #test_datetime";

                    // ClearParamList is necessary here ...
                    query.ClearParameters();
                    query.SetSql( sql );
                    query.Execute();
                    query.RequireRowCount(1);
                    BOOST_CHECK( query.HasMoreResultSets() );
                    CQuery::iterator it = query.begin();
                    BOOST_CHECK( it != query.end() );
                    BOOST_CHECK( !it[2].IsNull());
                    CTime dt_value2 = it[2].AsDateTime();
                    BOOST_CHECK_EQUAL( dt_value.AsString(), dt_value2.AsString() );
                    BOOST_CHECK_NO_THROW(query.VerifyDone(CQuery::eAllResultSets));
                }

                // Insert NULL data using parameters ...
                {
                    query.SetSql( "DELETE FROM #test_datetime" );
                    query.Execute();
                    query.RequireRowCount(0);
                    BOOST_CHECK_NO_THROW(query.VerifyDone(CQuery::eAllResultSets));

                    query.SetNullParameter( "@dt_val", eSDB_DateTime );

                    sql = "INSERT INTO #test_datetime(id, dt_field) "
                          "VALUES(1, @dt_val)";

                    query.SetSql( sql );
                    query.Execute();
                    query.RequireRowCount(0);
                    BOOST_CHECK_NO_THROW(query.VerifyDone(CQuery::eAllResultSets));
                }


                // Retrieve data again ...
                {
                    sql = "SELECT * FROM #test_datetime";

                    // ClearParamList is necessary here ...
                    query.ClearParameters();
                    query.SetSql( sql );
                    query.Execute();
                    query.RequireRowCount(1);
                    BOOST_CHECK( query.HasMoreResultSets() );
                    CQuery::iterator it = query.begin();
                    BOOST_CHECK( it != query.end() );
                    BOOST_CHECK( it[2].IsNull());
                    BOOST_CHECK_NO_THROW(query.VerifyDone(CQuery::eAllResultSets));
                }
            }
        }
    }
    catch(const CException& ex) {
        DBAPI_BOOST_FAIL(ex);
    }
}