List:MySQL++« Previous MessageNext Message »
From:Adrian Cornish Date:May 19 2011 2:06am
Subject:Re: SSQLS: Number of colomns in a table
View as plain text  
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
Thread
Crash in DBDriver::fetch_row on a heavily loaded system...dancook)12 Apr
  • Re: Crash in DBDriver::fetch_row on a heavily loaded system...Adrian Cornish12 Apr
    • RE: Crash in DBDriver::fetch_row on a heavily loaded system...dancook)12 Apr
    • RE: Crash in DBDriver::fetch_row on a heavily loaded system...dancook)13 Apr
      • Re: Crash in DBDriver::fetch_row on a heavily loaded system...Warren Young13 Apr
        • Re: Crash in DBDriver::fetch_row on a heavily loaded system...Adrian Cornish13 Apr
          • Re: Crash in DBDriver::fetch_row on a heavily loaded system...Warren Young13 Apr
        • RE: Crash in DBDriver::fetch_row on a heavily loaded system...dancook)15 Apr
          • Re: Crash in DBDriver::fetch_row on a heavily loaded system...Warren Young15 Apr
            • Re: Crash in DBDriver::fetch_row on a heavily loaded system...Warren Young15 Apr
            • RE: Crash in DBDriver::fetch_row on a heavily loaded system...dancook)16 Apr
              • Re: Crash in DBDriver::fetch_row on a heavily loaded system...Warren Young16 Apr
          • SSQLS: Number of colomns in a tabledancook)19 May
            • Re: SSQLS: Number of colomns in a tableAdrian Cornish19 May
            • Re: SSQLS: Number of colomns in a tableAdrian Cornish19 May
              • Re: SSQLS: Number of colomns in a tableWarren Young19 May
                • Re: SSQLS: Number of colomns in a tableAdrian Cornish19 May
                  • RE: SSQLS: Number of colomns in a tabledancook)19 May
                  • Re: SSQLS: Number of colomns in a tableWarren Young19 May
                    • Re: SSQLS: Number of colomns in a tableWarren Young20 May
      • Re: Crash in DBDriver::fetch_row on a heavily loaded system...Adrian Cornish13 Apr
        • Re: Crash in DBDriver::fetch_row on a heavily loaded system...Warren Young13 Apr