Hi,

I have laboured over the functor business and can get transactors to 
work. However I need to pass a stream object to a transactor but this 
results in all kinds of problems. I have included my program below which 
works without the stream. I have tried to incorporate a stream using 
your explicit constructor in the tutorial. I don't understand this line 
from the section on "How Transactors Work"-

explicit HelloFunctor(ostream &S) : Stream(S) {}

My compiler and I agree that HelloFunctor is not derived from Stream(S).

Can anyone provide more detailed explanation on what this line really does.

Thanks in advance.

Regards,

Rabin

My compiler is gcc 4.1.1 on Fedora 6.

My program:

#include <iostream>
#include <pqxx/pqxx>
#include <pqxx/connection>
#include <pqxx/nontransaction>
#include <pqxx/transactor>
#include <pqxx/result>

using namespace std;
using std::string;
using namespace PGSTD;
using namespace pqxx;

class alphaTransactor:public transactor<transaction<read_committed> >
{       
    public:
       
        //Copy Constructor?
        alphaTransactor() : transactor<transaction<read_committed> 
 >("genericTransactor")
        {}
        //Becomes functor
        void operator()(transaction<read_committed>  &T)
        {
            qResultSet = T.exec(qString);
        }
       
        void on_commit()
        {
            for (result::size_type indxi=0; indxi != qResultSet.size(); 
++indxi)
            {   
                for (result::tuple::size_type  indxj = 0;  indxj != 
qResultSet.columns(); ++indxj)
                {
                    cout << qResultSet[indxi][indxj] << "\t";
                }
                cout << "\n";
            }
        }           
        void setQueryString(string setTo)
        {   
            qString = setTo;
        }
       
    private:
            result qResultSet;
            string qString;
};

int main ()
{
    string inputQuery;
    cout << "Please input query string: ";
    getline(cin, inputQuery);
   
        try
        {
            connection Conn("dbname=db001 user=rabin03");
            cout << "Connected to " << Conn.dbname() << endl;
           
            //Creation of instance of alphaTransactor does not seem 
neccessary in the tutorial! - However below -
            alphaTransactor * betaTransactor = new alphaTransactor;
            betaTransactor->setQueryString(inputQuery);
            //Use of 'transactor' instead of  'transaction'
            Conn.perform((*betaTransactor));
           
        }
       
        catch (const sql_error &e)
        {
            cerr << "SQL error: " << e.what() << endl
                    <<"Query was: " << e.query() << "" << endl;
            return 1;
        }
       
        catch (const exception &e)
        {
            cerr << "Exception: " << e.what() << endl;
            return 2;
        }
       
        catch (...)
        {
            //All errors not caught above
            cerr << "Unhandled exception" << endl;
            return 3;
        }
       
        return 0;
}

_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general

Reply via email to