Qt 4.8
Public Functions | Public Variables | List of all members
QIBaseResultPrivate Class Reference

Public Functions

void cleanup ()
 
bool commit ()
 
QVariant fetchArray (int pos, ISC_QUAD *arr)
 
QVariant fetchBlob (ISC_QUAD *bId)
 
bool isError (const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
 
bool isSelect ()
 
 QIBaseResultPrivate (QIBaseResult *d, const QIBaseDriver *ddb)
 
bool transaction ()
 
bool writeArray (int i, const QList< QVariant > &list)
 
bool writeBlob (int i, const QByteArray &ba)
 
 ~QIBaseResultPrivate ()
 

Public Variables

const QIBaseDriverdb
 
isc_db_handle ibase
 
XSQLDA * inda
 
bool localTransaction
 
QIBaseResultq
 
int queryType
 
XSQLDA * sqlda
 
ISC_STATUS status [20]
 
isc_stmt_handle stmt
 
QTextCodectc
 
isc_tr_handle trans
 

Detailed Description

Definition at line 349 of file qsql_ibase.cpp.

Constructors and Destructors

◆ QIBaseResultPrivate()

QIBaseResultPrivate::QIBaseResultPrivate ( QIBaseResult d,
const QIBaseDriver ddb 
)

Definition at line 393 of file qsql_ibase.cpp.

393  :
394  q(d), db(ddb), trans(0), stmt(0), ibase(ddb->d->ibase), sqlda(0), inda(0), queryType(-1), tc(ddb->d->tc)
395 {
396  localTransaction = (ddb->d->ibase == 0);
397 }
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
QIBaseDriverPrivate * d
Definition: qsql_ibase.h:125
QIBaseResult * q
Definition: qsql_ibase.cpp:378
const QIBaseDriver * db
Definition: qsql_ibase.cpp:379
isc_db_handle ibase
Definition: qsql_ibase.cpp:385
isc_db_handle ibase
Definition: qsql_ibase.cpp:330
isc_stmt_handle stmt
Definition: qsql_ibase.cpp:384

◆ ~QIBaseResultPrivate()

QIBaseResultPrivate::~QIBaseResultPrivate ( )
inline

Definition at line 353 of file qsql_ibase.cpp.

353 { cleanup(); }

Functions

◆ cleanup()

void QIBaseResultPrivate::cleanup ( )

Definition at line 399 of file qsql_ibase.cpp.

Referenced by QIBaseResult::prepare().

400 {
401  commit();
402  if (!localTransaction)
403  trans = 0;
404 
405  if (stmt) {
406  isc_dsql_free_statement(status, &stmt, DSQL_drop);
407  stmt = 0;
408  }
409 
410  delDA(sqlda);
411  delDA(inda);
412 
413  queryType = -1;
414  q->cleanup();
415 }
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
QIBaseResult * q
Definition: qsql_ibase.cpp:378
static void delDA(XSQLDA *&sqlda)
Definition: qsql_ibase.cpp:155
isc_stmt_handle stmt
Definition: qsql_ibase.cpp:384
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ commit()

bool QIBaseResultPrivate::commit ( )

Definition at line 854 of file qsql_ibase.cpp.

Referenced by cleanup(), and QIBaseResult::exec().

855 {
856  if (!trans)
857  return false;
858  // don't commit driver's transaction, the driver will do it for us
859  if (!localTransaction)
860  return true;
861 
862  isc_commit_transaction(status, &trans);
863  trans = 0;
864  return !isError(QT_TRANSLATE_NOOP("QIBaseResult", "Unable to commit transaction"),
866 }
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ fetchArray()

QVariant QIBaseResultPrivate::fetchArray ( int  pos,
ISC_QUAD *  arr 
)

Definition at line 571 of file qsql_ibase.cpp.

Referenced by QIBaseResult::gotoNext().

572 {
573  QList<QVariant> list;
574  ISC_ARRAY_DESC desc;
575 
576  if (!arr)
577  return list;
578 
579  QByteArray relname(sqlda->sqlvar[pos].relname, sqlda->sqlvar[pos].relname_length);
580  QByteArray sqlname(sqlda->sqlvar[pos].aliasname, sqlda->sqlvar[pos].aliasname_length);
581 
582  isc_array_lookup_bounds(status, &ibase, &trans, relname.data(), sqlname.data(), &desc);
583  if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not find array"),
585  return list;
586 
587 
588  int arraySize = 1, subArraySize;
589  short dimensions = desc.array_desc_dimensions;
590  QVarLengthArray<short> numElements(dimensions);
591 
592  for(int i = 0; i < dimensions; ++i) {
593  subArraySize = (desc.array_desc_bounds[i].array_bound_upper -
594  desc.array_desc_bounds[i].array_bound_lower + 1);
595  numElements[i] = subArraySize;
596  arraySize = subArraySize * arraySize;
597  }
598 
599  ISC_LONG bufLen;
600  QByteArray ba;
601  /* varying arrayelements are stored with 2 trailing null bytes
602  indicating the length of the string
603  */
604  if (desc.array_desc_dtype == blr_varying
605  || desc.array_desc_dtype == blr_varying2) {
606  desc.array_desc_length += 2;
607  bufLen = desc.array_desc_length * arraySize * sizeof(short);
608  } else {
609  bufLen = desc.array_desc_length * arraySize;
610  }
611 
612 
613  ba.resize(int(bufLen));
614  isc_array_get_slice(status, &ibase, &trans, arr, &desc, ba.data(), &bufLen);
615  if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not get array data"),
617  return list;
618 
619  readArrayBuffer(list, ba.data(), 0, numElements.data(), &desc, tc);
620 
621  return QVariant(list);
622 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
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
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
static char * readArrayBuffer(QList< QVariant > &list, char *buffer, short curDim, short *numElements, ISC_ARRAY_DESC *arrayDesc, QTextCodec *tc)
Definition: qsql_ibase.cpp:496
isc_db_handle ibase
Definition: qsql_ibase.cpp:385
void resize(int size)
Sets the size of the byte array to size bytes.
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ fetchBlob()

QVariant QIBaseResultPrivate::fetchBlob ( ISC_QUAD *  bId)

Definition at line 437 of file qsql_ibase.cpp.

Referenced by QIBaseResult::gotoNext().

438 {
439  isc_blob_handle handle = 0;
440 
441  isc_open_blob2(status, &ibase, &trans, &handle, bId, 0, 0);
442  if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Unable to open BLOB"),
444  return QVariant();
445 
446  unsigned short len = 0;
447  QByteArray ba;
448  int chunkSize = QIBaseChunkSize;
449  ba.resize(chunkSize);
450  int read = 0;
451  while (isc_get_segment(status, &handle, &len, chunkSize, ba.data() + read) == 0 || status[1] == isc_segment) {
452  read += len;
453  ba.resize(read + chunkSize);
454  }
455  ba.resize(read);
456 
457  bool isErr = (status[1] == isc_segstr_eof ? false :
458  isError(QT_TRANSLATE_NOOP("QIBaseResult",
459  "Unable to read BLOB"),
461 
462  isc_close_blob(status, &handle);
463 
464  if (isErr)
465  return QVariant();
466 
467  ba.resize(read);
468  return ba;
469 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
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
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
isc_db_handle ibase
Definition: qsql_ibase.cpp:385
void resize(int size)
Sets the size of the byte array to size bytes.
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ isError()

bool QIBaseResultPrivate::isError ( const char *  msg,
QSqlError::ErrorType  typ = QSqlError::UnknownError 
)
inline

Definition at line 356 of file qsql_ibase.cpp.

Referenced by commit(), QIBaseResult::exec(), fetchArray(), fetchBlob(), QIBaseResult::gotoNext(), isSelect(), QIBaseResult::numRowsAffected(), QIBaseResult::prepare(), transaction(), writeArray(), and writeBlob().

357  {
358  QString imsg;
359  ISC_LONG sqlcode;
360  if (!getIBaseError(imsg, status, sqlcode, tc))
361  return false;
362 
363  q->setLastError(QSqlError(QCoreApplication::translate("QIBaseResult", msg),
364  imsg, typ, int(sqlcode)));
365  return true;
366  }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
QIBaseResult * q
Definition: qsql_ibase.cpp:378
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
virtual void setLastError(const QSqlError &e)
This function is provided for derived classes to set the last error to error.
Definition: qsqlresult.cpp:417
static bool getIBaseError(QString &msg, ISC_STATUS *status, ISC_LONG &sqlcode, QTextCodec *tc)
Definition: qsql_ibase.cpp:73
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ isSelect()

bool QIBaseResultPrivate::isSelect ( )

Definition at line 820 of file qsql_ibase.cpp.

Referenced by QIBaseResult::prepare().

821 {
822  char acBuffer[9];
823  char qType = isc_info_sql_stmt_type;
824  isc_dsql_sql_info(status, &stmt, 1, &qType, sizeof(acBuffer), acBuffer);
825  if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not get query info"),
827  return false;
828  int iLength = isc_vax_integer(&acBuffer[1], 2);
829  queryType = isc_vax_integer(&acBuffer[3], iLength);
830  return (queryType == isc_info_sql_stmt_select || queryType == isc_info_sql_stmt_exec_procedure);
831 }
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
isc_stmt_handle stmt
Definition: qsql_ibase.cpp:384
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ transaction()

bool QIBaseResultPrivate::transaction ( )

Definition at line 833 of file qsql_ibase.cpp.

Referenced by QIBaseResult::exec(), and QIBaseResult::prepare().

834 {
835  if (trans)
836  return true;
837  if (db->d->trans) {
838  localTransaction = false;
839  trans = db->d->trans;
840  return true;
841  }
842  localTransaction = true;
843 
844  isc_start_transaction(status, &trans, 1, &ibase, 0, NULL);
845  if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not start transaction"),
847  return false;
848 
849  return true;
850 }
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
QIBaseDriverPrivate * d
Definition: qsql_ibase.h:125
isc_tr_handle trans
Definition: qsql_ibase.cpp:331
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
const QIBaseDriver * db
Definition: qsql_ibase.cpp:379
isc_db_handle ibase
Definition: qsql_ibase.cpp:385
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ writeArray()

bool QIBaseResultPrivate::writeArray ( int  i,
const QList< QVariant > &  list 
)

Definition at line 760 of file qsql_ibase.cpp.

Referenced by QIBaseResult::exec().

761 {
762  QString error;
763  ISC_QUAD *arrayId = (ISC_QUAD*) inda->sqlvar[column].sqldata;
764  ISC_ARRAY_DESC desc;
765 
766  QByteArray relname(inda->sqlvar[column].relname, inda->sqlvar[column].relname_length);
767  QByteArray sqlname(inda->sqlvar[column].aliasname, inda->sqlvar[column].aliasname_length);
768 
769  isc_array_lookup_bounds(status, &ibase, &trans, relname.data(), sqlname.data(), &desc);
770  if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not find array"),
772  return false;
773 
774  short arraySize = 1;
775  ISC_LONG bufLen;
776  QList<QVariant> subList = list;
777 
778  short dimensions = desc.array_desc_dimensions;
779  for(int i = 0; i < dimensions; ++i) {
780  arraySize *= (desc.array_desc_bounds[i].array_bound_upper -
781  desc.array_desc_bounds[i].array_bound_lower + 1);
782  }
783 
784  /* varying arrayelements are stored with 2 trailing null bytes
785  indicating the length of the string
786  */
787  if (desc.array_desc_dtype == blr_varying ||
788  desc.array_desc_dtype == blr_varying2)
789  desc.array_desc_length += 2;
790 
791  bufLen = desc.array_desc_length * arraySize;
792  QByteArray ba;
793  ba.resize(int(bufLen));
794 
795  if (list.size() > arraySize) {
796  error = QLatin1String("Array size missmatch: size of %1 is %2, size of provided list is %3");
797  error = error.arg(QLatin1String(sqlname)).arg(arraySize).arg(list.size());
799  return false;
800  }
801 
802  if (!createArrayBuffer(ba.data(), list,
803  qIBaseTypeName(desc.array_desc_dtype, inda->sqlvar[column].sqlscale < 0),
804  0, &desc, error, tc)) {
805  q->setLastError(QSqlError(error.arg(QLatin1String(sqlname)), QLatin1String(""),
807  return false;
808  }
809 
810  /* readjust the buffer size*/
811  if (desc.array_desc_dtype == blr_varying
812  || desc.array_desc_dtype == blr_varying2)
813  desc.array_desc_length -= 2;
814 
815  isc_array_put_slice(status, &ibase, &trans, arrayId, &desc, ba.data(), &bufLen);
816  return true;
817 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
QIBaseResult * q
Definition: qsql_ibase.cpp:378
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static char * createArrayBuffer(char *buffer, const QList< QVariant > &list, QVariant::Type type, short curDim, ISC_ARRAY_DESC *arrayDesc, QString &error, QTextCodec *tc)
Definition: qsql_ibase.cpp:675
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
isc_db_handle ibase
Definition: qsql_ibase.cpp:385
virtual void setLastError(const QSqlError &e)
This function is provided for derived classes to set the last error to error.
Definition: qsqlresult.cpp:417
static QVariant::Type qIBaseTypeName(int iType, bool hasScale)
Definition: qsql_ibase.cpp:167
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
void resize(int size)
Sets the size of the byte array to size bytes.
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ writeBlob()

bool QIBaseResultPrivate::writeBlob ( int  i,
const QByteArray ba 
)

Definition at line 417 of file qsql_ibase.cpp.

Referenced by QIBaseResult::exec().

418 {
419  isc_blob_handle handle = 0;
420  ISC_QUAD *bId = (ISC_QUAD*)inda->sqlvar[i].sqldata;
421  isc_create_blob2(status, &ibase, &trans, &handle, bId, 0, 0);
422  if (!isError(QT_TRANSLATE_NOOP("QIBaseResult", "Unable to create BLOB"),
424  int i = 0;
425  while (i < ba.size()) {
426  isc_put_segment(status, &handle, qMin(ba.size() - i, int(QIBaseChunkSize)),
427  const_cast<char*>(ba.data()) + i);
428  if (isError(QT_TRANSLATE_NOOP("QIBaseResult", "Unable to write BLOB")))
429  return false;
430  i += qMin(ba.size() - i, int(QIBaseChunkSize));
431  }
432  }
433  isc_close_blob(status, &handle);
434  return true;
435 }
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
Definition: qglobal.h:1215
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
isc_db_handle ibase
Definition: qsql_ibase.cpp:385
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

Properties

◆ db

const QIBaseDriver* QIBaseResultPrivate::db

Definition at line 379 of file qsql_ibase.cpp.

Referenced by QIBaseResult::record(), and transaction().

◆ ibase

isc_db_handle QIBaseResultPrivate::ibase

◆ inda

XSQLDA* QIBaseResultPrivate::inda

◆ localTransaction

bool QIBaseResultPrivate::localTransaction

Definition at line 383 of file qsql_ibase.cpp.

Referenced by cleanup(), commit(), QIBaseResultPrivate(), and transaction().

◆ q

QIBaseResult* QIBaseResultPrivate::q

Definition at line 378 of file qsql_ibase.cpp.

Referenced by cleanup(), and writeArray().

◆ queryType

int QIBaseResultPrivate::queryType

◆ sqlda

XSQLDA* QIBaseResultPrivate::sqlda

◆ status

ISC_STATUS QIBaseResultPrivate::status[20]

◆ stmt

isc_stmt_handle QIBaseResultPrivate::stmt

◆ tc

QTextCodec* QIBaseResultPrivate::tc

◆ trans

isc_tr_handle QIBaseResultPrivate::trans

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