Simple Newbie question about accessing a Variable out of a class of a class
Hi
After compiling "Hello World", I am on the way to code a shared
library - but now I have some trouble. I have a class which is holding
a Database connection. In this class there are other classes holding
data from sql statements. For now I cannot access the connection
object in the classes of the "connectonholding"-class, which is what I
need.
Here I paste my code and marked the sentence where the problem is,
probably you can better imagine what I want.
Thanks for your Help!
Christian Maier
//foo.h
#include <pqxx/pqxx>
using namespace PGSTD;
using namespace pqxx;
typedef long long llong;
class FiMi
{
public:
void setDB(string);
void setHost(string);
void setPort(string);
void setUser(string);
void setPasswd(string);
void setSchema(string);
void doConnect();
void doDisconnect();
connection * getConnection;
private:
string db;
string host;
string port;
string user;
string passwd;
string schema;
string connectionstring;
connection dbCon(string);
public:
class fProvider
// I must have access to the connection object
{
public:
long long getProvider(string); //from
caption
void getAllProviders(string[]);
void getAllProviderTypes(string[]);
long long getProvideType(string); //from
caption
void addProvider(string,long long, string); //caption,
ptype_id, additional
void delProvider(long long); //via
provider_id
void updProvider(long long); //via
provider_id
};
};
//foo.cpp
#include <pqxx/pqxx>
#include "foo.h"
using namespace PGSTD;
using namespace pqxx;
typedef long long llong;
void FiMi::doConnect()
{
connectionstring = "dbname=" + db + " " +
"host=" + host + " " +
"port=" + port + " " +
"user=" + user + " " +
"password=" + passwd;
try
{
cout << "ich bin hier " + connectionstring + " \n";
connection dbCon(connectionstring);
cout << "connected to " << dbCon.dbname() << " \n";
//probably I want to use the connection from client code for
native sqls ....
getConnection = &dbCon;
}
catch (const broken_connection &e)
{
cout << "beim verbinen ist folgender fehler passiert:\n";
throw logic_error( e.what() );
}
};
llong FiMi::fProvider::getProvider(string caption)
{
try
{
/* ####################### HERE IS WHAT I NEED
###########################
THE dbCon Object is no access habe her which is what i
need, how to do this
cout << dbCon.Database << endl;
######################################################################
*/
return 0;
}
catch (const sql_error &e)
{
cerr << "SQL error: " << e.what() << endl
<< "Query was: '" << e.query() << "'" << endl;
return -1;
}
};
int main( int argc, char *argv[] )
{
FiMi a;
return 0;
}