Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ODBCPreparedStatement.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ODBCPreparedStatement.cxx
1 // $Id: ODBCPreparedStatement.cxx,v 1.4 2014/02/14 16:51:27 jinhuang Exp $
2 //*-- Author : Valeriy Onuchin 14/02/2000
3 //
4 
5 /**************************************************************************
6 
7  ROOT wrappers of libodbc++ library
8 
9  Copyright (C) 1999-2000 Manush Dodunekov <manush@stendahls.net>
10 
11  This library is free software; you can redistribute it and/or
12  modify it under the terms of the GNU Library General Public
13  License as published by the Free Software Foundation; either
14  version 2 of the License, or (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  Library General Public License for more details.
20 
21  You should have received a copy of the GNU Library General Public License
22  along with this library; see the file COPYING. If not, write to
23  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24  Boston, MA 02111-1307, USA.
25 
26 **************************************************************************/
27 
29 //
30 // An object that represents a precompiled SQL statement.
31 //
32 // A SQL statement is pre-compiled and stored in a
33 // TSQLPreparedStatement object. This object can then be used to
34 // efficiently ODBCPreparedStatement::Execute() this statement
35 // multiple times.
36 //
37 // Note: The ODBCPreparedStatement::SetXXX methods for setting IN
38 // parameter values must specify types that are compatible with the
39 // defined SQL type of the input parameter. For instance, if the
40 // IN parameter has SQL type integer, then the method
41 // ODBCPreparedStatement::SetInt() should be used.
42 //
43 // Example of TSQLPreparedStatement setting a parameter;
44 // con is an active connection
45 //
46 //
47 // TSQLPreparedStatement* pstmt =
48 // con->PrepareStatement("UPDATE EMPLOYEES SET SALARY = ?
49 // WHERE ID = ?");
50 //
51 // pstmt->SetInt(2, 110592);
52 //
53 //
54 // See also:
55 // TSQLConnection::PrepareStatement(const TString&),
56 // TSQLResultSet TSQLStatement TSQLCallableStatement
57 //
58 //
60 
61 #include "ODBCPreparedStatement.h"
62 #include "ODBCResultSet.h"
63 #include <RDBC/odbc++/statement.h>
65 #include <RDBC/odbc++/resultset.h>
66 #include <iostream>
67 #include <sstream>
68 #include <TList.h>
69 
70 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
71 #include <TBufferFile.h>
72 #endif
73 
74 using namespace std;
75 using namespace odbc;
76 
78 
79 
80 //___________________________________________________________________
82  TSQLPreparedStatement(con,imp)
83 
84 {
85  // ctor
86 }
87 
88 //___________________________________________________________________
90 {
91  // dtor
92 
94 
95  try {
96  if(imp) delete imp;
97  } catch(odbc::SQLException& e) {
100  e.getErrorCode()) );
101  }
102 
103  // implementation part of fCurrentResult is deleted with statement
104  if(fCurrentResult) ((ODBCResultSet*)fCurrentResult)->fImp = 0;
105  fImp = 0;
106 }
107 
108 //___________________________________________________________________
109 void ODBCPreparedStatement::SetNull( Int_t parameterIndex,Int_t sqlType )
110 {
111  // Sets the designated parameter to SQL NULL.
112  //
113  // Note: You must specify the parameter's SQL type.
114  //
115  // Parameters:
116  // parameterIndex - the first parameter is 1,
117  // the second is 2, ...
118  // sqlType - the SQL type code defined in TSQLTypes
119  // Throws:
120  // TSQLException - if a database access error occurs
121 
122  if(!fImp) { Destroyed(); return; }
124 
125  try {
126  imp->setNull(parameterIndex,sqlType);
127 
128  } catch(odbc::SQLException& e) {
131  e.getErrorCode()) );
132  }
133 }
134 
135 //___________________________________________________________________
136 void ODBCPreparedStatement::SetBoolean( Int_t parameterIndex,Bool_t x )
137 {
138  // Sets the designated parameter to a Bool_t value. The
139  // driver converts this to an SQL BIT value when it sends it to
140  // the database.
141  //
142  // Parameters:
143  // parameterIndex - the first parameter is 1,
144  // the second is 2, ...
145  // x - the parameter value
146  // Throws:
147  // TSQLException - if a database access error occurs
148 
149  if(!fImp) { Destroyed(); return; }
151 
152  try {
153  imp->setBoolean(parameterIndex,x);
154 
155  } catch(odbc::SQLException& e) {
158  e.getErrorCode()) );
159  }
160 }
161 
162 //___________________________________________________________________
163 void ODBCPreparedStatement::SetByte( Int_t parameterIndex,Char_t x )
164 {
165  // Sets the designated parameter to a byte value. The
166  // driver converts this to an SQL TINYINT value when it sends
167  // it to the database.
168  //
169  // Parameters:
170  // parameterIndex - the first parameter is 1,
171  // the second is 2, ...
172  // x - the parameter value
173  // Throws:
174  // TSQLException - if a database access error occurs
175 
176  if(!fImp) { Destroyed(); return; }
178 
179  try {
180  imp->setByte(parameterIndex,x);
181 
182  } catch(odbc::SQLException& e) {
185  e.getErrorCode()) );
186  }
187 }
188 
189 //___________________________________________________________________
190 void ODBCPreparedStatement::SetShort( Int_t parameterIndex,Short_t x )
191 {
192  // Sets the designated parameter to a short value. The
193  // driver converts this to an SQL SMALLINT value when it sends
194  // it to the database.
195  //
196  // Parameters:
197  // parameterIndex - the first parameter is 1,
198  // the second is 2, ...
199  // x - the parameter value
200  // Throws:
201  // TSQLException - if a database access error occurs
202 
203  if(!fImp) { Destroyed(); return; }
205 
206  try {
207  imp->setShort(parameterIndex,x);
208 
209  } catch(odbc::SQLException& e) {
212  e.getErrorCode()) );
213  }
214 }
215 
216 //___________________________________________________________________
217 void ODBCPreparedStatement::SetInt( Int_t parameterIndex,Int_t x )
218 {
219  // Sets the designated parameter to a int value. The
220  // driver converts this to an SQL INTEGER value when it sends
221  // it to the database.
222  //
223  // Parameters:
224  // parameterIndex - the first parameter is 1,
225  // the second is 2, ...
226  // x - the parameter value
227  // Throws:
228  // TSQLException - if a database access error occurs
229 
230  if(!fImp) { Destroyed(); return; }
232 
233  try {
234  imp->setInt(parameterIndex,x);
235 
236  } catch(odbc::SQLException& e) {
239  e.getErrorCode()) );
240  }
241 }
242 
243 //___________________________________________________________________
244 void ODBCPreparedStatement::SetLong( Int_t parameterIndex,Long_t x )
245 {
246  // Sets the designated parameter to a long value. The
247  // driver converts this to an SQL BIGINT value when it sends it
248  // to the database.
249  //
250  // Parameters:
251  // parameterIndex - the first parameter is 1,
252  // the second is 2, ...
253  // x - the parameter value
254  // Throws:
255  // TSQLException - if a database access error occurs
256 
257  if(!fImp) { Destroyed(); return; }
259 
260  try {
261  imp->setLong(parameterIndex,x);
262 
263  } catch(odbc::SQLException& e) {
266  e.getErrorCode()) );
267  }
268 }
269 
270 //___________________________________________________________________
271 void ODBCPreparedStatement::SetFloat( Int_t parameterIndex,Float_t x )
272 {
273  // Sets the designated parameter to a float value. The
274  // driver converts this to an SQL FLOAT value when it sends it
275  // to the database.
276  //
277  // Parameters:
278  // parameterIndex - the first parameter is 1,
279  // the second is 2, ...
280  // x - the parameter value
281  // Throws:
282  // TSQLException - if a database access error occurs
283 
284  if(!fImp) { Destroyed(); return; }
286 
287  try {
288  imp->setFloat(parameterIndex,x);
289 
290  } catch(odbc::SQLException& e) {
293  e.getErrorCode()) );
294  }
295 }
296 
297 //___________________________________________________________________
298 void ODBCPreparedStatement::SetDouble( Int_t parameterIndex,Double_t x )
299 {
300  // Sets the designated parameter to a double value. The
301  // driver converts this to an SQL DOUBLE value when it sends it
302  // to the database.
303  //
304  // Parameters:
305  // parameterIndex - the first parameter is 1,
306  // the second is 2, ...
307  // x - the parameter value
308  // Throws:
309  // TSQLException - if a database access error occurs
310 
311  if(!fImp) { Destroyed(); return; }
313 
314  try {
315  imp->setDouble(parameterIndex,x);
316 
317  } catch(odbc::SQLException& e) {
320  e.getErrorCode()) );
321  }
322 }
323 
324 //___________________________________________________________________
325 void ODBCPreparedStatement::SetString( Int_t parameterIndex,
326  const TString& x )
327 {
328  // Sets the designated parameter to a TString value. The
329  // driver converts this to an SQL VARCHAR or LONGVARCHAR value
330  // (depending on the argument's size relative to the driver's
331  // limits on VARCHARs) when it sends it to the database.
332  //
333  // Parameters:
334  // parameterIndex - the first parameter is 1,
335  // the second is 2, ...
336  // x - the parameter value
337  // Throws:
338  // TSQLException - if a database access error occurs
339 
340  if(!fImp) { Destroyed(); return; }
342 
343  try {
344  imp->setString( parameterIndex, ODBCXX_STRING_C(x.Data()) );
345 
346  } catch(odbc::SQLException& e) {
349  e.getErrorCode()) );
350  }
351 }
352 
353 //___________________________________________________________________
354 void ODBCPreparedStatement::SetBytes( Int_t parameterIndex,
355  const TArrayC& x )
356 {
357  // Sets the designated parameter to a array of bytes. The
358  // driver converts this to an SQL VARBINARY or LONGVARBINARY
359  // (depending on the argument's size relative to the driver's
360  // limits on VARBINARYs) when it sends it to the database.
361  //
362  // Parameters:
363  // parameterIndex - the first parameter is 1,
364  // the second is 2, ...
365  // x - the parameter value
366  // Throws:
367  // TSQLException - if a database access error occurs
368 
369  if(!fImp) { Destroyed(); return; }
371 
372  try {
373  imp->setBytes( parameterIndex,
374  ODBCXX_BYTES_C(x.GetArray(),x.GetSize()) );
375 
376  } catch(odbc::SQLException& e) {
379  e.getErrorCode()) );
380  }
381 }
382 
383 //___________________________________________________________________
384 void ODBCPreparedStatement::SetDate( Int_t parameterIndex,
385  const TSQLDate& x )
386 {
387  // Sets the designated parameter to a TSQLDate value. The
388  // driver converts this to an SQL DATE value when it sends it
389  // to the database.
390  //
391  // Parameters:
392  // parameterIndex - the first parameter is 1,
393  // the second is 2, ...
394  // x - the parameter value
395  // Throws:
396  // TSQLException - if a database access error occurs
397 
398  if(!fImp) { Destroyed(); return; }
400 
401  try {
402  odbc::Date dt( x.GetYear(),
403  x.GetMonth(),
404  x.GetDay() );
405 
406  imp->setDate(parameterIndex,dt);
407 
408  } catch(odbc::SQLException& e) {
411  e.getErrorCode()) );
412  }
413 }
414 
415 //___________________________________________________________________
416 void ODBCPreparedStatement::SetTime( Int_t parameterIndex,
417  const TSQLTime& x )
418 {
419  // Sets the designated parameter to a TSQLTime value. The
420  // driver converts this to an SQL TIME value when it sends it
421  // to the database.
422  //
423  // Parameters:
424  // parameterIndex - the first parameter is 1,
425  // the second is 2, ...
426  // x - the parameter value
427  // Throws:
428  // TSQLException - if a database access error occurs
429 
430  if(!fImp) { Destroyed(); return; }
432 
433  try {
434  odbc::Time tm( x.GetHour(),
435  x.GetMinute(),
436  x.GetSecond() );
437 
438  imp->setTime(parameterIndex,tm);
439 
440  } catch(odbc::SQLException& e) {
443  e.getErrorCode()) );
444  }
445 }
446 
447 //___________________________________________________________________
448 void ODBCPreparedStatement::SetTimestamp( Int_t parameterIndex,
449  const TSQLTimestamp& x )
450 {
451  // Sets the designated parameter to a TSQLTimestamp value.
452  // The driver converts this to an SQL TIMESTAMP value when it
453  // sends it to the database.
454  //
455  // Parameters:
456  // parameterIndex - the first parameter is 1,
457  // the second is 2, ...
458  // x - the parameter value
459  // Throws:
460  // TSQLException - if a database access error occurs
461 
462  if(!fImp) { Destroyed(); return; }
464 
465  try {
466  odbc::Timestamp tmstmp( x.GetYear(),
467  x.GetMonth(),
468  x.GetDay(),
469  x.GetHour(),
470  x.GetMinute(),
471  x.GetSecond(),
472  x.GetNanos() );
473 
474  imp->setTimestamp(parameterIndex,tmstmp);
475 
476  } catch(odbc::SQLException& e) {
479  e.getErrorCode()) );
480  }
481 }
482 
483 //___________________________________________________________________
484 void ODBCPreparedStatement::SetAsciiStream( Int_t parameterIndex,
485  TBuffer* x,
486  Int_t length )
487 {
488  // Sets the designated parameter to the given input stream,
489  // which will have the specified number of bytes. When a very
490  // large ASCII value is input to a LONGVARCHAR parameter, it
491  // may be more practical to send it via a TBuffer
492  // will read the data from the stream as needed, until it
493  // reaches end-of-file. The driver will do any necessary
494  // conversion from ASCII to the database char format.
495  //
496  // Parameters:
497  // parameterIndex - the first parameter is 1,
498  // the second is 2, ...
499  // x - the input stream that contains the ASCII
500  // parameter value
501  // length - the number of bytes in the stream,
502  // total size of buffer is by default.
503  // Throws:
504  // TSQLException - if a database access error occurs
505 
506  if(!fImp) { Destroyed(); return; }
508 
509  try {
510  Int_t xl = x->BufferSize()>length ? length : x->BufferSize();
511  std::istringstream* s = new std::istringstream(x->Buffer());
512  imp->setAsciiStream( parameterIndex,(std::istream*)s,xl );
513 
514  } catch(odbc::SQLException& e) {
517  e.getErrorCode()) );
518  }
519 }
520 
521 //___________________________________________________________________
522 void ODBCPreparedStatement::SetBinaryStream( Int_t parameterIndex,
523  TBuffer* x,
524  Int_t length )
525 {
526  // Sets the designated parameter to the given input stream,
527  // which will have the specified number of bytes. When a very
528  // large binary value is input to a LONGVARBINARY parameter, it
529  // may be more practical to send it via a TBuffer.
530  // will read the data from the stream as needed, until it
531  // reaches end-of-file.
532  //
533  // Parameters:
534  // parameterIndex - the first parameter is 1,
535  // the second is 2, ...
536  // x - the input tream which contains the binary
537  // parameter value
538  // length - the number of bytes in the stream
539  // total size of buffer is by default.
540  // Throws:
541  // TSQLException - if a database access error occurs
542 
543  if(!fImp) { Destroyed(); return; }
545 
546  try {
547  Int_t xl = x->BufferSize()>length ? length : x->BufferSize();
548  std::string a(x->Buffer(),xl);
549 
550  std::istream* s = new std::istringstream(a);
551 
552  _vec_str_buf.push_back(boost::shared_ptr<std::istream>(s));
553 
554  imp->setBinaryStream( parameterIndex,s,xl );
555  } catch(odbc::SQLException& e) {
558  e.getErrorCode()) );
559  }
560 }
561 
562 //___________________________________________________________________
563 void ODBCPreparedStatement::SetObject( Int_t parameterIndex,TObject* x )
564 {
565  // Sets the designated parameter to the given ROOT object
566  //
567  // Parameters:
568  // parameterIndex - the first parameter is 1,
569  // the second is 2, ...
570  // x - the ROOT object
571  // Throws:
572  // TSQLException - if a database access error occurs
573 
574 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
575  TBuffer *b = new TBufferFile(TBuffer::kWrite);
576 #else
577  TBuffer *b = new TBuffer(TBuffer::kWrite);
578 #endif
579  b->WriteObject(x);
580  SetBinaryStream(parameterIndex,b,b->BufferSize());
581  // b->DetachBuffer();
582  delete b;
583 }
584 
585 //___________________________________________________________________
587 {
588  // Clears the current parameter values immediately.
589  //
590  // In general, parameter values remain in force for repeated
591  // use of a TSQLStatement. Setting a parameter value
592  // automatically clears its previous value. However, in some
593  // cases it is useful to immediately release the resources used
594  // by the current parameter values; this can be done by calling
595  // ClearParameters().
596  //
597  // Throws:
598  // TSQLException - if a database access error occurs
599 
600  if(!fImp) { Destroyed(); return; }
602 
603  try {
604  imp->clearParameters();
605 
606  } catch(odbc::SQLException& e) {
609  e.getErrorCode()) );
610  }
611 }
612 
613 //___________________________________________________________________
615 {
616  // Executes a SQL statement that returns a single TSQLResultSet
617  //
618  // This method also implicitly closes current TSQLResultSet
619  //
620  // Returns:
621  // a TSLResultSet that contains the data produced by the query;
622  // NULL - in case of error
623  //
624  // Throws:
625  // TSQLException - if a database access error occurs
626 
627  if(!fImp) { Destroyed(); return 0; }
630  odbc::ResultSet* rs = 0;
631  ClearWarnings();
632 
633  if(fCurrentResult) delete fCurrentResult;
634 
635  try {
636  if(!sql.IsNull()) {
637  rs = stmt->executeQuery(ODBCXX_STRING_C(sql.Data()));
638  } else {
639  rs = imp->executeQuery();
640  }
641  } catch(odbc::SQLException& e) {
644  e.getErrorCode()) );
645  if(rs) delete rs;
646  fCurrentResult = 0;
647  return 0;
648  }
649 
650  return fCurrentResult = new ODBCResultSet(this,(void*)rs);;
651 }
652 
653 //___________________________________________________________________
654 Bool_t ODBCPreparedStatement::Execute( const TString& sql )
655 {
656  // Executes a SQL statement that may return multiple results.
657  // Under some (uncommon) situations a single SQL statement may
658  // return multiple result sets and/or update counts. Normally you
659  // can ignore this unless you are (1) executing a stored
660  // procedure that you know may return multiple results or (2) you
661  // are dynamically executing an unknown SQL string. The methods
662  // execute, GetMoreResults(), GetResultSet(), and GetUpdateCount()
663  // let you navigate through multiple results.
664  // The execute method executes a SQL statement and indicates the
665  // form of the first result. You can then use GetResultSet() or
666  // GetUpdateCount() to retrieve the result, and GetMoreResults()
667  // to move to any subsequent result(s).
668  //
669  // Parameters:
670  // sql - any SQL statement
671  // Returns:
672  // kTRUE if the next result is a TSQLResultSet;
673  // kFALSE if it is an update count or there are no more
674  // results
675  // Throws:
676  // TSQLException - if a database access error occurs
677  // See Also:
678  // GetResultSet(), GetUpdateCount(), GetMoreResults()
679 
680  if(!fImp) { Destroyed(); return kFALSE; }
681 
682  Bool_t return_value = kFALSE;
683  ClearWarnings();
686 
687  try {
688  if(!sql.IsNull()) {
689  return_value = (Bool_t)stmt->execute(ODBCXX_STRING_C(sql.Data()));
690  } else {
691  return_value = imp->execute();
692  }
693  } catch(odbc::SQLException& e) {
696  e.getErrorCode()) );
697  return_value = kFALSE;
698  }
699  return return_value;
700 }
701 
702 //___________________________________________________________________
703 Int_t ODBCPreparedStatement::ExecuteUpdate( const TString& sql )
704 {
705  // Executes an SQL INSERT, UPDATE or DELETE statement.
706  // In addition, SQL statements that return nothing,
707  // such as SQL DDL statements, can be executed.
708  //
709  // Parameters:
710  // sql - a SQL INSERT, UPDATE or DELETE statement or
711  // a SQL statement that returns nothing
712  //
713  // Returns:
714  // either the row count for INSERT, UPDATE or DELETE or
715  // 0 for SQL statements that return nothing
716  // Throws:
717  // TSQLException - if a database access error occurs
718 
719  if(!fImp) { Destroyed(); return 0; }
720 
721  Int_t return_value = 0;
722  ClearWarnings();
725 
726  try {
727  if(!sql.IsNull()) {
728  return_value = stmt->executeUpdate(ODBCXX_STRING_C(sql.Data()));
729  } else {
730  return_value = imp->executeUpdate();
731  }
732  } catch(odbc::SQLException& e) {
735  e.getErrorCode()) );
736  return_value = 0;
737  }
738  return return_value;
739 }
740 
741 //___________________________________________________________________
743 {
744  // Returns the current result as a TSQLResultSet object.
745  // This method should be called only once per result.
746  //
747  // This method also implicitly closes any current TSQLResultSet
748  //
749  // Returns:
750  // the current result as a TSQLResultSet; null if the result
751  // is an update count or there are no more results
752  // Throws:
753  // TSQLException - if a database access error occurs
754  // See Also:
755  // Execute(const TString&)
756 
757  if(!fImp) { Destroyed(); return 0; }
758  odbc::ResultSet* rs;
760 
761  if(fCurrentResult) delete fCurrentResult;
762 
763  try {
764  rs = stmt->getResultSet();
765  } catch(odbc::SQLException& e) {
768  e.getErrorCode()) );
769  if(rs) delete rs;
770  fCurrentResult = 0;
771  return 0;
772  }
773 
774  return fCurrentResult = new ODBCResultSet(this,(void*)rs);
775 }
776 
777 //___________________________________________________________________
779 {
780  // Returns the current result as an update count;
781  // if there are no more results, -1 is returned.
782  // This method should be called only once per result.
783  //
784  // Returns:
785  // the current result as an update count; -1 if it is a
786  // TSQLResultSet or there are no more results
787  // Throws:
788  // TSQLException - if a database access error occurs
789  // See Also:
790  // Execute(const TString&)
791 
792  if(!fImp) { Destroyed(); return 0; }
793 
794  Int_t return_value = 0;
796 
797  try {
798  return_value = stmt->getUpdateCount();
799  } catch(odbc::SQLException& e) {
802  e.getErrorCode()) );
803  return 0;
804  }
805  return return_value;
806 }
807 
808 //___________________________________________________________________
810 {
811  // Moves to a ODBCStatement's next result. It returns kTRUE if
812  // this result is a TSQLResultSet.
813  //
814  // There are no more results when
815  // (!GetMoreResults() && (GetUpdateCount() == -1)
816  //
817  // Returns:
818  // kTRUE if the next result is a TSQLResultSet;
819  // kFALSE if it is an update count or there are no more results
820  //
821  // Throws:
822  // TSQLException - if a database access error occurs
823  // See Also:
824  // Execute(const TString&)
825 
826  Bool_t return_value = kFALSE;
827 
828  if(!fImp) { Destroyed(); return return_value; }
830 
831  try {
832  return_value = (Bool_t)stmt->getMoreResults();
833  } catch(odbc::SQLException& e) {
836  e.getErrorCode()) );
837  return kFALSE;
838  }
839  return return_value;
840 }
841 
842 //___________________________________________________________________
844 {
845  // Returns the maximum number of bytes allowed for any column
846  // value. This limit is the maximum number of bytes that can be
847  // returned for any column value. The limit applies only to
848  // kBINARY, kVARBINARY, kLONGVARBINARY, kCHAR, kVARCHAR, and
849  // kLONGVARCHAR columns (see TSQLTypes.h). If the limit is exceeded,
850  // the excess data is silently discarded.
851  //
852  // Returns:
853  // the current max column size limit; zero means unlimited
854  // Throws:
855  // TSQLException - if a database access error occurs
856 
857  if(!fImp) { Destroyed(); return 0; }
858 
859  Int_t return_value = 0;
861 
862  try {
863  return_value = stmt->getMaxFieldSize();
864  } catch(odbc::SQLException& e) {
867  e.getErrorCode()) );
868  return 0;
869  }
870  return return_value;
871 }
872 
873 //___________________________________________________________________
875 {
876  // Sets the limit for the maximum number of bytes in a column to
877  // the given number of bytes. This is the maximum number of bytes
878  // that can be returned for any column value. This limit applies
879  // only to kBINARY, kVARBINARY, kLONGVARBINARY, kCHAR, kVARCHAR,
880  // and kLONGVARCHAR fields (see TSQLTypes.h) . If the limit is exceeded,
881  // the excess data is silently discarded. For maximum portability,
882  // use values greater than 256.
883  //
884  // Parameters:
885  // max - the new max column size limit; zero means unlimited
886  // Throws:
887  // TSQLException - if a database access error occurs
888 
889  if(!fImp) { Destroyed(); return; }
891 
892  try {
893  stmt->setMaxFieldSize(max);
894  } catch(odbc::SQLException& e) {
897  e.getErrorCode()) );
898  }
899 }
900 
901 //___________________________________________________________________
903 {
904  // Retrieves the maximum number of rows that a TSQLResultSet can
905  // contain. If the limit is exceeded, the excess rows are silently
906  // dropped.
907  //
908  // Returns:
909  // the current max row limit; zero means unlimited
910  // Throws:
911  // TSQLException - if a database access error occurs
912 
913  if(!fImp) { Destroyed(); return 0; }
914 
915  Int_t return_value = 0;
917 
918  try {
919  return_value = stmt->getMaxRows();
920  } catch(odbc::SQLException& e) {
923  e.getErrorCode()) );
924  return 0;
925  }
926  return return_value;
927 }
928 
929 //___________________________________________________________________
931 {
932  // Sets the limit for the maximum number of rows that any
933  // TSQLResultSet can contain to the given number. If the limit is
934  // exceeded, the excess rows are silently dropped.
935  //
936  // Parameters:
937  // max - the new max rows limit; zero means unlimited
938  // Throws:
939  // TSQLException - if a database access error occurs
940 
941  if(!fImp) { Destroyed(); return; }
943 
944  try {
945  stmt->setMaxRows(max);
946  } catch(odbc::SQLException& e) {
949  e.getErrorCode()) );
950  }
951 }
952 
953 //___________________________________________________________________
955 {
956  // Sets escape processing on or off. If escape scanning is on
957  // (the default), the driver will do escape substitution before
958  // sending the SQL to the database.
959  //
960  // Note:
961  // Since prepared statements have usually been parsed prior to
962  // making this call, disabling escape processing for prepared
963  // statements will have no effect.
964  //
965  // Parameters:
966  // enable - kTRUE to enable; kFALSE to disable
967  // Throws:
968  // TSQLException - if a database access error occurs
969 
970  if(!fImp) { Destroyed(); return; }
972 
973  try {
974  stmt->setEscapeProcessing(enable);
975  } catch(odbc::SQLException& e) {
978  e.getErrorCode()) );
979  }
980 }
981 
982 //___________________________________________________________________
984 {
985  // Returns if escape processing is on or off.
986  // If escape scanning is on (the default), the driver will do escape
987  // substitution before sending the SQL to the database.
988  //
989  // Note:
990  // Since prepared statements have usually been parsed prior to
991  // making this call, disabling escape processing for prepared
992  // statements will have no effect.
993  //
994  // Parameters:
995  // enable - kTRUE to enable; kFALSE to disable
996  // Throws:
997  // TSQLException - if a database access error occurs
998 
999  if(!fImp) { Destroyed(); return kFALSE; }
1000 
1001  Bool_t return_value = kFALSE;
1003 
1004  try {
1005  return_value = stmt->getEscapeProcessing();
1006  } catch(odbc::SQLException& e) {
1009  e.getErrorCode()) );
1010  return kFALSE;
1011  }
1012  return return_value;
1013 }
1014 
1015 //___________________________________________________________________
1017 {
1018  // Retrieves the number of seconds the driver will wait for a
1019  // ODBCStatement to execute. If the limit is exceeded, a
1020  // TSQLException is thrown.
1021  //
1022  // Returns:
1023  // the current query timeout limit in seconds; zero means
1024  // unlimited
1025  // Throws:
1026  // TSQLException - if a database access error occurs
1027 
1028  Int_t return_value = 0;
1029 
1030  if(!fImp) { Destroyed(); return return_value; }
1032 
1033  try {
1034  return_value = stmt->getQueryTimeout();
1035  } catch(odbc::SQLException& e) {
1038  e.getErrorCode()) );
1039  return 0;
1040  }
1041  return return_value;
1042 }
1043 
1044 //___________________________________________________________________
1046 {
1047  // Sets the number of seconds the driver will wait for a
1048  // ODBCStatement to execute to the given number of seconds.
1049  // If the limit is exceeded, a TSQLException is thrown.
1050  //
1051  // Parameters:
1052  // seconds - the new query timeout limit in seconds;
1053  // zero means unlimited
1054  // Throws:
1055  // TSQLException - if a database access error occurs
1056 
1057  if(!fImp) { Destroyed(); return; }
1059 
1060  try {
1061  stmt->setQueryTimeout(seconds);
1062  } catch(odbc::SQLException& e) {
1065  e.getErrorCode()) );
1066  }
1067 }
1068 
1069 //___________________________________________________________________
1071 {
1072  // Cancels this statement object if both the DBMS and driver
1073  // support aborting an SQL statement. This method can be used by
1074  // one thread to cancel a statement that is being executed by
1075  // another thread.
1076  //
1077  // Throws:
1078  // TSQLException - if a database access error occurs
1079 
1080  if(!fImp) { Destroyed(); return; }
1082 
1083  try {
1084  stmt->cancel();
1085  } catch(odbc::SQLException& e) {
1088  e.getErrorCode()) );
1089  }
1090 }
1091 
1092 //___________________________________________________________________
1094 {
1095  // Avoid using this method. Use delete ODBCStatement instead.
1096  //
1097  // Note: When a ODBCStatement is closed, its current
1098  // TSQLResultSet, if one exists, is also closed.
1099  //
1100  // Throws:
1101  // TSQLException - if a database access error occurs
1102 
1103  if(!fImp) { Destroyed(); return; }
1104 
1105  try {
1106  if(fCurrentResult) {
1107  delete fCurrentResult;
1108  fCurrentResult = 0;
1109  }
1110  ClearBatch();
1111  SafeDelete(fBatches);
1112 
1114  if(imp) delete imp;
1115  } catch(odbc::SQLException& e) {
1118  e.getErrorCode()) );
1119  }
1120  fImp = 0;
1121  Destroyed();
1122 }
1123 
1124 //___________________________________________________________________
1126 {
1127  // Defines the SQL cursor name that will be used by subsequent
1128  // ODBCStatement execute methods. This name can then be used in
1129  // SQL positioned update/delete statements to identify the
1130  // current row in the TSQLResultSet generated by this statement.
1131  // If the database doesn't support positioned update/delete,
1132  // this method is a noop. To insure that a cursor has the proper
1133  // isolation level to support updates, the cursor's SELECT
1134  // statement should be of the form 'SELECT FOR UPDATE ...'. If
1135  // the 'FOR UPDATE' phrase is omitted, positioned updates may
1136  // fail.
1137  //
1138  // Note: By definition, positioned update/delete execution must
1139  // be done by a different ODBCStatement than the one which
1140  // generated the TSQLResultSet being used for positioning.
1141  // Also, cursor names must be unique within a connection.
1142  //
1143  // Parameters:
1144  // name - the new cursor name, which must be unique within
1145  // a connection
1146  // Throws:
1147  // TSQLException - if a database access error occurs
1148 
1149  if(!fImp) { Destroyed(); return; }
1151 
1152  try {
1153  stmt->setCursorName(ODBCXX_STRING_C(name.Data()));
1154  } catch(odbc::SQLException& e) {
1157  e.getErrorCode()) );
1158  }
1159 }
1160 
1161 //___________________________________________________________________
1162 void ODBCPreparedStatement::SetFetchDirection( Int_t /* direction */ )
1163 {
1164  // Gives the driver a hint as to the direction in which the
1165  // rows in a result set will be processed. The hint applies only
1166  // to result sets created using this statement object.
1167  // The default value is TSQLResultSet::kTYPE_FORWARD_ONLY
1168  //
1169  // Note that this method sets the default fetch direction for
1170  // result sets generated by this statement object.
1171  //
1172  // Parameters:
1173  // direction - the initial direction for processing rows
1174  // Throws:
1175  // TSQLException - if a database access error occurs or the
1176  // given direction is not one of
1177  //
1178 
1179  if(!fImp) { Destroyed(); return; }
1180 }
1181 
1182 //___________________________________________________________________
1184 {
1185  // Retrieves the direction for fetching rows from database
1186  // tables that is the default for result sets generated from this
1187  // statement object. If this statement object has not set
1188  // a fetch direction by calling the method SetFetchDirection(),
1189  // the return value is implementation-specific.
1190  //
1191  // Returns:
1192  // the default fetch direction for result sets generated
1193  // from this statement object
1194  // Throws:
1195  // TSQLException - if a database access error occurs
1196 
1197  return 0;
1198 }
1199 
1200 //___________________________________________________________________
1201 void ODBCPreparedStatement::SetFetchSize( Int_t /* rows */ )
1202 {
1203  // Gives the driver a hint as to the number of rows that
1204  // should be fetched from the database when more rows are needed.
1205  // The number of rows specified affects only result sets created
1206  // using this statement. If the value specified is zero, then the
1207  // hint is ignored. The default value is zero.
1208  //
1209  // Parameters:
1210  // rows - the number of rows to fetch
1211  // Throws:
1212  // TSQLException - if a database access error occurs, or
1213  // the condition 0 <= rows <= GetMaxRows() is not satisfied.
1214 
1215  if(!fImp) { Destroyed(); return; }
1216 }
1217 
1218 //___________________________________________________________________
1220 {
1221  // Retrieves the number of result set rows that is the default
1222  // fetch size for result sets generated from this ODBCStatement
1223  // object. If this statement object has not set a fetch size
1224  // by calling the method SetFetchSize(), the return value is
1225  // implementation-specific.
1226  //
1227  // Returns:
1228  // the default fetch size for result sets generated from
1229  // this statement object
1230  // Throws:
1231  // TSQLException - if a database access error occurs
1232 
1233  Int_t return_value = 0;
1234 
1235  if(!fImp) { Destroyed(); return return_value; }
1237 
1238  try {
1239  return_value = stmt->getFetchSize();
1240  } catch(odbc::SQLException& e) {
1243  e.getErrorCode()) );
1244  return 0;
1245  }
1246  return return_value;
1247 }
1248 
1249 //___________________________________________________________________
1251 {
1252  // Retrieves the result set concurrency.
1253  //
1254  // enum EResultSetConcurrency{
1255  // kCONCUR_READ_ONLY,
1256  // kCONCUR_UPDATABLE
1257  // };
1258 
1259  Int_t return_value = 0;
1260 
1261  if(!fImp) { Destroyed(); return return_value; }
1263 
1264  try {
1265  return_value = stmt->getResultSetConcurrency();
1266  } catch(odbc::SQLException& e) {
1269  e.getErrorCode()) );
1270  return 0;
1271  }
1272  return return_value;
1273 }
1274 
1275 //___________________________________________________________________
1277 {
1278  // Determine the result set type.
1279  //
1280  // enum EResultSetType{
1281  // kTYPE_FORWARD_ONLY,
1282  // kTYPE_SCROLL_INSENSITIVE,
1283  // kTYPE_SCROLL_SENSITIVE
1284  // };
1285  //
1286 
1287  Int_t return_value = 0;
1288 
1289  if(!fImp) { Destroyed(); return return_value; }
1291 
1292  try {
1293  return_value = stmt->getResultSetType();
1294  } catch(odbc::SQLException& e) {
1297  e.getErrorCode()) );
1298  return 0;
1299  }
1300  return return_value;
1301 }
1302 
1303 //___________________________________________________________________
1304 void ODBCPreparedStatement::AddBatch( const TString& /* sql */)
1305 {
1306  // Adds a SQL command to the current batch of commmands for
1307  // the statement. This method is optional.
1308  //
1309  // Parameters:
1310  // sql - typically this is a static SQL INSERT or UPDATE
1311  // statement
1312  // Throws:
1313  // TSQLException - if a database access error occurs, or
1314  // the driver does not support batch statements
1315 
1316 }
1317 
1318 //___________________________________________________________________
1320 {
1321  // Makes the set of commands in the current batch empty. This
1322  // method is optional.
1323  //
1324  // Throws:
1325  // TSQLException - if a database access error occurs or
1326  // the driver does not support batch statements
1327 
1328 }
1329 
1330 //___________________________________________________________________
1332 {
1333  // Submits a batch of commands to the database for execution.
1334  // This method is optional.
1335  //
1336  // Returns:
1337  // an array of update counts containing one element for
1338  // each command in the batch. The array is ordered
1339  // according to the order in which commands were inserted
1340  // into the batch.
1341  //
1342  // Throws:
1343  // TSQLException - if a database access error occurs or
1344  // the driver does not support batch statements
1345 
1346  return 0;
1347 }