Skip to content
Snippets Groups Projects
Commit 923af989 authored by Rene Brun's avatar Rene Brun
Browse files

From Sergey Linev:

1. New virtual method TSQLStatement::SetMaxFieldSize(). It implemented for now only for Oracle and
   specifies maximum size in bytes, which should be used for field in read/write operation.

2. Improved implementation of TOracleStatement::GetBinary method. Now not only BLOB, but also
   CLOB, LONG, BFILE, CFILE Oracle datatypes are supported for reading. Fow now BFILE and CFILE
   not supported for writing.


git-svn-id: http://root.cern.ch/svn/root/trunk@19293 27541ba8-7e3a-0410-8455-c3a389f83636
parent 91cff94e
Branches
Tags
No related merge requests found
// @(#)root/net:$Name: $:$Id: TSQLStatement.h,v 1.5 2006/06/25 18:43:24 brun Exp $ // @(#)root/net:$Name: $:$Id: TSQLStatement.h,v 1.6 2006/09/05 13:37:08 brun Exp $
// Author: Sergey Linev 6/02/2006 // Author: Sergey Linev 6/02/2006
/************************************************************************* /*************************************************************************
...@@ -68,6 +68,7 @@ public: ...@@ -68,6 +68,7 @@ public:
virtual Bool_t StoreResult() = 0; virtual Bool_t StoreResult() = 0;
virtual Int_t GetNumFields() = 0; virtual Int_t GetNumFields() = 0;
virtual const char *GetFieldName(Int_t) = 0; virtual const char *GetFieldName(Int_t) = 0;
virtual Bool_t SetMaxFieldSize(Int_t, Long_t) { return kFALSE; }
virtual Bool_t NextResultRow() = 0; virtual Bool_t NextResultRow() = 0;
virtual Bool_t IsNull(Int_t) { return kTRUE; } virtual Bool_t IsNull(Int_t) { return kTRUE; }
......
// @(#)root/oracle:$Name: $:$Id: TOracleStatement.h,v 1.4 2006/06/25 18:43:24 brun Exp $ // @(#)root/oracle:$Name: $:$Id: TOracleStatement.h,v 1.5 2006/09/05 13:37:08 brun Exp $
// Author: Sergey Linev 6/02/2006 // Author: Sergey Linev 6/02/2006
/************************************************************************* /*************************************************************************
...@@ -87,6 +87,7 @@ public: ...@@ -87,6 +87,7 @@ public:
virtual Bool_t StoreResult(); virtual Bool_t StoreResult();
virtual Int_t GetNumFields(); virtual Int_t GetNumFields();
virtual const char *GetFieldName(Int_t nfield); virtual const char *GetFieldName(Int_t nfield);
virtual Bool_t SetMaxFieldSize(Int_t nfield, Long_t maxsize);
virtual Bool_t NextResultRow(); virtual Bool_t NextResultRow();
virtual Bool_t IsNull(Int_t); virtual Bool_t IsNull(Int_t);
......
// @(#)root/oracle:$Name: $:$Id: TOracleStatement.cxx,v 1.5 2006/06/25 18:43:24 brun Exp $ // @(#)root/oracle:$Name: $:$Id: TOracleStatement.cxx,v 1.6 2006/09/05 13:37:08 brun Exp $
// Author: Sergey Linev 6/02/2006 // Author: Sergey Linev 6/02/2006
...@@ -508,6 +508,28 @@ Bool_t TOracleStatement::StoreResult() ...@@ -508,6 +508,28 @@ Bool_t TOracleStatement::StoreResult()
return kFALSE; return kFALSE;
} }
//______________________________________________________________________________
Bool_t TOracleStatement::SetMaxFieldSize(Int_t nfield, Long_t maxsize)
{
// Defines maximum size for field which must be used for read or write operation
// Some Oracle types as LONG (long binary continer) requires this call
// before any data can be read from database. Call it once before first call to NextResultRow()
CheckStatement("SetMaxFieldSize", kFALSE);
try {
if (fResult)
fResult->setMaxColumnSize(nfield+1, maxsize);
else
fStmt->setMaxParamSize(nfield+1, maxsize);
return kTRUE;
} catch (SQLException &oraex) {
SetError(oraex.getErrorCode(), oraex.getMessage().c_str(), "SetMaxFieldSize");
}
return kFALSE;
}
//______________________________________________________________________________ //______________________________________________________________________________
Int_t TOracleStatement::GetNumFields() Int_t TOracleStatement::GetNumFields()
{ {
...@@ -568,6 +590,10 @@ Bool_t TOracleStatement::NextResultRow() ...@@ -568,6 +590,10 @@ Bool_t TOracleStatement::NextResultRow()
return kTRUE; return kTRUE;
} catch (SQLException &oraex) { } catch (SQLException &oraex) {
SetError(oraex.getErrorCode(), oraex.getMessage().c_str(), "NextResultRow"); SetError(oraex.getErrorCode(), oraex.getMessage().c_str(), "NextResultRow");
if (oraex.getErrorCode()==32108)
Info("NextResultRow", "Use TSQLStatement::SetMaxFieldSize() to solve a problem");
} }
return kFALSE; return kFALSE;
...@@ -775,6 +801,9 @@ const char* TOracleStatement::GetString(Int_t npar) ...@@ -775,6 +801,9 @@ const char* TOracleStatement::GetString(Int_t npar)
Bool_t TOracleStatement::GetBinary(Int_t npar, void* &mem, Long_t& size) Bool_t TOracleStatement::GetBinary(Int_t npar, void* &mem, Long_t& size)
{ {
// Return field value as binary array // Return field value as binary array
// Supports LONG, BLOB, CLOB, BFILE, CFILE types of columns
// Reads complete content of the column, therefore not suitable for
// big structures
mem = 0; mem = 0;
size = 0; size = 0;
...@@ -789,31 +818,90 @@ Bool_t TOracleStatement::GetBinary(Int_t npar, void* &mem, Long_t& size) ...@@ -789,31 +818,90 @@ Bool_t TOracleStatement::GetBinary(Int_t npar, void* &mem, Long_t& size)
try { try {
if (fResult->isNull(npar+1)) return kTRUE; if (fResult->isNull(npar+1)) return kTRUE;
int datatype = (*fFieldInfo)[npar].getInt(MetaData::ATTR_DATA_TYPE);
Blob parblob = fResult->getBlob(npar+1); switch (datatype) {
case SQLT_LNG: {
parblob.open(OCCI_LOB_READONLY); Bytes parbytes = fResult->getBytes(npar+1);
size = parblob.length(); size = parbytes.length();
fBuffer[npar].strbufsize = size;
if (size>0) {
mem = malloc(size);
fBuffer[npar].strbuf = (char*) mem;
Stream* parstream = parblob.getStream(); fBuffer[npar].strbufsize = size;
if (size>0) {
mem = malloc(size);
fBuffer[npar].strbuf = (char*) mem;
parbytes.getBytes((unsigned char*) mem, size);
}
break;
}
case SQLT_BLOB: {
Blob parblob = fResult->getBlob(npar+1);
size = parblob.length();
fBuffer[npar].strbufsize = size;
if (size>0) {
mem = malloc(size);
fBuffer[npar].strbuf = (char*) mem;
parblob.read(size, (unsigned char*) mem, size);
}
break;
}
char* buf = (char*) mem; case SQLT_CLOB: {
Clob parclob = fResult->getClob(npar+1);
size = parclob.length();
fBuffer[npar].strbufsize = size;
if (size>0) {
mem = malloc(size);
fBuffer[npar].strbuf = (char*) mem;
parclob.read(size, (unsigned char*) mem, size);
}
break;
}
case SQLT_BFILEE:
case SQLT_CFILEE: {
Bfile parbfile = fResult->getBfile(npar+1);
size = parbfile.length();
fBuffer[npar].strbufsize = size;
if (size>0) {
mem = malloc(size);
fBuffer[npar].strbuf = (char*) mem;
parbfile.read(size, (unsigned char*) mem, size);
}
break;
}
/*int len = */ parstream->readBuffer(buf, size); default:
Error("GetBinary", "Oracle data type %d not supported", datatype);
parblob.closeStream(parstream); SetError(-1, "Unsupported type for binary convertion", "GetBinary");
return false;
} }
parblob.close();
return kTRUE; return kTRUE;
} catch (SQLException &oraex) { } catch (SQLException &oraex) {
...@@ -823,6 +911,7 @@ Bool_t TOracleStatement::GetBinary(Int_t npar, void* &mem, Long_t& size) ...@@ -823,6 +911,7 @@ Bool_t TOracleStatement::GetBinary(Int_t npar, void* &mem, Long_t& size)
return kFALSE; return kFALSE;
} }
//______________________________________________________________________________ //______________________________________________________________________________
Bool_t TOracleStatement::GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day) Bool_t TOracleStatement::GetDate(Int_t npar, Int_t& year, Int_t& month, Int_t& day)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment