On Thu, June 1, 2006 04:12, Rilson Nascimento wrote:
> I would like to hear from you guys a suggestion how could I use a struct
> (if
> possible) to insert a row in a PgSQL table via tablewriter.
> The table I want to insert has the same definition of the struct
> (char[20],
> int, double). Is there a way to insert this one-row struct into the table
> via tablewirter? if not, which other approaches do you suggest?
Something along these lines is projected for the distant future. For now,
one way to do it would be to provide a very simple "iterator" type for
your struct so the tablewriter could treat your struct as a sequence of
strings.
All it would take besides constructors are a pre-increment iterator that
does something along the lines of "++currentfield ; return *this;"
comparison iterators that compare two of these iterators' currentfield
members; and a dereferencing operator with a body along the lines of:
switch (currentfield)
{
case 0: return FIELD_A;
case 1: return to_string(FIELD_B);
case 2: return to_string(FIELD_C);
}
return "";
Then you pass a pair of these iterators to the tablewriter's insertion
function--one with currentfield set to zero and one with currentfield set
to 3.
Jeroen
_______________________________________________
Libpqxx-general mailing list
[email protected]
http://gborg.postgresql.org/mailman/listinfo/libpqxx-general