If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > [C++] result from PostgreSQL query...

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-09-10, 20:40
Sam.Online Sam.Online is offline
Registered User
 
Join Date: Sep 2008
Posts: 1
[C++] result from PostgreSQL query...

Hello, i'm sorry for posting such question but, i can't resolve this by myself .

Code:
using namespace std;
typedef map < const char*, const char* > Tuple;
typedef vector < Tuple > QueryResult;
typedef map < const char*, QueryResult::iterator > Entry; 


QueryResult ParseQuery ( PGresult *result ) {
	QueryResult Query;
	Tuple mapping;
	char fieldName[50];
	char fieldResult[50];

	for ( int nTuples = 0; nTuples != PQntuples ( result ); ++nTuples ) {

		for ( int nFields = 0; nFields != PQnfields ( result ); ++nFields ) {
			
			strcpy_s ( fieldName, PQfname ( result, nFields ) );
			strcpy_s ( fieldResult, PQgetvalue ( result, nTuples, nFields ) );

			mapping [ fieldName ] = fieldResult;

			printf ( "this field is ?%s.\n", fieldName );
			if ( fieldName == "userid" )
				printf ( "BLA!\n" );
			else
				printf ( " Not Yet . \n" );
		} 
		Query.push_back ( mapping );
		mapping.clear ( );
	}


	return Query;
}
the problem is: when it come to: if ( fieldName == "userid" ). It will always return false, but i have the field "userid" in my table, and i know its exist, the line: printf ( "this field is ?%s.\n", fieldName ); show it.

Again, i'm sorry for posting question here, but the reason remain obscure, and it drives me crazy xD.
Reply With Quote
  #2 (permalink)  
Old 10-07-10, 08:59
Daniil.Monin Daniil.Monin is offline
Registered User
 
Join Date: Oct 2010
Posts: 19
Use "userid\0".

Is it CLI C++? The use string.compare (such as in C#).
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On