List:MySQL++« Previous MessageNext Message »
From:Adrian Cornish Date:May 19 2011 3:27am
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?

What do people think of this patch to easily solve Dan's problem.

Also includes a fix for the warning using -Wextra
./examples/stock.h:46:1: warning: type qualifiers ignored on function
return type [-Wignored-qualifiers]

Index: doc/userman/ssqls.dbx
===================================================================
--- doc/userman/ssqls.dbx       (revision 2690)
+++ doc/userman/ssqls.dbx       (working copy)
@@ -534,7 +534,19 @@
     gets used for many operations over an extended span of code.</para>
   </sect2>

+  <sect2 id="ssqls-field-count">
+    <title>Accessing total number of fields</title>
+    <para>This is the number of fields defined for the SSQLS structure.
+    it can be used with the static names[] array</para>
+    <programlisting>
+size_t num=stock::field_count;</programlisting>

+    <programlisting>
+for(size_t i=0; i<stock::field_count; ++i)
+   std::cout &lt;&lt; stock::names[i] &lt;&lt; std::endl;
+    </programlisting>
+  </sect2>
+
   <sect2 id="ssqls-in-header">
     <title>Using an SSQLS in Multiple Modules</title>

Index: lib/ssqls.pl
===================================================================
--- lib/ssqls.pl        (revision 2690)
+++ lib/ssqls.pl        (working copy)
@@ -499,8 +499,9 @@
        sql_compare_define_##CMP(NAME, $parmC)
        sql_construct_define_##CONTR(NAME, $parmC)
        static const char* names[];
+       static const size_t field_count = NAME##_NULL;
        static void table(const char* t) { table_ = t; }
-       const char* const table() const
+       const char* table() const
                        { return table_override_ ? table_override_ :
NAME::table_; }
        void instance_table(const char* t) { table_override_ = t; }
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