Qt 4.8
Public Functions | Protected Functions | Properties | Friends | List of all members
QIBaseResult Class Reference

#include <qsql_ibase.h>

Inheritance diagram for QIBaseResult:
QSqlCachedResult QSqlResult

Public Functions

bool exec ()
 Executes the query, returning true if successful; otherwise returns false. More...
 
QVariant handle () const
 Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVariant if there is no handle. More...
 
bool prepare (const QString &query)
 Prepares the given query for execution; the query will normally use placeholders so that it can be executed repeatedly. More...
 
 QIBaseResult (const QIBaseDriver *db)
 
virtual ~QIBaseResult ()
 
- Public Functions inherited from QSqlCachedResult
virtual ~QSqlCachedResult ()
 
- Public Functions inherited from QSqlResult
virtual ~QSqlResult ()
 Destroys the object and frees any allocated resources. More...
 

Protected Functions

bool gotoNext (QSqlCachedResult::ValueCache &row, int rowIdx)
 
int numRowsAffected ()
 Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or if the query is a SELECT statement. More...
 
QSqlRecord record () const
 Returns the current record if the query is active; otherwise returns an empty QSqlRecord. More...
 
bool reset (const QString &query)
 Sets the result to use the SQL statement query for subsequent data retrieval. More...
 
int size ()
 Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELECT statement. More...
 
- Protected Functions inherited from QSqlCachedResult
ValueCachecache ()
 
void cleanup ()
 
void clearValues ()
 
int colCount () const
 
QVariant data (int i)
 Returns the data for field index in the current row as a QVariant. More...
 
bool fetch (int i)
 Positions the result to an arbitrary (zero-based) row index. More...
 
bool fetchFirst ()
 Positions the result to the first record (row 0) in the result. More...
 
bool fetchLast ()
 Positions the result to the last record (last row) in the result. More...
 
bool fetchNext ()
 Positions the result to the next available record (row) in the result. More...
 
bool fetchPrevious ()
 Positions the result to the previous record (row) in the result. More...
 
void init (int colCount)
 
bool isNull (int i)
 Returns true if the field at position index in the current row is null; otherwise returns false. More...
 
 QSqlCachedResult (const QSqlDriver *db)
 
void virtual_hook (int id, void *data)
 
- Protected Functions inherited from QSqlResult
void addBindValue (const QVariant &val, QSql::ParamType type)
 Binds the value val of parameter type paramType to the next available position in the current record (row). More...
 
int at () const
 Returns the current (zero-based) row position of the result. More...
 
BindingSyntax bindingSyntax () const
 Returns the binding syntax used by prepared queries. More...
 
virtual void bindValue (int pos, const QVariant &val, QSql::ParamType type)
 Binds the value val of parameter type paramType to position index in the current record (row). More...
 
virtual void bindValue (const QString &placeholder, const QVariant &val, QSql::ParamType type)
 Binds the value val of parameter type paramType to the placeholder name in the current record (row). More...
 
QSql::ParamType bindValueType (const QString &placeholder) const
 Returns the parameter type for the value bound with the given placeholder name. More...
 
QSql::ParamType bindValueType (int pos) const
 Returns the parameter type for the value bound at position index. More...
 
QVariant boundValue (const QString &placeholder) const
 Returns the value bound by the given placeholder name in the current record (row). More...
 
QVariant boundValue (int pos) const
 Returns the value bound at position index in the current record (row). More...
 
int boundValueCount () const
 Returns the number of bound values in the result. More...
 
QString boundValueName (int pos) const
 Returns the name of the bound value at position index in the current record (row). More...
 
QVector< QVariant > & boundValues () const
 Returns a vector of the result's bound values for the current record (row). More...
 
void clear ()
 Clears the entire result set and releases any associated resources. More...
 
void detachFromResultSet ()
 
const QSqlDriverdriver () const
 Returns the driver associated with the result. More...
 
bool execBatch (bool arrayBind=false)
 Executes a prepared query in batch mode if the driver supports it, otherwise emulates a batch execution using bindValue() and exec(). More...
 
QString executedQuery () const
 Returns the query that was actually executed. More...
 
bool hasOutValues () const
 Returns true if at least one of the query's bound values is a QSql::Out or a QSql::InOut; otherwise returns false. More...
 
bool isActive () const
 Returns true if the result has records to be retrieved; otherwise returns false. More...
 
bool isForwardOnly () const
 Returns true if you can only scroll forward through the result set; otherwise returns false. More...
 
bool isSelect () const
 Returns true if the current result is from a SELECT statement; otherwise returns false. More...
 
bool isValid () const
 Returns true if the result is positioned on a valid record (that is, the result is not positioned before the first or after the last record); otherwise returns false. More...
 
QSqlError lastError () const
 Returns the last error associated with the result. More...
 
virtual QVariant lastInsertId () const
 Returns the object ID of the most recent inserted row if the database supports it. More...
 
QString lastQuery () const
 Returns the current SQL query text, or an empty string if there isn't one. More...
 
bool nextResult ()
 
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy () const
 
 QSqlResult (const QSqlDriver *db)
 Creates a QSqlResult using database driver db. More...
 
virtual bool savePrepare (const QString &sqlquery)
 Prepares the given query, using the underlying database functionality where possible. More...
 
virtual void setActive (bool a)
 This function is provided for derived classes to set the internal active state to active. More...
 
virtual void setAt (int at)
 This function is provided for derived classes to set the internal (zero-based) row position to index. More...
 
virtual void setForwardOnly (bool forward)
 Sets forward only mode to forward. More...
 
virtual void setLastError (const QSqlError &e)
 This function is provided for derived classes to set the last error to error. More...
 
void setNumericalPrecisionPolicy (QSql::NumericalPrecisionPolicy policy)
 
virtual void setQuery (const QString &query)
 Sets the current query for the result to query. More...
 
virtual void setSelect (bool s)
 This function is provided for derived classes to indicate whether or not the current statement is a SQL SELECT statement. More...
 

Properties

QIBaseResultPrivated
 

Friends

class QIBaseResultPrivate
 

Additional Inherited Members

- Public Types inherited from QSqlCachedResult
typedef QVector< QVariantValueCache
 
- Protected Types inherited from QSqlResult
enum  BindingSyntax { PositionalBinding, NamedBinding }
 This enum type specifies the different syntaxes for specifying placeholders in prepared queries. More...
 
enum  VirtualHookOperation { BatchOperation, DetachFromResultSet, SetNumericalPrecision, NextResult }
 

Detailed Description

Definition at line 57 of file qsql_ibase.h.

Constructors and Destructors

◆ QIBaseResult()

QIBaseResult::QIBaseResult ( const QIBaseDriver db)
explicit

Definition at line 870 of file qsql_ibase.cpp.

Referenced by record().

870  :
871  QSqlCachedResult(db)
872 {
873  d = new QIBaseResultPrivate(this, db);
874 }
QSqlCachedResult(const QSqlDriver *db)
QIBaseResultPrivate * d
Definition: qsql_ibase.h:77
friend class QIBaseResultPrivate
Definition: qsql_ibase.h:59

◆ ~QIBaseResult()

QIBaseResult::~QIBaseResult ( )
virtual

Definition at line 876 of file qsql_ibase.cpp.

877 {
878  delete d;
879 }
QIBaseResultPrivate * d
Definition: qsql_ibase.h:77

Functions

◆ exec()

bool QIBaseResult::exec ( )
virtual

Executes the query, returning true if successful; otherwise returns false.

See also
prepare()

Reimplemented from QSqlResult.

Definition at line 957 of file qsql_ibase.cpp.

Referenced by reset().

958 {
959  bool ok = true;
960 
961  if (!d->trans)
962  d->transaction();
963 
964  if (!driver() || !driver()->isOpen() || driver()->isOpenError())
965  return false;
966  setActive(false);
968 
969  if (d->inda) {
971  int i;
972  if (values.count() > d->inda->sqld) {
973  qWarning("QIBaseResult::exec: Parameter mismatch, expected %d, got %d parameters",
974  d->inda->sqld, values.count());
975  return false;
976  }
977  int para = 0;
978  for (i = 0; i < values.count(); ++i) {
979  para = i;
980  if (!d->inda->sqlvar[para].sqldata)
981  // skip unknown datatypes
982  continue;
983  const QVariant val(values[i]);
984  if (d->inda->sqlvar[para].sqltype & 1) {
985  if (val.isNull()) {
986  // set null indicator
987  *(d->inda->sqlvar[para].sqlind) = -1;
988  // and set the value to 0, otherwise it would count as empty string.
989  // it seems to be working with just setting sqlind to -1
990  //*((char*)d->inda->sqlvar[para].sqldata) = 0;
991  continue;
992  }
993  // a value of 0 means non-null.
994  *(d->inda->sqlvar[para].sqlind) = 0;
995  }
996  switch(d->inda->sqlvar[para].sqltype & ~1) {
997  case SQL_INT64:
998  if (d->inda->sqlvar[para].sqlscale < 0)
999  *((qint64*)d->inda->sqlvar[para].sqldata) =
1000  (qint64)floor(0.5 + val.toDouble() * pow(10.0, d->inda->sqlvar[para].sqlscale * -1));
1001  else
1002  *((qint64*)d->inda->sqlvar[para].sqldata) = val.toLongLong();
1003  break;
1004  case SQL_LONG:
1005  if (d->inda->sqlvar[para].sqlscale < 0)
1006  *((long*)d->inda->sqlvar[para].sqldata) =
1007  (long)floor(0.5 + val.toDouble() * pow(10.0, d->inda->sqlvar[para].sqlscale * -1));
1008  else
1009  *((long*)d->inda->sqlvar[para].sqldata) = (long)val.toLongLong();
1010  break;
1011  case SQL_SHORT:
1012  if (d->inda->sqlvar[para].sqlscale < 0)
1013  *((short*)d->inda->sqlvar[para].sqldata) =
1014  (short)floor(0.5 + val.toDouble() * pow(10.0, d->inda->sqlvar[para].sqlscale * -1));
1015  else
1016  *((short*)d->inda->sqlvar[para].sqldata) = (short)val.toInt();
1017  break;
1018  case SQL_FLOAT:
1019  *((float*)d->inda->sqlvar[para].sqldata) = (float)val.toDouble();
1020  break;
1021  case SQL_DOUBLE:
1022  *((double*)d->inda->sqlvar[para].sqldata) = val.toDouble();
1023  break;
1024  case SQL_TIMESTAMP:
1025  *((ISC_TIMESTAMP*)d->inda->sqlvar[para].sqldata) = toTimeStamp(val.toDateTime());
1026  break;
1027  case SQL_TYPE_TIME:
1028  *((ISC_TIME*)d->inda->sqlvar[para].sqldata) = toTime(val.toTime());
1029  break;
1030  case SQL_TYPE_DATE:
1031  *((ISC_DATE*)d->inda->sqlvar[para].sqldata) = toDate(val.toDate());
1032  break;
1033  case SQL_VARYING:
1034  case SQL_TEXT:
1035  qFillBufferWithString(d->inda->sqlvar[para].sqldata, val.toString(),
1036  d->inda->sqlvar[para].sqllen,
1037  (d->inda->sqlvar[para].sqltype & ~1) == SQL_VARYING, false, d->tc);
1038  break;
1039  case SQL_BLOB:
1040  ok &= d->writeBlob(para, val.toByteArray());
1041  break;
1042  case SQL_ARRAY:
1043  ok &= d->writeArray(para, val.toList());
1044  break;
1045  default:
1046  qWarning("QIBaseResult::exec: Unknown datatype %d",
1047  d->inda->sqlvar[para].sqltype & ~1);
1048  break;
1049  }
1050  }
1051  }
1052 
1053  if (ok) {
1054  if (colCount() && d->queryType != isc_info_sql_stmt_exec_procedure) {
1055  isc_dsql_free_statement(d->status, &d->stmt, DSQL_close);
1056  if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Unable to close statement")))
1057  return false;
1058  cleanup();
1059  }
1060  if (d->queryType == isc_info_sql_stmt_exec_procedure)
1061  isc_dsql_execute2(d->status, &d->trans, &d->stmt, FBVERSION, d->inda, d->sqlda);
1062  else
1063  isc_dsql_execute(d->status, &d->trans, &d->stmt, FBVERSION, d->inda);
1064  if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Unable to execute query")))
1065  return false;
1066 
1067  // Not all stored procedures necessarily return values.
1068  if (d->queryType == isc_info_sql_stmt_exec_procedure && d->sqlda && d->sqlda->sqld == 0)
1069  delDA(d->sqlda);
1070 
1071  if (d->sqlda)
1072  init(d->sqlda->sqld);
1073 
1074  if (!isSelect())
1075  d->commit();
1076 
1077  setActive(true);
1078  return true;
1079  }
1080  return false;
1081 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
const QSqlDriver * driver() const
Returns the driver associated with the result.
Definition: qsqlresult.cpp:389
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
#define FBVERSION
Definition: qsql_ibase.cpp:62
static ISC_DATE toDate(const QDate &t)
Definition: qsql_ibase.cpp:268
static char * qFillBufferWithString(char *buffer, const QString &string, short buflen, bool varying, bool array, QTextCodec *tc)
Definition: qsql_ibase.cpp:650
int count(const T &t) const
Returns the number of occurrences of value in the vector.
Definition: qvector.h:742
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index...
Definition: qsqlresult.cpp:352
static ISC_TIMESTAMP toTimeStamp(const QDateTime &dt)
Definition: qsql_ibase.cpp:228
Q_CORE_EXPORT void qWarning(const char *,...)
bool writeArray(int i, const QList< QVariant > &list)
Definition: qsql_ibase.cpp:760
__int64 qint64
Definition: qglobal.h:942
bool writeBlob(int i, const QByteArray &ba)
Definition: qsql_ibase.cpp:417
quint16 values[128]
static void delDA(XSQLDA *&sqlda)
Definition: qsql_ibase.cpp:155
QIBaseResultPrivate * d
Definition: qsql_ibase.h:77
T floor(const T &a)
isc_stmt_handle stmt
Definition: qsql_ibase.cpp:384
bool isSelect() const
Returns true if the current result is from a SELECT statement; otherwise returns false.
Definition: qsqlresult.cpp:379
virtual void setActive(bool a)
This function is provided for derived classes to set the internal active state to active...
Definition: qsqlresult.cpp:402
static ISC_TIME toTime(const QTime &t)
Definition: qsql_ibase.cpp:252
void init(int colCount)
QVector< QVariant > & boundValues() const
Returns a vector of the result&#39;s bound values for the current record (row).
Definition: qsqlresult.cpp:859
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ gotoNext()

bool QIBaseResult::gotoNext ( QSqlCachedResult::ValueCache row,
int  rowIdx 
)
protectedvirtual

Implements QSqlCachedResult.

Definition at line 1090 of file qsql_ibase.cpp.

1091 {
1092  ISC_STATUS stat = 0;
1093 
1094  // Stored Procedures are special - they populate our d->sqlda when executing,
1095  // so we don't have to call isc_dsql_fetch
1096  if (d->queryType == isc_info_sql_stmt_exec_procedure) {
1097  // the first "fetch" shall succeed, all consecutive ones will fail since
1098  // we only have one row to fetch for stored procedures
1099  if (rowIdx != 0)
1100  stat = 100;
1101  } else {
1102  stat = isc_dsql_fetch(d->status, &d->stmt, FBVERSION, d->sqlda);
1103  }
1104 
1105  if (stat == 100) {
1106  // no more rows
1108  return false;
1109  }
1110  if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not fetch next item"),
1112  return false;
1113  if (rowIdx < 0) // not interested in actual values
1114  return true;
1115 
1116  for (int i = 0; i < d->sqlda->sqld; ++i) {
1117  int idx = rowIdx + i;
1118  char *buf = d->sqlda->sqlvar[i].sqldata;
1119  int size = d->sqlda->sqlvar[i].sqllen;
1120  Q_ASSERT(buf);
1121 
1122  if ((d->sqlda->sqlvar[i].sqltype & 1) && *d->sqlda->sqlvar[i].sqlind) {
1123  // null value
1124  QVariant v;
1125  v.convert(qIBaseTypeName2(d->sqlda->sqlvar[i].sqltype, d->sqlda->sqlvar[i].sqlscale < 0));
1126  if(v.type() == QVariant::Double) {
1127  switch(numericalPrecisionPolicy()) {
1130  break;
1133  break;
1134  case QSql::HighPrecision:
1136  break;
1137  }
1138  }
1139  row[idx] = v;
1140  continue;
1141  }
1142 
1143  switch(d->sqlda->sqlvar[i].sqltype & ~1) {
1144  case SQL_VARYING:
1145  // pascal strings - a short with a length information followed by the data
1146  if (d->tc)
1147  row[idx] = d->tc->toUnicode(buf + sizeof(short), *(short*)buf);
1148  else
1149  row[idx] = QString::fromUtf8(buf + sizeof(short), *(short*)buf);
1150  break;
1151  case SQL_INT64:
1152  if (d->sqlda->sqlvar[i].sqlscale < 0)
1153  row[idx] = *(qint64*)buf * pow(10.0, d->sqlda->sqlvar[i].sqlscale);
1154  else
1155  row[idx] = QVariant(*(qint64*)buf);
1156  break;
1157  case SQL_LONG:
1158  if (d->sqlda->sqlvar[i].sqllen == 4)
1159  if (d->sqlda->sqlvar[i].sqlscale < 0)
1160  row[idx] = QVariant(*(qint32*)buf * pow(10.0, d->sqlda->sqlvar[i].sqlscale));
1161  else
1162  row[idx] = QVariant(*(qint32*)buf);
1163  else
1164  row[idx] = QVariant(*(qint64*)buf);
1165  break;
1166  case SQL_SHORT:
1167  if (d->sqlda->sqlvar[i].sqlscale < 0)
1168  row[idx] = QVariant(long((*(short*)buf)) * pow(10.0, d->sqlda->sqlvar[i].sqlscale));
1169  else
1170  row[idx] = QVariant(int((*(short*)buf)));
1171  break;
1172  case SQL_FLOAT:
1173  row[idx] = QVariant(double((*(float*)buf)));
1174  break;
1175  case SQL_DOUBLE:
1176  row[idx] = QVariant(*(double*)buf);
1177  break;
1178  case SQL_TIMESTAMP:
1179  row[idx] = fromTimeStamp(buf);
1180  break;
1181  case SQL_TYPE_TIME:
1182  row[idx] = fromTime(buf);
1183  break;
1184  case SQL_TYPE_DATE:
1185  row[idx] = fromDate(buf);
1186  break;
1187  case SQL_TEXT:
1188  if (d->tc)
1189  row[idx] = d->tc->toUnicode(buf, size);
1190  else
1191  row[idx] = QString::fromUtf8(buf, size);
1192  break;
1193  case SQL_BLOB:
1194  row[idx] = d->fetchBlob((ISC_QUAD*)buf);
1195  break;
1196  case SQL_ARRAY:
1197  row[idx] = d->fetchArray(i, (ISC_QUAD*)buf);
1198  break;
1199  default:
1200  // unknown type - don't even try to fetch
1201  row[idx] = QVariant();
1202  break;
1203  }
1204  if (d->sqlda->sqlvar[i].sqlscale < 0) {
1205  QVariant v = row[idx];
1206  switch(numericalPrecisionPolicy()) {
1208  if(v.convert(QVariant::Int))
1209  row[idx]=v;
1210  break;
1213  row[idx]=v;
1214  break;
1216  if(v.convert(QVariant::Double))
1217  row[idx]=v;
1218  break;
1219  case QSql::HighPrecision:
1220  if(v.convert(QVariant::String))
1221  row[idx]=v;
1222  break;
1223  }
1224  }
1225  }
1226 
1227  return true;
1228 }
QVariant fetchBlob(ISC_QUAD *bId)
Definition: qsql_ibase.cpp:437
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
#define FBVERSION
Definition: qsql_ibase.cpp:62
int qint32
Definition: qglobal.h:937
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy() const
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
QVariant fetchArray(int pos, ISC_QUAD *arr)
Definition: qsql_ibase.cpp:571
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index...
Definition: qsqlresult.cpp:352
static QDateTime fromTimeStamp(char *buffer)
Definition: qsql_ibase.cpp:238
static QTime fromTime(char *buffer)
Definition: qsql_ibase.cpp:258
static QString fromUtf8(const char *, int size=-1)
Returns a QString initialized with the first size bytes of the UTF-8 string str.
Definition: qstring.cpp:4302
int size()
Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELE...
__int64 qint64
Definition: qglobal.h:942
bool convert(Type t)
Casts the variant to the requested type, t.
Definition: qvariant.cpp:2959
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
QIBaseResultPrivate * d
Definition: qsql_ibase.h:77
isc_stmt_handle stmt
Definition: qsql_ibase.cpp:384
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
static QVariant::Type qIBaseTypeName2(int iType, bool hasScale)
Definition: qsql_ibase.cpp:199
static QDate fromDate(char *buffer)
Definition: qsql_ibase.cpp:277
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ handle()

QVariant QIBaseResult::handle ( ) const
virtual

Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVariant if there is no handle.

Warning
Use this with uttermost care and only if you know what you're doing.
The handle returned here can become a stale pointer if the result is modified (for example, if you clear it).
The handle can be NULL if the result was not executed yet.

The handle returned here is database-dependent, you should query the type name of the variant before accessing it.

This example retrieves the handle for a sqlite result:

QSqlQuery query = ...
QVariant v = query.result()->handle();
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3_stmt*")) {
// v.data() returns a pointer to the handle
sqlite3_stmt *handle = *static_cast<sqlite3_stmt **>(v.data());
if (handle != 0) { // check that it is not NULL
...
}
}

This snippet returns the handle for PostgreSQL or MySQL:

if (v.typeName() == "PGresult*") {
PGresult *handle = *static_cast<PGresult **>(v.data());
if (handle != 0) ...
}
if (v.typeName() == "MYSQL_STMT*") {
MYSQL_STMT *handle = *static_cast<MYSQL_STMT **>(v.data());
if (handle != 0) ...
}
See also
QSqlDriver::handle()

Reimplemented from QSqlResult.

Definition at line 1364 of file qsql_ibase.cpp.

Referenced by QIBaseDriver::open().

1365 {
1366  return QVariant(qRegisterMetaType<isc_stmt_handle>("isc_stmt_handle"), &d->stmt);
1367 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
QIBaseResultPrivate * d
Definition: qsql_ibase.h:77
isc_stmt_handle stmt
Definition: qsql_ibase.cpp:384

◆ numRowsAffected()

int QIBaseResult::numRowsAffected ( )
protectedvirtual

Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or if the query is a SELECT statement.

See also
size()

Implements QSqlResult.

Definition at line 1281 of file qsql_ibase.cpp.

1282 {
1283  static char acCountInfo[] = {isc_info_sql_records};
1284  char cCountType;
1285 
1286  switch (d->queryType) {
1287  case isc_info_sql_stmt_select:
1288  cCountType = isc_info_req_select_count;
1289  break;
1290  case isc_info_sql_stmt_update:
1291  cCountType = isc_info_req_update_count;
1292  break;
1293  case isc_info_sql_stmt_delete:
1294  cCountType = isc_info_req_delete_count;
1295  break;
1296  case isc_info_sql_stmt_insert:
1297  cCountType = isc_info_req_insert_count;
1298  break;
1299  default:
1300  qWarning() << "numRowsAffected: Unknown statement type (" << d->queryType << ")";
1301  return -1;
1302  }
1303 
1304  char acBuffer[33];
1305  int iResult = -1;
1306  isc_dsql_sql_info(d->status, &d->stmt, sizeof(acCountInfo), acCountInfo, sizeof(acBuffer), acBuffer);
1307  if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not get statement info"),
1309  return -1;
1310  for (char *pcBuf = acBuffer + 3; *pcBuf != isc_info_end; /*nothing*/) {
1311  char cType = *pcBuf++;
1312  short sLength = isc_vax_integer (pcBuf, 2);
1313  pcBuf += 2;
1314  int iValue = isc_vax_integer (pcBuf, sLength);
1315  pcBuf += sLength;
1316 
1317  if (cType == cCountType) {
1318  iResult = iValue;
1319  break;
1320  }
1321  }
1322  return iResult;
1323 }
#define QT_TRANSLATE_NOOP(scope, x)
Marks the string literal sourceText for dynamic translation in the given context; i...
Definition: qglobal.h:2487
Q_CORE_EXPORT void qWarning(const char *,...)
QIBaseResultPrivate * d
Definition: qsql_ibase.h:77
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

◆ prepare()

bool QIBaseResult::prepare ( const QString query)
virtual

Prepares the given query for execution; the query will normally use placeholders so that it can be executed repeatedly.

Returns true if the query is prepared successfully; otherwise returns false.

See also
exec()

Reimplemented from QSqlResult.

Definition at line 881 of file qsql_ibase.cpp.

Referenced by reset().

882 {
883 // qDebug("prepare: %s", qPrintable(query));
884  if (!driver() || !driver()->isOpen() || driver()->isOpenError())
885  return false;
886  d->cleanup();
887  setActive(false);
889 
890  createDA(d->sqlda);
891  if (d->sqlda == (XSQLDA*)0) {
892  qWarning()<<"QIOBaseResult: createDA(): failed to allocate memory";
893  return false;
894  }
895 
896  createDA(d->inda);
897  if (d->inda == (XSQLDA*)0){
898  qWarning()<<"QIOBaseResult: createDA(): failed to allocate memory";
899  return false;
900  }
901 
902  if (!d->transaction())
903  return false;
904 
905  isc_dsql_allocate_statement(d->status, &d->ibase, &d->stmt);
906  if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not allocate statement"),
908  return false;
909  isc_dsql_prepare(d->status, &d->trans, &d->stmt, 0,
910  const_cast<char*>(encodeString(d->tc, query).constData()), FBVERSION, d->sqlda);
911  if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not prepare statement"),
913  return false;
914 
915  isc_dsql_describe_bind(d->status, &d->stmt, FBVERSION, d->inda);
916  if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult",
917  "Could not describe input statement"), QSqlError::StatementError))
918  return false;
919  if (d->inda->sqld > d->inda->sqln) {
920  enlargeDA(d->inda, d->inda->sqld);
921  if (d->inda == (XSQLDA*)0) {
922  qWarning()<<"QIOBaseResult: enlargeDA(): failed to allocate memory";
923  return false;
924  }
925 
926  isc_dsql_describe_bind(d->status, &d->stmt, FBVERSION, d->inda);
927  if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult",
928  "Could not describe input statement"), QSqlError::StatementError))
929  return false;
930  }
931  initDA(d->inda);
932  if (d->sqlda->sqld > d->sqlda->sqln) {
933  // need more field descriptors
934  enlargeDA(d->sqlda, d->sqlda->sqld);
935  if (d->sqlda == (XSQLDA*)0) {
936  qWarning()<<"QIOBaseResult: enlargeDA(): failed to allocate memory";
937  return false;
938  }
939 
940  isc_dsql_describe(d->status, &d->stmt, FBVERSION, d->sqlda);
941  if (d->isError(QT_TRANSLATE_NOOP("QIBaseResult", "Could not describe statement"),
943  return false;
944  }
945  initDA(d->sqlda);
946 
947  setSelect(d->isSelect());
948  if (!isSelect()) {
949  free(d->sqlda);
950  d->sqlda = 0;
951  }
952 
953  return true;
954 }
const QSqlDriver * driver() const
Returns the driver associated with the result.
Definition: qsqlresult.cpp:389
isc_tr_handle trans
Definition: qsql_ibase.cpp:381
#define FBVERSION
Definition: qsql_ibase.cpp:62
#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
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index...
Definition: qsqlresult.cpp:352
virtual void setSelect(bool s)
This function is provided for derived classes to indicate whether or not the current statement is a S...
Definition: qsqlresult.cpp:367
static QByteArray encodeString(QTextCodec *tc, const QString &str)
Definition: qsql_ibase.cpp:289
Q_CORE_EXPORT void qWarning(const char *,...)
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QIBaseResultPrivate * d
Definition: qsql_ibase.h:77
isc_stmt_handle stmt
Definition: qsql_ibase.cpp:384
static void enlargeDA(XSQLDA *&sqlda, int n)
Definition: qsql_ibase.cpp:108
bool isSelect() const
Returns true if the current result is from a SELECT statement; otherwise returns false.
Definition: qsqlresult.cpp:379
virtual void setActive(bool a)
This function is provided for derived classes to set the internal active state to active...
Definition: qsqlresult.cpp:402
bool isError(const char *msg, QSqlError::ErrorType typ=QSqlError::UnknownError)
Definition: qsql_ibase.cpp:356
static void initDA(XSQLDA *sqlda)
Definition: qsql_ibase.cpp:118
static void createDA(XSQLDA *&sqlda)
Definition: qsql_ibase.cpp:97
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

◆ record()

QSqlRecord QIBaseResult::record ( ) const
protectedvirtual

Returns the current record if the query is active; otherwise returns an empty QSqlRecord.

The default implementation always returns an empty QSqlRecord.

See also
isActive()

Reimplemented from QSqlResult.

Definition at line 1325 of file qsql_ibase.cpp.

Referenced by QIBaseDriver::open().

1326 {
1327  QSqlRecord rec;
1328  if (!isActive() || !d->sqlda)
1329  return rec;
1330 
1331  XSQLVAR v;
1332  for (int i = 0; i < d->sqlda->sqld; ++i) {
1333  v = d->sqlda->sqlvar[i];
1334  QSqlField f(QString::fromLatin1(v.aliasname, v.aliasname_length).simplified(),
1335  qIBaseTypeName2(v.sqltype, v.sqlscale < 0));
1336  f.setLength(v.sqllen);
1337  f.setPrecision(qAbs(v.sqlscale));
1338  f.setRequiredStatus((v.sqltype & 1) == 0 ? QSqlField::Required : QSqlField::Optional);
1339  if(v.sqlscale < 0) {
1340  QSqlQuery q(new QIBaseResult(d->db));
1341  q.setForwardOnly(true);
1342  q.exec(QLatin1String("select b.RDB$FIELD_PRECISION, b.RDB$FIELD_SCALE, b.RDB$FIELD_LENGTH, a.RDB$NULL_FLAG "
1343  "FROM RDB$RELATION_FIELDS a, RDB$FIELDS b "
1344  "WHERE b.RDB$FIELD_NAME = a.RDB$FIELD_SOURCE "
1345  "AND a.RDB$RELATION_NAME = '") + QString::fromAscii(v.relname, v.relname_length).toUpper() + QLatin1String("' "
1346  "AND a.RDB$FIELD_NAME = '") + QString::fromAscii(v.sqlname, v.sqlname_length).toUpper() + QLatin1String("' "));
1347  if(q.first()) {
1348  if(v.sqlscale < 0) {
1349  f.setLength(q.value(0).toInt());
1350  f.setPrecision(qAbs(q.value(1).toInt()));
1351  } else {
1352  f.setLength(q.value(2).toInt());
1353  f.setPrecision(0);
1354  }
1355  f.setRequiredStatus(q.value(3).toBool() ? QSqlField::Required : QSqlField::Optional);
1356  }
1357  }
1358  f.setSqlType(v.sqltype);
1359  rec.append(f);
1360  }
1361  return rec;
1362 }
bool isActive() const
Returns true if the result has records to be retrieved; otherwise returns false.
Definition: qsqlresult.cpp:340
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
const QIBaseDriver * db
Definition: qsql_ibase.cpp:379
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
Q_DECL_CONSTEXPR T qAbs(const T &t)
Definition: qglobal.h:1201
void setLength(int fieldLength)
Sets the field&#39;s length to fieldLength.
Definition: qsqlfield.cpp:254
QIBaseResult(const QIBaseDriver *db)
Definition: qsql_ibase.cpp:870
QIBaseResultPrivate * d
Definition: qsql_ibase.h:77
QString simplified() const Q_REQUIRED_RESULT
Returns a string that has whitespace removed from the start and the end, and that has each sequence o...
Definition: qstring.cpp:4415
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
Definition: qsqlrecord.cpp:312
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
static QVariant::Type qIBaseTypeName2(int iType, bool hasScale)
Definition: qsql_ibase.cpp:199

◆ reset()

bool QIBaseResult::reset ( const QString query)
protectedvirtual

Sets the result to use the SQL statement query for subsequent data retrieval.

Derived classes must reimplement this function and apply the query to the database. This function is only called after the result is set to an inactive state and is positioned before the first record of the new result. Derived classes should return true if the query was successful and ready to be used, or false otherwise.

See also
setQuery()

Implements QSqlResult.

Definition at line 1083 of file qsql_ibase.cpp.

1084 {
1085  if (!prepare(query))
1086  return false;
1087  return exec();
1088 }
bool exec()
Executes the query, returning true if successful; otherwise returns false.
Definition: qsql_ibase.cpp:957
bool prepare(const QString &query)
Prepares the given query for execution; the query will normally use placeholders so that it can be ex...
Definition: qsql_ibase.cpp:881

◆ size()

int QIBaseResult::size ( )
protectedvirtual

Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELECT statement.

See also
numRowsAffected()

FIXME

Implements QSqlResult.

Definition at line 1230 of file qsql_ibase.cpp.

Referenced by gotoNext().

1231 {
1232  return -1;
1233 
1234 #if 0
1235  static char sizeInfo[] = {isc_info_sql_records};
1236  char buf[64];
1237 
1238  //qDebug() << sizeInfo;
1239  if (!isActive() || !isSelect())
1240  return -1;
1241 
1242  char ct;
1243  short len;
1244  int val = 0;
1245 // while(val == 0) {
1246  isc_dsql_sql_info(d->status, &d->stmt, sizeof(sizeInfo), sizeInfo, sizeof(buf), buf);
1247 // isc_database_info(d->status, &d->ibase, sizeof(sizeInfo), sizeInfo, sizeof(buf), buf);
1248 
1249  for(int i = 0; i < 66; ++i)
1250  qDebug() << QString::number(buf[i]);
1251 
1252  for (char* c = buf + 3; *c != isc_info_end; /*nothing*/) {
1253  ct = *(c++);
1254  len = isc_vax_integer(c, 2);
1255  c += 2;
1256  val = isc_vax_integer(c, len);
1257  c += len;
1258  qDebug() << "size" << val;
1259  if (ct == isc_info_req_select_count)
1260  return val;
1261  }
1262  //qDebug() << "size -1";
1263  return -1;
1264 
1265  unsigned int i, result_size;
1266  if (buf[0] == isc_info_sql_records) {
1267  i = 3;
1268  result_size = isc_vax_integer(&buf[1],2);
1269  while (buf[i] != isc_info_end && i < result_size) {
1270  len = (short)isc_vax_integer(&buf[i+1],2);
1271  if (buf[i] == isc_info_req_select_count)
1272  return (isc_vax_integer(&buf[i+3],len));
1273  i += len+3;
1274  }
1275  }
1276 // }
1277  return -1;
1278 #endif
1279 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
bool isActive() const
Returns true if the result has records to be retrieved; otherwise returns false.
Definition: qsqlresult.cpp:340
unsigned char c[8]
Definition: qnumeric_p.h:62
Q_CORE_EXPORT void qDebug(const char *,...)
QIBaseResultPrivate * d
Definition: qsql_ibase.h:77
isc_stmt_handle stmt
Definition: qsql_ibase.cpp:384
bool isSelect() const
Returns true if the current result is from a SELECT statement; otherwise returns false.
Definition: qsqlresult.cpp:379
ISC_STATUS status[20]
Definition: qsql_ibase.cpp:380

Friends and Related Functions

◆ QIBaseResultPrivate

friend class QIBaseResultPrivate
friend

Definition at line 59 of file qsql_ibase.h.

Referenced by QIBaseResult().

Properties

◆ d

QIBaseResultPrivate* QIBaseResult::d
private

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