Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DbiDemoData3.cxx

Go to the documentation of this file.
00001 
00002 // $Id: DbiDemoData3.cxx,v 1.24 2008/03/05 06:59:21 west Exp $
00003 //
00004 // DbiDemoData3
00005 //
00006 // Package: Dbi (Database Interface).
00007 
00008 // Begin_Html<img src="../../pedestrians.gif" align=center>
00009 // <a href="../source_warning.html">Warning for beginners</a>.<br>
00010 // Also see <a href="../../root_crib/index.html">The ROOT Crib</a> and
00011 // <a href="../index.html">The MINOS Class User Guide</a>End_Html
00012 //
00013 // N. West 02/2001
00014 //
00015 // Concept: A concrete data type corresponding to a single row in a
00016 //          database table of non-aggregated data with string data.
00017 //   
00018 // Purpose: Example type for test and demonstration purposes.
00019 //
00021 
00022 #include "TObject.h"    //Prevent hiding of TObject Compare
00023 
00024 #include "DatabaseInterface/test/DbiDemoData3.h"
00025 #include "MessageService/MsgService.h"
00026 #include "DatabaseInterface/DbiResultSet.h"
00027 #include "DatabaseInterface/DbiOutRowStream.h"
00028 #include "DatabaseInterface/DbiValidityRec.h"
00029 #include <cmath>
00030 
00031 ClassImp(DbiDemoData3)
00032 
00033 //   Definition of static data members
00034 //   *********************************
00035 
00036 CVSID("$Id: DbiDemoData3.cxx,v 1.24 2008/03/05 06:59:21 west Exp $\n  \
00037       CVSID_DBIRESULTPTR ");
00038 
00039 //   Definition of static  members functions
00040 //   ***************************************
00041 
00042 string DbiDemoData3::GetTableDescr(const char* alternateName /*= 0*/) {
00043 //
00044 //
00045 //  Purpose:  Return string "create table {DBIDEMODATA3|alternateName}(....)" to make table.
00046 //
00047 
00048   string sql("create table ");
00049   if ( alternateName ) sql += alternateName;
00050   else                 sql += "DBIDEMODATA3";
00051   sql += "( SEQNO          INT NOT NULL,";
00052   sql += "  ROW_COUNTER    INT NOT NULL,";
00053   sql += "  MYBOOL_1       CHAR,";
00054   sql += "  MYBOOL_2       CHAR,";
00055   sql += "  MYCHAR         CHAR,";
00056   sql += "  MYSTRING       TEXT,";
00057   sql += "  MYCHARS        CHAR(20),";
00058   sql += "  MYCHARS2       CHAR(2),";
00059   sql += "  MY_SS_TINY_1   TINYINT,";
00060   sql += "  MY_SS_TINY_2   TINYINT,";
00061   sql += "  MY_SS_TINY_3   TINYINT,";
00062   sql += "  MY_SS_TINY_4   TINYINT,";
00063   sql += "  MY_UU_TINY_1   TINYINT UNSIGNED,";
00064   sql += "  MY_UU_TINY_2   TINYINT UNSIGNED,";
00065   sql += "  MY_UU_TINY_3   TINYINT UNSIGNED,";
00066   sql += "  MY_UU_TINY_4   TINYINT UNSIGNED,";
00067   sql += "  MY_US_TINY_1   TINYINT,";
00068   sql += "  MY_US_TINY_2   TINYINT,";
00069   sql += "  MY_US_TINY_3   TINYINT,";
00070   sql += "  MY_US_TINY_4   TINYINT,";
00071   sql += "  MY_SS_SHORT_1  SMALLINT,";
00072   sql += "  MY_SS_SHORT_2  SMALLINT,";
00073   sql += "  MY_SS_SHORT_3  SMALLINT,";
00074   sql += "  MY_SS_SHORT_4  SMALLINT,";
00075   sql += "  MY_UU_SHORT_1  SMALLINT UNSIGNED,";
00076   sql += "  MY_UU_SHORT_2  SMALLINT UNSIGNED,";
00077   sql += "  MY_UU_SHORT_3  SMALLINT UNSIGNED,";
00078   sql += "  MY_UU_SHORT_4  SMALLINT UNSIGNED,";
00079   sql += "  MY_US_SHORT_1  SMALLINT,";
00080   sql += "  MY_US_SHORT_2  SMALLINT,";
00081   sql += "  MY_US_SHORT_3  SMALLINT,";
00082   sql += "  MY_US_SHORT_4  SMALLINT,";
00083   sql += "  MY_SS_INT_1    INT,";
00084   sql += "  MY_SS_INT_2    INT,";
00085   sql += "  MY_SS_INT_3    INT,";
00086   sql += "  MY_SS_INT_4    INT,";
00087   sql += "  MY_US_INT_1    INT,";
00088   sql += "  MY_US_INT_2    INT,";
00089   sql += "  MY_US_INT_3    INT,";
00090   sql += "  MY_US_INT_4    INT,";
00091   sql += "  MYFLOAT_1      FLOAT,";
00092   sql += "  MYFLOAT_2      FLOAT,";
00093   sql += "  MYDOUBLE_1     DOUBLE,";
00094   sql += "  MYDOUBLE_2     DOUBLE,";
00095   sql += "  primary key(SEQNO,ROW_COUNTER))";
00096   return sql;
00097 }
00098 
00099 //  Instantiate associated Result Pointer and Writer classes.
00100 //  ********************************************************
00101 
00102 #include "DatabaseInterface/DbiResultPtr.tpl"
00103 template class  DbiResultPtr<DbiDemoData3>;
00104 
00105 #include "DatabaseInterface/DbiWriter.tpl"
00106 template class  DbiWriter<DbiDemoData3>;
00107 
00108 // Apparently (Stroustrup 3rd edition) - 'static' is deprecated for
00109 // limiting function scope to file - unnamed namespace is better.
00110 
00111 namespace {
00112 
00113 // Helper function for Compare
00114 
00115   template<class T> void CompareValue(const T& thisValue, 
00116                                 const T& thatValue,
00117                                 const char* name,
00118                                 bool  printDiff,
00119                                 bool& matchedSofar) {
00120   
00121     if ( thisValue == thatValue ) return;
00122     if ( printDiff ) {
00123       if ( matchedSofar ) 
00124           MSG("Dbi",Msg::kInfo) << "Mismatch between DbiDemoData3 objects:-\n";
00125       MSG("Dbi",Msg::kInfo) << "   member " << name  << " this: " << thisValue << endl;
00126       MSG("Dbi",Msg::kInfo) << "   member " << name  << " that: " << thatValue << endl;
00127   
00128     }
00129     matchedSofar = false;
00130   }
00131   template<class T> void CompareValuewithTol(const T& thisValue, 
00132                                 const T& thatValue,
00133                                 const char* name,
00134                                 bool  printDiff,
00135                                            bool& matchedSofar,
00136                                 float tol) {
00137 
00138     float diff =  fabs(thisValue - thatValue)
00139                  /(fabs(thisValue) + fabs(thatValue));  
00140     if ( diff <= tol ) return;
00141     if ( printDiff ) {
00142       if ( matchedSofar ) 
00143         MSG("Dbi",Msg::kInfo) << "Mismatch between DbiDemoData3 objects:-\n" << setprecision(22);
00144       MSG("Dbi",Msg::kInfo) << "   member " << name  << " this: " << thisValue << endl;
00145       MSG("Dbi",Msg::kInfo) << "   member " << name  << " that: " << thatValue 
00146                           << " % difference: " << diff << endl;
00147     }
00148     matchedSofar = false;
00149   }
00150 }  // End of unnamed namespace
00151 
00152 
00153 // Definition of member functions (alphabetical order)
00154 // ***************************************************
00155 
00156 
00157 //.....................................................................
00158 
00159 DbiDemoData3::DbiDemoData3():
00160 fBool_1(1 == 1),
00161 fBool_2(1 != 1),
00162 fChar('a'),
00163 fString("Check special chars: backslash: \\ tab: \t newline: \n single quote: \' double quote:\""),
00164 fChars("abcdefgh"),
00165 fChars2("yz"),
00166 fSS_Tiny_1(0x0000),
00167 fSS_Tiny_2(0x007f),
00168 fSS_Tiny_3(-128),   //For some reason gcc 4.1 objects to 0xff80
00169 fSS_Tiny_4(-1),     //  "   "    "     "   "    "      " 0xffff
00170 fUU_Tiny_1(0x0000),
00171 fUU_Tiny_2(0x007f),
00172 fUU_Tiny_3(0x0080),
00173 fUU_Tiny_4(0x00ff),
00174 fUS_Tiny_1(0x0000),
00175 fUS_Tiny_2(0x007f),
00176 fUS_Tiny_3(0x0080),
00177 fUS_Tiny_4(0x00ff),
00178 fSS_Short_1(0x0000),
00179 fSS_Short_2(0x7fff),
00180 fSS_Short_3(0x8000),
00181 fSS_Short_4(0xffff),
00182 fUU_Short_1(0x0000),
00183 fUU_Short_2(0x7fff),
00184 fUU_Short_3(0x8000),
00185 fUU_Short_4(0xffff),
00186 fUS_Short_1(0x0000),
00187 fUS_Short_2(0x7fff),
00188 fUS_Short_3(0x8000),
00189 fUS_Short_4(0xffff),
00190 fSS_Int_1(0x00000000),
00191 fSS_Int_2(0x7fffffff),
00192 fSS_Int_3(0x80000001),
00193 fSS_Int_4(0xffffffff),
00194 fUS_Int_1(0x00000000),
00195 fUS_Int_2(0x7fffffff),
00196 fUS_Int_3(0x80000001),
00197 fUS_Int_4(0xffffffff),
00198 fFloat_1(14511.7998),
00199 fFloat_2(12345.550e+16),
00200 fDouble_1(-1.234567890123456789012345e+100),
00201 fDouble_2( 1.234567890123456789012345e-100)
00202 { 
00203 
00204 //  The default ctor.
00205 
00206  LEA_CTOR; 
00207 
00208  // Aug 2006: Testing using the new ROOT SQL interface there is a problem
00209  //           reading MySQL unsigned data if top bit set.  As we have no
00210  //           such data (and never will have as unsigned is now banned)
00211  //           just reset the values that cause problems.
00212 
00213  fUU_Tiny_3  = fUU_Tiny_4  = fUU_Tiny_1;
00214  fUU_Short_3 = fUU_Short_4 = fUU_Short_1;
00215 }
00216 
00217 //.....................................................................
00218 
00219 Bool_t DbiDemoData3::Compare(const DbiDemoData3* that, 
00220                              Bool_t printDiff /*= true*/) const {
00221 //
00222 //
00223 //  Purpose:  Compare to 'that' and optionally print differences
00224 //
00225 //  Return:   true if match.
00226 
00227   bool compare = true;
00228 
00229   if ( ! that ) {
00230     if ( printDiff )  MSG("Dbi",Msg::kInfo) << "Cannot compare DbiDemoData3 object; null pointer passed\n" << endl;
00231     return false;
00232   }
00233 
00234   float tol_double = 2.e-16;
00235   float tol_single = 0.;
00236 
00237   CompareValue(this->fBool_1,that->fBool_1,"fBool_1",printDiff,compare);
00238   CompareValue(this->fBool_2,that->fBool_2,"fBool_2",printDiff,compare);
00239   CompareValue(this->fChar,that->fChar,"fChar",printDiff,compare);
00240   CompareValue(this->fString,that->fString,"fString",printDiff,compare);
00241   CompareValue(this->fChars,that->fChars,"fChars",printDiff,compare);
00242   CompareValue(this->fChars2,that->fChars2,"fChars2",printDiff,compare);
00243   CompareValue(this->fSS_Tiny_1,that->fSS_Tiny_1,"fSS_Tiny_1",printDiff,compare);
00244   CompareValue(this->fSS_Tiny_2,that->fSS_Tiny_2,"fSS_Tiny_2",printDiff,compare);
00245   CompareValue(this->fSS_Tiny_3,that->fSS_Tiny_3,"fSS_Tiny_3",printDiff,compare);
00246   CompareValue(this->fSS_Tiny_4,that->fSS_Tiny_4,"fSS_Tiny_4",printDiff,compare);
00247   CompareValue(this->fUU_Tiny_1,that->fUU_Tiny_1,"fUU_Tiny_1",printDiff,compare);
00248   CompareValue(this->fUU_Tiny_2,that->fUU_Tiny_2,"fUU_Tiny_2",printDiff,compare);
00249   CompareValue(this->fUU_Tiny_3,that->fUU_Tiny_3,"fUU_Tiny_3",printDiff,compare);
00250   CompareValue(this->fUU_Tiny_4,that->fUU_Tiny_4,"fUU_Tiny_4",printDiff,compare);
00251   CompareValue(this->fUS_Tiny_1,that->fUS_Tiny_1,"fUS_Tiny_1",printDiff,compare);
00252   CompareValue(this->fUS_Tiny_2,that->fUS_Tiny_2,"fUS_Tiny_2",printDiff,compare);
00253   CompareValue(this->fUS_Tiny_3,that->fUS_Tiny_3,"fUS_Tiny_3",printDiff,compare);
00254   CompareValue(this->fUS_Tiny_4,that->fUS_Tiny_4,"fUS_Tiny_4",printDiff,compare);
00255   CompareValue(this->fSS_Short_1,that->fSS_Short_1,"fSS_Short_1",printDiff,compare);
00256   CompareValue(this->fSS_Short_2,that->fSS_Short_2,"fSS_Short_2",printDiff,compare);
00257   CompareValue(this->fSS_Short_3,that->fSS_Short_3,"fSS_Short_3",printDiff,compare);
00258   CompareValue(this->fSS_Short_4,that->fSS_Short_4,"fSS_Short_4",printDiff,compare);
00259   CompareValue(this->fUU_Short_1,that->fUU_Short_1,"fUU_Short_1",printDiff,compare);
00260   CompareValue(this->fUU_Short_2,that->fUU_Short_2,"fUU_Short_2",printDiff,compare);
00261 
00262 //  Exclude short unsigned application to unsigned table where top bit is set.
00263 //  Currently (as of December 2005) there is a problem with these when run in
00264 //  a mixed (Oracle,MySQL) cascade.  Unsigned isn't support although it still
00265 //  works with a MySQL database so skipping this test isn't a bad thing to do.
00266 
00267 //  CompareValue(this->fUU_Short_3,that->fUU_Short_3,"fUU_Short_3",printDiff,compare);
00268 //  CompareValue(this->fUU_Short_4,that->fUU_Short_4,"fUU_Short_4",printDiff,compare);
00269 
00270   CompareValue(this->fUS_Short_1,that->fSS_Short_1,"fUS_Short_1",printDiff,compare);
00271   CompareValue(this->fUS_Short_2,that->fUS_Short_2,"fUS_Short_2",printDiff,compare);
00272   CompareValue(this->fUS_Short_3,that->fUS_Short_3,"fUS_Short_3",printDiff,compare);
00273   CompareValue(this->fUS_Short_4,that->fUS_Short_4,"fUS_Short_4",printDiff,compare);
00274   CompareValue(this->fSS_Int_1,that->fSS_Int_1,"fSS_Int_1",printDiff,compare);
00275   CompareValue(this->fSS_Int_2,that->fSS_Int_2,"fSS_Int_2",printDiff,compare);
00276   CompareValue(this->fSS_Int_3,that->fSS_Int_3,"fSS_Int_3",printDiff,compare);
00277   CompareValue(this->fSS_Int_4,that->fSS_Int_4,"fSS_Int_4",printDiff,compare);
00278   CompareValue(this->fUS_Int_1,that->fUS_Int_1,"fUS_Int_1",printDiff,compare);
00279   CompareValue(this->fUS_Int_2,that->fUS_Int_2,"fUS_Int_2",printDiff,compare);
00280   CompareValue(this->fUS_Int_3,that->fUS_Int_3,"fUS_Int_3",printDiff,compare);
00281   CompareValue(this->fUS_Int_4,that->fUS_Int_4,"fUS_Int_4",printDiff,compare);
00282   CompareValuewithTol(this->fFloat_1,that->fFloat_1,"fFloat_1",printDiff,compare,tol_single);
00283   CompareValuewithTol(this->fFloat_2,that->fFloat_2,"fFloat_2",printDiff,compare,tol_single);
00284   CompareValuewithTol(this->fDouble_1,that->fDouble_1,"fDouble_1",printDiff,compare,tol_double);
00285   CompareValuewithTol(this->fDouble_2,that->fDouble_2,"fDouble_2",printDiff,compare,tol_double);
00286   return compare;
00287 
00288 }
00289 
00290 
00291 //.....................................................................
00292 
00293 void DbiDemoData3::Fill(DbiResultSet& rs,
00294                         const DbiValidityRec* /* vrec */) {
00295 //
00296 //
00297 //  Purpose:  Fill oject from Result Set
00298 //
00299 //  Arguments: 
00300 //    rs           in    Result Set used to fill object
00301 //    vrec         in    Associated validity record (or 0 if filling
00302 //                                                    DbiValidityRec)
00303 //
00304 //  Return:    
00305 //
00306 //  Contact:   N. West
00307 //
00308 //  Specification:-
00309 //  =============
00310 //
00311 //  o Fill object from current row of Result Set.
00312 
00313 //  Program Notes:-
00314 //  =============
00315 
00316 //  None.
00317 
00318   this->JunkFill();
00319   rs >> fBool_1     >> fBool_2   >> fChar >> fString >> fChars >> fChars2
00320      >> fSS_Tiny_1  >> fSS_Tiny_2  >> fSS_Tiny_3  >> fSS_Tiny_4 
00321      >> fUU_Tiny_1  >> fUU_Tiny_2  >> fUU_Tiny_3  >> fUU_Tiny_4
00322      >> fUS_Tiny_1  >> fUS_Tiny_2  >> fUS_Tiny_3  >> fUS_Tiny_4
00323      >> fSS_Short_1 >> fSS_Short_2 >> fSS_Short_3 >> fSS_Short_4 
00324      >> fUU_Short_1 >> fUU_Short_2 >> fUU_Short_3 >> fUU_Short_4
00325      >> fUS_Short_1 >> fUS_Short_2 >> fUS_Short_3 >> fUS_Short_4
00326      >> fSS_Int_1   >> fSS_Int_2   >> fSS_Int_3   >> fSS_Int_4 
00327      >> fUS_Int_1   >> fUS_Int_2   >> fUS_Int_3   >> fUS_Int_4
00328      >> fFloat_1    >> fFloat_2    >> fDouble_1   >> fDouble_2 ;
00329 
00330 }
00331 
00332 //.....................................................................
00333 
00334 void DbiDemoData3::JunkFill() {
00335 //
00336 //
00337 //  Purpose:  Fill oject with junk (to ensure a subsequent positive fill test is genuine)
00338 //
00339 
00340  fBool_1 = 0;
00341  fBool_2 = 1;
00342  fChar = 'z';
00343  fString = "";
00344  fChars = "";
00345  fChars2 = "";
00346  fSS_Tiny_1  = fSS_Tiny_2  = fSS_Tiny_3  = fSS_Tiny_4 = 999;
00347  fUU_Tiny_1  = fUU_Tiny_2  = fUU_Tiny_3  = fUU_Tiny_4 = 999;
00348  fUS_Tiny_1  = fUS_Tiny_2  = fUS_Tiny_3  = fUS_Tiny_4 = 999;
00349  fSS_Short_1 = fSS_Short_2 = fSS_Short_3 = fSS_Short_4 = 999;
00350  fUU_Short_1 = fUU_Short_2 = fUU_Short_3 = fUU_Short_4 = 999;
00351  fUS_Short_1 = fUS_Short_2 = fUS_Short_3 = fUS_Short_4 = 999;
00352  fSS_Int_1   = fSS_Int_2   = fSS_Int_3   = fSS_Int_4   = 999;
00353  fUS_Int_1   = fUS_Int_2   = fUS_Int_3   = fUS_Int_4   = 999;
00354  fFloat_1    = fFloat_2    = fDouble_1   = fDouble_2   = 999.999;
00355    
00356 }
00357 
00358 //.....................................................................
00359 
00360 void DbiDemoData3::Store(DbiOutRowStream& ors,
00361                          const DbiValidityRec* /* vrec */) const {
00362 //
00363 //
00364 //  Purpose:  Stream object to output row stream
00365 //
00366 //  Arguments: 
00367 //    ors          in     Output row stream.
00368 //    vrec         in    Associated validity record (or 0 if filling
00369 //                                                    DbiValidityRec)
00370 //
00371 //  Return:    
00372 //
00373 //  Contact:   N. West
00374 //
00375 //  Specification:-
00376 //  =============
00377 //
00378 //  o  Stream object to output row stream.
00379 
00380 //  Program Notes:-
00381 //  =============
00382 
00383 //  None.
00384 
00385   const Char_t*  pChars = fChars.c_str();  // Test char* output
00386 
00387   ors << fBool_1     << fBool_2   << fChar << fString << pChars << fChars2
00388       << fSS_Tiny_1  << fSS_Tiny_2  << fSS_Tiny_3  << fSS_Tiny_4 
00389       << fUU_Tiny_1  << fUU_Tiny_2  << fUU_Tiny_3  << fUU_Tiny_4
00390       << fUS_Tiny_1  << fUS_Tiny_2  << fUS_Tiny_3  << fUS_Tiny_4
00391       << fSS_Short_1 << fSS_Short_2 << fSS_Short_3 << fSS_Short_4 
00392       << fUU_Short_1 << fUU_Short_2 << fUU_Short_3 << fUU_Short_4
00393       << fUS_Short_1 << fUS_Short_2 << fUS_Short_3 << fUS_Short_4
00394       << fSS_Int_1   << fSS_Int_2   << fSS_Int_3   << fSS_Int_4 
00395       << fUS_Int_1   << fUS_Int_2   << fUS_Int_3   << fUS_Int_4
00396       << fFloat_1    << fFloat_2    << fDouble_1   << fDouble_2 ;
00397    
00398 }
00399 
00400 /*    Template for New Member Function
00401 
00402 //.....................................................................
00403 
00404 DbiDemoData3:: {
00405 //
00406 //
00407 //  Purpose:  
00408 //
00409 //  Arguments: 
00410 //    xxxxxxxxx    in    yyyyyy
00411 //
00412 //  Return:    
00413 //
00414 //  Contact:   N. West
00415 //
00416 //  Specification:-
00417 //  =============
00418 //
00419 //  o 
00420 
00421 //  Program Notes:-
00422 //  =============
00423 
00424 //  None.
00425 
00426 
00427 }
00428 
00429 */
00430 

Generated on Mon Feb 15 11:06:34 2010 for loon by  doxygen 1.3.9.1