コード例 #1
0
ファイル: VValueBag.cpp プロジェクト: StephaneH/core-XToolbox
CharSet VValueBag::DebugDump(char* inTextBuffer, sLONG& inBufferSize) const
{
	if (VProcess::Get() != NULL)
	{
		VString dump;
		VString temp;
		VIndex i;
		VIndex count = GetAttributesCount();
		for (i = 1 ; i <= count ; ++i)
		{
			const VValueSingle* theValue = GetNthAttribute( i, &temp);
			dump.AppendPrintf("%S = %A\n", &temp, theValue);
		}
		
		count = GetElementNamesCount();
		for (i = 1 ; i <= count ; ++i)
		{
			const VBagArray *theBagArray = GetNthElementName( i, &temp);

			dump.AppendPrintf("=======\n%d %S :\n", theBagArray->GetCount(), &temp);
			
			for (sLONG j = 1 ; j <= theBagArray->GetCount() ; ++j) {
				dump.AppendPrintf("--\n%V", theBagArray->RetainNth(j));
			}
		}

		dump.Truncate(inBufferSize/2);
		inBufferSize = (sLONG) dump.ToBlock(inTextBuffer, inBufferSize, VTC_UTF_16, false, false);
	} else
		inBufferSize = 0;
	return VTC_UTF_16;
}
コード例 #2
0
void VSysLogOutput::Put( std::vector< const XBOX::VValueBag* >& inValuesVector)
{
	for (std::vector< const XBOX::VValueBag* >::iterator bagIter = inValuesVector.begin() ; bagIter != inValuesVector.end() ; ++bagIter)
	{
		EMessageLevel bagLevel = ILoggerBagKeys::level.Get( *bagIter);
		if ((fFilter & (1 << bagLevel)) != 0)
		{
			VString logMsg;
						
			VError errorCode = VE_OK;
			ILoggerBagKeys::error_code.Get( *bagIter, errorCode);
		
			VString loggerID;
			ILoggerBagKeys::source.Get( *bagIter, loggerID);
			
			OsType componentSignature = 0;
			if (!ILoggerBagKeys::component_signature.Get( *bagIter, componentSignature))
				componentSignature = COMPONENT_FROM_VERROR( errorCode);
			
			if (componentSignature != 0)
			{
				if (!loggerID.IsEmpty())
					loggerID.AppendUniChar( L'.');
				loggerID.AppendOsType( componentSignature);
			}
			
			if (!loggerID.IsEmpty())
				logMsg.Printf( "[%S]", &loggerID);
			
			// build message string
			VString message;
			
			if (errorCode != VE_OK)
				message.AppendPrintf( "error %d", ERRCODE_FROM_VERROR( errorCode));
			
			VString bagMsg;
			if (ILoggerBagKeys::message.Get( *bagIter, bagMsg))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( bagMsg);
			}
						
			sLONG taskId=-1;
			if (ILoggerBagKeys::task_id.Get( *bagIter, taskId))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"task #");
				message.AppendLong( taskId);
			}
			
			VString taskName;
			if (!ILoggerBagKeys::task_name.Get( *bagIter, taskName))
				VTask::GetCurrent()->GetName( taskName);
			if (!taskName.IsEmpty())
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( taskName);
			}
			
			sLONG socketDescriptor=-1;
			if (ILoggerBagKeys::socket.Get( *bagIter, socketDescriptor))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"socket ");
				message.AppendLong(socketDescriptor);
			}
			
			VString localAddr;
			if (ILoggerBagKeys::local_addr.Get( *bagIter, localAddr))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"local addr is ");
				message.AppendString( localAddr);
			}
			
			VString peerAddr;
			if (ILoggerBagKeys::peer_addr.Get( *bagIter, peerAddr))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"peer addr is ");
				message.AppendString( peerAddr);
			}
			
			bool exchangeEndPointID=false;
			if (ILoggerBagKeys::exchange_id.Get( *bagIter, exchangeEndPointID))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( (exchangeEndPointID) ? L"exchange endpoint id" : L"do not exchange endpoint id");
			}
			
			bool isBlocking=false;
			if (ILoggerBagKeys::is_blocking.Get( *bagIter, isBlocking))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( (isBlocking) ? L"is blocking" : L"is not blocking");
			}
			
			bool isSSL=false;
			if (ILoggerBagKeys::is_ssl.Get( *bagIter, isSSL))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( (isSSL) ? L"with SSL" : L"without SSL");
			}
			
			bool isSelectIO=false;
			if (ILoggerBagKeys::is_select_io.Get( *bagIter, isSelectIO))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( (isSelectIO) ? L"with SelectIO" : L"without SelectIO");
			}
			
			sLONG ioTimeout=-1;
			if (ILoggerBagKeys::ms_timeout.Get( *bagIter, ioTimeout))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"with ");
				message.AppendLong( ioTimeout);
				message.AppendString( L"ms timeout");
			}
			
			sLONG askedCount=-1;
			if (ILoggerBagKeys::count_bytes_asked.Get( *bagIter, askedCount))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"asked for ");
				message.AppendLong( askedCount);
				message.AppendString( L" byte(s)");
			}
			
			sLONG sentCount=-1;
			if (ILoggerBagKeys::count_bytes_sent.Get(*bagIter, sentCount))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"sent ");
				message.AppendLong( sentCount);
				message.AppendString( L" byte(s)");
			}
			
			sLONG receivedCount=-1;
			if (ILoggerBagKeys::count_bytes_received.Get( *bagIter, receivedCount))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"received ");
				message.AppendLong( receivedCount);
				message.AppendString( L" byte(s)");
			}
			
			sLONG ioSpent=-1;
			if (ILoggerBagKeys::ms_spent.Get( *bagIter, ioSpent))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"done in ");
				message.AppendLong( ioSpent);
				message.AppendString( L"ms");
			}
			
			sLONG dumpOffset=-1;
			if (ILoggerBagKeys::dump_offset.Get( *bagIter, dumpOffset))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"offset ");
				message.AppendLong( dumpOffset);
			}
			
			VString dumpBuffer;
			if (ILoggerBagKeys::dump_buffer.Get( *bagIter, dumpBuffer))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L"data : ");
				message.AppendString( dumpBuffer);
			}
			
			VString fileName;
			if (ILoggerBagKeys::file_name.Get( *bagIter, fileName))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( fileName);
			}
			
			sLONG lineNumber;
			if (ILoggerBagKeys::line_number.Get( *bagIter, lineNumber))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendLong( lineNumber);
			}
			
			VString stackCrawl;
			if (ILoggerBagKeys::stack_crawl.Get( *bagIter, stackCrawl))
			{
				if (!message.IsEmpty())
					message.AppendString( L", ");
				message.AppendString( L", {");
				stackCrawl.ExchangeAll( L"\n", L" ; ");
				message.AppendString( stackCrawl);
				message.AppendUniChar( L'}');
			}
			
			if (!logMsg.IsEmpty())
				logMsg.AppendUniChar( L' ');
			logMsg.AppendString( message);
			
			if (!logMsg.IsEmpty())
			{
				StStringConverter<char> messageConverter( VTC_StdLib_char);
		
				switch( bagLevel)
				{
					case EML_Dump:
					case EML_Assert:
					case EML_Debug:
						syslog( LOG_DEBUG, messageConverter.ConvertString( logMsg));
						break;
						
					case EML_Trace:
						syslog( LOG_NOTICE, messageConverter.ConvertString( logMsg));
						break;

					case EML_Information:
						syslog( LOG_INFO, messageConverter.ConvertString( logMsg));
						break;
							   
					case EML_Warning:
						syslog( LOG_WARNING, messageConverter.ConvertString( logMsg));
						break;
							   
					case EML_Error:
						syslog( LOG_ERR, messageConverter.ConvertString( logMsg));
						break;
						
					case EML_Fatal:
						syslog( LOG_CRIT, messageConverter.ConvertString( logMsg));
						break;
							   
				   default:
					   assert(false);
					   break;
				}
			}
		}
	}
}
コード例 #3
0
static void _ExplainTTRFormat_V1()
{
	VString		doc;

	char		theTime[512] = {0};
	time_t now = ::time( NULL);
	::strftime( theTime, sizeof( theTime),"%Y-%m-%dT%H:%M:%S", localtime( &now));

	doc = "Text (Tab-Tab-Return) format version ";
	doc.AppendLong(kTTR_FORMAT_VERSION);
	doc.AppendCString("\r\r");

	// ===============================================
	doc += "--------------------------------------------------\r";
	doc += "General\r";
	doc += "--------------------------------------------------\r";
	doc.AppendPrintf("Every entry is quoted by square brackets. For example: [%d] for \"FlushFromLanguage\".\r", eCLEntryKind_FlushFromLanguage);
	doc.AppendPrintf("First entry in the log is the \"start\" entry (%d), it gives the current date-time.\r", eCLEntryKind_Start);
	doc += "Then, every other entry is followed by [tab] ellapsed second since log started [tab] Task ID {and optionnaly: [tab] other infos...}\r\r";
	doc += "For example, when the log starts, first line is something like:\r";
	doc.AppendPrintf("[%d]\t%s\t10\r", eCLEntryKind_Start, theTime);
	doc += "Then you may have (FlushFromLanguage, executed 5 seconds since the log started, for task ID 10):\r";
	doc.AppendPrintf("[%d]\t5\t10\r", eCLEntryKind_FlushFromLanguage);

	doc += "\rEntries may be quoted with start/end. In this case, the format is [entry num]s and [entry num]e.";
	doc += " Between both tags, several other entries may be logged, from the same task ID or from others.\r";
	doc += "In all cases, the 'end' tag is formatted: [entry num]e [tab] ellapsed second since log started [tab] taskID [tab] count of milliseconds since [entry num]start\r";
	doc += "For example, with the FlushFromLanguage kind launched from task ID 10, the log could be:\r";
	doc.AppendPrintf("[%d]s\t123\t10\t(...other infos - see format)\r", eCLEntryKind_FlushFromLanguage);
	doc += ". . .\r. . .\r. . .\r";
	doc.AppendPrintf("[%d]s\t126\t10\t(...other infos - see format)\r", eCLEntryKind_FlushFromLanguage);

	// ===============================================
	doc += "--------------------------------------------------\r";
	doc += "List of all kinds of entry (name [tab] value)\r";
	doc += "--------------------------------------------------\r";
	doc.AppendPrintf("Unknown\t%d\r", eCLEntryKind_Unknown);
	doc.AppendPrintf("Start\t%d\r", eCLEntryKind_Start);
	doc.AppendPrintf("Stop\t%d\r", eCLEntryKind_Stop);
	doc.AppendPrintf("Comment\t%d\r", eCLEntryKind_Comment);
	doc.AppendPrintf("NeedsBytes\t%d\r", eCLEntryKind_NeedsBytes);
	doc.AppendPrintf("CallNeedsBytes\t%d\r", eCLEntryKind_CallNeedsBytes);
	doc.AppendPrintf("FlushFromLanguage\t%d\r", eCLEntryKind_FlushFromLanguage);
	doc.AppendPrintf("FlushFromMenuCommand\t%d\r", eCLEntryKind_FlushFromMenuCommand);
	doc.AppendPrintf("FlushFromScheduler\t%d\r", eCLEntryKind_FlushFromScheduler);
	doc.AppendPrintf("FlushFromBackup\t%d\r", eCLEntryKind_FlushFromBackup);
	doc.AppendPrintf("FlushFromNeedsBytes\t%d\r", eCLEntryKind_FlushFromNeedsBytes);
	doc.AppendPrintf("FlushFromRemote\t%d\r", eCLEntryKind_FlushFromRemote);
	doc.AppendPrintf("FlushFromUnknown\t%d\r", eCLEntryKind_FlushFromUnknown);
	doc.AppendPrintf("Flush\t%d\r", eCLEntryKind_Flush);
	doc.AppendPrintf("MemStats\t%d\r", eCLEntryKind_MemStats);

	doc.AppendCString("\r\r");

	// ===============================================
	doc += "--------------------------------------------------\r";
	doc += "Format and meaning of each kind\r";
	doc += "--------------------------------------------------\r";

	doc.AppendPrintf("[%d]\r", eCLEntryKind_Unknown);
	doc += "Unknown entry kind\r";
	doc.AppendPrintf("[%d] [tab] ellapsed second since log started [tab] taskID\r\r", eCLEntryKind_Unknown);

	doc.AppendPrintf("[%d]\r", eCLEntryKind_Start);
	doc += "The log starts. Quoted (start/end) entry, with misc. infos between the start and the end.\r";
	doc.AppendPrintf("[%d]s [tab] current time [tab] taskID [tab] version [cr]\r", eCLEntryKind_Start);
	doc.AppendPrintf("struct [tab] path to host database structure file [cr]\r");
	doc.AppendPrintf("data [tab] path to host database data file [cr]\r");
	doc.AppendPrintf("[%d]e\r\r", eCLEntryKind_Start);

	doc.AppendPrintf("[%d]\r", eCLEntryKind_Stop);
	doc += "The log ends\r";
	doc.AppendPrintf("[%d] [tab] ellapsed second since log started [tab] taskID\r\r", eCLEntryKind_Stop);

	doc.AppendPrintf("[%d]\r", eCLEntryKind_Comment);
	doc += "A comment added by the developer. Comments are always quoted with start and end, a \\r is added at beginning and end.\r";
	doc.AppendPrintf("[%d]start [tab] ellapsed second since log started [tab] taskID [cr] the comment [cr] [%d]end [tab] time [tab] taskID [tab] 0 (the milliseconds)\r\r", eCLEntryKind_Comment);

	doc.AppendPrintf("[%d]\r", eCLEntryKind_NeedsBytes);
	doc += "Any source asks memory to the cache manager\r";
	doc.AppendPrintf("[%d] [tab] ellapsed second since log started [tab] taskID [tab] task name [tab] process 4D num [tab] needed bytes (very large int.)\r", eCLEntryKind_NeedsBytes);
	doc.AppendPrintf("Note: may be followed by [%d]\r\r", eCLEntryKind_MemStats);

	doc.AppendPrintf("[%d]\r", eCLEntryKind_CallNeedsBytes);
	doc += "Memory manager asks memory to the cache manager: not enough space in the cache to allocate memory. The cache manager will try to free unused objects, to flush, etc...\r";
	doc.AppendPrintf("[%d] [tab] ellapsed second since log started [tab] taskID [tab] task name [tab] process 4D num [tab] needed bytes (very large int.)\r", eCLEntryKind_CallNeedsBytes);
	doc.AppendPrintf("Note: may be followed by [%d]\r\r", eCLEntryKind_MemStats);

	doc.AppendPrintf("[%d], [%d], [%d], [%d], [%d], [%d], [%d]\r", eCLEntryKind_FlushFromLanguage,
																	eCLEntryKind_FlushFromMenuCommand,
																	eCLEntryKind_FlushFromScheduler,
																	eCLEntryKind_FlushFromBackup,
																	eCLEntryKind_FlushFromNeedsBytes,
																	eCLEntryKind_FlushFromRemote,
																	eCLEntryKind_FlushFromUnknown);
	doc += "Action at the origin of a flush. All the 'FlushFrom...' share the same format.\r";
	doc.AppendPrintf("[%d] [tab] ellapsed second since log started [tab] taskID [tab] task name [tab] process 4D num [tab] isWaitUntilDone (1 = yes, 0 = no, -1 = unknown) [tab] isEmptyCache (1 = yes, 0 = no, -1 = unknown)\r", eCLEntryKind_CallNeedsBytes);
	doc.AppendPrintf("Note: may be followed by [%d]\r", eCLEntryKind_MemStats);
	doc.AppendPrintf("Note: [%d] means a flush was requested from the remote, but we don't have the exact origin (does a client called FLUSH BUFFERS explicitely? ...)\r\r", eCLEntryKind_FlushFromRemote);

	doc.AppendPrintf("[%d]\r", eCLEntryKind_Flush);
	doc += "Flush (we are inside the Flush Manager)\r";
	doc.AppendPrintf("[%d] [tab] ellapsed second since log started [tab] taskID\r", eCLEntryKind_Flush);
	doc.AppendPrintf("Note: may be followed by [%d]\r\r", eCLEntryKind_MemStats);

	doc.AppendPrintf("[%d]\r", eCLEntryKind_MemStats);
	doc += "The memory statistics. Level of stats is a bit field, to get specific stats, add the following values:\r";
	doc.AppendPrintf("Mini stats (default value): %d\r", eCLDumpStats_Mini);
	doc.AppendPrintf("Objects: %d\r", eCLDumpStats_Objects);
	doc.AppendPrintf("Blocks: %d\r", eCLDumpStats_Blocks);
	doc.AppendPrintf("SmallBlocks: %d\r", eCLDumpStats_SmallBlocks);
	doc.AppendPrintf("BigBlocks: %d\r", eCLDumpStats_BigBlocks);
	doc.AppendPrintf("OtherBlocks: %d\r", eCLDumpStats_OtherBlocks);
	doc.AppendPrintf("All: %d\r", eCLDumpStats_All);

	doc.AppendPrintf("[%d] [tab] ellapsed second since log started [tab] taskID [tab] origin of the stats (a log entry number) [cr] the stats\r", eCLEntryKind_MemStats);
	doc += "the stats themselves are in xml:\r";
	doc += "Main tag: <mem_stats level=\"stat level\" size=\"total amount of memory\" used=\"amount ofused memory\">\r";
	doc += "Then come the details:\r";
	doc += "<system phys=\"physical memory size\" free=\"free memory size\" app_used_phys=\"physical used by app\" used_virtual=\"virtual meory used\" />\r";
	doc += "Allocations blocks: <alloc count=\"number of virtual allocations\" tot=\"total allocated\" />\r";
	doc += "Then come the detailed stats, depending on the level. Note: infos are the same as the one found in GET CACHE STATISTIC.";
	doc += ", the xml uses some abbreviations to reduce a bit the size: bb = \"big blocks\", sb = \"small blocks\", ob = \"other blocks\"\r";
	doc += "Example of log:\r";

	doc += "<mem_stats level=\"1\" tid=\"13\" tname=\"P_1\" pnum=\"5\" size=\"10704570434977792\" used=\"2306663092733982407\">\r";
	doc += "<system phys=\"2143993856\" free=\"1\" app_used_phys=\"2882306048\" used_virtual=\"0\"/>";
	doc += "<alloc count=\"2\" tot=\"104857600\"/>";
	doc += "<stats free=\"102365184\" nb_bb=\"165\" used_bb=\"163\" free_bb=\"2\" nb_pages=\"104\" nb_sb=\"4411\" used_sb=\"4401\" free_sb=\"10\" biggest_block=\"70124512\" biggest_free_block=\"70124512\" nb_obj=\"3852\"/>";
	doc += "</mem_stats>\r\r";

	VFolder *userDocsFolder = VFolder::RetainSystemFolder(eFK_UserDocuments, false);
	if(userDocsFolder != NULL)
	{
		VFile	logDoc(*userDocsFolder, CVSTR("cache_log_doc_v1.txt"));

		VError err = VE_OK;
		if(logDoc.Exists())
			err = logDoc.Delete();

		err = logDoc.Create();

		if(err == VE_OK)
		{
			VFileStream logDocDump(&logDoc);

			err = logDocDump.OpenWriting();

			if(err == VE_OK)
			{
				logDocDump.PutText(doc);
			}
			
			
			if(err == VE_OK)
				err = logDocDump.CloseWriting();
		}
		userDocsFolder->Release();
	}

}
コード例 #4
0
void testMySQLConnectorPreparedStatementWithTypeDouble()
{
    CSQLConnector* connector = (CSQLConnector*) ( VComponentManager::RetainComponent ( 'MYSQ', 'SQL ' ) );

    VJSONObject* params = new VJSONObject();

    params->SetProperty ( "hostname",	MYSQL_HOST );

    params->SetProperty ( "user",		MYSQL_USER );

    params->SetProperty ( "password",	MYSQL_CORRECT_PASSWORD );

    params->SetProperty ( "database",	MYSQL_DATABASE );

    params->SetProperty ( "port",		MYSQL_PORT );

    params->SetProperty ( "ssl",			MYSQL_SSL_FALSE );

    ISQLSession* session = connector->CreateSession ( params );

    ReleaseRefCountable ( &params );

    if ( session != NULL )
    {
        ISQLStatement* statement = session->CreateStatement ( "SELECT * FROM test_double" );

        VError error = VE_OK;

        ISQLPreparedStatement* pStmt = statement->CreatePreparedStatement ( error );

        ISQLResultSet* res = pStmt->Execute ( error );

        if ( error == VE_OK )
        {
            if ( res->IsError() )
            {
                printf ( "an error occured in the execution of the prepared statement!\n" );
            }
            else
            {
                while ( !res->IsEOF() )
                {
                    ISQLRow* row = res->RetainNextRow();

                    VValue* value = row->GetNthValue ( 2 );

                    VString dbgMsg;

                    dbgMsg.AppendPrintf ( "value = %V", value );

                    DebugMsg ( "%V\n", &dbgMsg );

                    ReleaseRefCountable ( &row );
                }
            }

            ReleaseRefCountable ( &res );
        }
        else
        {
            printf ( "an error occured in the execution of the prepared statement!\n" );
        }

        ReleaseRefCountable ( &session );
    }
    else
    {
        printf ( "connection to mysql server failed ..\n" );
    }

    ReleaseRefCountable ( &connector );
}
コード例 #5
0
void testMySQLConnectorPreparedStatementWithDateParam()
{
    CSQLConnector* connector = (CSQLConnector*) ( VComponentManager::RetainComponent ( 'MYSQ', 'SQL ' ) );

    VJSONObject* params = new VJSONObject();

    params->SetProperty ( "hostname",	MYSQL_HOST );

    params->SetProperty ( "user",		MYSQL_USER );

    params->SetProperty ( "password",	MYSQL_CORRECT_PASSWORD );

    params->SetProperty ( "database",	MYSQL_DATABASE );

    params->SetProperty ( "port",		MYSQL_PORT );

    params->SetProperty ( "ssl",			MYSQL_SSL_FALSE );

    ISQLSession* session = connector->CreateSession ( params );

    ReleaseRefCountable ( &params );

    if ( session != NULL )
    {
        ISQLStatement* statement = session->CreateStatement ( "SELECT * FROM people WHERE date_of_birth = ?" );

        VError error = VE_OK;

        ISQLPreparedStatement* pStmt = statement->CreatePreparedStatement ( error );

        VTime keyDate;

        keyDate.FromUTCTime ( 1984, 8, 11, 0, 0, 0, 0 );

        pStmt->SetNthParameter ( 1, keyDate );

        ISQLResultSet* res = pStmt->Execute ( error );

        if ( error == VE_OK )
        {
            if ( res->IsError() )
            {
                printf ( "an error occured in the execution of the prepared statement!\n" );

                VString msg = res->GetErrorMessage();

                printf ( "error msg = %V\n", &msg );
            }
            else
            {
                while ( !res->IsEOF() )
                {
                    ISQLRow* row = res->RetainNextRow();

                    VValue* idValue = row->GetNthValue ( 1 );

                    VValue* firstNameValue = row->GetNthValue ( 3 );

                    VValue* dateValue = row->GetNthValue ( 5 );

                    VString DbgMsg;

                    DbgMsg.AppendPrintf ( "idValue = %V, firstNameValue = %V, dateValue = %V", idValue, firstNameValue, dateValue );

                    DebugMsg ( "%V", &DbgMsg );

                    ReleaseRefCountable ( &row );
                }
            }

            ReleaseRefCountable ( &res );
        }
        else
        {
            printf ( "an error occured in the execution of the prepared statement!\n" );
        }

        ReleaseRefCountable ( &session );
    }
    else
    {
        printf ( "connection to mysql server failed ..\n" );
    }

    ReleaseRefCountable ( &connector );

}
コード例 #6
0
void testMySQLConnectorStatement()
{
    CSQLConnector* connector = (CSQLConnector*) ( VComponentManager::RetainComponent ( 'MYSQ', 'SQL ' ) );

    VJSONObject* params = new VJSONObject();

    params->SetProperty ( "hostname",	MYSQL_HOST );

    params->SetProperty ( "user",		MYSQL_USER );

    params->SetProperty ( "password",	MYSQL_CORRECT_PASSWORD );

    params->SetProperty ( "database",	MYSQL_DATABASE );

    params->SetProperty ( "port",		MYSQL_PORT );

    params->SetProperty ( "ssl",			MYSQL_SSL_FALSE );

    ISQLSession* session = connector->CreateSession ( params );

    ReleaseRefCountable ( &params );

    if ( session != NULL )
    {
        ISQLStatement* stmt = session->CreateStatement ( "SELECT * FROM people WHERE id < 5" );

        VError error = VE_OK;

        ISQLResultSet* res = stmt->Execute ( error );

        if ( error == VE_OK )
        {
            if ( res->IsError() )
            {
                printf ( "an error occured in the execution of the prepared statement!\n" );
            }
            else
            {
                while ( !res->IsEOF() )
                {
                    ISQLRow* row = res->RetainNextRow();


                    VValue* idValue = row->GetNthValue ( 1 );
                    VString id;
                    id.AppendPrintf ( "%V", idValue );
                    DebugMsg ( "id = %V\n", &id );


                    VValue* firstNameValue = row->GetNthValue ( 3 );
                    VString firstName;
                    firstName.AppendPrintf ( "%V", firstNameValue );
                    DebugMsg ( "first name = %V\n", &firstName );


                    VValue* dateValue = row->GetNthValue ( 5 );
                    VString date;
                    date.AppendPrintf ( "%V", dateValue );
                    DebugMsg ( "date = %V\n", &date );


                    ReleaseRefCountable ( &row );
                }
            }

            ReleaseRefCountable ( &res );
        }
        else
        {
            printf ( "an error occured in the execution of the prepared statement!\n" );
        }

        ReleaseRefCountable ( &session );
    }
    else
    {
        printf ( "connection to mysql server failed ..\n" );
    }

    ReleaseRefCountable ( &connector );
}