I'm trying to provide custom exception handling mechanism to a class inherited from mysqlpp::StoreQueryResult in mysql++ library. But what i'm finding really hard to do is to find a way to refer to the actual object within the class, so i'm unable to use the vector operation at() properly in order to retrieve a value at an index.
Here is the header
/* MySQLQueryResult.h */
#ifndef MYSQLQUERYRESULT_H
#define MYSQLQUERYRESULT_H
#include <mysql++.h>
#include <result.h>
namespace MinesScanner {
namespace MoonStone {
class MySQLQueryResult : public mysqlpp::StoreQueryResult {
public:
MySQLQueryResult();
MySQLQueryResult(const MySQLQueryResult &other);
MySQLQueryResult& operator=(const MySQLQueryResult &other);
mysqlpp::Row& operator[](int index);
private:
int _dat;
};
}
}
#endif /* MYSQLQUERYRESULT_H */
Here is the source file
/* MySQLQueryResult.cpp */
#include "MySQLQueryResult.h"
namespace MinesScanner {
namespace MoonStone {
MySQLQueryResult::MySQLQueryResult( )
: StoreQueryResult( )
{
}
MySQLQueryResult::MySQLQueryResult( const StoreQueryResult &ob )
: StoreQueryResult( ob )
{
}
MySQLQueryResult& MySQLQueryResult::operator=( const StoreQueryResult &ob )
{
StoreQueryResult::operator=( ob ) ;
return *this ;
}
mysqlpp::Row& MySQLQueryResult::operator[]( int index )
{
try {
std::cout << " Called " << this->at( index ) << std::endl ;
return this->at( index ) ;
} catch ( std::exception& excpn_ob ) {
std::cerr << " Exception caught : " << excpn_ob.what( ) << std::endl ;
}
}
}
}
A simple usage example will show more clearly what i want to achieve.
#include "MySQLQueryResult.h"
int main() {
StoreQueryResult lisres = getMinesData( ( string ) row.at( 0 ) ) ; // returns StoreQueryResult object storing the result
cout << lisres[0][7] << endl; // outputs "Falkreath Stormcloak Mines"
MySQLQueryResult my_lisres = getMinesData( ( string ) row.at( 0 ) ) ; // returns StoreQueryResult object storing the result
cout << my_lisres[0][7] << endl; // ERROR!
}
So i basically want to add more boundary checking, check for null values , and handle out_of_range exception using the operator[] in class MySQLQueryResult but its not working.
I want to be able to access MySQLQueryResult object using array subscripts . Either i'm getting a garbage value or a Seg fault. Please let me know how to get this right