On Tue, May 17, 2011 at 3:26 PM, Dan Cook (dancook) <dancook@stripped> wrote:
> I hope this is an "easy" question.
> I would like to know if there is a way to know how many columns a table
> has. I would like to use the equal list similar to the sample code, but
> the size of the vector<bool> is "hard coded" with the number of columns.
> Is there a variable I can look at to get the number of columns on a
> SSQLS object?
>
> Sample Code:
> vector<bool> v(5, false);
> v[stock_weight] = true;
> v[stock_price] = true;
> query << "select * from stock where "
> << res[0].equal_list(" and ", v);
>
> I am looking for a variable to replace "5" in the above code.
Dan,
There is an enumeration value created called <tablename>_NULL which is
1 based count of fields. Not sure you can rely on it - but it might be
nice to add to a const to the struct like stock::table_ for the
tablename
#include "stock.h"
int main()
{
std::cout << "Fields=" << stock_NULL << std::endl;
}
adrian@iceweasel:~/mysqlpp/examples> a.out
Fields=6
Or another alternative is the INFORMATION_SCHEMA. but they may not
match the SSQLS
mysql> select count(*) as total FROM INFORMATION_SCHEMA.COLUMNS WHERE
TABLE_NAME="stock" AND TABLE_SCHEMA="mysql_cpp_data";
+-------+
| total |
+-------+
| 6 |
+-------+
1 row in set (0.01 sec)
Adrian