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 << stock::names[i] << 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; }