Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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
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 = nullptr;
49}
50
51////////////////////////////////////////////////////////////////////////////////
52/// Get name of specified field.
53
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 nullptr;
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) return nullptr;
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 nullptr;
90}
const char Option_t
Definition RtypesCore.h:66
#define ClassImp(name)
Definition Rtypes.h:382
TSQLRow * Next() final
Get next query result row.
virtual ~TODBCResult()
Cleanup ODBC query result.
const char * GetFieldName(Int_t field) final
Get name of specified field.
TString fNameBuffer
Definition TODBCResult.h:35
Int_t fFieldCount
Definition TODBCResult.h:34
void Close(Option_t *opt="") final
Close (cleanup) ODBC result object. Deletes statement.
TODBCResult(SQLHSTMT stmt)
Constructor.
SQLHSTMT fHstmt
Definition TODBCResult.h:33