Author: wyoung
Date: Fri Feb 15 09:51:18 2008
New Revision: 2204

URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2204&view=rev
Log:
- Added SSQLS::instance_table(const char*) instance member function,
  paralleling the table(const char*) static member function, allowing
  you to override the table name on a per-instance basis if you need to.
- SSQLS::table(void) is now an instance member function, not static, so
  it can return the per-instance table name override if it's set.  If
  not, it returns the static one, like always.  Syntax for calling this
  doesn't change, so it shouldn't break anything.

Modified:
    trunk/doc/userman/ssqls.dbx
    trunk/lib/ssqls.pl

Modified: trunk/doc/userman/ssqls.dbx
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/doc/userman/ssqls.dbx?rev=2204&r1=2203&r2=2204&view=diff
==============================================================================
--- trunk/doc/userman/ssqls.dbx (original)
+++ trunk/doc/userman/ssqls.dbx Fri Feb 15 09:51:18 2008
@@ -208,13 +208,36 @@
     features.</para>
 
     <para>Another feature you might find a use for is changing the
-    table name used in queries. By default, the table in the MySQL
-    database is assumed to have the same name as the SSQLS structure
-    type. But if this is inconvenient, you can globally change the
-    table name used in queries like this:</para>
+    table name MySQL++ uses to build queries involving SSQLSes. By
+    default, the database server table is assumed to have the same name
+    as the SSQLS structure type. But if this is inconvenient, you can
+    globally change the table name used in queries like this:</para>
 
     <programlisting>
 stock::table("MyStockData");</programlisting>
+
+    <para>It&rsquo;s also possible to change the name of a table on
+    a per-instance basis:</para>
+
+    <programlisting>
+stock s;
+s.instance_table("AlternateTable");</programlisting>
+
+    <para>This is useful when you have an SSQLS definition that is
+    compatible with multiple tables, so the table name to use for each
+    instance is different. The simplest way this can happen is if the
+    tables all have identical definitions; it saves you from having
+    to define a separate SSQLS for each table. It is also useful for
+    mapping a class hierarchy onto a set of table definitions. The
+    common SSQLS definition is the &ldquo;superclass&rdquo; for a
+    given set of tables.</para>
+
+    <para>Strictly speaking, you only need to use this feature in
+    multithreaded programs. Changing the static table name before
+    using each instance is safe if all changes happen within a single
+    thread. That said, it may still be convenient to change the name of
+    the table for an SSQLS instance in a single-threaded program if it
+    gets used for many operations over an extended span of code.</para>
   </sect2>
 
 

Modified: trunk/lib/ssqls.pl
URL: 
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/ssqls.pl?rev=2204&r1=2203&r2=2204&view=diff
==============================================================================
--- trunk/lib/ssqls.pl (original)
+++ trunk/lib/ssqls.pl Fri Feb 15 09:51:18 2008
@@ -188,10 +188,10 @@
 #define sql_COMPARE__0(NAME, $parm1)
 
 #define sql_compare_type_def_0(NAME, WHAT, NUM) \\
-  sql_compare_type_def_##NUM (NAME, WHAT, NUM)
+  sql_compare_type_def_##NUM(NAME, WHAT, NUM)
 
 #define sql_compare_type_defe_0(NAME, WHAT, NUM) \\
-  sql_compare_type_defe_##NUM (NAME, WHAT, NUM)
+  sql_compare_type_defe_##NUM(NAME, WHAT, NUM)
 
 // ---------------------------------------------------
 //                 End Mandatory Compare 
@@ -229,7 +229,7 @@
 // ---------------------------------------------------
 
 #define sql_compare_define_$i(NAME, $parm0) \\
-  NAME ($parm2) : $define {} \\
+  NAME($parm2) : $define {} \\
   void set  ($parm2) { \\
 $set \\
   } \\
@@ -239,7 +239,7 @@
   void set  ($parm2) { \\
 $set \\
   } \\
-  NAME ($parm2) : $define {}
+  NAME($parm2) : $define, table_override_(0) {}
 
 #define sql_compare_type_def_$i(NAME, WHAT, NUM) \\
   return WHAT##_list(d, m, $compp)
@@ -249,7 +249,7 @@
 
 #define sql_COMPARE__$i(NAME, $parm1) \\
   template <mysqlpp::sql_dummy_type dummy> \\
-  int sql_compare_##NAME (const NAME &x, const NAME &y) { \\
+  int sql_compare_##NAME(const NAME &x, const NAME &y) { \\
 $compr \\
   } \\
   template <mysqlpp::sql_dummy_type dummy> \\
@@ -471,18 +471,20 @@
       : obj(o), include(i), del_vector(false), delim(d), comp(c), manip(m) {}
   };
 
-  template <mysqlpp::sql_dummy_type dummy> int sql_compare_##NAME (const NAME 
&, const NAME &);
+  template <mysqlpp::sql_dummy_type dummy> int sql_compare_##NAME(const NAME&, 
const NAME&);
 
   struct NAME { 
 $defs 
-    NAME () {} 
-    NAME (const mysqlpp::Row &row);
-    void set (const mysqlpp::Row &row);
+    NAME() : table_override_(0) {} 
+    NAME(const mysqlpp::Row& row);
+    void set(const mysqlpp::Row &row);
     sql_compare_define_##CMP(NAME, $parmC)
     sql_construct_define_##CONTR(NAME, $parmC)
     static const char* names[];
-    static const char* const table() { return table_; }
     static void table(const char* t) { table_ = t; }
+    const char* const table() const
+            { return table_override_ ? table_override_ : NAME::table_; }
+    void instance_table(const char* t) { table_override_ = t; }
 
     NAME##_value_list<mysqlpp::quote_type0> value_list() const {
       return value_list(",", mysqlpp::quote);}
@@ -654,12 +656,13 @@
 
   private:
     static const char* table_;
+    const char* table_override_;
   }; 
   MYSQLPP_SSQLS_CONDITIONAL_STATICS(
          const char *NAME::names[] = { 
                 $names
          }; 
-         const char *NAME::table_ = #NAME ;
+         const char* NAME::table_ = #NAME;
   )
 
   template <class Manip>
@@ -842,31 +845,36 @@
   template <class Manip>
   inline NAME##_cus_value_list<Manip> 
   NAME::value_list(const char *d, Manip m, mysqlpp::sql_cmp_type /*sc*/) const 
{
-    sql_compare_type_def_##CMP (NAME, value, NUM);
+    sql_compare_type_def_##CMP(NAME, value, NUM);
   }
 
   template <class Manip>
   inline NAME##_cus_field_list<Manip> 
   NAME::field_list(const char *d, Manip m, mysqlpp::sql_cmp_type /*sc*/) const 
{
-    sql_compare_type_def_##CMP (NAME, field, NUM);
+    sql_compare_type_def_##CMP(NAME, field, NUM);
   }
 
   template <class Manip>
   inline NAME##_cus_equal_list<Manip> 
   NAME::equal_list(const char *d, const char *c, Manip m, 
mysqlpp::sql_cmp_type /*sc*/) const {
-    sql_compare_type_defe_##CMP (NAME, equal, NUM);
+    sql_compare_type_defe_##CMP(NAME, equal, NUM);
   }
 
   template <mysqlpp::sql_dummy_type dummy> 
-  void populate_##NAME (NAME *s, const mysqlpp::Row &row) { 
+  void populate_##NAME(NAME *s, const mysqlpp::Row &row) { 
        mysqlpp::NoExceptions ignore_schema_mismatches(row);
 $popul
   } 
 
-  inline NAME::NAME (const mysqlpp::Row &row) 
-                                        
{populate_##NAME<mysqlpp::sql_dummy>(this, row);}
-  inline void NAME::set (const mysqlpp::Row &row)
-                                        
{populate_##NAME<mysqlpp::sql_dummy>(this, row);}
+  inline NAME::NAME(const mysqlpp::Row& row) :
+  table_override_(0)
+  {
+    populate_##NAME<mysqlpp::sql_dummy>(this, row);
+  }
+  inline void NAME::set(const mysqlpp::Row& row)
+  {
+    populate_##NAME<mysqlpp::sql_dummy>(this, row);
+  }
 
   sql_COMPARE__##CMP(NAME, $parmc )
 


_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits

Reply via email to