Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ODBCResultSet.cxx
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ODBCResultSet.cxx
1 // $Id: ODBCResultSet.cxx,v 1.3 2007/02/28 21:33:40 phnxbld 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 
28 //
30 //
31 // A TSQLResultSet provides access to a table of data. A
32 // TSQLResultSet object is usually generated by executing
33 // TSQLStatement.
34 //
35 // A TSQLResultSet maintains a cursor pointing to its current row
36 // of data. Initially the cursor is positioned before the first
37 // row. The Next() method moves the cursor to the next row.
38 //
39 // The GetXXX methods retrieve column values for the current row.
40 // You can retrieve values using either the index number of the
41 // column or the name of the column. In general,using the column
42 // index will be more efficient. Columns are numbered from 1.
43 //
44 // For maximum portability, TSQLResultSet columns within each row
45 // should be read in left-to-right order and each column should be
46 // read only once.
47 //
48 // For the GetXXX methods, the driver attempts to convert the
49 // underlying data to the specified ROOT type and returns a suitable
50 // value. See the specification for allowable mappings
51 // from SQL types to ROOT types with the ODBCResultSet::GetXXX
52 // methods.
53 //
54 // Column names used as input to GetXXX methods are case
55 // insensitive. When performing a GetXXX using a column name,
56 // if several columns have the same name, then the value of the
57 // first matching column will be returned. The column name option
58 // is designed to be used when column names are used in the SQL
59 // query. For columns that are NOT explicitly named in the query,
60 // it is best to use column numbers. If column names are used, there
61 // is no way for the programmer to guarantee that they actually refer
62 // to the intended columns.
63 //
64 // A TSQLResultSet is automatically closed by the TSQLStatement that
65 // generated it when that TSQLStatement is closed, re-executed,
66 // or used to retrieve the next result from a sequence of multiple
67 // results.
68 //
69 // The number, types and properties of a TSQLResultSet's columns are
70 // provided by the TSQLResulSetMetaData object returned by the
71 // GetMetaData() method.
72 //
73 // See also:
74 // TSQLStatement::ExecuteQuery(const TString&),
75 // TSQLStatement::GetResultSet(), TSQLResultSetMetaData
76 //
77 //___________________________________________________________________
78 //
79 // kCONCUR_READ_ONLY
80 //
81 // The concurrency mode for a TSQLResultSet object that may
82 // NOT be updated.
83 //___________________________________________________________________
84 //
85 // kCONCUR_UPDATABLE
86 //
87 // The concurrency mode for a TSQLResultSet
88 // object that may be updated.
89 //___________________________________________________________________
90 //
91 // kFETCH_FORWARD
92 //
93 // The rows in a result set will be
94 // processed in a forward direction; first-to-last.
95 //___________________________________________________________________
96 //
97 // kFETCH_REVERSE
98 //
99 // The rows in a result set will be
100 // processed in a reverse direction; last-to-first.
101 //___________________________________________________________________
102 //
103 // kFETCH_UNKNOWN
104 //
105 // The order in which rows in a result set
106 // will be processed is unknown.
107 //___________________________________________________________________
108 //
109 // kTYPE_FORWARD_ONLY
110 //
111 // The type for a TSQLResultSet object whose
112 // cursor may move only forward.
113 //___________________________________________________________________
114 //
115 // kTYPE_SCROLL_INSENSITIVE
116 //
117 // The type for a TSQLResultSet object that is
118 // scrollable but generally not sensitive to changes made by
119 // others.
120 //___________________________________________________________________
121 //
122 // kTYPE_SCROLL_SENSITIVE
123 //
124 // The type for a TSQLResultSet object that is
125 // scrollable and generally sensitive to changes made by
126 // others.
127 //
129 
130 #include <ODBCResultSet.h>
131 #include <ODBCResultSetMetaData.h>
132 #include <ODBCStatement.h>
133 #include <TList.h>
134 #include <TMath.h>
135 #include <TStopwatch.h>
136 #include <TBuffer.h>
137 #include <TTree.h>
138 #include <TRandom.h>
139 #include <TBranch.h>
140 #include <RDBC/odbc++/resultset.h>
142 #include <iostream>
143 #include <sstream>
144 #include <ctype.h>
145 #include <time.h>
146 #include <TSQLRow.h>
147 
148 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
149 #include <TBufferFile.h>
150 #endif
151 
152 using namespace odbc;
153 using namespace std;
154 
156 
157 
158 class RDBCRow: public TSQLRow
159 {
160 friend class ODBCResultSet;
161 
162 private:
163  TSQLResultSet* fResultSet; // parent result set
164  RDBCRow(TSQLResultSet *result=0) { fResultSet=result; }
165  RDBCRow* Set(TSQLResultSet *result) { fResultSet=result; return this; }
166  virtual ~RDBCRow() { fResultSet = 0; }
167  TString fField; // selected field
168 
169 public:
170  void Close(Option_t* /* opt="" */) { fResultSet = 0; }
171  ULong_t GetFieldLength(Int_t field) { return fResultSet ? fResultSet->GetMetaData()->GetColumnDisplaySize(field-1) : 0; }
172  const char* GetField(Int_t field) { fField = fResultSet ? fResultSet->GetString(field-1).Data() : ""; return fField.Data(); }
173 };
174 
176 //___________________________________________________________________
178  TSQLResultSet(stmt,imp)
179 {
180  // ctor
181 
182  fStatement = stmt;
183  odbc::ResultSet* rs = (odbc::ResultSet*)imp;
184  fImp = rs;
185  fRow = new RDBCRow(this);
186 
187  try {
188  odbc::ResultSetMetaData* mdimp = rs->getMetaData();
189  fMetaData = new ODBCResultSetMetaData(this,mdimp);
190 
191  } catch(odbc::SQLException& e) {
194  e.getErrorCode()) );
195  }
196 }
197 
198 //___________________________________________________________________
200 {
201  // destructor.
202 
204 
205  try {
206  if(imp) delete imp;
207  } catch(odbc::SQLException& e) {
210  e.getErrorCode()) );
211  }
212 
213  fImp = 0;
214 
216  if(fRow) delete fRow;
217 
219  if(stmt->fCurrentResult==this) stmt->fCurrentResult = 0;
220 
221  fMetaData = 0;
222  fRow = 0;
223 }
224 
225 //___________________________________________________________________
227 {
228  // Reports whether the last column read had a value of SQL NULL.
229  // Note that you must first call GetXXX on a column to try to
230  // read its value and then call WasNull() to see if the value
231  // read was SQL NULL.
232  //
233  // Returns:
234  // kTRUE if last column read was SQL NULL and
235  // kFALSE - otherwise
236  // Throws:
237  // TSQLException - if a database access error occurs
238 
239  Bool_t return_value = kFALSE;
240 
241  if(!fImp) { Destroyed(); return return_value; }
243 
244  try {
245  return_value = rs->wasNull();
246 
247  } catch(odbc::SQLException& e) {
250  e.getErrorCode()) );
251  return_value = kFALSE;
252  }
253  return return_value;
254 }
255 
256 //___________________________________________________________________
257 TString ODBCResultSet::GetString( Int_t columnIndex )
258 {
259  // Gets the value of a column in the current row as a TString.
260  //
261  // Parameters:
262  // columnIndex - the first column is 1, the second is 2, ...
263  // Returns:
264  // the column value; if the value is SQL NULL, the result
265  // is null
266  // Throws:
267  // TSQLException - if a database access error occurs
268 
269  TString str;
270 
271  if(!fImp) { Destroyed(); return str; }
273 
274  try {
275  str = ODBCXX_STRING_CSTR( rs->getString(columnIndex) );
276 
277  } catch(odbc::SQLException& e) {
280  e.getErrorCode()) );
281  return "";
282  }
283  return str;
284 }
285 
286 //___________________________________________________________________
287 Bool_t ODBCResultSet::GetBoolean( Int_t columnIndex )
288 {
289  // Gets the value of a column in the current row as a boolean.
290  //
291  // Parameters:
292  // columnIndex - the first column is 1, the second is 2, ...
293  // Returns:
294  // the column value; if the value is SQL NULL, the result is
295  // kFALSE
296  // Throws:
297  // TSQLException - if a database access error occurs
298 
299  Bool_t return_value = kFALSE;
300 
301  if(!fImp) { Destroyed(); return return_value; }
303 
304  try {
305  return_value = rs->getBoolean(columnIndex);
306 
307  } catch(odbc::SQLException& e) {
310  e.getErrorCode()) );
311  return_value = kFALSE;
312  }
313  return return_value;
314 }
315 
316 //___________________________________________________________________
317 Char_t ODBCResultSet::GetByte( Int_t columnIndex )
318 {
319  // Gets the value of a column in the current row as a byte.
320  //
321  // Parameters:
322  // columnIndex - the first column is 1, the second is 2, ...
323  // Returns:
324  // the column value; if the value is SQL NULL,
325  // the result is 0
326  // Throws:
327  // TSQLException - if a database access error occurs
328 
329  Char_t return_value = 0;
330 
331  if(!fImp) { Destroyed(); return return_value; }
333 
334  try {
335  return_value = rs->getByte(columnIndex);
336 
337  } catch(odbc::SQLException& e) {
340  e.getErrorCode()) );
341  return_value = 0;
342  }
343  return return_value;
344 }
345 
346 //___________________________________________________________________
347 Short_t ODBCResultSet::GetShort( Int_t columnIndex )
348 {
349  // Gets the value of a column in the current row as a Short_t.
350  //
351  // Parameters:
352  // columnIndex - the first column is 1, the second is 2, ...
353  // Returns:
354  // the column value; if the value is SQL NULL,
355  // the result is 0
356  // Throws:
357  // TSQLException - if a database access error occurs
358 
359  Short_t return_value = 0;
360 
361  if(!fImp) { Destroyed(); return return_value; }
363 
364  try {
365  return_value = rs->getShort(columnIndex);
366 
367  } catch(odbc::SQLException& e) {
370  e.getErrorCode()) );
371  return_value = 0;
372  }
373  return return_value;
374 }
375 
376 //___________________________________________________________________
377 Int_t ODBCResultSet::GetInt( Int_t columnIndex )
378 {
379  // Gets the value of a column in the current row as a Int_t.
380  //
381  // Parameters:
382  // columnIndex - the first column is 1, the second is 2, ...
383  // Returns:
384  // the column value; if the value is SQL NULL,
385  // the result is 0
386  // Throws:
387  // TSQLException - if a database access error occurs
388 
389  Int_t return_value = 0;
390 
391  if(!fImp) { Destroyed(); return return_value; }
393 
394  try {
395  return_value = rs->getInt(columnIndex);
396 
397  } catch(odbc::SQLException& e) {
400  e.getErrorCode()) );
401  return_value = 0;
402  }
403  return return_value;
404 }
405 
406 //___________________________________________________________________
407 Long_t ODBCResultSet::GetLong( Int_t columnIndex )
408 {
409  // Gets the value of a column in the current row as a Long_t.
410  //
411  // Parameters:
412  // columnIndex - the first column is 1, the second is 2, ...
413  // Returns:
414  // the column value; if the value is SQL NULL,
415  // the result is 0
416  // Throws:
417  // TSQLException - if a database access error occurs
418 
419  Long_t return_value = 0;
420 
421  if(!fImp) { Destroyed(); return return_value; }
423 
424  try {
425  return_value = rs->getLong(columnIndex);
426 
427  } catch(odbc::SQLException& e) {
430  e.getErrorCode()) );
431  return_value = 0;
432  }
433  return return_value;
434 }
435 
436 //___________________________________________________________________
437 Float_t ODBCResultSet::GetFloat( Int_t columnIndex )
438 {
439  // Gets the value of a column in the current row as a Float_t.
440  //
441  // Parameters:
442  // columnIndex - the first column is 1, the second is 2, ...
443  // Returns:
444  // the column value; if the value is SQL NULL,
445  // the result is 0
446  // Throws:
447  // TSQLException - if a database access error occurs
448 
449  Float_t return_value = 0;
450 
451  if(!fImp) { Destroyed(); return return_value; }
453 
454  try {
455  return_value = rs->getFloat(columnIndex);
456 
457  } catch(odbc::SQLException& e) {
460  e.getErrorCode()) );
461  return_value = 0;
462  }
463  return return_value;
464 }
465 
466 //___________________________________________________________________
467 Double_t ODBCResultSet::GetDouble( Int_t columnIndex )
468 {
469  // Gets the value of a column in the current row as a Double_t.
470  //
471  // Parameters:
472  // columnIndex - the first column is 1, the second is 2, ...
473  // Returns:
474  // the column value; if the value is SQL NULL,
475  // the result is 0
476  // Throws:
477  // TSQLException - if a database access error occurs
478 
479  Double_t return_value = 0;
480 
481  if(!fImp) { Destroyed(); return return_value; }
483 
484  try {
485  return_value = rs->getDouble(columnIndex);
486 
487  } catch(odbc::SQLException& e) {
490  e.getErrorCode()) );
491  return_value = 0;
492  }
493  return return_value;
494 }
495 
496 //___________________________________________________________________
497 TArrayC ODBCResultSet::GetBytes( Int_t columnIndex )
498 {
499  // Gets the value of a column in the current row as a char array.
500  // The chars represent the raw values returned by the driver.
501  //
502  // Parameters:
503  // columnIndex - the first column is 1, the second is 2, ...
504  // Returns:
505  // the column value; if the value is SQL NULL,
506  // the result is null
507  // Throws:
508  // TSQLException - if a database access error occurs
509 
510  TArrayC array;
511 
512  if(!fImp) { Destroyed(); return array; }
514 
515  try {
516  ODBCXX_BYTES b = rs->getBytes(columnIndex);
517 
518  array.Set( (Int_t)ODBCXX_BYTES_SIZE(b),
519  (Char_t*)ODBCXX_BYTES_DATA(b) );
520 
521  } catch(odbc::SQLException& e) {
524  e.getErrorCode()) );
525  }
526  return array;
527 }
528 
529 //___________________________________________________________________
530 TSQLDate ODBCResultSet::GetDate( Int_t columnIndex )
531 {
532  // Gets the value of a column in the current row as a TSQLDate
533  // object.
534  //
535  // Parameters:
536  // columnIndex - the first column is 1, the second is 2, ...
537  // Returns:
538  // the column value; if the value is SQL NULL,
539  // the result is null
540  // Throws:
541  // TSQLException - if a database access error occurs
542 
543  TSQLDate return_value;
544 
545  if(!fImp) { Destroyed(); return return_value; }
547 
548  try {
549  odbc::Date dt = rs->getDate(columnIndex);
550  return_value = TSQLDate( dt.getYear(),
551  dt.getMonth(),
552  dt.getDay() );
553 
554  } catch(odbc::SQLException& e) {
557  e.getErrorCode()) );
558  }
559  return return_value;
560 }
561 
562 //___________________________________________________________________
563 TSQLTime ODBCResultSet::GetTime( Int_t columnIndex )
564 {
565  // Gets the value of a column in the current row as a TSQLTime
566  // object.
567  //
568  // Parameters:
569  // columnIndex - the first column is 1, the second is 2, ...
570  // Returns:
571  // the column value; if the value is SQL NULL,
572  // the result is null
573  // Throws:
574  // TSQLException - if a database access error occurs
575 
576  TSQLTime return_value;
577 
578  if(!fImp) { Destroyed(); return return_value; }
580 
581  try {
582  odbc::Time tm = rs->getTime(columnIndex);
583 
584  return_value = TSQLTime( tm.getHour(),
585  tm.getMinute(),
586  tm.getSecond() );
587 
588  } catch(odbc::SQLException& e) {
591  e.getErrorCode()) );
592  }
593  return return_value;
594 }
595 
596 //___________________________________________________________________
598 {
599  // Gets the value of a column in the current row as a
600  // TSQLTimestamp object.
601  //
602  // Parameters:
603  // columnIndex - the first column is 1, the second is 2, ...
604  // Returns:
605  // the column value; if the value is SQL NULL,
606  // the result is null
607  // Throws:
608  // TSQLException - if a database access error occurs
609 
610  TSQLTimestamp return_value;
611 
612  if(!fImp) { Destroyed(); return return_value; }
614 
615  try {
616  odbc::Timestamp tmstmp = rs->getTimestamp(columnIndex);
617  return_value = TSQLTimestamp( tmstmp.getYear(),
618  tmstmp.getMonth(),
619  tmstmp.getDay(),
620  tmstmp.getHour(),
621  tmstmp.getMinute(),
622  tmstmp.getSecond(),
623  tmstmp.getNanos() );
624 
625  } catch(odbc::SQLException& e) {
628  e.getErrorCode()) );
629  }
630  return return_value;
631 }
632 
633 //___________________________________________________________________
634 TBuffer* ODBCResultSet::GetAsciiStream( Int_t columnIndex )
635 {
636  // Gets the value of a column in the current row as a stream
637  // of ASCII characters. The value can then be read in chunks from
638  // the stream. This method is particularly suitable for
639  // retrieving large LONGVARCHAR values. The driver will do
640  // any necessary conversion from the database format into ASCII.
641  //
642  // Note: All the data in the returned stream must be read prior
643  // to getting the value of any other column. The next call to
644  // a get method implicitly closes the stream. Also, a stream
645  // may return 0 when the method available is called whether
646  // there is data available or not.
647  //
648  // Parameters:
649  // columnIndex - the first column is 1, the second is 2, ...
650  // Returns:
651  // A TBuffer that delivers the database column
652  // value as a stream of one char ASCII characters.
653  // If the value is SQL NULL then the result is null.
654  //
655  // Throws:
656  // TSQLException - if a database access error occurs
657 
658  TBuffer* buffer = 0;
659 
660  if(!fImp) { Destroyed(); return buffer; }
662 
663  try {
664  ODBCXX_STREAM* rsStream = rs->getAsciiStream(columnIndex);
665  Int_t bufsiz = rsStream->rdbuf()->in_avail();
666  if(bufsiz<=0) return 0;
667 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
668  buffer = new TBufferFile(TBuffer::kWrite, bufsiz);
669 #else
670  buffer = new TBuffer(TBuffer::kWrite, bufsiz);
671 #endif
672  int c;
673  while ((c = rsStream->get()) != EOF)
674  {
675  *buffer << (char) c;
676  }
677  buffer->SetBufferOffset();
678  buffer->SetReadMode();
679  } catch(odbc::SQLException& e) {
682  e.getErrorCode()) );
683  buffer = 0;
684  }
685  return buffer;
686 }
687 
688 //___________________________________________________________________
689 TBuffer* ODBCResultSet::GetBinaryStream( Int_t columnIndex )
690 {
691  // Gets the value of a column in the current row as a stream of
692  // uninterpreted chars. The value can then be read in chunks
693  // from the stream. This method is particularly suitable for
694  // retrieving large LONGVARBINARY values.
695  //
696  // Note: All the data in the returned stream must be read
697  // prior to getting the value of any other column. The next
698  // call to a Get method implicitly closes the stream. Also,
699  // a stream may return 0 when the method available is called
700  // whether there is data available or not.
701  //
702  // Parameters:
703  // columnIndex - the first column is 1, the second is 2, ...
704  // Returns:
705  // TBuffer that delivers the database column
706  // value as a stream of uninterpreted chars. If the value
707  // is SQL NULL then the result is null.
708  // Throws:
709  // TSQLException - if a database access error occurs
710 
711  TBuffer* buffer = 0;
712 
713  if(!fImp) { Destroyed(); return buffer; }
715 
716  try {
717  ODBCXX_STREAM* rsStream = rs->getBinaryStream(columnIndex);
718  Int_t bufsiz = rsStream->rdbuf()->in_avail();
719  if(bufsiz<=0) return 0;
720 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
721  buffer = new TBufferFile(TBuffer::kWrite, bufsiz);
722 #else
723  buffer = new TBuffer(TBuffer::kWrite, bufsiz);
724 #endif
725  int c;
726  while ((c = rsStream->get()) != EOF)
727  {
728  *buffer << (char) c;
729  }
730  buffer->SetBufferOffset();
731  buffer->SetReadMode();
732  } catch(odbc::SQLException& e) {
735  e.getErrorCode()) );
736  buffer = 0;
737  }
738  return buffer;
739 }
740 
741 //___________________________________________________________________
742 TObject* ODBCResultSet::GetObject( Int_t columnIndex )
743 {
744  // Gets the value of a column in the current row as ROOT object.
745  //
746  // Parameters:
747  // columnIndex - the first column is 1, the second is 2, ...
748  // Returns:
749  // TObject
750  // Throws:
751  // TSQLException - if a database access error occurs
752 
753  TObject* obj =0;
754 
755  TBuffer *b = GetBinaryStream(columnIndex);
756  obj = (TObject *)b->ReadObjectAny(TObject::Class());
757  // Laurent found that this causes a memory leak, Valeriy Onuchin never responded to this
758  // b->DetachBuffer();
759  delete b;
760  return obj;
761 }
762 
763 //___________________________________________________________________
764 TString ODBCResultSet::GetString( const TString& columnName )
765 {
766  // Gets the value of a column in the current row as a TString.
767  //
768  // Parameters:
769  // columnName - the SQL name of the column
770  // Returns:
771  // the column value; if the value is SQL NULL,
772  // the result is null
773  // Throws:
774  // TSQLException - if a database access error occurs
775 
776  return GetString(FindColumn(columnName));
777 }
778 
779 //___________________________________________________________________
780 Bool_t ODBCResultSet::GetBoolean( const TString& columnName )
781 {
782  // Gets the value of a column in the current row as a boolean.
783  //
784  // Parameters:
785  // columnName - the SQL name of the column
786  // Returns:
787  // the column value; if the value is SQL NULL,
788  // the result is kFALSE
789  // Throws:
790  // TSQLException - if a database access error occurs
791 
792  return GetBoolean(FindColumn(columnName));
793 }
794 
795 //___________________________________________________________________
796 Char_t ODBCResultSet::GetByte( const TString& columnName )
797 {
798  // Gets the value of a column in the current row as a Char_t.
799  //
800  // Parameters:
801  // columnName - the SQL name of the column
802  // Returns:
803  // the column value; if the value is SQL NULL,
804  // the result is 0
805  // Throws:
806  // TSQLException - if a database access error occurs
807 
808  return GetByte(FindColumn(columnName));
809 }
810 
811 //___________________________________________________________________
812 Short_t ODBCResultSet::GetShort( const TString& columnName )
813 {
814  // Gets the value of a column in the current row as a Short_t.
815  //
816  // Parameters:
817  // columnName - the SQL name of the column
818  // Returns:
819  // the column value; if the value is SQL NULL,
820  // the result is 0
821  // Throws:
822  // TSQLException - if a database access error occurs
823 
824  return GetShort(FindColumn(columnName));
825 }
826 
827 //___________________________________________________________________
828 Int_t ODBCResultSet::GetInt( const TString& columnName )
829 {
830  // Gets the value of a column in the current row as a Int_t.
831  //
832  // Parameters:
833  // columnName - the SQL name of the column
834  // Returns:
835  // the column value; if the value is SQL NULL,
836  // the result is 0
837  // Throws:
838  // TSQLException - if a database access error occurs
839 
840  return GetInt(FindColumn(columnName));
841 }
842 
843 //___________________________________________________________________
844 Long_t ODBCResultSet::GetLong( const TString& columnName )
845 {
846  // Gets the value of a column in the current row as a Long_t.
847  //
848  // Parameters:
849  // columnName - the SQL name of the column
850  // Returns:
851  // the column value; if the value is SQL NULL,
852  // the result is 0
853  // Throws:
854  // TSQLException - if a database access error occurs
855 
856  return GetLong(FindColumn(columnName));
857 }
858 
859 //___________________________________________________________________
860 Float_t ODBCResultSet::GetFloat( const TString& columnName )
861 {
862  // Gets the value of a column in the current row as a Float_t.
863  //
864  // Parameters:
865  // columnName - the SQL name of the column
866  // Returns:
867  // the column value; if the value is SQL NULL,
868  // the result is 0
869  // Throws:
870  // TSQLException - if a database access error occurs
871 
872  return GetFloat(FindColumn(columnName));
873 }
874 
875 //___________________________________________________________________
876 Double_t ODBCResultSet::GetDouble( const TString& columnName )
877 {
878  // Gets the value of a column in the current row as a Double_t.
879  //
880  // Parameters:
881  // columnName - the SQL name of the column
882  // Returns:
883  // the column value; if the value is SQL NULL,
884  // the result is 0
885  // Throws:
886  // TSQLException - if a database access error occurs
887 
888  return GetDouble(FindColumn(columnName));
889 }
890 
891 //___________________________________________________________________
892 TArrayC ODBCResultSet::GetBytes( const TString& columnName )
893 {
894  // Gets the value of a column in the current row as a char
895  // array. The chars represent the raw values returned by the
896  // driver.
897  //
898  // Parameters:
899  // columnName - the SQL name of the column
900  // Returns:
901  // the column value; if the value is SQL NULL,
902  // the result is null
903  // Throws:
904  // TSQLException - if a database access error occurs
905 
906  return GetBytes(FindColumn(columnName));
907 }
908 
909 //___________________________________________________________________
910 TSQLDate ODBCResultSet::GetDate( const TString& columnName )
911 {
912  // Gets the value of a column in the current row as a TSQLDate
913  // object.
914  //
915  // Parameters:
916  // columnName - the SQL name of the column
917  // Returns:
918  // the column value; if the value is SQL NULL,
919  // the result is null
920  // Throws:
921  // TSQLException - if a database access error occurs
922 
923  return GetDate(FindColumn(columnName));
924 }
925 
926 //___________________________________________________________________
927 TSQLTime ODBCResultSet::GetTime( const TString& columnName )
928 {
929  // Gets the value of a column in the current row as a TSQLTime
930  // object.
931  //
932  // Parameters:
933  // columnName - the SQL name of the column
934  // Returns:
935  // the column value; if the value is SQL NULL,
936  // the result is null
937  // Throws:
938  // TSQLException - if a database access error occurs
939 
940  return GetTime(FindColumn(columnName));
941 }
942 
943 //___________________________________________________________________
944 TSQLTimestamp ODBCResultSet::GetTimestamp( const TString& columnName )
945 {
946  // Gets the value of a column in the current row as a
947  // TSQLTimestamp object.
948  //
949  // Parameters:
950  // columnName - the SQL name of the column
951  // Returns:
952  // the column value; if the value is SQL NULL,
953  // the result is null
954  // Throws:
955  // TSQLException - if a database access error occurs
956 
957  return GetTimestamp(FindColumn(columnName));
958 }
959 
960 //___________________________________________________________________
961 TBuffer* ODBCResultSet::GetAsciiStream( const TString& columnName )
962 {
963  // Gets the value of a column in the current row as a stream
964  // of ASCII characters. The value can then be read in chunks
965  // from the stream. This method is particularly suitable for
966  // retrieving large LONGVARCHAR values. The driver will do
967  // any necessary conversion from the database format into ASCII.
968  //
969  // Note: All the data in the returned stream must be read prior
970  // to getting the value of any other column. The next call to
971  // a Get method implicitly closes the stream. Also, a stream
972  // may return 0 when the method available is called whether
973  // there is data available or not.
974  //
975  // Parameters:
976  // columnName - the SQL name of the column
977  // Returns:
978  // TBuffer that delivers the database column
979  // value as a stream of one char ASCII characters. If
980  // the value is SQL NULL then the result is null.
981  // Throws:
982  // TSQLException - if a database access error occurs
983 
984  return GetAsciiStream(FindColumn(columnName));
985 }
986 
987 //___________________________________________________________________
988 TBuffer* ODBCResultSet::GetBinaryStream( const TString& columnName )
989 {
990  // Gets the value of a column in the current row as a stream of
991  // uninterpreted chars. The value can then be read in chunks
992  // from the stream. This method is particularly suitable for
993  // retrieving large LONGVARBINARY values. The driver will
994  // do any necessary conversion from the database format into
995  // uninterpreted chars.
996  //
997  // Note: All the data in the returned stream must be read
998  // prior to getting the value of any other column. The next
999  // call to a Get method implicitly closes the stream. Also,
1000  // a stream may return 0 when the method available is called
1001  // whether there is data available or not.
1002  //
1003  // Parameters:
1004  // columnName - the SQL name of the column
1005  // Returns:
1006  // TBuffer that delivers the database column
1007  // value as a stream of uninterpreted chars. If the value
1008  // is SQL NULL then the result is null.
1009  // Throws:
1010  // TSQLException - if a database access error occurs
1011 
1012  return GetBinaryStream(FindColumn(columnName));
1013 }
1014 
1015 //___________________________________________________________________
1016 TObject* ODBCResultSet::GetObject( const TString& columnName )
1017 {
1018  // Gets the value of a column in the current row as ROOT object.
1019  //
1020  // Parameters:
1021  // columnIndex - the first column is 1, the second is 2, ...
1022  // Returns:
1023  // TObject
1024  // Throws:
1025  // TSQLException - if a database access error occurs
1026 
1027  return GetObject(FindColumn(columnName));
1028 }
1029 
1030 //___________________________________________________________________
1032 {
1033  // Gets the name of the SQL cursor used by this TSQLResultSet.
1034  //
1035  // In SQL, a result table is retrieved through a cursor that
1036  // is named. The current row of a result can be updated or
1037  // deleted using a positioned Update/Delete statement that
1038  // references the cursor name. To insure that the cursor has
1039  // the proper isolation level to support update, the cursor's
1040  // select statement should be of the form 'SELECT FOR UPDATE'.
1041  // If the 'FOR UPDATE' clause is omitted the positioned
1042  // updates may fail.
1043  // The current row of a TSQLResultSet is also the current row
1044  // of this SQL cursor.
1045  //
1046  // Note: If positioned update is not supported a
1047  // SQLException is thrown
1048  // Returns:
1049  // the TSQLResultSet's SQL cursor name
1050  // Throws:
1051  // TSQLException - if a database access error occurs
1052 
1053  TString str;
1054 
1055  if(!fImp) { Destroyed(); return str; }
1057 
1058  try {
1059  str = ODBCXX_STRING_CSTR( rs->getCursorName() );
1060 
1061  } catch(odbc::SQLException& e) {
1064  e.getErrorCode()) );
1065  return "";
1066  }
1067  return str;
1068 }
1069 
1070 //___________________________________________________________________
1072 {
1073  // Retrieves the number, types and properties of a
1074  // TSQLResultSet's columns.
1075  //
1076  // Returns:
1077  // the description of a TSQLResultSet's columns
1078  // Throws:
1079  // TSQLException - if a database access error occurs
1080 
1081  return fMetaData;
1082 }
1083 
1084 //___________________________________________________________________
1085 Int_t ODBCResultSet::FindColumn( const TString& columnName )
1086 {
1087  // Maps the given resultset column name to its TSQLResultSet
1088  // column index.
1089  //
1090  // Parameters:
1091  // columnName - the name of the column
1092  // Returns:
1093  // the column index
1094  // Throws:
1095  // TSQLException - if a database access error occurs
1096 
1097  Int_t return_value = 0;
1098 
1099  if(!fImp) { Destroyed(); return return_value; }
1101 
1102  try {
1103  return_value = rs->findColumn(
1104  ODBCXX_STRING_C(columnName.Data()) );
1105 
1106  } catch(odbc::SQLException& e) {
1109  e.getErrorCode()) );
1110  return_value = 0;
1111  }
1112  return return_value;
1113 }
1114 
1115 //___________________________________________________________________
1117 {
1118  // Indicates whether the cursor is before the first row in
1119  // the result set.
1120  //
1121  // Returns:
1122  // kTRUE if the cursor is before the first row,
1123  // kFALSE otherwise. Returns kFALSE when the
1124  // result set contains no rows.
1125  // Throws:
1126  // TSQLException - if a database access error occurs
1127 
1128  Bool_t return_value = kFALSE;
1129 
1130  if(!fImp) { Destroyed(); return return_value; }
1132 
1133  try {
1134  return_value = rs->isBeforeFirst();
1135 
1136  } catch(odbc::SQLException& e) {
1139  e.getErrorCode()) );
1140  return_value = kFALSE;
1141  }
1142  return return_value;
1143 }
1144 
1145 //___________________________________________________________________
1147 {
1148  // Indicates whether the cursor is after the last row in
1149  // the result set.
1150  //
1151  // Returns:
1152  // kTRUE if the cursor is after the last row,
1153  // kFALSE otherwise. Returns kFALSE when the
1154  // result set contains no rows.
1155  // Throws:
1156  // TSQLException - if a database access error occurs
1157 
1158  Bool_t return_value = kFALSE;
1159 
1160  if(!fImp) { Destroyed(); return return_value; }
1162 
1163  try {
1164  return_value = rs->isAfterLast();
1165 
1166  } catch(odbc::SQLException& e) {
1169  e.getErrorCode()) );
1170  return_value = kFALSE;
1171  }
1172  return return_value;
1173 }
1174 
1175 //___________________________________________________________________
1177 {
1178  // Indicates whether the cursor is on the first row of
1179  // the result set.
1180  //
1181  // Returns:
1182  // kTRUE if the cursor is on the first row,
1183  // kFALSE otherwise.
1184  // Throws:
1185  // TSQLException - if a database access error occurs
1186 
1187  Bool_t return_value = kFALSE;
1188 
1189  if(!fImp) { Destroyed(); return return_value; }
1191 
1192  try {
1193  return_value = rs->isFirst();
1194 
1195  } catch(odbc::SQLException& e) {
1198  e.getErrorCode()) );
1199  return_value = kFALSE;
1200  }
1201  return return_value;
1202 }
1203 
1204 //___________________________________________________________________
1206 {
1207  // Indicates whether the cursor is on the last row of the
1208  // result set.
1209  //
1210  // Note: Calling the method IsLast() may be expensive because
1211  // the driver might need to fetch ahead one row in
1212  // order to determine whether the current row is the
1213  // last row in the result set.
1214  //
1215  // Returns:
1216  // kTRUE if the cursor is on the last row,
1217  // kFALSE otherwise.
1218  // Throws:
1219  // TSQLException - if a database access error occurs
1220 
1221  Bool_t return_value = kFALSE;
1222 
1223  if(!fImp) { Destroyed(); return return_value; }
1225 
1226  try {
1227  return_value = rs->isLast();
1228 
1229  } catch(odbc::SQLException& e) {
1232  e.getErrorCode()) );
1233  return_value = kFALSE;
1234  }
1235  return return_value;
1236 }
1237 
1238 //___________________________________________________________________
1240 {
1241  // Moves the cursor to the front of the result set, just before
1242  // the first row. Has no effect if the result set contains no
1243  // rows.
1244  //
1245  // Throws:
1246  // TSQLException - if a database access error occurs or
1247  // the result set type is kTYPE_FORWARD_ONLY
1248 
1249  if(!fImp) { Destroyed(); return; }
1251 
1252  try {
1253  rs->beforeFirst();
1254 
1255  } catch(odbc::SQLException& e) {
1258  e.getErrorCode()) );
1259  }
1260 }
1261 
1262 //___________________________________________________________________
1264 {
1265  // Moves the cursor to the end of the result set, just after
1266  // the last row. Has no effect if the result set contains no
1267  // rows.
1268  //
1269  // Throws:
1270  // TSQLException - if a database access error occurs or
1271  // the result set type is kTYPE_FORWARD_ONLY
1272 
1273  if(!fImp) { Destroyed(); return; }
1275 
1276  try {
1277  rs->afterLast();
1278 
1279  } catch(odbc::SQLException& e) {
1282  e.getErrorCode()) );
1283  }
1284 }
1285 
1286 //___________________________________________________________________
1288 {
1289  // Retrieves the current row number. The first row is number 1,
1290  // the second number 2, and so on.
1291  //
1292  // Returns:
1293  // the current row number; 0 if there is no current row
1294  // Throws:
1295  // TSQLException - if a database access error occurs
1296 
1297  Int_t return_value = 0;
1298 
1299  if(!fImp) { Destroyed(); return return_value; }
1301 
1302  try {
1303  return_value = rs->getRow();
1304 
1305  } catch(odbc::SQLException& e) {
1308  e.getErrorCode()) );
1309  return_value = 0;
1310  }
1311  return return_value;
1312 }
1313 
1314 //___________________________________________________________________
1315 void ODBCResultSet::SetFetchDirection(Int_t /* direction */)
1316 {
1317  // Gives a hint as to the direction in which the rows in this
1318  // result set will be processed. The initial value is determined
1319  // by the TSQLStatement that produced the result set.
1320  // The fetch direction may be changed at any time.
1321  //
1322  // Throws:
1323  // TSQLException - if a database access error occurs or
1324  // the result set type is kTYPE_FORWARD_ONLY and the fetch
1325  // direction is not forward
1326 
1327 }
1328 
1329 //___________________________________________________________________
1331 {
1332  // Returns the fetch direction for this result set.
1333  //
1334  // Returns:
1335  // the current fetch direction for this result set
1336  // Throws:
1337  // TSQLException - if a database access error occurs
1338 
1339  return 0; // not applied
1340 }
1341 
1342 //___________________________________________________________________
1344 {
1345  // Gives the driver a hint as to the number of rows that
1346  // should be fetched from the database when more rows are needed
1347  // for this result set. If the fetch size specified is zero,
1348  // the driver ignores the value and is free to make its own
1349  // best guess as to what the fetch size should be. The default
1350  // value is set by the statement that created the result set.
1351  // The fetch size may be changed at any time.
1352  //
1353  // Parameters:
1354  // rows - the number of rows to fetch
1355  // Throws:
1356  // TSQLException - if a database access error occurs or the
1357  // condition 0 <= rows <= GetMaxRows() is not satisfied.
1358 
1359  if(!fImp) { Destroyed(); return; }
1361 
1362  try {
1363  rs->setFetchSize(rows);
1364 
1365  } catch(odbc::SQLException& e) {
1368  e.getErrorCode()) );
1369  }
1370 }
1371 
1372 //___________________________________________________________________
1374 {
1375  // Returns the fetch size for this result set.
1376  //
1377  // Returns:
1378  // the current fetch size for this result set
1379  // Throws:
1380  // TSQLException - if a database access error occurs
1381 
1382  Int_t return_value = 0;
1383 
1384  if(!fImp) { Destroyed(); return return_value; }
1386 
1387  try {
1388  return_value = rs->getFetchSize();
1389 
1390  } catch(odbc::SQLException& e) {
1393  e.getErrorCode()) );
1394  return_value = 0;
1395  }
1396  return return_value;
1397 }
1398 
1399 //___________________________________________________________________
1401 {
1402  // Returns the type of this result set. The type is
1403  // determined by the TSQLStatement that created the result set.
1404  //
1405  // Returns:
1406  // kTYPE_FORWARD_ONLY, kTYPE_SCROLL_INSENSITIVE, or
1407  // kTYPE_SCROLL_SENSITIVE
1408  // Throws:
1409  // TSQLException - if a database access error occurs
1410 
1411  Int_t return_value = 0;
1412 
1413  if(!fImp) { Destroyed(); return return_value; }
1415 
1416  try {
1417  return_value = rs->getType();
1418 
1419  } catch(odbc::SQLException& e) {
1422  e.getErrorCode()) );
1423  return_value = 0;
1424  }
1425  return return_value;
1426 }
1427 
1428 //___________________________________________________________________
1430 {
1431  // Returns the concurrency mode of this result set. The
1432  // concurrency used is determined by the TSQLStatement that
1433  // created the result set.
1434  //
1435  // Returns:
1436  // the concurrency type, kCONCUR_READ_ONLY or
1437  // kCONCUR_UPDATABLE
1438  // Throws:
1439  // TSQLException - if a database access error occurs
1440 
1441  Int_t return_value = 0;
1442 
1443  if(!fImp) { Destroyed(); return return_value; }
1445 
1446  try {
1447  return_value = rs->getConcurrency();
1448 
1449  } catch(odbc::SQLException& e) {
1452  e.getErrorCode()) );
1453  return_value = 0;
1454  }
1455  return return_value;
1456 }
1457 
1458 //___________________________________________________________________
1460 {
1461  // Indicates whether the current row has been updated. The
1462  // value returned depends on whether or not the result set
1463  // can detect updates.
1464  //
1465  // Returns:
1466  // kTRUE if the row has been visibly updated by
1467  // the owner or another, and updates are detected
1468  // Throws:
1469  // TSQLException - if a database access error occurs
1470  // See Also:
1471  // TSQLDatabaseMetaData::updatesAreDetected(Int_t)
1472 
1473  Bool_t return_value = kFALSE;
1474 
1475  if(!fImp) { Destroyed(); return return_value; }
1477 
1478  try {
1479  return_value = rs->rowUpdated();
1480 
1481  } catch(odbc::SQLException& e) {
1484  e.getErrorCode()) );
1485  return_value = kFALSE;
1486  }
1487  return return_value;
1488 }
1489 
1490 //___________________________________________________________________
1492 {
1493  // Indicates whether the current row has had an insertion.
1494  // The value returned depends on whether or not the
1495  // result set can detect visible inserts.
1496  //
1497  // Returns:
1498  // kTRUE if a row has had an insertion and insertions
1499  // are detected
1500  // Throws:
1501  // TSQLException - if a database access error occurs
1502  // See Also:
1503  // TSQLDatabaseMetaData::insertsAreDetected(Int_t)
1504 
1505  Bool_t return_value = kFALSE;
1506 
1507  if(!fImp) { Destroyed(); return return_value; }
1509 
1510  try {
1511  return_value = rs->rowInserted();
1512 
1513  } catch(odbc::SQLException& e) {
1516  e.getErrorCode()) );
1517  return_value = kFALSE;
1518  }
1519  return return_value;
1520 }
1521 
1522 //___________________________________________________________________
1524 {
1525  // Indicates whether a row has been deleted. A deleted row
1526  // may leave a visible "hole" in a result set. This method
1527  // can be used to detect holes in a result set. The value
1528  // returned depends on whether or not the result set can
1529  // detect deletions.
1530  //
1531  // Returns:
1532  // kTRUE if a row was deleted and deletions are detected
1533  // Throws:
1534  // TSQLException - if a database access error occurs
1535  // See Also:
1536  // TSQLDatabaseMetaData::deletesAreDetected(Int_t)
1537 
1538  Bool_t return_value = kFALSE;
1539 
1540  if(!fImp) { Destroyed(); return return_value; }
1542 
1543  try {
1544  return_value = rs->rowDeleted();
1545 
1546  } catch(odbc::SQLException& e) {
1549  e.getErrorCode()) );
1550  return_value = kFALSE;
1551  }
1552  return return_value;
1553 }
1554 
1555 //___________________________________________________________________
1556 void ODBCResultSet::UpdateNull( Int_t columnIndex )
1557 {
1558  // Give a nullable column a null value. The UpdateXXX methods
1559  // are used to update column values in the current row,
1560  // or the insert row. The UpdateXXX methods do not update the
1561  // underlying database; instead the UpdateRow() or InsertRow()
1562  // methods are called to update the database.
1563  //
1564  // Parameters:
1565  // columnIndex - the first column is 1, the second is 2, ...
1566  // Throws:
1567  // TSQLException - if a database access error occurs
1568 
1569  if(!fImp) { Destroyed(); return; }
1571 
1572  try {
1573  rs->updateNull(columnIndex);
1574 
1575  } catch(odbc::SQLException& e) {
1578  e.getErrorCode()) );
1579  }
1580 }
1581 
1582 //___________________________________________________________________
1583 void ODBCResultSet::UpdateBoolean( Int_t columnIndex,Bool_t x )
1584 {
1585  // Updates a column with a boolean value. The UpdateXXX
1586  // methods are used to update column values in the current row,
1587  // or the insert row. The UpdateXXX methods do not update the
1588  // underlying database; instead the UpdateRow() or InsertRow()
1589  // methods are called to update the database.
1590  //
1591  // Parameters:
1592  // columnIndex - the first column is 1, the second is 2, ...
1593  // x - the new column value
1594  // Throws:
1595  // TSQLException - if a database access error occurs
1596 
1597  if(!fImp) { Destroyed(); return; }
1599 
1600  try {
1601  rs->updateBoolean(columnIndex,x);
1602 
1603  } catch(odbc::SQLException& e) {
1606  e.getErrorCode()) );
1607  }
1608 }
1609 
1610 //___________________________________________________________________
1611 void ODBCResultSet::UpdateByte( Int_t columnIndex,Char_t x )
1612 {
1613  // Updates a column with a Char_t value. The UpdateXXX methods
1614  // are used to update column values in the current row,
1615  // or the insert row. The UpdateXXX methods do not update the
1616  // underlying database; instead the UpdateRow() or InsertRow()
1617  // methods are called to update the database.
1618  //
1619  // Parameters:
1620  // columnIndex - the first column is 1, the second is 2, ...
1621  // x - the new column value
1622  // Throws:
1623  // TSQLException - if a database access error occurs
1624 
1625  if(!fImp) { Destroyed(); return; }
1627 
1628  try {
1629  rs->updateByte(columnIndex,x);
1630 
1631  } catch(odbc::SQLException& e) {
1634  e.getErrorCode()) );
1635  }
1636 }
1637 
1638 //___________________________________________________________________
1639 void ODBCResultSet::UpdateShort( Int_t columnIndex,Short_t x )
1640 {
1641  // Updates a column with a Short_t value. The UpdateXXX methods
1642  // are used to update column values in the current row,
1643  // or the insert row. The UpdateXXX methods do not update the
1644  // underlying database; instead the UpdateRow() or InsertRow()
1645  // methods are called to update the database.
1646  //
1647  // Parameters:
1648  // columnIndex - the first column is 1, the second is 2, ...
1649  // x - the new column value
1650  // Throws:
1651  // TSQLException - if a database access error occurs
1652 
1653  if(!fImp) { Destroyed(); return; }
1655 
1656  try {
1657  rs->updateShort(columnIndex,x);
1658 
1659  } catch(odbc::SQLException& e) {
1662  e.getErrorCode()) );
1663  }
1664 }
1665 
1666 //___________________________________________________________________
1667 void ODBCResultSet::UpdateInt( Int_t columnIndex,Int_t x )
1668 {
1669  // Updates a column with an integer value. The UpdateXXX
1670  // methods are used to update column values in the current row,
1671  // or the insert row. The UpdateXXX methods do not update the
1672  // underlying database; instead the UpdateRow() or InsertRow()
1673  // methods are called to update the database.
1674  //
1675  // Parameters:
1676  // columnIndex - the first column is 1, the second is 2, ...
1677  // x - the new column value
1678  // Throws:
1679  // TSQLException - if a database access error occurs
1680 
1681  if(!fImp) { Destroyed(); return; }
1683 
1684  try {
1685  rs->updateInt(columnIndex,x);
1686 
1687  } catch(odbc::SQLException& e) {
1690  e.getErrorCode()) );
1691  }
1692 }
1693 
1694 //___________________________________________________________________
1695 void ODBCResultSet::UpdateLong( Int_t columnIndex,Long_t x )
1696 {
1697  // Updates a column with a Long_t value. The UpdateXXX methods
1698  // are used to update column values in the current row,
1699  // or the insert row. The UpdateXXX methods do not update the
1700  // underlying database; instead the UpdateRow() or InsertRow()
1701  // methods are called to update the database.
1702  //
1703  // Parameters:
1704  // columnIndex - the first column is 1, the second is 2, ...
1705  // x - the new column value
1706  // Throws:
1707  // TSQLException - if a database access error occurs
1708 
1709  if(!fImp) { Destroyed(); return; }
1711 
1712  try {
1713  rs->updateLong(columnIndex,x);
1714 
1715  } catch(odbc::SQLException& e) {
1718  e.getErrorCode()) );
1719  }
1720 }
1721 
1722 //___________________________________________________________________
1723 void ODBCResultSet::UpdateFloat( Int_t columnIndex,Float_t x )
1724 {
1725  // Updates a column with a Float_t value. The UpdateXXX methods
1726  // are used to update column values in the current row,
1727  // or the insert row. The UpdateXXX methods do not update the
1728  // underlying database; instead the UpdateRow() or InsertRow()
1729  // methods are called to update the database.
1730  //
1731  // Parameters:
1732  // columnIndex - the first column is 1, the second is 2, ...
1733  // x - the new column value
1734  // Throws:
1735  // TSQLException - if a database access error occurs
1736 
1737  if(!fImp) { Destroyed(); return; }
1739 
1740  try {
1741  rs->updateFloat(columnIndex,x);
1742 
1743  } catch(odbc::SQLException& e) {
1746  e.getErrorCode()) );
1747  }
1748 }
1749 
1750 //___________________________________________________________________
1751 void ODBCResultSet::UpdateDouble( Int_t columnIndex,
1752  Double_t x )
1753 {
1754  // Updates a column with a Double value. The UpdateXXX
1755  // methods are used to update column values in the current row,
1756  // or the insert row. The UpdateXXX methods do not update the
1757  // underlying database; instead the UpdateRow() or InsertRow()
1758  // methods are called to update the database.
1759  //
1760  // Parameters:
1761  // columnIndex - the first column is 1, the second is 2, ...
1762  // x - the new column value
1763  // Throws:
1764  // TSQLException - if a database access error occurs
1765 
1766  if(!fImp) { Destroyed(); return; }
1768 
1769  try {
1770  rs->updateDouble(columnIndex,x);
1771 
1772  } catch(odbc::SQLException& e) {
1775  e.getErrorCode()) );
1776  }
1777 }
1778 
1779 //___________________________________________________________________
1780 void ODBCResultSet::UpdateString( Int_t columnIndex,
1781  const TString& x )
1782 {
1783  // Updates a column with a TString value. The UpdateXXX
1784  // methods are used to update column values in the current row,
1785  // or the insert row. The UpdateXXX methods do not update the
1786  // underlying database; instead the UpdateRow() or InsertRow()
1787  // methods are called to update the database.
1788  //
1789  // Parameters:
1790  // columnIndex - the first column is 1, the second is 2, ...
1791  // x - the new column value
1792  // Throws:
1793  // TSQLException - if a database access error occurs
1794 
1795  if(!fImp) { Destroyed(); return; }
1797 
1798  try {
1799  ODBCXX_STRING s = ODBCXX_STRING_C(x.Data());
1800  rs->updateString(columnIndex,s);
1801 
1802  } catch(odbc::SQLException& e) {
1805  e.getErrorCode()) );
1806  }
1807 }
1808 
1809 //___________________________________________________________________
1810 void ODBCResultSet::UpdateBytes( Int_t columnIndex,
1811  const TArrayC& x )
1812 {
1813  // Updates a column with a Char_t array value. The UpdateXXX
1814  // methods are used to update column values in the current row,
1815  // or the insert row. The UpdateXXX methods do not update the
1816  // underlying database; instead the UpdateRow() or InsertRow()
1817  // methods are called to update the database.
1818  //
1819  // Parameters:
1820  // columnIndex - the first column is 1, the second is 2, ...
1821  // x - the new column value
1822  // Throws:
1823  // TSQLException - if a database access error occurs
1824 
1825  if(!fImp) { Destroyed(); return; }
1827 
1828  try {
1829  ODBCXX_BYTES b = ODBCXX_BYTES_C(x.GetArray(),x.GetSize());
1830  rs->updateBytes(columnIndex,b);
1831 
1832  } catch(odbc::SQLException& e) {
1835  e.getErrorCode()) );
1836  }
1837 }
1838 
1839 //___________________________________________________________________
1840 void ODBCResultSet::UpdateDate( Int_t columnIndex,
1841  const TSQLDate& x )
1842 {
1843  // Updates a column with a TSQLDate value. The UpdateXXX methods
1844  // are used to update column values in the current row,
1845  // or the insert row. The UpdateXXX methods do not update the
1846  // underlying database; instead the UpdateRow() or InsertRow()
1847  // methods are called to update the database.
1848  //
1849  // Parameters:
1850  // columnIndex - the first column is 1, the second is 2, ...
1851  // x - the new column value
1852  // Throws:
1853  // TSQLException - if a database access error occurs
1854 
1855  if(!fImp) { Destroyed(); return; }
1857 
1858  try {
1859  odbc::Date dt( x.GetYear(),
1860  x.GetMonth(),
1861  x.GetDay() );
1862 
1863  rs->updateDate(columnIndex,dt);
1864 
1865  } catch(odbc::SQLException& e) {
1868  e.getErrorCode()) );
1869  }
1870 }
1871 
1872 //___________________________________________________________________
1873 void ODBCResultSet::UpdateTime( Int_t columnIndex,
1874  const TSQLTime& x )
1875 {
1876  // Updates a column with a TSQLTime value. The UpdateXXX methods
1877  // are used to update column values in the current row,
1878  // or the insert row. The UpdateXXX methods do not update the
1879  // underlying database; instead the UpdateRow() or InsertRow()
1880  // methods are called to update the database.
1881  //
1882  // Parameters:
1883  // columnIndex - the first column is 1, the second is 2, ...
1884  // x - the new column value
1885  // Throws:
1886  // TSQLException - if a database access error occurs
1887 
1888  if(!fImp) { Destroyed(); return; }
1890 
1891  try {
1892  odbc::Time tm( x.GetHour(),
1893  x.GetMinute(),
1894  x.GetSecond() );
1895 
1896  rs->updateTime(columnIndex,tm);
1897 
1898  } catch(odbc::SQLException& e) {
1901  e.getErrorCode()) );
1902  }
1903 }
1904 
1905 //___________________________________________________________________
1906 void ODBCResultSet::UpdateTimestamp( Int_t columnIndex,
1907  const TSQLTimestamp& x )
1908 {
1909  // Updates a column with a TSQLTimestamp value. The UpdateXXX
1910  // methods are used to update column values in the current row,
1911  // or the insert row. The UpdateXXX methods do not update the
1912  // underlying database; instead the UpdateRow() or InsertRow()
1913  // methods are called to update the database.
1914  //
1915  // Parameters:
1916  // columnIndex - the first column is 1, the second is 2, ...
1917  // x - the new column value
1918  // Throws:
1919  // TSQLException - if a database access error occurs
1920 
1921  if(!fImp) { Destroyed(); return; }
1923 
1924  try {
1925  odbc::Timestamp tmstmp( x.GetYear(),
1926  x.GetMonth(),
1927  x.GetDay(),
1928  x.GetHour(),
1929  x.GetMinute(),
1930  x.GetSecond(),
1931  x.GetNanos() );
1932 
1933  rs->updateTimestamp(columnIndex,tmstmp);
1934 
1935  } catch(odbc::SQLException& e) {
1938  e.getErrorCode()) );
1939  }
1940 }
1941 
1942 //___________________________________________________________________
1943 void ODBCResultSet::UpdateAsciiStream( Int_t columnIndex,
1944  TBuffer* x,
1945  Int_t length )
1946 {
1947  // Updates a column with an ascii stream value. The UpdateXXX
1948  // methods are used to update column values in the current row,
1949  // or the insert row. The UpdateXXX methods do not update the
1950  // underlying database; instead the UpdateRow() or InsertRow()
1951  // methods are called to update the database.
1952  //
1953  // Parameters:
1954  // columnIndex - the first column is 1, the second is 2, ...
1955  // x - the new column value
1956  // length - length of stream
1957  // Throws:
1958  // TSQLException - if a database access error occurs
1959 
1960  if(!fImp) { Destroyed(); return; }
1962 
1963  try {
1964  Int_t xl = (x->BufferSize()>length) && (length>0) ? length : x->BufferSize();
1965  std::istringstream* s = new std::istringstream(x->Buffer()); //
1966  rs->updateAsciiStream( columnIndex,(std::istream*)s,xl );
1967 
1968  } catch(odbc::SQLException& e) {
1971  e.getErrorCode()) );
1972  }
1973 }
1974 
1975 //___________________________________________________________________
1976 void ODBCResultSet::UpdateBinaryStream( Int_t columnIndex,
1977  TBuffer* x,
1978  Int_t length )
1979 {
1980  // Updates a column with a binary stream value. The UpdateXXX
1981  // methods are used to update column values in the current row,
1982  // or the insert row. The UpdateXXX methods do not update the
1983  // underlying database; instead the UpdateRow() or InsertRow()
1984  // methods are called to update the database.
1985  //
1986  // Parameters:
1987  // columnIndex - the first column is 1, the second is 2, ...
1988  // x - the new column value
1989  // length - length of stream
1990  // Throws:
1991  // TSQLException - if a database access error occurs
1992 
1993  if(!fImp) { Destroyed(); return; }
1995 
1996  try {
1997  Int_t xl = (x->BufferSize()>length) && (length>0) ? length : x->BufferSize();
1998  std::istringstream* s = new std::istringstream(x->Buffer());
1999  rs->updateBinaryStream( columnIndex,(std::istream*)s,xl );
2000 
2001  } catch(odbc::SQLException& e) {
2004  e.getErrorCode()) );
2005  }
2006 }
2007 
2008 //___________________________________________________________________
2009 void ODBCResultSet::UpdateObject( Int_t columnIndex,TObject* x )
2010 {
2011  // Updates a column with a ROOT object. The UpdateXXX
2012  // methods are used to update column values in the current row,
2013  // or the insert row. The UpdateXXX methods do not update the
2014  // underlying database; instead the UpdateRow() or InsertRow()
2015  // methods are called to update the database.
2016  //
2017  // Parameters:
2018  // columnIndex - the first column is 1, the second is 2, ...
2019  // x - the new column value
2020  // length - length of stream
2021  // Throws:
2022  // TSQLException - if a database access error occurs
2023 
2024 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,15,0)
2025  TBuffer *b = new TBufferFile(TBuffer::kWrite);
2026 #else
2027  TBuffer *b = new TBuffer(TBuffer::kWrite);
2028 #endif
2029  b->WriteObject(x);
2030  UpdateBinaryStream(columnIndex,b,b->BufferSize());
2031  b->DetachBuffer();
2032  delete b;
2033 }
2034 
2035 //___________________________________________________________________
2036 void ODBCResultSet::UpdateNull( const TString& columnName )
2037 {
2038  // Updates a column with a null value. The UpdateXXX methods
2039  // are used to update column values in the current row,
2040  // or the insert row. The UpdateXXX methods do not update the
2041  // underlying database; instead the UpdateRow() or InsertRow()
2042  // methods are called to update the database.
2043  //
2044  // Parameters:
2045  // columnIndex - the first column is 1, the second is 2, ...
2046  // x - the new column value
2047  // Throws:
2048  // TSQLException - if a database access error occurs
2049 
2050  UpdateNull(FindColumn(columnName));
2051 }
2052 
2053 //___________________________________________________________________
2054 void ODBCResultSet::UpdateBoolean( const TString& columnName,Bool_t x )
2055 {
2056  // Updates a column with a boolean value. The UpdateXXX methods
2057  // are used to update column values in the current row,
2058  // or the insert row. The UpdateXXX methods do not update the
2059  // underlying database; instead the UpdateRow() or InsertRow()
2060  // methods are called to update the database.
2061  //
2062  // Parameters:
2063  // columnIndex - the first column is 1, the second is 2, ...
2064  // x - the new column value
2065  // Throws:
2066  // TSQLException - if a database access error occurs
2067 
2068  UpdateBoolean(FindColumn(columnName),x);
2069 }
2070 
2071 //___________________________________________________________________
2072 void ODBCResultSet::UpdateByte( const TString& columnName,Char_t x )
2073 {
2074  // Updates a column with a Char_t value. The UpdateXXX methods
2075  // are used to update column values in the current row,
2076  // or the insert row. The UpdateXXX methods do not update the
2077  // underlying database; instead the UpdateRow() or InsertRow()
2078  // methods are called to update the database.
2079  //
2080  // Parameters:
2081  // columnIndex - the first column is 1, the second is 2, ...
2082  // x - the new column value
2083  // Throws:
2084  // TSQLException - if a database access error occurs
2085 
2086  UpdateByte(FindColumn(columnName),x);
2087 }
2088 
2089 //___________________________________________________________________
2090 void ODBCResultSet::UpdateShort( const TString& columnName,Short_t x )
2091 {
2092  // Updates a column with a short value. The UpdateXXX methods
2093  // are used to update column values in the current row,
2094  // or the insert row. The UpdateXXX methods do not update the
2095  // underlying database; instead the UpdateRow() or InsertRow()
2096  // methods are called to update the database.
2097  //
2098  // Parameters:
2099  // columnIndex - the first column is 1, the second is 2, ...
2100  // x - the new column value
2101  // Throws:
2102  // TSQLException - if a database access error occurs
2103 
2104  UpdateShort(FindColumn(columnName),x);
2105 }
2106 
2107 //___________________________________________________________________
2108 void ODBCResultSet::UpdateInt( const TString& columnName,Int_t x )
2109 {
2110  // Updates a column with an integer value. The UpdateXXX methods
2111  // are used to update column values in the current row,
2112  // or the insert row. The UpdateXXX methods do not update the
2113  // underlying database; instead the UpdateRow() or InsertRow()
2114  // methods are called to update the database.
2115  //
2116  // Parameters:
2117  // columnIndex - the first column is 1, the second is 2, ...
2118  // x - the new column value
2119  // Throws:
2120  // TSQLException - if a database access error occurs
2121 
2122  UpdateInt(FindColumn(columnName),x);
2123 }
2124 
2125 //___________________________________________________________________
2126 void ODBCResultSet::UpdateLong( const TString& columnName,Long_t x )
2127 {
2128  // Updates a column with a long value. The UpdateXXX methods
2129  // are used to update column values in the current row,
2130  // or the insert row. The UpdateXXX methods do not update the
2131  // underlying database; instead the UpdateRow() or InsertRow()
2132  // methods are called to update the database.
2133  //
2134  // Parameters:
2135  // columnIndex - the first column is 1, the second is 2, ...
2136  // x - the new column value
2137  // Throws:
2138  // TSQLException - if a database access error occurs
2139 
2140  UpdateLong(FindColumn(columnName),x);
2141 }
2142 
2143 //___________________________________________________________________
2144 void ODBCResultSet::UpdateFloat( const TString& columnName,Float_t x )
2145 {
2146  // Updates a column with a float value. The UpdateXXX methods
2147  // are used to update column values in the current row,
2148  // or the insert row. The UpdateXXX methods do not update the
2149  // underlying database; instead the UpdateRow() or InsertRow()
2150  // methods are called to update the database.
2151  //
2152  // Parameters:
2153  // columnIndex - the first column is 1, the second is 2, ...
2154  // x - the new column value
2155  // Throws:
2156  // TSQLException - if a database access error occurs
2157 
2158  UpdateFloat(FindColumn(columnName),x);
2159 }
2160 
2161 //___________________________________________________________________
2162 void ODBCResultSet::UpdateDouble( const TString& columnName,Double_t x )
2163 {
2164  // Updates a column with a double value. The UpdateXXX methods
2165  // are used to update column values in the current row,
2166  // or the insert row. The UpdateXXX methods do not update the
2167  // underlying database; instead the UpdateRow() or InsertRow()
2168  // methods are called to update the database.
2169  //
2170  // Parameters:
2171  // columnIndex - the first column is 1, the second is 2, ...
2172  // x - the new column value
2173  // Throws:
2174  // TSQLException - if a database access error occurs
2175 
2176  UpdateDouble(FindColumn(columnName),x);
2177 }
2178 
2179 //___________________________________________________________________
2180 void ODBCResultSet::UpdateString( const TString& columnName,
2181  const TString& x )
2182 {
2183  // Updates a column with a TString value. The UpdateXXX methods
2184  // are used to update column values in the current row,
2185  // or the insert row. The UpdateXXX methods do not update the
2186  // underlying database; instead the UpdateRow() or InsertRow()
2187  // methods are called to update the database.
2188  //
2189  // Parameters:
2190  // columnIndex - the first column is 1, the second is 2, ...
2191  // x - the new column value
2192  // Throws:
2193  // TSQLException - if a database access error occurs
2194 
2195  UpdateString(FindColumn(columnName),x);
2196 }
2197 
2198 //___________________________________________________________________
2199 void ODBCResultSet::UpdateBytes( const TString& columnName,
2200  const TArrayC& x )
2201 {
2202  // Updates a column with a bytes array value. The update methods
2203  // are used to update column values in the current row,
2204  // or the insert row. The UpdateXXX methods do not update the
2205  // underlying database; instead the UpdateRow() or InsertRow()
2206  // methods are called to update the database.
2207  //
2208  // Parameters:
2209  // columnIndex - the first column is 1, the second is 2, ...
2210  // x - the new column value
2211  // Throws:
2212  // TSQLException - if a database access error occurs
2213 
2214  UpdateBytes(FindColumn(columnName),x);
2215 }
2216 
2217 //___________________________________________________________________
2218 void ODBCResultSet::UpdateDate( const TString& columnName,
2219  const TSQLDate& x )
2220 {
2221  // Updates a column with a TSQLDate value. The UpdateXXX methods
2222  // are used to update column values in the current row,
2223  // or the insert row. The UpdateXXX methods do not update the
2224  // underlying database; instead the UpdateRow() or InsertRow()
2225  // methods are called to update the database.
2226  //
2227  // Parameters:
2228  // columnIndex - the first column is 1, the second is 2, ...
2229  // x - the new column value
2230  // Throws:
2231  // TSQLException - if a database access error occurs
2232 
2233  UpdateDate(FindColumn(columnName),x);
2234 }
2235 
2236 //___________________________________________________________________
2237 void ODBCResultSet::UpdateTime( const TString& columnName,
2238  const TSQLTime& x )
2239 {
2240  // Updates a column with a TSQLTime value. The UpdateXXX methods
2241  // are used to update column values in the current row,
2242  // or the insert row. The UpdateXXX methods do not update the
2243  // underlying database; instead the UpdateRow() or InsertRow()
2244  // methods are called to update the database.
2245  //
2246  // Parameters:
2247  // columnIndex - the first column is 1, the second is 2, ...
2248  // x - the new column value
2249  // Throws:
2250  // TSQLException - if a database access error occurs
2251 
2252  UpdateTime(FindColumn(columnName),x);
2253 }
2254 
2255 //___________________________________________________________________
2256 void ODBCResultSet::UpdateTimestamp( const TString& columnName,
2257  const TSQLTimestamp& x )
2258 {
2259  // Updates a column with a TSQLTimestamp value. The update methods
2260  // are used to update column values in the current row,
2261  // or the insert row. The UpdateXXX methods do not update the
2262  // underlying database; instead the UpdateRow() or InsertRow()
2263  // methods are called to update the database.
2264  //
2265  // Parameters:
2266  // columnIndex - the first column is 1, the second is 2, ...
2267  // x - the new column value
2268  // Throws:
2269  // TSQLException - if a database access error occurs
2270 
2271  UpdateTimestamp(FindColumn(columnName),x);
2272 }
2273 
2274 //___________________________________________________________________
2275 void ODBCResultSet::UpdateAsciiStream( const TString& columnName,
2276  TBuffer* x,
2277  Int_t length )
2278 {
2279  // Updates a column with an ascii stream value. The update methods
2280  // are used to update column values in the current row,
2281  // or the insert row. The UpdateXXX methods do not update the
2282  // underlying database; instead the UpdateRow() or InsertRow()
2283  // methods are called to update the database.
2284  //
2285  // Parameters:
2286  // columnIndex - the first column is 1, the second is 2, ...
2287  // x - the new column value
2288  // length - length of stream
2289  // Throws:
2290  // TSQLException - if a database access error occurs
2291 
2292  UpdateAsciiStream(FindColumn(columnName),x,length);
2293 }
2294 
2295 //___________________________________________________________________
2296 void ODBCResultSet::UpdateBinaryStream( const TString& columnName,
2297  TBuffer* x,
2298  Int_t length )
2299 {
2300  // Updates a column with a binary stream value. The update methods
2301  // are used to update column values in the current row,
2302  // or the insert row. The UpdateXXX methods do not update the
2303  // underlying database; instead the UpdateRow() or InsertRow()
2304  // methods are called to update the database.
2305  //
2306  // Parameters:
2307  // columnIndex - the first column is 1, the second is 2, ...
2308  // x - the new column value
2309  // length - length of stream
2310  // Throws:
2311  // TSQLException - if a database access error occurs
2312 
2313  UpdateBinaryStream(FindColumn(columnName),x,length);
2314 }
2315 
2316 //___________________________________________________________________
2317 void ODBCResultSet::UpdateObject(const TString& columnName,TObject* x)
2318 {
2319  // Updates a column with a ROOT object. The update methods
2320  // are used to update column values in the current row,
2321  // or the insert row. The UpdateXXX methods do not update the
2322  // underlying database; instead the UpdateRow() or InsertRow()
2323  // methods are called to update the database.
2324  //
2325  // Parameters:
2326  // columnIndex - the first column is 1, the second is 2, ...
2327  // x - the new column value
2328  // length - length of stream
2329  // Throws:
2330  // TSQLException - if a database access error occurs
2331 
2332  UpdateObject(FindColumn(columnName),x);
2333 }
2334 
2335 //___________________________________________________________________
2337 {
2338  // Inserts the contents of the insert row into the result set
2339  // and the database. Must be on the insert row when this method
2340  // is called.
2341  //
2342  // Throws:
2343  // TSQLException - if a database access error occurs, if
2344  // called when not on the insert row, or if not all of
2345  // non-nullable columns in the insert row have been given
2346  // a value.
2347 
2348  if(!fImp) { Destroyed(); return; }
2350 
2351  try {
2352  rs->insertRow();
2353 
2354  } catch(odbc::SQLException& e) {
2357  e.getErrorCode()) );
2358  }
2359 }
2360 
2361 //___________________________________________________________________
2363 {
2364  // Updates the underlying database with the new contents of
2365  // the current row. Cannot be called when on the insert row.
2366  //
2367  // Throws:
2368  // TSQLException - if a database access error occurs or if
2369  // called when on the insert row
2370 
2371  if(!fImp) { Destroyed(); return; }
2373 
2374  try {
2375  rs->updateRow();
2376 
2377  } catch(odbc::SQLException& e) {
2380  e.getErrorCode()) );
2381  }
2382 }
2383 
2384 //___________________________________________________________________
2386 {
2387  // Deletes the current row from the result set and the underlying
2388  // database. Cannot be called when on the insert row.
2389  //
2390  // Throws:
2391  // TSQLException - if a database access error occurs or
2392  // if called when on the insert row.
2393 
2394  if(!fImp) { Destroyed(); return; }
2396 
2397  try {
2398  rs->deleteRow();
2399 
2400  } catch(odbc::SQLException& e) {
2403  e.getErrorCode()) );
2404  }
2405 }
2406 
2407 //___________________________________________________________________
2409 {
2410  // Refreshes the current row with its most recent value in
2411  // the database. Cannot be called when on the insert row.
2412  // The RefreshRow() method provides a way for an application to
2413  // explicitly tell the driver to refetch a row(s) from the
2414  // database. An application may want to call RefreshRow() when
2415  // caching or prefetching is being done by the driver to
2416  // fetch the latest value of a row from the database. The
2417  // driver may actually refresh multiple rows at once if the
2418  // fetch size is greater than one. All values are refetched
2419  // subject to the transaction isolation level and cursor
2420  // sensitivity. If RefreshRow() is called after calling UpdateXXX,
2421  // but before calling UpdateRow(), then the updates made to the
2422  // row are lost. Calling the method RefreshRow() frequently will
2423  // likely slow performance.
2424  //
2425  // Throws:
2426  // TSQLException - if a database access error occurs or
2427  // if called when on the insert row
2428 
2429  if(!fImp) { Destroyed(); return; }
2431 
2432  try {
2433  rs->refreshRow();
2434 
2435  } catch(odbc::SQLException& e) {
2438  e.getErrorCode()) );
2439  }
2440 }
2441 
2442 //___________________________________________________________________
2444 {
2445  // Cancels the updates made to a row. This method may be
2446  // called after calling an UpdateXXX method(s) and before
2447  // calling UpdateRow() to rollback the updates made to a row.
2448  // If no updates have been made or UpdateRow() has already been
2449  // called then this method has no effect.
2450  //
2451  // Throws:
2452  // TSQLException - if a database access error occurs or if
2453  // called when on the insert row
2454 
2455  if(!fImp) { Destroyed(); return; }
2457 
2458  try {
2459  rs->cancelRowUpdates();
2460 
2461  } catch(odbc::SQLException& e) {
2464  e.getErrorCode()) );
2465  }
2466 }
2467 
2468 //___________________________________________________________________
2470 {
2471  // Moves the cursor to the insert row. The current cursor
2472  // position is remembered while the cursor is positioned on
2473  // the insert row. The insert row is a special row associated
2474  // with an updatable result set. It is essentially a buffer
2475  // where a new row may be constructed by calling the UpdateXXX
2476  // methods prior to inserting the row into the result set.
2477  // Only the UpdateXXX, GetXXX, and InsertRow() methods may be
2478  // called when the cursor is on the insert row.
2479  // All of the columns in a result set must be given a value
2480  // each time this method is called before calling InsertRow().
2481  // The method UpdateXXX must be called before a GetXXX method
2482  // can be called on a column value.
2483  //
2484  // Throws:
2485  // TSQLException - if a database access error occurs
2486  // or the result set is not updatable
2487 
2488  if(!fImp) { Destroyed(); return; }
2490 
2491  try {
2492  rs->moveToInsertRow();
2493 
2494  } catch(odbc::SQLException& e) {
2497  e.getErrorCode()) );
2498  }
2499 }
2500 
2501 //___________________________________________________________________
2503 {
2504  // Moves the cursor to the remembered cursor position,
2505  // usually the current row. This method has no effect if the
2506  // cursor is not on the insert row.
2507  //
2508  // Throws:
2509  // TSQLException - if a database access error occurs or
2510  // the result set is not updatable
2511 
2512  if(!fImp) { Destroyed(); return; }
2514 
2515  try {
2516  rs->moveToCurrentRow();
2517 
2518  } catch(odbc::SQLException& e) {
2521  e.getErrorCode()) );
2522  }
2523 }
2524 
2525 //___________________________________________________________________
2527 {
2528  // Moves the cursor down one row from its current position. A
2529  // TSQLResultSet cursor is initially positioned before the first
2530  // row; the first call to next makes the first row the current
2531  // row; the second call makes the second row the current row,
2532  // and so on.
2533  //
2534  // If an input stream is open for the current row, a call to the
2535  // method next will implicitly close it. The TSQLResultSet's
2536  // warning chain is cleared when a new row is read.
2537  //
2538  // Returns:
2539  // pointer to TSQLRow(kTRUE) if the new current row is valid;
2540  // null(kFALSE) if there are no more rows
2541  // Throws:
2542  // TSQLException - if a database access error occurs
2543 
2544  Bool_t return_value=kFALSE;
2545 
2546  if(!fImp) { Destroyed(); return 0; }
2548 
2549  try {
2550  return_value = rs->next();
2551 
2552  } catch(odbc::SQLException& e) {
2555  e.getErrorCode()) );
2556  return_value = 0;
2557  }
2558  return return_value ? fRow->Set(this) : 0;
2559 }
2560 
2561 //___________________________________________________________________
2563 {
2564  // Moves the cursor to the first row in the result set.
2565  //
2566  // Returns:
2567  // pointer to TSQLRow(kTRUE) if the cursor is on a valid row;
2568  // null(kFALSE) if there are no rows in the result set
2569  // Throws:
2570  // TSQLException - if a database access error occurs or
2571  // the result set type is kTYPE_FORWARD_ONLY
2572 
2573 
2574  Bool_t return_value = kFALSE;
2575 
2576  if(!fImp) { Destroyed(); return 0; }
2578 
2579  try {
2580  return_value = rs->first();
2581 
2582  } catch(odbc::SQLException& e) {
2585  e.getErrorCode()) );
2586  return_value = 0;
2587  }
2588  return return_value ? fRow->Set(this) : 0;
2589 }
2590 
2591 //___________________________________________________________________
2592 TSQLRow* ODBCResultSet::Absolute( Int_t row )
2593 {
2594  // Moves the cursor to the given row number in the result set.
2595  // If the row number is positive, the cursor moves to the
2596  // given row number with respect to the beginning of the
2597  // result set. The first row is row 1, the second is row 2,
2598  // and so on.
2599  //
2600  // If the given row number is negative, the cursor moves to an
2601  // absolute row position with respect to the end of the result
2602  // set. For example, calling Absolute(-1) positions the cursor
2603  // on the last row, Absolute(-2) indicates the next-to-last row,
2604  // and so on.
2605  //
2606  // An attempt to position the cursor beyond the first/last row
2607  // in the result set leaves the cursor before/after the first/last
2608  // row, respectively.
2609  //
2610  // Note: calling Absolute(1) is the same as calling First().
2611  // calling Absolute(-1) is the same as calling Last().
2612  //
2613  // Returns:
2614  // pointer to TSQLRow(kTRUE) if the cursor is on the result set;
2615  // null(kFALSE) otherwise
2616  // Throws:
2617  // TSQLException - if a database access error occurs or
2618  // row is 0, or result set type is kTYPE_FORWARD_ONLY
2619 
2620  Bool_t return_value = kFALSE;
2621 
2622  if(!fImp) { Destroyed(); return 0; }
2624 
2625  try {
2626  return_value = rs->absolute(row);
2627 
2628  } catch(odbc::SQLException& e) {
2631  e.getErrorCode()) );
2632  return_value = 0;
2633  }
2634  return return_value ? fRow->Set(this) : 0;
2635 }
2636 
2637 //___________________________________________________________________
2639 {
2640  // Moves the cursor a relative number of rows, either positive or
2641  // negative. Attempting to move beyond the first/last row in
2642  // the result set positions the cursor before/after the the
2643  // first/last row. Calling Relative(0) is valid, but does not
2644  // change the cursor position.
2645  //
2646  // Note: Calling Relative(1) is different from calling Next()
2647  // because is makes sense to call Next() when there is
2648  // no current row, for example, when the cursor is
2649  // positioned before the first row or after the last row
2650  // of the result set.
2651  // Returns:
2652  // pointer to TSQLRow(kTRUE) if the cursor is on a row;
2653  // null(kFALSE) otherwise
2654  // Throws:
2655  // TSQLException - if a database access error occurs,
2656  // there is no current row, or the result set type
2657  // is kTYPE_FORWARD_ONLY
2658 
2659  Bool_t return_value = kFALSE;
2660 
2661  if(!fImp) { Destroyed(); return 0; }
2663 
2664  try {
2665  return_value = rs->relative(rows);
2666 
2667  } catch(odbc::SQLException& e) {
2670  e.getErrorCode()) );
2671  return_value = 0;
2672  }
2673  return return_value ? fRow->Set(this) : 0;
2674 }
2675 
2676 //___________________________________________________________________
2678 {
2679  // Moves the cursor to the previous row in the result set.
2680  //
2681  // Note: Previous() is not the same as Relative(-1)
2682  // because it makes sense to call Previous()
2683  // when there is no current row.
2684  //
2685  // Returns:
2686  // pointer to TSQLRow(kTRUE) if the cursor is on a valid row;
2687  // null(kFALSE) if it is off the result set
2688  // Throws:
2689  // TSQLException - if a database access error occurs or
2690  // the result set type is kTYPE_FORWARD_ONLY
2691 
2692  Bool_t return_value = kFALSE;
2693 
2694  if(!fImp) { Destroyed(); return 0; }
2696 
2697  try {
2698  return_value = rs->previous();
2699 
2700  } catch(odbc::SQLException& e) {
2703  e.getErrorCode()) );
2704  return_value = 0;
2705  }
2706  return return_value ? fRow->Set(this) : 0;
2707 }
2708 
2709 //___________________________________________________________________
2711 {
2712  // Moves the cursor to the last row in the result set.
2713  //
2714  // Returns:
2715  // pointer to TSQLRow(kTRUE) if the cursor is on a valid row;
2716  // null(kFALSE) if there are norows in the result set
2717  //
2718  // Throws:
2719  // TSQLException - if a database access error occurs or
2720  // the result set type is kTYPE_FORWARD_ONLY
2721 
2722  Bool_t return_value = kFALSE;
2723 
2724  if(!fImp) { Destroyed(); return 0; }
2726 
2727  try {
2728  return_value = rs->last();
2729 
2730  } catch(odbc::SQLException& e) {
2733  e.getErrorCode()) );
2734  return_value = 0;
2735  }
2736  return return_value ? fRow->Set(this) : 0;
2737 }
2738 
2739 //___________________________________________________________________
2740 void ODBCResultSet::Close(Option_t * /* option */)
2741 {
2742  // Releases this TSQLResultSet object's database and resources
2743  // immediately instead of waiting for this to happen when it is
2744  // automatically closed.
2745  //
2746  // Note: A TSQLResultSet is automatically closed by the
2747  // statement that generated it when that statement
2748  // is closed, re-executed, or is used to retrieve the next
2749  // result from a sequence of multiple results. A TSQLResultSet
2750  // is also automatically closed when it is garbage collected.
2751  //
2752  // Throws:
2753  // TSQLException - if a database access error occurs
2754 
2755  if(!fImp) { Destroyed(); return; }
2756 
2757  try {
2758  if(fMetaData) delete ((ODBCResultSetMetaData*)fMetaData);
2759  if(fRow) delete fRow;
2760 
2761  if(fImp) {
2763  delete imp;
2764  }
2765  } catch(odbc::SQLException& e) {
2768  e.getErrorCode()) );
2769  }
2770 
2771  fMetaData = 0;
2772  fRow = 0;
2773  fImp = 0;
2774  Destroyed();
2775 }