Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

Snapshot.cpp

Go to the documentation of this file.
00001 // /******************************************************************************\
00002 // *
00003 // * File:          Snapshot.cpp
00004 // * Creation date: May 17, 2001 19:02
00005 // * Author:        ClassBuilder
00006 // *                XXXX
00007 // * Purpose:       Method implementations of class 'DOSnapshot'
00008 // *
00009 // * Modifications: @INSERT_MODIFICATIONS(* )
00010 // * June 01, 2001 16:48 WERS
00011 // *     Updated code of method 'Let'
00012 // *     Updated code of method 'Let'
00013 // * May 25, 2001 15:27 WERS
00014 // *     Updated interface of method 'CommitAdd'
00015 // * May 25, 2001 15:21 WERS
00016 // *     Added member 'm_LastInsertId'
00017 // *     Updated code of method 'CommitAdd'
00018 // * May 25, 2001 14:48 WERS
00019 // *     Updated interface of method 'Let'
00020 // * May 25, 2001 14:47 WERS
00021 // *     Added method 'Let'
00022 // *     Added method 'Let'
00023 // * May 18, 2001 10:36 WERS
00024 // *     Updated code of method 'Let'
00025 // *     Updated code of method 'Let'
00026 // *     Updated code of method 'Edit'
00027 // * May 18, 2001 10:34 WERS
00028 // *     Updated code of method 'CommitEdit'
00029 // * May 18, 2001 10:27 WERS
00030 // *     Updated code of method 'CommitAdd'
00031 // *     Updated code of method 'AddNew'
00032 // * May 17, 2001 20:47 WERS
00033 // *     Updated interface of method 'CommitEdit'
00034 // *     Updated interface of method 'CommitAdd'
00035 // * May 17, 2001 19:39 WERS
00036 // *     Updated code of method 'CommitAdd'
00037 // * May 17, 2001 19:31 WERS
00038 // *     Added method 'Edit'
00039 // *     Added method 'CommitEdit'
00040 // *     Added method 'CommitAdd'
00041 // * May 17, 2001 19:22 WERS
00042 // *     Added method 'Let'
00043 // *     Added method 'Let'
00044 // * May 17, 2001 19:13 WERS
00045 // *     Updated code of method 'AddNew'
00046 // *     Updated member 'm_pNewData'
00047 // * May 17, 2001 19:09 WERS
00048 // *     Added method 'AddNew'
00049 // *     Added member 'm_pNewData'
00050 // *     Updated code of method '~DOSnapshot'
00051 // * May 17, 2001 19:04 WERS
00052 // *     Updated code of method '~DOSnapshot'
00053 // *     Updated code of method 'DOSnapshot'
00054 // * May 17, 2001 19:02 WERS
00055 // *     Added method 'DestructorInclude'
00056 // *     Added method 'ConstructorInclude'
00057 // *     Added method '~DOSnapshot'
00058 // *     Added method 'DOSnapshot'
00059 // *     Added inheritance 'DOQuery'
00060 // *
00061 // *
00062 // \******************************************************************************/
00063 //@START_USER1
00068 /* --------------------------------------------------------------
00069 Copyright (C) 2001 LifeLine Networks BV <soap2corba@lifeline.nl>
00070 
00071 This program is free software; you can redistribute it and/or
00072 modify it under the terms of the GNU General Public License
00073 as published by the Free Software Foundation; either
00074 version 2 of the License, or (at your option) any later
00075 version.
00076 
00077 This program is distributed in the hope that it will be useful,
00078 but WITHOUT ANY WARRANTY; without even the implied warranty of
00079 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00080 GNU General Public License for more details.
00081 
00082 You should have received a copy of the GNU General Public License
00083 along with this program; if not, write to the Free Software
00084 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00085 -------------------------------------------------------------- */
00086 //@END_USER1
00087 
00088 
00089 // Master include file
00090 #include "DbObjects.h"
00091 
00092 
00093 //@START_USER2
00094 //@END_USER2
00095 
00096 
00097 // Static members
00098 
00099 
00103 DOSnapshot::DOSnapshot(DOConnection* pConnection,
00104                        const char* tableName) //@INIT_267
00105     : DOQuery(pConnection)
00106     , m_pNewData(NULL)
00107     , m_LastInsertId(0)
00108 {//@CODE_267
00109     ConstructorInclude();
00110 
00111     CString q = "select * from ";
00112     q += tableName;
00113     Query (q);
00114 }//@CODE_267
00115 
00116 
00120 DOSnapshot::~DOSnapshot()
00121 {//@CODE_262
00122     DestructorInclude();
00123     if (m_pNewData) {
00124         unsigned int i, nfld = GetNumFields ();
00125         for (i = 0; i < nfld; i ++) {
00126             delete m_pNewData [i];
00127             m_pNewData [i] = NULL;
00128         }
00129         delete[] m_pNewData;
00130     }
00131 
00132     // Put in your own code
00133 }//@CODE_262
00134 
00135 
00142 void DOSnapshot::AddNew()
00143 {//@CODE_271
00144     unsigned int i, nfld = GetNumFields ();
00145     if (!m_pNewData) {
00146         m_pNewData = new CString* [nfld];
00147         for (i = 0; i < nfld; i ++) {
00148             m_pNewData [i] = NULL;
00149         }
00150     } else {
00151         for (i = 0; i < nfld; i ++) {
00152             delete m_pNewData [i];
00153             m_pNewData [i] = NULL;
00154         }
00155     }
00156 }//@CODE_271
00157 
00158 
00165 void DOSnapshot::CommitAdd(bool refresh, bool delayedAllowed)
00166 {//@CODE_281
00167     CString query;
00168     if (refresh || !delayedAllowed) query = "insert into ";
00169     else query = "insert delayed into ";
00170     query += m_query.Mid (m_query.ReverseFind (' ') + 1);
00171     query += "(";
00172     bool first = true;
00173     DOQuery::QueryFieldIterator iFld(this);
00174     while (++iFld)
00175     {
00176         if (m_pNewData [iFld->GetNumber ()]) {
00177             if (!first) query += ", ";
00178             else first = false;
00179             query += iFld->GetName ();
00180         }
00181     }
00182     query += ") values (";
00183     iFld.Reset ();
00184     first = true;
00185     while (++iFld)
00186     {
00187         if (m_pNewData [iFld->GetNumber ()]) {
00188             if (!first) query += ", ";
00189             else first = false;
00190             if (!iFld->isNum ()) {
00191                 query += "'";
00192             }
00193             query += *(m_pNewData [iFld->GetNumber ()]);
00194             if (!iFld->isNum ()) {
00195                 query += "'";
00196             }
00197         }
00198     }
00199     query += ")";
00200     mysql_query (GetConnection()->GetHdl(), query);
00201     if (refresh || !delayedAllowed) {
00202         m_LastInsertId = (int) mysql_insert_id (GetConnection()->GetHdl());
00203     } else {
00204         m_LastInsertId = 0;
00205     }
00206     if (refresh) Query (m_query);
00207 }//@CODE_281
00208 
00209 
00219 void DOSnapshot::CommitEdit(bool refresh)
00220 {//@CODE_282
00221     CString query = "update low_priority ";
00222     query += m_query.Mid (m_query.ReverseFind (' ') + 1);
00223     query += " set ";
00224     CString where, sets;
00225     bool first = true;
00226     DOQuery::QueryFieldIterator iFld(this);
00227     while (++iFld)
00228     {
00229         if (m_pNewData [iFld->GetNumber ()] && 
00230             *(m_pNewData [iFld->GetNumber ()]) != iFld->GetValue ()) {
00231             if (!first) sets += ", ";
00232             else first = false;
00233             sets += iFld->GetName ();
00234             sets += '=';
00235             if (!iFld->isNum ()) {
00236                 sets += "'";
00237             }
00238             sets += *(m_pNewData [iFld->GetNumber ()]);
00239             if (!iFld->isNum ()) {
00240                 sets += "'";
00241             }
00242         } else if (!m_pNewData [iFld->GetNumber ()] && !iFld->isNull ()) {
00243             if (!first) sets += ", ";
00244             else first = false;
00245             sets += iFld->GetName ();
00246             sets += "=NULL";
00247         }
00248         if (iFld->isPriKey ()) {
00249             if (where.IsEmpty ()) {
00250                 where = " where (";
00251             } else {
00252                 where += " and (";
00253             }
00254             where += iFld->GetName ();
00255             where += '=';
00256             if (!iFld->isNum ()) {
00257                 where += "'";
00258             }
00259             where += iFld->GetValue ();
00260             if (!iFld->isNum ()) {
00261                 where += "'";
00262             }
00263             where += ")";
00264         }
00265     }
00266     if (!first && (!where.IsEmpty () || GetNumRows () == 1)) {
00267         mysql_query (GetConnection()->GetHdl(), query + sets + where);
00268         if (refresh) Query (m_query);
00269     }
00270 }//@CODE_282
00271 
00272 
00279 void DOSnapshot::Edit()
00280 {//@CODE_283
00281     unsigned int nfld = GetNumFields ();
00282     if (!m_pNewData) {
00283         m_pNewData = new CString* [nfld];
00284         unsigned int i;
00285         for (i = 0; i < nfld; i ++) {
00286             m_pNewData [i] = NULL;
00287         }
00288     }
00289     DOQuery::QueryFieldIterator iFld(this);
00290     while (++iFld)
00291     {
00292         if (iFld->isNull()) {
00293             delete m_pNewData [iFld->GetNumber ()];
00294             m_pNewData [iFld->GetNumber ()] = NULL;
00295         } else {
00296             if (!m_pNewData [iFld->GetNumber ()]) {
00297                 m_pNewData [iFld->GetNumber ()] = new CString;
00298             }
00299             *(m_pNewData [iFld->GetNumber ()]) = iFld->GetValue ();
00300         }
00301     }
00302 }//@CODE_283
00303 
00304 
00308 void DOSnapshot::Let(const char* fldName, const char* value)
00309 {//@CODE_272
00310     Let (FindQueryField(fldName)->GetNumber (), value);
00311 }//@CODE_272
00312 
00313 
00317 void DOSnapshot::Let(const unsigned int fldNum, const char* value)
00318 {//@CODE_275
00319     if (!m_pNewData) return;
00320     if (fldNum >= GetNumFields ()) return;
00321     if (value && !m_pNewData [fldNum]) m_pNewData [fldNum] = new CString;
00322     if (value) {
00323         *(m_pNewData [fldNum]) = value;
00324     } else {
00325         delete m_pNewData [fldNum];
00326         m_pNewData [fldNum] = NULL;
00327     }
00328 }//@CODE_275
00329 
00330 
00334 void DOSnapshot::Let(const char* fldName, int value)
00335 {//@CODE_291
00336     CString num;
00337     num.Format ("%d", value);
00338     Let (fldName, num);
00339 }//@CODE_291
00340 
00341 
00345 void DOSnapshot::Let(const unsigned int fldNum, int value)
00346 {//@CODE_294
00347     CString num;
00348     num.Format ("%d", value);
00349     Let (fldNum, num);
00350 }//@CODE_294
00351 
00352 
00353 //{{AFX DO NOT EDIT CODE BELOW THIS LINE !!!
00354 
00358 void DOSnapshot::ConstructorInclude()
00359 {
00360 }
00361 
00362 
00366 void DOSnapshot::DestructorInclude()
00367 {
00368 }
00369 
00370 
00371 // Methods for the relation(s) of the class
00372 
00373 //}}AFX DO NOT EDIT CODE ABOVE THIS LINE !!!
00374 
00375 //@START_USER3
00376 

This documentation is part of the "SOAP to CORBA bridge" project
Copyright © 2000 by Lifeline Networks bv.
All rights are reserved.