ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TODBCResult.cxx
Go to the documentation of this file.
1 // @(#)root/odbc:$Id$
2 // Author: Sergey Linev 6/02/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #include "TODBCResult.h"
13 #include "TODBCRow.h"
14 
15 
17 
18 ////////////////////////////////////////////////////////////////////////////////
19 /// Constructor
20 
21 TODBCResult::TODBCResult(SQLHSTMT stmt)
22 {
23  fHstmt = stmt;
24  fFieldCount = 0;
25 
26  SQLSMALLINT columnCount;
27 
28  SQLRETURN retcode = SQLNumResultCols(fHstmt, &columnCount);
29 
30  if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
31  fFieldCount = columnCount;
32 }
33 
34 ////////////////////////////////////////////////////////////////////////////////
35 /// Cleanup ODBC query result.
36 
38 {
39  Close();
40 }
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 /// Close (cleanup) ODBC result object. Deletes statement
44 
46 {
47  SQLFreeHandle(SQL_HANDLE_STMT, fHstmt);
48  fHstmt = 0;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Get name of specified field.
53 
54 const char *TODBCResult::GetFieldName(Int_t field)
55 {
56  SQLCHAR columnName[1024];
57 
58  SQLSMALLINT nameLength;
59  SQLSMALLINT dataType;
60  SQLULEN columnSize;
61  SQLSMALLINT decimalDigits;
62  SQLSMALLINT nullable;
63 
64  SQLRETURN retcode =
65  SQLDescribeCol(fHstmt, field+1, columnName, 1024,
66  &nameLength, &dataType,
67  &columnSize, &decimalDigits, &nullable);
68 
69  if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) return 0;
70 
71  fNameBuffer = (const char*) columnName;
72 
73  return fNameBuffer;
74 }
75 
76 ////////////////////////////////////////////////////////////////////////////////
77 /// Get next query result row. The returned object must be
78 /// deleted by the user.
79 
81 {
82  if (fHstmt==0) return 0;
83 
84  SQLRETURN retcode = SQLFetch(fHstmt);
85 
86  if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
87  return new TODBCRow(fHstmt, fFieldCount);
88 
89  return 0;
90 }
SQLHSTMT fHstmt
Definition: TODBCResult.h:37
const char Option_t
Definition: RtypesCore.h:62
int Int_t
Definition: RtypesCore.h:41
TString fNameBuffer
Definition: TODBCResult.h:39
TSQLRow * Next()
Get next query result row.
Definition: TODBCResult.cxx:80
void Close(Option_t *opt="")
Close (cleanup) ODBC result object. Deletes statement.
Definition: TODBCResult.cxx:45
ClassImp(TODBCResult) TODBCResult
Constructor.
Definition: TODBCResult.cxx:16
const char * GetFieldName(Int_t field)
Get name of specified field.
Definition: TODBCResult.cxx:54
virtual ~TODBCResult()
Cleanup ODBC query result.
Definition: TODBCResult.cxx:37
Int_t fFieldCount
Definition: TODBCResult.h:38