Qt 4.8
Public Functions | Public Variables | List of all members
QOCIResultPrivate Struct Reference

Public Functions

int bindValue (OCIStmt *sql, OCIBind **hbnd, OCIError *err, int pos, const QVariant &val, dvoid *indPtr, ub2 *tmpSize, QList< QByteArray > &tmpStorage)
 
int bindValues (QVector< QVariant > &values, IndicatorArray &indicators, SizeArray &tmpSizes, QList< QByteArray > &tmpStorage)
 
bool isBinaryValue (int i) const
 
bool isOutValue (int i) const
 
void outValues (QVector< QVariant > &values, IndicatorArray &indicators, QList< QByteArray > &tmpStorage)
 
 QOCIResultPrivate (QOCIResult *result, const QOCIDriverPrivate *driver)
 
void setCharset (dvoid *handle, ub4 type) const
 
void setStatementAttributes ()
 
 ~QOCIResultPrivate ()
 

Public Variables

QOCIColscols
 
OCIEnvenv
 
OCIError * err
 
int prefetchMem
 
int prefetchRows
 
QOCIResultq
 
int serverVersion
 
OCIStmt * sql
 
OCISvcCtx *& svc
 
bool transaction
 

Detailed Description

Definition at line 164 of file qsql_oci.cpp.

Constructors and Destructors

◆ QOCIResultPrivate()

QOCIResultPrivate::QOCIResultPrivate ( QOCIResult result,
const QOCIDriverPrivate driver 
)

Definition at line 1777 of file qsql_oci.cpp.

1778  : cols(0), q(result), env(driver->env), err(0), svc(const_cast<OCISvcCtx*&>(driver->svc)),
1779  sql(0), transaction(driver->transaction), serverVersion(driver->serverVersion),
1781 {
1782  int r = OCIHandleAlloc(env,
1783  reinterpret_cast<void **>(&err),
1784  OCI_HTYPE_ERROR,
1785  0,
1786  0);
1787  if (r != 0)
1788  qWarning("QOCIResult: unable to alloc error handle");
1789 }
OCISvcCtx * svc
Definition: qsql_oci.cpp:470
QOCICols * cols
Definition: qsql_oci.cpp:169
QOCIResult * q
Definition: qsql_oci.cpp:170
OCISvcCtx *& svc
Definition: qsql_oci.cpp:173
Q_CORE_EXPORT void qWarning(const char *,...)
OCIError * err
Definition: qsql_oci.cpp:172

◆ ~QOCIResultPrivate()

QOCIResultPrivate::~QOCIResultPrivate ( )

Definition at line 1791 of file qsql_oci.cpp.

1792 {
1793  delete cols;
1794 
1795  int r = OCIHandleFree(err, OCI_HTYPE_ERROR);
1796  if (r != 0)
1797  qWarning("~QOCIResult: unable to free statement handle");
1798 }
QOCICols * cols
Definition: qsql_oci.cpp:169
Q_CORE_EXPORT void qWarning(const char *,...)
OCIError * err
Definition: qsql_oci.cpp:172

Functions

◆ bindValue()

int QOCIResultPrivate::bindValue ( OCIStmt *  sql,
OCIBind **  hbnd,
OCIError *  err,
int  pos,
const QVariant val,
dvoid *  indPtr,
ub2 *  tmpSize,
QList< QByteArray > &  tmpStorage 
)

Definition at line 257 of file qsql_oci.cpp.

Referenced by QOCICols::execBatch().

259 {
260  int r = OCI_SUCCESS;
261  void *data = const_cast<void *>(val.constData());
262 
263  switch (val.type()) {
264  case QVariant::ByteArray:
265  r = OCIBindByPos(sql, hbnd, err,
266  pos + 1,
267  isOutValue(pos)
268  ? const_cast<char *>(reinterpret_cast<QByteArray *>(data)->constData())
269  : reinterpret_cast<QByteArray *>(data)->data(),
270  reinterpret_cast<QByteArray *>(data)->size(),
271  SQLT_BIN, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
272  break;
273  case QVariant::Time:
274  case QVariant::Date:
275  case QVariant::DateTime: {
276  QByteArray ba = qMakeOraDate(val.toDateTime());
277  r = OCIBindByPos(sql, hbnd, err,
278  pos + 1,
279  ba.data(),
280  ba.size(),
281  SQLT_DAT, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
282  tmpStorage.append(ba);
283  break; }
284  case QVariant::Int:
285  r = OCIBindByPos(sql, hbnd, err,
286  pos + 1,
287  // if it's an out value, the data is already detached
288  // so the const cast is safe.
289  const_cast<void *>(data),
290  sizeof(int),
291  SQLT_INT, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
292  break;
293  case QVariant::UInt:
294  r = OCIBindByPos(sql, hbnd, err,
295  pos + 1,
296  // if it's an out value, the data is already detached
297  // so the const cast is safe.
298  const_cast<void *>(data),
299  sizeof(uint),
300  SQLT_UIN, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
301  break;
302  case QVariant::LongLong:
303  {
305  r = OCIBindByPos(sql, hbnd, err,
306  pos + 1,
307  ba.data(),
308  ba.size(),
309  SQLT_VNU, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
310  tmpStorage.append(ba);
311  break;
312  }
313  case QVariant::ULongLong:
314  {
316  r = OCIBindByPos(sql, hbnd, err,
317  pos + 1,
318  ba.data(),
319  ba.size(),
320  SQLT_VNU, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
321  tmpStorage.append(ba);
322  break;
323  }
324  case QVariant::Double:
325  r = OCIBindByPos(sql, hbnd, err,
326  pos + 1,
327  // if it's an out value, the data is already detached
328  // so the const cast is safe.
329  const_cast<void *>(data),
330  sizeof(double),
331  SQLT_FLT, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
332  break;
333  case QVariant::UserType:
334  if (val.canConvert<QOCIRowIdPointer>() && !isOutValue(pos)) {
335  // use a const pointer to prevent a detach
337  r = OCIBindByPos(sql, hbnd, err,
338  pos + 1,
339  // it's an IN value, so const_cast is ok
340  const_cast<OCIRowid **>(&rptr->id),
341  -1,
342  SQLT_RDD, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
343  } else {
344  qWarning("Unknown bind variable");
345  r = OCI_ERROR;
346  }
347  break;
348  case QVariant::String: {
349  const QString s = val.toString();
350  if (isBinaryValue(pos)) {
351  r = OCIBindByPos(sql, hbnd, err,
352  pos + 1,
353  const_cast<ushort *>(s.utf16()),
354  s.length() * sizeof(QChar),
355  SQLT_LNG, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
356  break;
357  } else if (!isOutValue(pos)) {
358  // don't detach the string
359  r = OCIBindByPos(sql, hbnd, err,
360  pos + 1,
361  // safe since oracle doesn't touch OUT values
362  const_cast<ushort *>(s.utf16()),
363  (s.length() + 1) * sizeof(QChar),
364  SQLT_STR, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
365  if (r == OCI_SUCCESS)
366  setCharset(*hbnd, OCI_HTYPE_BIND);
367  break;
368  }
369  } // fall through for OUT values
370  default: {
371  const QString s = val.toString();
372  // create a deep-copy
373  QByteArray ba(reinterpret_cast<const char *>(s.utf16()), (s.length() + 1) * sizeof(QChar));
374  if (isOutValue(pos)) {
375  ba.reserve((s.capacity() + 1) * sizeof(QChar));
376  *tmpSize = ba.size();
377  r = OCIBindByPos(sql, hbnd, err,
378  pos + 1,
379  ba.data(),
380  ba.capacity(),
381  SQLT_STR, indPtr, tmpSize, 0, 0, 0, OCI_DEFAULT);
382  } else {
383  r = OCIBindByPos(sql, hbnd, err,
384  pos + 1,
385  ba.data(),
386  ba.size(),
387  SQLT_STR, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
388  }
389  if (r == OCI_SUCCESS)
390  setCharset(*hbnd, OCI_HTYPE_BIND);
391  tmpStorage.append(ba);
392  break;
393  } // default case
394  } // switch
395  if (r != OCI_SUCCESS)
396  qOraWarning("QOCIResultPrivate::bindValue:", err);
397  return r;
398 }
bool isOutValue(int i) const
Definition: qsql_oci.cpp:186
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static QByteArray qMakeOraDate(const QDateTime &dt)
Convert QDateTime to the internal Oracle DATE format NB! It does not handle BCE dates.
Definition: qsql_oci.cpp:702
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
Definition: qvariant.cpp:2270
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
qulonglong toULongLong(bool *ok=0) const
Returns the variant as as an unsigned long long int if the variant has type() ULongLong ...
Definition: qvariant.cpp:2675
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
unsigned int uint
Definition: qglobal.h:996
bool isBinaryValue(int i) const
Definition: qsql_oci.cpp:188
OCIError * err
Definition: qsql_oci.cpp:172
int capacity() const
Returns the maximum number of characters that can be stored in the string without forcing a reallocat...
Definition: qstring.h:727
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
const void * constData() const
Definition: qvariant.cpp:3065
static QByteArray qMakeOCINumber(const qlonglong &ll, OCIError *err)
Convert qlonglong to the internal Oracle OCINumber format.
Definition: qsql_oci.cpp:725
T qvariant_cast(const QVariant &)
Definition: qvariant.h:571
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
int capacity() const
Returns the maximum number of bytes that can be stored in the byte array without forcing a reallocati...
Definition: qbytearray.h:446
void setCharset(dvoid *handle, ub4 type) const
Definition: qsql_oci.cpp:191
void reserve(int size)
Attempts to allocate memory for at least size bytes.
Definition: qbytearray.h:449
static void qOraWarning(const char *msg, OCIError *err)
Definition: qsql_oci.cpp:531
The QSharedDataPointer class represents a pointer to an implicitly shared object. ...
Definition: qshareddata.h:54
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ bindValues()

int QOCIResultPrivate::bindValues ( QVector< QVariant > &  values,
IndicatorArray indicators,
SizeArray tmpSizes,
QList< QByteArray > &  tmpStorage 
)

Definition at line 400 of file qsql_oci.cpp.

Referenced by QOCIResult::exec().

402 {
403  int r = OCI_SUCCESS;
404  for (int i = 0; i < values.count(); ++i) {
405  if (isOutValue(i))
406  values[i].detach();
407  const QVariant &val = values.at(i);
408 
409  OCIBind * hbnd = 0; // Oracle handles these automatically
410  sb2 *indPtr = &indicators[i];
411  *indPtr = val.isNull() ? -1 : 0;
412 
413  bindValue(sql, &hbnd, err, i, val, indPtr, &tmpSizes[i], tmpStorage);
414  }
415  return r;
416 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool isOutValue(int i) const
Definition: qsql_oci.cpp:186
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
int bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, int pos, const QVariant &val, dvoid *indPtr, ub2 *tmpSize, QList< QByteArray > &tmpStorage)
Definition: qsql_oci.cpp:257
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
OCIError * err
Definition: qsql_oci.cpp:172

◆ isBinaryValue()

bool QOCIResultPrivate::isBinaryValue ( int  i) const
inline

Definition at line 188 of file qsql_oci.cpp.

189  { return q->bindValueType(i) & QSql::Binary; }
QOCIResult * q
Definition: qsql_oci.cpp:170
QSql::ParamType bindValueType(const QString &placeholder) const
Returns the parameter type for the value bound with the given placeholder name.
Definition: qsqlresult.cpp:838

◆ isOutValue()

bool QOCIResultPrivate::isOutValue ( int  i) const
inline

Definition at line 186 of file qsql_oci.cpp.

Referenced by QOCICols::execBatch().

187  { return q->bindValueType(i) & QSql::Out; }
QOCIResult * q
Definition: qsql_oci.cpp:170
QSql::ParamType bindValueType(const QString &placeholder) const
Returns the parameter type for the value bound with the given placeholder name.
Definition: qsqlresult.cpp:838
Definition: qsql.h:68

◆ outValues()

void QOCIResultPrivate::outValues ( QVector< QVariant > &  values,
IndicatorArray indicators,
QList< QByteArray > &  tmpStorage 
)

Definition at line 446 of file qsql_oci.cpp.

Referenced by QOCIResult::exec().

448 {
449  for (int i = 0; i < values.count(); ++i) {
450 
451  if (!isOutValue(i))
452  continue;
453 
454  qOraOutValue(values[i], tmpStorage, err);
455 
456  QVariant::Type typ = values.at(i).type();
457  if (indicators[i] == -1) // NULL
458  values[i] = QVariant(typ);
459  else
460  values[i] = QVariant(typ, values.at(i).constData());
461  }
462 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
bool isOutValue(int i) const
Definition: qsql_oci.cpp:186
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
static void qOraOutValue(QVariant &value, QList< QByteArray > &storage, OCIError *err)
Definition: qsql_oci.cpp:419
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
const T & at(int i) const
Returns the item at index position i in the vector.
Definition: qvector.h:350
OCIError * err
Definition: qsql_oci.cpp:172
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
const void * constData() const
Definition: qvariant.cpp:3065

◆ setCharset()

void QOCIResultPrivate::setCharset ( dvoid *  handle,
ub4  type 
) const
inline

Definition at line 191 of file qsql_oci.cpp.

Referenced by QOCICols::QOCICols().

192  {
193  int r = 0;
194  Q_ASSERT(handle);
195 
196 #ifdef OCI_ATTR_CHARSET_FORM
197  r = OCIAttrSet(handle,
198  type,
199  // this const cast is safe since OCI doesn't touch
200  // the charset.
201  const_cast<void *>(static_cast<const void *>(&qOraCharsetForm)),
202  0,
203  OCI_ATTR_CHARSET_FORM,
204  //Strange Oracle bug: some Oracle servers crash the server process with non-zero error handle (mostly for 10g).
205  //So ignore the error message here.
206  0);
207  #ifdef QOCI_DEBUG
208  if (r != 0)
209  qWarning("QOCIResultPrivate::setCharset: Couldn't set OCI_ATTR_CHARSET_FORM.");
210  #endif
211 #endif
212 
213  r = OCIAttrSet(handle,
214  type,
215  // this const cast is safe since OCI doesn't touch
216  // the charset.
217  const_cast<void *>(static_cast<const void *>(&qOraCharset)),
218  0,
219  OCI_ATTR_CHARSET_ID,
220  err);
221  if (r != 0)
222  qOraWarning("QOCIResultPrivate::setCharsetI Couldn't set OCI_ATTR_CHARSET_ID: ", err);
223 
224  }
int type
Definition: qmetatype.cpp:239
static const ub2 qOraCharset
Definition: qsql_oci.cpp:107
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
Q_CORE_EXPORT void qWarning(const char *,...)
OCIError * err
Definition: qsql_oci.cpp:172
static void qOraWarning(const char *msg, OCIError *err)
Definition: qsql_oci.cpp:531

◆ setStatementAttributes()

void QOCIResultPrivate::setStatementAttributes ( )

Definition at line 227 of file qsql_oci.cpp.

Referenced by QOCIResult::prepare().

228 {
229  Q_ASSERT(sql);
230 
231  int r = 0;
232 
233  if (prefetchRows >= 0) {
234  r = OCIAttrSet(sql,
235  OCI_HTYPE_STMT,
236  &prefetchRows,
237  0,
238  OCI_ATTR_PREFETCH_ROWS,
239  err);
240  if (r != 0)
241  qOraWarning("QOCIResultPrivate::setStatementAttributes:"
242  " Couldn't set OCI_ATTR_PREFETCH_ROWS: ", err);
243  }
244  if (prefetchMem >= 0) {
245  r = OCIAttrSet(sql,
246  OCI_HTYPE_STMT,
247  &prefetchMem,
248  0,
249  OCI_ATTR_PREFETCH_MEMORY,
250  err);
251  if (r != 0)
252  qOraWarning("QOCIResultPrivate::setStatementAttributes:"
253  " Couldn't set OCI_ATTR_PREFETCH_MEMORY: ", err);
254  }
255 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
OCIError * err
Definition: qsql_oci.cpp:172
static void qOraWarning(const char *msg, OCIError *err)
Definition: qsql_oci.cpp:531

Properties

◆ cols

QOCICols* QOCIResultPrivate::cols

◆ env

OCIEnv* QOCIResultPrivate::env

◆ err

OCIError* QOCIResultPrivate::err

◆ prefetchMem

int QOCIResultPrivate::prefetchMem

Definition at line 177 of file qsql_oci.cpp.

◆ prefetchRows

int QOCIResultPrivate::prefetchRows

Definition at line 177 of file qsql_oci.cpp.

◆ q

QOCIResult* QOCIResultPrivate::q

Definition at line 170 of file qsql_oci.cpp.

Referenced by QOCICols::execBatch(), QOCICols::getValues(), and QOCICols::qMakeOraField().

◆ serverVersion

int QOCIResultPrivate::serverVersion

Definition at line 176 of file qsql_oci.cpp.

◆ sql

OCIStmt* QOCIResultPrivate::sql

◆ svc

OCISvcCtx*& QOCIResultPrivate::svc

Definition at line 173 of file qsql_oci.cpp.

Referenced by QOCIResult::exec(), QOCICols::execBatch(), and qReadLob().

◆ transaction

bool QOCIResultPrivate::transaction

Definition at line 175 of file qsql_oci.cpp.

Referenced by QOCIResult::exec(), and QOCICols::execBatch().


The documentation for this struct was generated from the following file: