Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2008
    Posts
    1

    Unanswered: [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.

  2. #2
    Join Date
    Oct 2010
    Posts
    19
    Use "userid\0".

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •