TODBCResult.cxx

Go to the documentation of this file.
00001 // @(#)root/odbc:$Id: TODBCResult.cxx 20882 2007-11-19 11:31:26Z rdm $
00002 // Author: Sergey Linev   6/02/2006
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2006, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #include "TODBCResult.h"
00013 #include "TODBCRow.h"
00014 
00015 
00016 ClassImp(TODBCResult)
00017 
00018 //______________________________________________________________________________
00019 TODBCResult::TODBCResult(SQLHSTMT stmt)
00020 {
00021    // Constructor
00022    
00023    fHstmt = stmt;
00024    fFieldCount = 0;
00025 
00026    SQLSMALLINT   columnCount;
00027 
00028    SQLRETURN retcode = SQLNumResultCols(fHstmt, &columnCount);
00029 
00030    if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
00031       fFieldCount = columnCount;
00032 }
00033 
00034 //______________________________________________________________________________
00035 TODBCResult::~TODBCResult()
00036 {
00037    // Cleanup ODBC query result.
00038 
00039    Close();
00040 }
00041 
00042 //______________________________________________________________________________
00043 void TODBCResult::Close(Option_t *)
00044 {
00045    // Close (cleanup) ODBC result object. Deletes statement
00046    
00047    SQLFreeHandle(SQL_HANDLE_STMT, fHstmt);
00048    fHstmt = 0;
00049 }
00050 
00051 //______________________________________________________________________________
00052 const char *TODBCResult::GetFieldName(Int_t field)
00053 {
00054    // Get name of specified field.
00055 
00056    SQLCHAR columnName[1024];
00057 
00058    SQLSMALLINT nameLength;
00059    SQLSMALLINT dataType;
00060    SQLULEN     columnSize;
00061    SQLSMALLINT decimalDigits;
00062    SQLSMALLINT nullable;
00063 
00064    SQLRETURN retcode =
00065       SQLDescribeCol(fHstmt, field+1, columnName, 1024,
00066                      &nameLength, &dataType,
00067                      &columnSize, &decimalDigits, &nullable);
00068 
00069    if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) return 0;
00070 
00071    fNameBuffer = (const char*) columnName;
00072 
00073    return fNameBuffer;
00074 }
00075 
00076 //______________________________________________________________________________
00077 TSQLRow *TODBCResult::Next()
00078 {
00079    // Get next query result row. The returned object must be
00080    // deleted by the user.
00081 
00082    if (fHstmt==0) return 0;
00083 
00084    SQLRETURN retcode = SQLFetch(fHstmt);
00085 
00086    if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
00087        return new TODBCRow(fHstmt, fFieldCount);
00088 
00089    return 0;
00090 }

Generated on Tue Jul 5 15:14:38 2011 for ROOT_528-00b_version by  doxygen 1.5.1