[Libpqxx-general] Tablewriter: entering specified fields only
Matthew Fanto
mfanto at gmail.com
Tue May 19 07:31:06 UTC 2009
On Tue, May 19, 2009 at 2:20 AM, Robert Backhaus-pqxx <pqxx at robbak.com>wrote:
> I am having trouble creating and using a tablewriter to enter data in only
> some fields of a table. Replies to this and other lists say it is done by
> specifying a list of column names, but I get only crashes.
>
I have an example that works for me, doing something similar, but take it
with a grain of salt. I could be completely off in the proper way of doing
it. It's also late, so I hope the pseudo-code makes sense.
I think the idea is you want to create a container of the column names. You
pass this container of column names to the tablewriter class. You then
create a container of the data to go into these columns. The final line,
W.push_back(dataForColumns) is because the tablewriter class supports STL
like inserters and push_back. effectively, you are pushing your container
into the table.
std::string TableName = "some table name";
std::vector<std::string> columnNames;
columnNames.push_back("name of column1");
columnNames.push_back("name of column2");
columnNames.push_back("name of column3");
columnNames.push_back("name of column4");
work P(*databaseConnection);
tablewriter W(P, TableName, columnNames.begin(), columnNames.end());
std::vector<std::string> dataForColumns;
dataForColumns.push_back(std::string for column 1);
dataForColumns.push_back(std::string for column 2);
dataForColumns.push_back(std::string for column 3);
dataForColumns.push_back(std::string for column 4);
W.push_back(dataForColumns); // push the data into the tablewriter
I hope this makes some sense, and feel free to correct any misunderstandings
I might have of how the class works.
Best,
Matthew Fanto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://pgfoundry.org/pipermail/libpqxx-general/attachments/20090519/2205079e/attachment.html
More information about the Libpqxx-general
mailing list