Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TSQLStatement.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TSQLStatement.cxx
1 // $Id: TSQLStatement.cxx,v 1.1.1.1 2004/02/18 20:58:02 dave Exp $
2 //*-- Author : Valeriy Onuchin 14/02/2000
3 //
4 
6 //
7 // The object used for executing a static SQL statement and
8 // obtaining the results produced by it.
9 //
10 // Only one TSQLResultSet per TSQLStatement can be open at any point
11 // in time. Therefore, if the reading of one TSQLResultSet is
12 // interleaved with the reading of another, each must have been
13 // generated by different TSQLStatements. All statement execute
14 // methods implicitly close a statment's current TSQLResultSet if
15 // an open one exists.
16 //
17 // See also:
18 // TSQLConnection::CreateStatement(), TSQLResultSet
19 // TSQLCallableStatement TSQLPreparedStatement
20 //Begin_Html
21 /*
22 <P>
23  The <TT>TSQLStatement</TT> class encapsulates SQL queries to your database.
24 Using several methods, these calls return objects that contain the
25 results of your SQL query. When you execute an SQL query, the data
26 that is returned to you is commonly called the result set. You can
27 choose from several result sets, depending on your needs:
28 <UL>
29 <LI><TT>TSQLResultSet* ExecuteQuery( const TString& sqlStatement)<BR></TT>
30 This method sends the SQL query contained in <TT>sqlStatement</TT>
31 and returns a single set of results. This method is best used
32 in sending <TT>SELECT</TT> statements. These statements typically
33 return a result set. This method implicitly deletes previous resultset.
34 
35 <LI><TT>Int_t ExecuteUpdate( const TString& sqlStatement )<BR></TT>
36 This method sends the SQL query contained in <TT>sqlStatement</TT>
37 and returns an integer. This method is useful when you send SQL
38 <TT>INSERT</TT>s, <TT>DELETE</TT>s, and <TT>UPDATE</TT>s. These commands return
39 a count of rows that were affected by your query. This statement
40 should not be used for queries that return result sets.
41 
42 <LI><TT>Bool_t Execute( const TString& sqlStatement )<BR></TT>
43 This method sends the <TT>sqlStatement</TT> to the database and returns
44 <TT>kTRUE</TT> if the statement returns a result set or <TT>kFALSE</TT> if the
45 statement returns an integer. This method is best used when multiple
46 result sets can be returned.
47 </UL>
48 <P>
49 Use the following methods to easily navigate the results a query returns:
50 <UL>
51 <LI><TT>Bool_t GetMoreResults()<BR> </TT>
52 This moves to the next result set in the <TT>TSQLStatement</TT>. This,
53 like the <TT>Execute()</TT> method, returns <TT>kTRUE</TT> if the next
54 result is a result set or <TT>kFALSE</TT> if it is an integer.
55 If you have already retrieved a <TT>TSQLResultSet</TT> from the
56 <TT>TSQLStatement</TT>, this method will close it before returning.
57 
58 <LI><TT>TSQLResultSet* GetResultSet()<BR></TT>
59 This method returns to you a result set in a <TT>TSQLResultSet</TT>
60 object. This result set is the current result set.
61 
62 <LI><TT>Int_t GetUpdateCount()<BR></TT>
63 This method returns to you the integer result that an
64 <TT>Execute()</TT> method returned.
65 </UL>
66 <P>
67 */
68 //End_Html
70 
71 #include <RDBC/TSQLStatement.h>
72 #include <RDBC/TSQLResultSet.h>
73 #include <RDBC/TSQLConnection.h>
74 #include <TList.h>
75 
77 
78 
79 //___________________________________________________________________
81 {
82  // ctor
83 
84  fBatches = new TList();
85  fConnection = con;
86  fCurrentResult = 0;
87 }
88 
89 //___________________________________________________________________
91 {
92  // dtor
93 
95  delete fCurrentResult;
96  fCurrentResult->fImp = 0;
97  }
98 
99  fCurrentResult = 0;
100 
101  if(fBatches) {
102  fBatches->Delete();
103  delete fBatches;
104  }
105 
106  fBatches = 0;
107 
108  if(fConnection) fConnection->GetListOfStatements()->Remove(this);
109 }