#include "TODBCRow.h"
#include <sqlext.h>
ClassImp(TODBCRow)
TODBCRow::TODBCRow(SQLHSTMT stmt, Int_t fieldcount)
{
fHstmt = stmt;
fFieldCount = fieldcount;
fBuffer = 0;
fLengths = 0;
if (fFieldCount>0) {
fBuffer = new char*[fFieldCount];
fLengths = new ULong_t[fFieldCount];
for (Int_t n = 0; n < fFieldCount; n++) {
fBuffer[n] = 0;
fLengths[n] = 0;
CopyFieldValue(n);
}
}
}
TODBCRow::~TODBCRow()
{
Close();
}
void TODBCRow::Close(Option_t *)
{
if (fBuffer!=0) {
for (Int_t n = 0; n < fFieldCount; n++)
delete[] fBuffer[n];
delete[] fBuffer;
fBuffer = 0;
}
if (fLengths!=0) {
delete[] fLengths;
fLengths = 0;
}
}
void TODBCRow::CopyFieldValue(Int_t field)
{
#define buffer_len 128
fBuffer[field] = new char[buffer_len];
SQLLEN ressize;
SQLRETURN retcode = SQLGetData(fHstmt, field+1, SQL_C_CHAR, fBuffer[field], buffer_len, &ressize);
if (ressize==SQL_NULL_DATA) {
delete[] fBuffer[field];
fBuffer[field] = 0;
return;
}
fLengths[field] = ressize;
if (retcode==SQL_SUCCESS_WITH_INFO) {
SQLINTEGER code;
SQLCHAR state[ 7 ];
SQLGetDiagRec(SQL_HANDLE_STMT, fHstmt, 1, state, &code, 0, 0, 0);
if (strcmp((char*)state,"01004")==0) {
char* newbuf = new char[ressize+10];
strncpy(newbuf, fBuffer[field], buffer_len-1);
delete fBuffer[field];
fBuffer[field] = newbuf;
newbuf+=(buffer_len-1);
retcode = SQLGetData(fHstmt, field+1, SQL_C_CHAR, newbuf, ressize+10-buffer_len, &ressize);
}
}
}
ULong_t TODBCRow::GetFieldLength(Int_t field)
{
if ((field<0) || (field>=fFieldCount)) return 0;
return fLengths[field];
}
const char *TODBCRow::GetField(Int_t field)
{
if ((field<0) || (field>=fFieldCount)) return 0;
return fBuffer[field];
}
ROOT page - Class index - Class Hierarchy - Top of the page
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.