Back to home page

sPhenix code displayed by LXR

 
 

    


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

0001 // $Id: MySQLPreparedStatement.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 // An object that represents a precompiled SQL statement. 
0008 //
0009 // A SQL statement is pre-compiled and stored in a 
0010 // TSQLPreparedStatement object. This object can then be used to 
0011 // efficiently  TSQLPreparedStatement::Execute() this statement 
0012 // multiple times. 
0013 //
0014 // Note: The TSQLPreparedStatement::SetXXX methods for setting IN 
0015 //    parameter values must specify types that are compatible with the 
0016 //    defined SQL type of the input parameter. For instance, if the 
0017 //    IN parameter has SQL type integer, then the method 
0018 //    TSQLPreparedStatement::SetInt() should be used. 
0019 //
0020 // Example of TSQLPreparedStatement setting a parameter; 
0021 // con is an active connection 
0022 //
0023 //
0024 //  TSQLPreparedStatement* pstmt = 
0025 //       con->PrepareStatement("UPDATE EMPLOYEES SET SALARY = ?  
0026 //                               WHERE ID = ?");
0027 //
0028 //   pstmt->SetInt(2, 110592);
0029 // 
0030 //
0031 // See also: 
0032 //      TSQLConnection::PrepareStatement(const TString&), 
0033 //      TSQLResultSet TSQLStatement TSQLCallableStatement
0034 //
0035 //
0036 /////////////////////////////////////////////////////////////////////
0037 
0038 #include <RDBC/TSQLPreparedStatement.h>
0039 #include <RDBC/TSQLResultSet.h>
0040 
0041 #include <iostream>
0042 #include <sstream>
0043 #include <TList.h>
0044 
0045 
0046 ClassImpQ(TSQLPreparedStatement)
0047 
0048 /////////////////////////////////////////////////////////////////////
0049 //___________________________________________________________________
0050 TSQLPreparedStatement::TSQLPreparedStatement(TSQLConnection* con,
0051                                     void* imp):TSQLStatement(con,imp)
0052    
0053 {
0054    // ctor.
0055 }
0056 
0057 //___________________________________________________________________
0058 void TSQLPreparedStatement::SetNull( Int_t parameterIndex,Int_t sqlType )
0059 {
0060    // Sets the designated parameter to SQL NULL. 
0061    //
0062    //   Note: You must specify the parameter's SQL type.
0063    //
0064    //   Parameters:
0065    //          parameterIndex - the first parameter is 1, 
0066    //                           the second is 2, ...
0067    //          sqlType - the SQL type code defined in TSQLTypes
0068    //   Throws:
0069    //          TSQLException - if a database access error occurs
0070    
0071 
0072 }
0073 
0074 //___________________________________________________________________
0075 void TSQLPreparedStatement::SetBoolean( Int_t parameterIndex,Bool_t x )
0076 {
0077    // Sets the designated parameter to a Bool_t value. The
0078    // driver converts this to an SQL BIT value when it sends it to
0079    // the database.
0080    //
0081    //   Parameters:
0082    //         parameterIndex - the first parameter is 1, 
0083    //                          the second is 2, ...
0084    //         x - the parameter value
0085    //   Throws:
0086    //         TSQLException - if a database access error occurs
0087  
0088 }
0089 
0090 //___________________________________________________________________
0091 void TSQLPreparedStatement::SetByte( Int_t parameterIndex,Char_t x )
0092 {
0093    // Sets the designated parameter to a  byte value. The
0094    // driver converts this to an SQL TINYINT value when it sends
0095    // it to the database.
0096    //
0097    //   Parameters:
0098    //         parameterIndex - the first parameter is 1, 
0099    //                          the second is 2, ...
0100    //         x - the parameter value
0101    //   Throws:
0102    //         TSQLException - if a database access error occurs
0103    
0104 }
0105 
0106 //___________________________________________________________________
0107 void TSQLPreparedStatement::SetShort( Int_t parameterIndex,Short_t x )
0108 {
0109    // Sets the designated parameter to a  short value. The
0110    //   driver converts this to an SQL SMALLINT value when it sends
0111    //   it to the database.
0112    //
0113    //   Parameters:
0114    //         parameterIndex - the first parameter is 1, 
0115    //                            the second is 2, ...
0116    //         x - the parameter value
0117    //   Throws:
0118    //         TSQLException - if a database access error occurs
0119 
0120 }
0121 
0122 //___________________________________________________________________
0123 void TSQLPreparedStatement::SetInt( Int_t parameterIndex,Int_t x )
0124 {
0125    // Sets the designated parameter to a  int value. The
0126    // driver converts this to an SQL INTEGER value when it sends
0127    // it to the database.
0128    //
0129    //   Parameters:
0130    //         parameterIndex - the first parameter is 1, 
0131    //                          the second is 2, ...
0132    //         x - the parameter value
0133    //   Throws:
0134    //         TSQLException - if a database access error occurs
0135 
0136 }
0137 
0138 //___________________________________________________________________
0139 void TSQLPreparedStatement::SetLong( Int_t parameterIndex,Long_t x )
0140 {
0141    // Sets the designated parameter to a  long value. The
0142    // driver converts this to an SQL BIGINT value when it sends it
0143    // to the database.
0144    //
0145    //   Parameters:
0146    //         parameterIndex - the first parameter is 1, 
0147    //                          the second is 2, ...
0148    //         x - the parameter value
0149    //   Throws:
0150    //         TSQLException - if a database access error occurs
0151 
0152 }
0153 
0154 //___________________________________________________________________
0155 void TSQLPreparedStatement::SetFloat( Int_t parameterIndex,Float_t x )
0156 {
0157    // Sets the designated parameter to a  float value. The
0158    // driver converts this to an SQL FLOAT value when it sends it
0159    // to the database.
0160    //
0161    //   Parameters:
0162    //         parameterIndex - the first parameter is 1, 
0163    //                          the second is 2, ...
0164    //         x - the parameter value
0165    //   Throws:
0166    //         TSQLException - if a database access error occurs
0167 
0168 }
0169 
0170 //___________________________________________________________________
0171 void TSQLPreparedStatement::SetDouble( Int_t parameterIndex,Double_t x )
0172 {
0173    // Sets the designated parameter to a  double value. The
0174    // driver converts this to an SQL DOUBLE value when it sends it
0175    // to the database.
0176    //
0177    //   Parameters:
0178    //         parameterIndex - the first parameter is 1, 
0179    //                          the second is 2, ...
0180    //         x - the parameter value
0181    //   Throws:
0182    //         TSQLException - if a database access error occurs
0183 
0184 }
0185 
0186 //___________________________________________________________________
0187 void TSQLPreparedStatement::SetString( Int_t parameterIndex, 
0188                                        const TString& x )
0189 {
0190    //  Sets the designated parameter to a  TString value. The
0191    //  driver converts this to an SQL VARCHAR or LONGVARCHAR value
0192    //  (depending on the argument's size relative to the driver's
0193    //  limits on VARCHARs) when it sends it to the database.
0194    //
0195    //   Parameters:
0196    //         parameterIndex - the first parameter is 1, 
0197    //                          the second is 2, ...
0198    //         x - the parameter value
0199    //   Throws:
0200    //         TSQLException - if a database access error occurs
0201 
0202 }
0203 
0204 //___________________________________________________________________
0205 void TSQLPreparedStatement::SetBytes( Int_t parameterIndex,
0206                                       const TArrayC& x )
0207 {
0208    // Sets the designated parameter to a  array of bytes. The
0209    // driver converts this to an SQL VARBINARY or LONGVARBINARY
0210    // (depending on the argument's size relative to the driver's
0211    // limits on VARBINARYs) when it sends it to the database.
0212    //
0213    //   Parameters:
0214    //         parameterIndex - the first parameter is 1, 
0215    //                          the second is 2, ...
0216    //         x - the parameter value
0217    //   Throws:
0218    //         TSQLException - if a database access error occurs
0219 
0220 }
0221 
0222 //___________________________________________________________________
0223 void TSQLPreparedStatement::SetDate( Int_t parameterIndex,
0224                                      const TSQLDate& x )
0225 {
0226    //  Sets the designated parameter to a TSQLDate value. The
0227    //  driver converts this to an SQL DATE value when it sends it
0228    //  to the database.
0229    //
0230    //   Parameters:
0231    //         parameterIndex - the first parameter is 1, 
0232    //                          the second is 2, ...
0233    //         x - the parameter value
0234    //   Throws:
0235    //         TSQLException - if a database access error occurs
0236 
0237 }
0238 
0239 //___________________________________________________________________
0240 void TSQLPreparedStatement::SetTime( Int_t parameterIndex,
0241                                      const TSQLTime& x )
0242 {
0243    // Sets the designated parameter to a TSQLTime value. The
0244    // driver converts this to an SQL TIME value when it sends it
0245    // to the database.
0246    //
0247    //   Parameters:
0248    //         parameterIndex - the first parameter is 1, 
0249    //                          the second is 2, ...
0250    //         x - the parameter value
0251    //   Throws:
0252    //         TSQLException - if a database access error occurs
0253 
0254 }
0255 
0256 //___________________________________________________________________
0257 void TSQLPreparedStatement::SetTimestamp( Int_t parameterIndex,
0258                                           const TSQLTimestamp& x )
0259 {
0260    // Sets the designated parameter to a TSQLTimestamp value.
0261    // The driver converts this to an SQL TIMESTAMP value when it
0262    // sends it to the database.
0263    //
0264    //   Parameters:
0265    //         parameterIndex - the first parameter is 1,
0266    //                          the second is 2, ...
0267    //         x - the parameter value
0268    //   Throws:
0269    //         TSQLException - if a database access error occurs
0270 
0271 }
0272 
0273 //___________________________________________________________________
0274 void TSQLPreparedStatement::SetAsciiStream( Int_t parameterIndex,
0275                                             TBuffer* x,
0276                                             Int_t length )
0277 {
0278   // Sets the designated parameter to the given input stream,
0279   // which will have the specified number of bytes. When a very
0280   // large ASCII value is input to a LONGVARCHAR parameter, it
0281   // may be more practical to send it via a TBuffer
0282   // will read the data from the stream as needed, until it
0283   // reaches end-of-file. The  driver will do any necessary
0284   // conversion from ASCII to the database char format. 
0285   //
0286   //    Parameters:
0287   //          parameterIndex - the first parameter is 1, 
0288   //                           the second is 2, ...
0289   //          x - the  input stream that contains the ASCII
0290   //              parameter value
0291   //          length - the number of bytes in the stream,
0292   //                   total size of buffer is by default. 
0293   //    Throws:
0294   //          TSQLException - if a database access error occurs
0295 
0296 }
0297 
0298 //___________________________________________________________________
0299 void TSQLPreparedStatement::SetBinaryStream( Int_t parameterIndex,
0300                                              TBuffer* x,
0301                                              Int_t length )
0302 {
0303    // Sets the designated parameter to the given input stream,
0304    // which will have the specified number of bytes. When a very
0305    // large binary value is input to a LONGVARBINARY parameter, it
0306    // may be more practical to send it via a TBuffer.
0307    // will read the data from the stream as needed, until it
0308    // reaches end-of-file. 
0309    //
0310    //   Parameters:
0311    //         parameterIndex - the first parameter is 1, 
0312    //                          the second is 2, ...
0313    //         x - the input tream which contains the binary
0314    //                  parameter value
0315    //         length - the number of bytes in the stream
0316    //                   total size of buffer is by default. 
0317    //   Throws:
0318    //         TSQLException - if a database access error occurs
0319 
0320 }
0321 
0322 //___________________________________________________________________
0323 void TSQLPreparedStatement::SetObject( Int_t parameterIndex,TObject* x )
0324 {
0325    // Sets the designated parameter to the given ROOT object
0326    //
0327    //   Parameters:
0328    //         parameterIndex - the first parameter is 1, 
0329    //                          the second is 2, ...
0330    //         x - the ROOT object
0331    //   Throws:
0332    //         TSQLException - if a database access error occurs
0333 
0334    TBuffer *b = new TBuffer(TBuffer::kWrite);
0335    b->WriteObject(x);
0336    SetBinaryStream(parameterIndex,b,b->BufferSize());
0337    b->DetachBuffer();
0338    delete b;
0339 }
0340 
0341 //___________________________________________________________________
0342 void TSQLPreparedStatement::ClearParameters()
0343 {
0344    // Clears the current parameter values immediately. 
0345    //
0346    //  In general, parameter values remain in force for repeated
0347    //  use of a TSQLStatement. Setting a parameter value 
0348    //  automatically clears its previous value. However, in some 
0349    //  cases it is useful to immediately release the resources used 
0350    //  by the current parameter values; this can be done by calling
0351    //  ClearParameters().
0352    //   
0353    //   Throws:
0354    //         TSQLException - if a database access error occurs
0355 
0356 }
0357 
0358 //___________________________________________________________________
0359 Bool_t TSQLPreparedStatement::Execute()
0360 {
0361    // Executes any kind of SQL statement. Some prepared statements
0362    // return multiple results; the TSQLPreparedStatement::Execute() 
0363    // method handles these complex statements as well as the simpler 
0364    // form of statements handled by  TSQLPreparedStatement::ExecuteQuery()
0365    // and TSQLPreparedStatement::ExecuteUpdate()
0366    //
0367    //    Throws:
0368    //          TSQLException - if a database access error occurs
0369    // 
0370    //    Return kTRUE if the result is a TSQLResultSet, 
0371    //           kFALSE if it's an  update count or unknown.
0372    //
0373    //    See Also: 
0374    //          TSQLStatement::Execute(const TString&)
0375 
0376 }
0377 
0378 //___________________________________________________________________
0379 Int_t TSQLPreparedStatement::ExecuteUpdate()
0380 {
0381    // Executes the SQL INSERT, UPDATE or DELETE statement in this
0382    // TSQLPreparedStatement object. In addition, SQL statements that
0383    // return nothing, such as SQL DDL statements, can be executed.
0384    // 
0385    //   Returns:
0386    //         either the row count for INSERT, UPDATE or DELETE
0387    //         statements; or 0 for SQL statements that return nothing
0388    //   Throws:
0389    //         TSQLException - if a database access error occurs
0390 
0391 }
0392 
0393 //___________________________________________________________________
0394 TSQLResultSet* TSQLPreparedStatement::ExecuteQuery()
0395 {
0396    //   Executes the SQL query in this TSQLPreparedStatement object 
0397    //   and returns the result set generated by the query.
0398    //
0399    //   Returns:
0400    //         a TSQLResultSet that contains the data produced by the
0401    //         query; never null
0402    //   Throws:
0403    //        TSQLException - if a database access error occurs
0404 
0405 }