List:MySQL++« Previous MessageNext Message »
From:Roland Sgorcea Date:May 30 2005 11:46am
Subject:Returning an object of type Result
View as plain text  
Hi,

Just started using mysql++ today for the first time. I went through
the examples and they worked fine.

I tried to make a generic function 

Result Select_From_Database ( const char* field_select, const char*
table_name, const char* field_name, const char* field_value)

My setup looks soemthing like this:

Result Select_From_Database ( const char* field_select, const char*
table_name, const char* field_name, const char* field_value)
{
  Connection con(use_exceptions);
	try {
		con.real_connect(MY_DATABASE, MY_HOST, MY_USER, MY_PASSWORD, 3306,
						 0, 60, NULL);
		// Create a query object that is bound to con.
		Query query = con.query();
		// reset the query object when re-using it.
		query.reset();
						
		query << "SELECT " << field_select << " FROM " << table_name
<< "
WHERE " << field_name << " = '" << field_value <<"'";
				
		Result res = query.store();
			   				
		return res;
			
	}
      // catch exceptions
}

and I have another function :

char* validate(const char* userlevel, const char* password) 
{ 
	Result res = Select_From_Database ( "password", "access",
"userlevel", userlevel);
	
		
	if ( strcmp(password, res[0][0]) == 0 )  {
       	  						
		char* access = createUserObject(userlevel);		
				
		return access; // Grants access
	}
	else {
		cout << "Login was not Succesfull "  << endl;
		return "-1"; // Access NOT GRANTED
	}	
}

Something really weird happens, in the Select_From_Database, the res
object size , res.size() is 1 (1 Record found)

but when I pass it on to validate the size becomes 134722808. The
result I'm looking for is still stored in the new res variable
res[0][0] and I can access it fine but after I finish executing the
validate function I get a Segmentation Error and the program shuts
down????

Would really appreciate some help with this !

Thanks in advance,

Roland
Thread
Returning an object of type ResultRoland Sgorcea30 May
  • Re: Returning an object of type ResultChris Frey31 May
  • Re: Returning an object of type ResultWarren Young1 Jun