int32 UParticleSystemAuditCommandlet::Main(const FString& Params) { if (!FParse::Value(*Params, TEXT("AuditOutputFolder="), AuditOutputFolder)) { // No output folder specified. Use the default folder. AuditOutputFolder = FPaths::GameSavedDir() / TEXT("Audit"); } // Add a timestamp to the folder AuditOutputFolder /= FDateTime::Now().ToString(); ProcessParticleSystems(); DumpResults(); return 0; }
BEGIN_NCBI_SCOPE /////////////////////////////////////////////////////////////////////////////// BOOST_AUTO_TEST_CASE(Test_Procedure) { try { // Test a regular IStatement with "exec" // Parameters are not allowed with this construction. { auto_ptr<IStatement> auto_stmt( GetConnection().GetStatement() ); // Execute it first time ... auto_stmt->SendSql( "exec sp_databases" ); while( auto_stmt->HasMoreResults() ) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch ( rs->GetResultType() ) { case eDB_RowResult: while( rs->Next() ) { // int col1 = rs->GetVariant(1).GetInt4(); } break; case eDB_ParamResult: while( rs->Next() ) { // int col1 = rs->GetVariant(1).GetInt4(); } break; case eDB_StatusResult: while( rs->Next() ) { int status = rs->GetVariant(1).GetInt4(); status = status; } break; case eDB_ComputeResult: case eDB_CursorResult: break; } } } // Execute it second time ... auto_stmt->SendSql( "exec sp_databases" ); while( auto_stmt->HasMoreResults() ) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch ( rs->GetResultType() ) { case eDB_RowResult: while( rs->Next() ) { // int col1 = rs->GetVariant(1).GetInt4(); } break; case eDB_ParamResult: while( rs->Next() ) { // int col1 = rs->GetVariant(1).GetInt4(); } break; case eDB_StatusResult: while( rs->Next() ) { int status = rs->GetVariant(1).GetInt4(); status = status; } break; case eDB_ComputeResult: case eDB_CursorResult: break; } } } // Same as before but do not retrieve data ... auto_stmt->SendSql( "exec sp_databases" ); auto_stmt->SendSql( "exec sp_databases" ); } // Test ICallableStatement // No parameters at this time. { // Execute it first time ... auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status auto_stmt->GetReturnStatus(); // Execute it second time ... auto_stmt.reset( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status auto_stmt->GetReturnStatus(); // Same as before but do not retrieve data ... auto_stmt.reset( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); auto_stmt.reset( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); } // Temporary test ... // !!! This is a bug ... if (false) { auto_ptr<IConnection> conn( GetDS().CreateConnection( CONN_OWNERSHIP ) ); BOOST_CHECK( conn.get() != NULL ); conn->Connect( "anyone", "allowed", "PUBSEQ_OS_LXA", "" ); auto_ptr<ICallableStatement> auto_stmt( conn->GetCallableStatement("id_seqid4gi") ); auto_stmt->SetParam( CVariant(1), "@gi" ); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: _ASSERT(false); while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status int status = auto_stmt->GetReturnStatus(); status = status; // Get rid of warnings. } if (false) { const string query("[db_alias] is not null"); auto_ptr<IConnection> conn( GetDS().CreateConnection( CONN_OWNERSHIP ) ); BOOST_CHECK( conn.get() != NULL ); conn->Connect( "*****", "******", "MSSQL31", "AlignDb_Info" ); auto_ptr<ICallableStatement> auto_stmt( conn->PrepareCall("[dbo].[FindAttributesEx]") ); auto_stmt->SetParam( CVariant(1), "@userid" ); auto_stmt->SetParam( CVariant("ALIGNDB"), "@application" ); auto_stmt->SetParam( CVariant("AlignDbMasterInfo"), "@classname" ); // LongChar doesn't work. // auto_stmt->SetParam( CVariant(new CDB_LongChar(query.length(), query)), "@query" ); // auto_stmt->SetParam( CVariant::LongChar(query.data(), query.length()), "@query" ); auto_stmt->SetParam( CVariant(query), "@query" ); auto_stmt->SetParam( CVariant(1), "@max_results" ); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: _ASSERT(false); while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status int status = auto_stmt->GetReturnStatus(); status = status; // Get rid of warnings. } // Test returned recordset ... { // In case of MS SQL 2005 sp_databases returns empty result set. // It is not a bug. It is a difference in setiings for MS SQL // 2005. if (GetArgs().GetServerType() != CDBConnParams::eMSSqlServer) { int num = 0; // Execute it first time ... auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_databases") ); auto_stmt->Execute(); BOOST_CHECK(auto_stmt->HasMoreResults()); BOOST_CHECK(auto_stmt->HasRows()); auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); BOOST_CHECK(rs.get() != NULL); while (rs->Next()) { BOOST_CHECK(rs->GetVariant(1).GetString().size() > 0); BOOST_CHECK(rs->GetVariant(2).GetInt4() > 0); BOOST_CHECK_EQUAL(rs->GetVariant(3).IsNull(), true); ++num; } BOOST_CHECK(num > 0); DumpResults(auto_stmt.get()); } { int num = 0; auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_server_info") ); auto_stmt->Execute(); BOOST_CHECK(auto_stmt->HasMoreResults()); BOOST_CHECK(auto_stmt->HasRows()); auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); BOOST_CHECK(rs.get() != NULL); while (rs->Next()) { BOOST_CHECK(rs->GetVariant(1).GetInt4() > 0); BOOST_CHECK(rs->GetVariant(2).GetString().size() > 0); BOOST_CHECK(rs->GetVariant(3).GetString().size() > 0); ++num; } BOOST_CHECK(num > 0); DumpResults(auto_stmt.get()); } } // Test ICallableStatement // With parameters. { { auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_server_info") ); // Set parameter to NULL ... auto_stmt->SetParam( CVariant(eDB_Int), "@attribute_id" ); auto_stmt->Execute(); if (GetArgs().GetServerType() == CDBConnParams::eSybaseSQLServer) { BOOST_CHECK_EQUAL( size_t(30), GetNumOfRecords(auto_stmt) ); } else { BOOST_CHECK_EQUAL( size_t(29), GetNumOfRecords(auto_stmt) ); } // Set parameter to 1 ... auto_stmt->SetParam( CVariant( Int4(1) ), "@attribute_id" ); auto_stmt->Execute(); BOOST_CHECK_EQUAL( size_t(1), GetNumOfRecords(auto_stmt) ); } // NULL value with CVariant ... { auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_statistics") ); auto_stmt->SetParam(CVariant((const char*) NULL), "@table_name"); auto_stmt->Execute(); DumpResults(auto_stmt.get()); } // Doesn't work for some reason ... if (false) { // Execute it first time ... auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("sp_statistics") ); auto_stmt->SetParam(CVariant(GetTableName()), "@table_name"); auto_stmt->Execute(); { BOOST_CHECK(auto_stmt->HasMoreResults()); BOOST_CHECK(auto_stmt->HasRows()); auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); BOOST_CHECK(rs.get() != NULL); BOOST_CHECK(rs->Next()); DumpResults(auto_stmt.get()); } // Execute it second time ... auto_stmt->SetParam(CVariant("#bulk_insert_table"), "@table_name"); auto_stmt->Execute(); { BOOST_CHECK(auto_stmt->HasMoreResults()); BOOST_CHECK(auto_stmt->HasRows()); auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); BOOST_CHECK(rs.get() != NULL); BOOST_CHECK(rs->Next()); DumpResults(auto_stmt.get()); } } if (false) { auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("DBAPI_Sample..TestBigIntProc") ); auto_stmt->SetParam(CVariant(Int8(1234567890)), "@num"); auto_stmt->ExecuteUpdate(); } } // Test output parameters ... if (false) { CRef<CDB_UserHandler_Diag> handler(new CDB_UserHandler_Diag()); I_DriverContext* drv_context = GetDS().GetDriverContext(); drv_context->PushDefConnMsgHandler(handler); auto_ptr<ICallableStatement> auto_stmt( GetConnection().GetCallableStatement("DBAPI_Sample..SampleProc3") ); auto_stmt->SetParam(CVariant(1), "@id"); auto_stmt->SetParam(CVariant(2.0), "@f"); auto_stmt->SetOutputParam(CVariant(eDB_Int), "@o"); auto_stmt->Execute(); // auto_stmt->SendSql( "exec DBAPI_Sample..TestProc4 @test_out output" ); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: BOOST_CHECK(rs->Next()); NcbiCout << "Output param: " << rs->GetVariant(1).GetInt4() << endl; break; case eDB_ComputeResult: break; case eDB_StatusResult: break; case eDB_CursorResult: break; default: break; } } } // BOOST_CHECK(auto_stmt->HasMoreResults()); // BOOST_CHECK(auto_stmt->HasRows()); // auto_ptr<IResultSet> rs(auto_stmt->GetResultSet()); // BOOST_CHECK(rs.get() != NULL); // // while (rs->Next()) { // BOOST_CHECK(rs->GetVariant(1).GetString().size() > 0); // BOOST_CHECK(rs->GetVariant(2).GetInt4() > 0); // BOOST_CHECK_EQUAL(rs->GetVariant(3).IsNull(), true); // ++num; // } // // BOOST_CHECK(num > 0); DumpResults(auto_stmt.get()); drv_context->PopDefConnMsgHandler(handler); } // Temporary test ... if (false) { auto_ptr<IConnection> conn( GetDS().CreateConnection( CONN_OWNERSHIP ) ); BOOST_CHECK( conn.get() != NULL ); conn->Connect( "anyone", "allowed", "", "GenomeHits" ); auto_ptr<ICallableStatement> auto_stmt( conn->GetCallableStatement("NewSub") ); auto_stmt->SetParam(CVariant("tsub2"), "@name"); auto_stmt->SetParam(CVariant("tst"), "@center"); auto_stmt->SetParam(CVariant("9606"), "@taxid"); auto_stmt->SetParam(CVariant("H**o sapiens"), "@organism"); auto_stmt->SetParam(CVariant(""), "@notes"); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: _ASSERT(false); while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status int status = auto_stmt->GetReturnStatus(); status = status; // Get rid of warnings. } // Temporary test ... if (false && GetArgs().GetServerType() != CDBConnParams::eSybaseSQLServer) { auto_ptr<IConnection> conn( GetDS().CreateConnection( CONN_OWNERSHIP ) ); BOOST_CHECK( conn.get() != NULL ); conn->Connect( "pmcupdate", "*******", "PMC3QA", "PMC3QA" ); auto_ptr<ICallableStatement> auto_stmt( conn->PrepareCall("id_new_id") ); auto_stmt->SetParam(CVariant("tsub2"), "@IdName"); auto_stmt->Execute(); while(auto_stmt->HasMoreResults()) { if( auto_stmt->HasRows() ) { auto_ptr<IResultSet> rs( auto_stmt->GetResultSet() ); switch( rs->GetResultType() ) { case eDB_RowResult: while(rs->Next()) { // retrieve row results } break; case eDB_ParamResult: _ASSERT(false); while(rs->Next()) { // Retrieve parameter row } break; default: break; } } } // Get status int status = auto_stmt->GetReturnStatus(); status = status; // Get rid of warnings. } } catch(const CException& ex) { DBAPI_BOOST_FAIL(ex); } }
HRESULT UdpClientLoop(StunClientLogicConfig& config, const ClientSocketConfig& socketconfig) { HRESULT hr = S_OK; CRefCountedStunSocket spStunSocket; CStunSocket stunSocket;; CRefCountedBuffer spMsg(new CBuffer(MAX_STUN_MESSAGE_SIZE)); int sock = -1; CSocketAddress addrDest; // who we send to CSocketAddress addrRemote; // who we CSocketAddress addrLocal; int ret; fd_set set; timeval tv = {}; std::string strAddr; std::string strAddrLocal; StunClientResults results; CStunClientLogic clientlogic; hr = clientlogic.Initialize(config); if (FAILED(hr)) { Logging::LogMsg(LL_ALWAYS, "Unable to initialize client: (error = x%x)", hr); Chk(hr); } hr = stunSocket.UDPInit(socketconfig.addrLocal, RolePP); if (FAILED(hr)) { Logging::LogMsg(LL_ALWAYS, "Unable to create local socket: (error = x%x)", hr); Chk(hr); } stunSocket.EnablePktInfoOption(true); sock = stunSocket.GetSocketHandle(); // let's get a loop going! while (true) { HRESULT hrRet; spMsg->SetSize(0); hrRet = clientlogic.GetNextMessage(spMsg, &addrDest, GetMillisecondCounter()); if (SUCCEEDED(hrRet)) { addrDest.ToString(&strAddr); ASSERT(spMsg->GetSize() > 0); if (Logging::GetLogLevel() >= LL_DEBUG) { std::string strAddr; addrDest.ToString(&strAddr); Logging::LogMsg(LL_DEBUG, "Sending message to %s", strAddr.c_str()); } ret = ::sendto(sock, spMsg->GetData(), spMsg->GetSize(), 0, addrDest.GetSockAddr(), addrDest.GetSockAddrLength()); if (ret <= 0) { Logging::LogMsg(LL_DEBUG, "ERROR. sendto failed (errno = %d)", errno); } // there's not much we can do if "sendto" fails except time out and try again } else if (hrRet == E_STUNCLIENT_STILL_WAITING) { Logging::LogMsg(LL_DEBUG, "Continuing to wait for response..."); } else if (hrRet == E_STUNCLIENT_RESULTS_READY) { break; } else { Logging::LogMsg(LL_DEBUG, "Fatal error (hr == %x)", hrRet); Chk(hrRet); } // now wait for a response spMsg->SetSize(0); FD_ZERO(&set); FD_SET(sock, &set); tv.tv_usec = 500000; // half-second tv.tv_sec = config.timeoutSeconds; ret = select(sock+1, &set, NULL, NULL, &tv); if (ret > 0) { ret = ::recvfromex(sock, spMsg->GetData(), spMsg->GetAllocatedSize(), MSG_DONTWAIT, &addrRemote, &addrLocal); if (ret > 0) { addrRemote.ToString(&strAddr); addrLocal.ToString(&strAddrLocal); Logging::LogMsg(LL_DEBUG, "Got response (%d bytes) from %s on interface %s", ret, strAddr.c_str(), strAddrLocal.c_str()); spMsg->SetSize(ret); clientlogic.ProcessResponse(spMsg, addrRemote, addrLocal); } } } results.Init(); clientlogic.GetResults(&results); DumpResults(config, results); Cleanup: return hr; }