List:MySQL++« Previous MessageNext Message »
From:Adrian Cornish Date:May 22 2011 4:04pm
Subject:Patch for number of fields from ssqls classes
View as plain text  
Warren,

It is impossible to replace the other two instances of NAME##_NULL
with static variable. Since this was the case I left it in the enum
anyway. I do not use it for the initializer for ssqls::field_count
though

Trying to use ssqls::field_count in initializer produces errors like this
./test/qssqls.cpp:56:1: error: pasting "test" and "::" does not give a
valid preprocessing token

Which can be easily replicated with below code. According to some
searching gcc is correct.
struct foo
{
   static int bar;
};
int foo::bar;
#define ref(NAME) NAME##::bar

int main(void)
{
   foo::bar=87;
   ref(foo)=23;
   return 0;
}
foo.cc:11:1: error: pasting "foo" and "::" does not give a valid
preprocessing token


Adrian

Index: doc/userman/ssqls.dbx
===================================================================
--- doc/userman/ssqls.dbx       (revision 2692)
+++ 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 2692)
+++ lib/ssqls.pl        (working copy)
@@ -499,6 +499,7 @@
        sql_compare_define_##CMP(NAME, $parmC)
        sql_construct_define_##CONTR(NAME, $parmC)
        static const char* names[];
+       static const size_t field_count = $i;
        static void table(const char* t) { table_ = t; }
        const char* const table() const
                        { return table_override_ ? table_override_ :
NAME::table_; }
Thread
Patch for number of fields from ssqls classesAdrian Cornish22 May
  • Re: Patch for number of fields from ssqls classesWarren Young23 May
    • RE: Patch for number of fields from ssqls classesdancook)31 May
      • Re: Patch for number of fields from ssqls classesWarren Young31 May
        • RE: Patch for number of fields from ssqls classesdancook)31 May
          • RE: Patch for number of fields from ssqls classesdancook)1 Jun