Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-03 08:22:06

0001 // $Id: TSQLStatement.cxx,v 1.1.1.1 2004/02/18 20:58:02 dave Exp $
0002 //*-- Author : Valeriy Onuchin 14/02/2000 
0003 //
0004 
0005 /////////////////////////////////////////////////////////////////////
0006 //
0007 // The object used for executing a static SQL statement and 
0008 // obtaining the results produced by it. 
0009 // 
0010 // Only one TSQLResultSet per TSQLStatement can be open at any point 
0011 // in time. Therefore, if the reading of one TSQLResultSet is
0012 // interleaved with the reading of another, each must have been 
0013 // generated by different TSQLStatements. All statement execute 
0014 // methods  implicitly close a statment's current TSQLResultSet if 
0015 // an open  one exists. 
0016 //
0017 // See also: 
0018 //    TSQLConnection::CreateStatement(), TSQLResultSet 
0019 //    TSQLCallableStatement TSQLPreparedStatement
0020 //Begin_Html
0021 /*
0022 <P>
0023    The <TT>TSQLStatement</TT> class encapsulates SQL queries to your database. 
0024 Using several methods, these calls return objects that contain the 
0025 results of your SQL query. When you execute an SQL query, the data 
0026 that is returned to you is commonly called the result set. You can 
0027 choose from several result sets, depending on your needs:
0028 <UL>
0029 <LI><TT>TSQLResultSet* ExecuteQuery( const TString& sqlStatement)<BR></TT>
0030 This method sends the SQL query contained in <TT>sqlStatement</TT>
0031 and returns a single set of results. This method is best used 
0032 in sending  <TT>SELECT</TT> statements. These statements typically 
0033 return a result set. This method implicitly deletes previous resultset.
0034 
0035 <LI><TT>Int_t ExecuteUpdate( const TString& sqlStatement )<BR></TT>
0036 This method sends the SQL query contained in <TT>sqlStatement</TT> 
0037 and returns an integer. This method is useful when you send SQL 
0038 <TT>INSERT</TT>s,  <TT>DELETE</TT>s, and <TT>UPDATE</TT>s.  These commands return 
0039 a count of rows  that were affected  by your query. This statement 
0040 should not be used for queries that  return result sets.
0041 
0042 <LI><TT>Bool_t Execute( const TString& sqlStatement )<BR></TT>
0043 This method sends the <TT>sqlStatement</TT> to the database and returns 
0044 <TT>kTRUE</TT> if the statement returns a result set or <TT>kFALSE</TT> if the 
0045 statement returns an integer. This method is best used when multiple 
0046 result sets can be returned.
0047 </UL>
0048 <P>
0049 Use the following methods to easily navigate the results a query returns:
0050 <UL>
0051 <LI><TT>Bool_t GetMoreResults()<BR> </TT>
0052 This moves to the next result set in the <TT>TSQLStatement</TT>. This, 
0053 like the <TT>Execute()</TT> method, returns <TT>kTRUE</TT> if the  next 
0054 result is a result set or <TT>kFALSE</TT> if it is an  integer.  
0055 If you have  already retrieved a <TT>TSQLResultSet</TT> from  the  
0056 <TT>TSQLStatement</TT>, this method will close it before returning.
0057 
0058 <LI><TT>TSQLResultSet* GetResultSet()<BR></TT>
0059 This method returns to you a result set in a <TT>TSQLResultSet</TT> 
0060 object. This result set is the current result set.
0061 
0062 <LI><TT>Int_t GetUpdateCount()<BR></TT>
0063 This method returns to you the integer result that an 
0064 <TT>Execute()</TT> method returned.
0065 </UL>
0066 <P>
0067 */
0068 //End_Html
0069 /////////////////////////////////////////////////////////////////////
0070 
0071 #include <RDBC/TSQLStatement.h>
0072 #include <RDBC/TSQLResultSet.h>
0073 #include <RDBC/TSQLConnection.h>
0074 #include <TList.h>
0075 
0076 ClassImpQ(TSQLStatement)
0077 
0078 /////////////////////////////////////////////////////////////////////
0079 //___________________________________________________________________
0080 TSQLStatement::TSQLStatement( TSQLConnection* con, void* imp ):TSQL(imp)
0081 {
0082    // ctor
0083  
0084    fBatches = new TList();
0085    fConnection = con;
0086    fCurrentResult = 0;
0087 }
0088 
0089 //___________________________________________________________________
0090 TSQLStatement::~TSQLStatement()
0091 {
0092    // dtor
0093   
0094    if(fCurrentResult && fCurrentResult->fImp) {
0095      delete fCurrentResult;
0096      fCurrentResult->fImp = 0;
0097    }
0098 
0099    fCurrentResult = 0;
0100 
0101    if(fBatches) {
0102       fBatches->Delete();
0103       delete fBatches;
0104    }
0105 
0106    fBatches = 0;
0107    
0108    if(fConnection) fConnection->GetListOfStatements()->Remove(this);
0109 }