Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MySQLPreparedStatement.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MySQLPreparedStatement.cxx
1 // $Id: MySQLPreparedStatement.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 // An object that represents a precompiled SQL statement.
8 //
9 // A SQL statement is pre-compiled and stored in a
10 // TSQLPreparedStatement object. This object can then be used to
11 // efficiently TSQLPreparedStatement::Execute() this statement
12 // multiple times.
13 //
14 // Note: The TSQLPreparedStatement::SetXXX methods for setting IN
15 // parameter values must specify types that are compatible with the
16 // defined SQL type of the input parameter. For instance, if the
17 // IN parameter has SQL type integer, then the method
18 // TSQLPreparedStatement::SetInt() should be used.
19 //
20 // Example of TSQLPreparedStatement setting a parameter;
21 // con is an active connection
22 //
23 //
24 // TSQLPreparedStatement* pstmt =
25 // con->PrepareStatement("UPDATE EMPLOYEES SET SALARY = ?
26 // WHERE ID = ?");
27 //
28 // pstmt->SetInt(2, 110592);
29 //
30 //
31 // See also:
32 // TSQLConnection::PrepareStatement(const TString&),
33 // TSQLResultSet TSQLStatement TSQLCallableStatement
34 //
35 //
37 
39 #include <RDBC/TSQLResultSet.h>
40 
41 #include <iostream>
42 #include <sstream>
43 #include <TList.h>
44 
45 
47 
48 
49 //___________________________________________________________________
51  void* imp):TSQLStatement(con,imp)
52 
53 {
54  // ctor.
55 }
56 
57 //___________________________________________________________________
58 void TSQLPreparedStatement::SetNull( Int_t parameterIndex,Int_t sqlType )
59 {
60  // Sets the designated parameter to SQL NULL.
61  //
62  // Note: You must specify the parameter's SQL type.
63  //
64  // Parameters:
65  // parameterIndex - the first parameter is 1,
66  // the second is 2, ...
67  // sqlType - the SQL type code defined in TSQLTypes
68  // Throws:
69  // TSQLException - if a database access error occurs
70 
71 
72 }
73 
74 //___________________________________________________________________
75 void TSQLPreparedStatement::SetBoolean( Int_t parameterIndex,Bool_t x )
76 {
77  // Sets the designated parameter to a Bool_t value. The
78  // driver converts this to an SQL BIT value when it sends it to
79  // the database.
80  //
81  // Parameters:
82  // parameterIndex - the first parameter is 1,
83  // the second is 2, ...
84  // x - the parameter value
85  // Throws:
86  // TSQLException - if a database access error occurs
87 
88 }
89 
90 //___________________________________________________________________
91 void TSQLPreparedStatement::SetByte( Int_t parameterIndex,Char_t x )
92 {
93  // Sets the designated parameter to a byte value. The
94  // driver converts this to an SQL TINYINT value when it sends
95  // it to the database.
96  //
97  // Parameters:
98  // parameterIndex - the first parameter is 1,
99  // the second is 2, ...
100  // x - the parameter value
101  // Throws:
102  // TSQLException - if a database access error occurs
103 
104 }
105 
106 //___________________________________________________________________
107 void TSQLPreparedStatement::SetShort( Int_t parameterIndex,Short_t x )
108 {
109  // Sets the designated parameter to a short value. The
110  // driver converts this to an SQL SMALLINT value when it sends
111  // it to the database.
112  //
113  // Parameters:
114  // parameterIndex - the first parameter is 1,
115  // the second is 2, ...
116  // x - the parameter value
117  // Throws:
118  // TSQLException - if a database access error occurs
119 
120 }
121 
122 //___________________________________________________________________
123 void TSQLPreparedStatement::SetInt( Int_t parameterIndex,Int_t x )
124 {
125  // Sets the designated parameter to a int value. The
126  // driver converts this to an SQL INTEGER value when it sends
127  // it to the database.
128  //
129  // Parameters:
130  // parameterIndex - the first parameter is 1,
131  // the second is 2, ...
132  // x - the parameter value
133  // Throws:
134  // TSQLException - if a database access error occurs
135 
136 }
137 
138 //___________________________________________________________________
139 void TSQLPreparedStatement::SetLong( Int_t parameterIndex,Long_t x )
140 {
141  // Sets the designated parameter to a long value. The
142  // driver converts this to an SQL BIGINT value when it sends it
143  // to the database.
144  //
145  // Parameters:
146  // parameterIndex - the first parameter is 1,
147  // the second is 2, ...
148  // x - the parameter value
149  // Throws:
150  // TSQLException - if a database access error occurs
151 
152 }
153 
154 //___________________________________________________________________
155 void TSQLPreparedStatement::SetFloat( Int_t parameterIndex,Float_t x )
156 {
157  // Sets the designated parameter to a float value. The
158  // driver converts this to an SQL FLOAT value when it sends it
159  // to the database.
160  //
161  // Parameters:
162  // parameterIndex - the first parameter is 1,
163  // the second is 2, ...
164  // x - the parameter value
165  // Throws:
166  // TSQLException - if a database access error occurs
167 
168 }
169 
170 //___________________________________________________________________
171 void TSQLPreparedStatement::SetDouble( Int_t parameterIndex,Double_t x )
172 {
173  // Sets the designated parameter to a double value. The
174  // driver converts this to an SQL DOUBLE value when it sends it
175  // to the database.
176  //
177  // Parameters:
178  // parameterIndex - the first parameter is 1,
179  // the second is 2, ...
180  // x - the parameter value
181  // Throws:
182  // TSQLException - if a database access error occurs
183 
184 }
185 
186 //___________________________________________________________________
187 void TSQLPreparedStatement::SetString( Int_t parameterIndex,
188  const TString& x )
189 {
190  // Sets the designated parameter to a TString value. The
191  // driver converts this to an SQL VARCHAR or LONGVARCHAR value
192  // (depending on the argument's size relative to the driver's
193  // limits on VARCHARs) when it sends it to the database.
194  //
195  // Parameters:
196  // parameterIndex - the first parameter is 1,
197  // the second is 2, ...
198  // x - the parameter value
199  // Throws:
200  // TSQLException - if a database access error occurs
201 
202 }
203 
204 //___________________________________________________________________
205 void TSQLPreparedStatement::SetBytes( Int_t parameterIndex,
206  const TArrayC& x )
207 {
208  // Sets the designated parameter to a array of bytes. The
209  // driver converts this to an SQL VARBINARY or LONGVARBINARY
210  // (depending on the argument's size relative to the driver's
211  // limits on VARBINARYs) when it sends it to the database.
212  //
213  // Parameters:
214  // parameterIndex - the first parameter is 1,
215  // the second is 2, ...
216  // x - the parameter value
217  // Throws:
218  // TSQLException - if a database access error occurs
219 
220 }
221 
222 //___________________________________________________________________
223 void TSQLPreparedStatement::SetDate( Int_t parameterIndex,
224  const TSQLDate& x )
225 {
226  // Sets the designated parameter to a TSQLDate value. The
227  // driver converts this to an SQL DATE value when it sends it
228  // to the database.
229  //
230  // Parameters:
231  // parameterIndex - the first parameter is 1,
232  // the second is 2, ...
233  // x - the parameter value
234  // Throws:
235  // TSQLException - if a database access error occurs
236 
237 }
238 
239 //___________________________________________________________________
240 void TSQLPreparedStatement::SetTime( Int_t parameterIndex,
241  const TSQLTime& x )
242 {
243  // Sets the designated parameter to a TSQLTime value. The
244  // driver converts this to an SQL TIME value when it sends it
245  // to the database.
246  //
247  // Parameters:
248  // parameterIndex - the first parameter is 1,
249  // the second is 2, ...
250  // x - the parameter value
251  // Throws:
252  // TSQLException - if a database access error occurs
253 
254 }
255 
256 //___________________________________________________________________
257 void TSQLPreparedStatement::SetTimestamp( Int_t parameterIndex,
258  const TSQLTimestamp& x )
259 {
260  // Sets the designated parameter to a TSQLTimestamp value.
261  // The driver converts this to an SQL TIMESTAMP value when it
262  // sends it to the database.
263  //
264  // Parameters:
265  // parameterIndex - the first parameter is 1,
266  // the second is 2, ...
267  // x - the parameter value
268  // Throws:
269  // TSQLException - if a database access error occurs
270 
271 }
272 
273 //___________________________________________________________________
274 void TSQLPreparedStatement::SetAsciiStream( Int_t parameterIndex,
275  TBuffer* x,
276  Int_t length )
277 {
278  // Sets the designated parameter to the given input stream,
279  // which will have the specified number of bytes. When a very
280  // large ASCII value is input to a LONGVARCHAR parameter, it
281  // may be more practical to send it via a TBuffer
282  // will read the data from the stream as needed, until it
283  // reaches end-of-file. The driver will do any necessary
284  // conversion from ASCII to the database char format.
285  //
286  // Parameters:
287  // parameterIndex - the first parameter is 1,
288  // the second is 2, ...
289  // x - the input stream that contains the ASCII
290  // parameter value
291  // length - the number of bytes in the stream,
292  // total size of buffer is by default.
293  // Throws:
294  // TSQLException - if a database access error occurs
295 
296 }
297 
298 //___________________________________________________________________
299 void TSQLPreparedStatement::SetBinaryStream( Int_t parameterIndex,
300  TBuffer* x,
301  Int_t length )
302 {
303  // Sets the designated parameter to the given input stream,
304  // which will have the specified number of bytes. When a very
305  // large binary value is input to a LONGVARBINARY parameter, it
306  // may be more practical to send it via a TBuffer.
307  // will read the data from the stream as needed, until it
308  // reaches end-of-file.
309  //
310  // Parameters:
311  // parameterIndex - the first parameter is 1,
312  // the second is 2, ...
313  // x - the input tream which contains the binary
314  // parameter value
315  // length - the number of bytes in the stream
316  // total size of buffer is by default.
317  // Throws:
318  // TSQLException - if a database access error occurs
319 
320 }
321 
322 //___________________________________________________________________
323 void TSQLPreparedStatement::SetObject( Int_t parameterIndex,TObject* x )
324 {
325  // Sets the designated parameter to the given ROOT object
326  //
327  // Parameters:
328  // parameterIndex - the first parameter is 1,
329  // the second is 2, ...
330  // x - the ROOT object
331  // Throws:
332  // TSQLException - if a database access error occurs
333 
334  TBuffer *b = new TBuffer(TBuffer::kWrite);
335  b->WriteObject(x);
336  SetBinaryStream(parameterIndex,b,b->BufferSize());
337  b->DetachBuffer();
338  delete b;
339 }
340 
341 //___________________________________________________________________
343 {
344  // Clears the current parameter values immediately.
345  //
346  // In general, parameter values remain in force for repeated
347  // use of a TSQLStatement. Setting a parameter value
348  // automatically clears its previous value. However, in some
349  // cases it is useful to immediately release the resources used
350  // by the current parameter values; this can be done by calling
351  // ClearParameters().
352  //
353  // Throws:
354  // TSQLException - if a database access error occurs
355 
356 }
357 
358 //___________________________________________________________________
360 {
361  // Executes any kind of SQL statement. Some prepared statements
362  // return multiple results; the TSQLPreparedStatement::Execute()
363  // method handles these complex statements as well as the simpler
364  // form of statements handled by TSQLPreparedStatement::ExecuteQuery()
365  // and TSQLPreparedStatement::ExecuteUpdate()
366  //
367  // Throws:
368  // TSQLException - if a database access error occurs
369  //
370  // Return kTRUE if the result is a TSQLResultSet,
371  // kFALSE if it's an update count or unknown.
372  //
373  // See Also:
374  // TSQLStatement::Execute(const TString&)
375 
376 }
377 
378 //___________________________________________________________________
380 {
381  // Executes the SQL INSERT, UPDATE or DELETE statement in this
382  // TSQLPreparedStatement object. In addition, SQL statements that
383  // return nothing, such as SQL DDL statements, can be executed.
384  //
385  // Returns:
386  // either the row count for INSERT, UPDATE or DELETE
387  // statements; or 0 for SQL statements that return nothing
388  // Throws:
389  // TSQLException - if a database access error occurs
390 
391 }
392 
393 //___________________________________________________________________
395 {
396  // Executes the SQL query in this TSQLPreparedStatement object
397  // and returns the result set generated by the query.
398  //
399  // Returns:
400  // a TSQLResultSet that contains the data produced by the
401  // query; never null
402  // Throws:
403  // TSQLException - if a database access error occurs
404 
405 }