On Tuesday 30 January 2007 22:00, satya satya wrote:
> Hello all,
>               I am new to libpqxx. I would like to store result set in a
> good data structure.
> could you please tell me the best data structure to store the result set
> and how to do it.

What is wrong with the result type defined and provided by pqxx itself? Read 
about it in [1].

Basically you declare a result object, execute a query and save the query 
result in that object. You can think of the result object as a 
two-dimensional array (one dimension is the rows, the other is the fields in 
each row) and access the data in various ways:

[code]
std::string connectstring("...");
pqxx::connection Conn(connectstring);
pqxx::result JobsToProcess;

// This uses the transactor technique described in [2]
// JobsToProcess now holds all rows selected by QueryNewJobs
Conn.perform(QueryNewJobs(JobsToProcess));

// Or something along the lines of
pqxx::work T(Conn, "MyTransaction");
JobsToProcess = T.exec(my_query_for_new_jobs);

[/code]

Now you can do stuff with the results you just saved:

[code]
// Walk through all rows in the result object using an iterator
for (pqxx::result::const_iterator it = JobsToProcess.begin(); 
        it != JobsToProcess.end(); 
        ++it) 
{
    int usr_id, job_id;
    long time_created;

    // Save the field "job_usr_id" to the variable usr_id
    c["job_usr_id"].to(usr_id);

    // Save the field "job_id" to the variable job_id
    c["job_id"].to(job_id);

    // Save the field "job_time_created" to the variable time_created
    c["job_time_created"].to(time_created);

    ...
}
[/code]

More on that can be found under [1] and of course in the test suite that comes 
with the pqxx tarball. It will be well worth your time to study that suite 
since it demonstrates just about everything you can do with pqxx.

HTH

Andreas

[1] 
http://thaiopensource.org/devprojects/libpqxx/doc/2.6.8/html/Tutorial/ch03s06.html
[2]
http://thaiopensource.org/devprojects/libpqxx/doc/2.6.8/html/Tutorial/ch03s07.html
-- 
Andreas "daff" Ntaflos
Vienna, Austria

GPG Fingerprint: 6234 2E8E 5C81 C6CB E5EC  7E65 397C E2A8 090C A9B4

Attachment: pgpZlLbYSXgHK.pgp
Description: PGP signature

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

Reply via email to