Qt 4.8
Classes | Macros | Functions | Variables
qsql_db2.cpp File Reference
#include "qsql_db2.h"
#include <qcoreapplication.h>
#include <qdatetime.h>
#include <qsqlfield.h>
#include <qsqlerror.h>
#include <qsqlindex.h>
#include <qsqlrecord.h>
#include <qstringlist.h>
#include <qvarlengtharray.h>
#include <qvector.h>
#include <QDebug>
#include <sqlcli1.h>
#include <string.h>

Go to the source code of this file.

Classes

class  QDB2DriverPrivate
 
class  QDB2ResultPrivate
 

Macros

#define UNICODE
 

Functions

static QString qDB2Warn (const QDB2DriverPrivate *d)
 
static QString qDB2Warn (const QDB2ResultPrivate *d)
 
static QVariant::Type qDecodeDB2Type (SQLSMALLINT sqltype)
 
static QString qFromTChar (SQLTCHAR *str)
 
static SQLBIGINT qGetBigIntData (SQLHANDLE hStmt, int column, bool &isNull)
 
static QByteArray qGetBinaryData (SQLHANDLE hStmt, int column, SQLINTEGER &lengthIndicator, bool &isNull)
 
static double qGetDoubleData (SQLHANDLE hStmt, int column, bool &isNull)
 
static int qGetIntData (SQLHANDLE hStmt, int column, bool &isNull)
 
static QString qGetStringData (SQLHANDLE hStmt, int column, int colSize, bool &isNull)
 
static QSqlError qMakeError (const QString &err, QSqlError::ErrorType type, const QDB2DriverPrivate *p)
 
static QSqlError qMakeError (const QString &err, QSqlError::ErrorType type, const QDB2ResultPrivate *p)
 
static QSqlField qMakeFieldInfo (const QDB2ResultPrivate *d, int i)
 
static QSqlField qMakeFieldInfo (const SQLHANDLE hStmt)
 
static bool qMakeStatement (QDB2ResultPrivate *d, bool forwardOnly, bool setForwardOnly=true)
 
static void qSplitTableQualifier (const QString &qualifier, QString *catalog, QString *schema, QString *table)
 
static void qSqlWarning (const QString &message, const QDB2DriverPrivate *d)
 
static void qSqlWarning (const QString &message, const QDB2ResultPrivate *d)
 
static SQLTCHAR * qToTChar (const QString &str)
 
static QString qWarnDB2Handle (int handleType, SQLHANDLE handle)
 

Variables

static const int COLNAMESIZE = 255
 
static const SQLSMALLINT qParamType [4] = { SQL_PARAM_INPUT, SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, SQL_PARAM_INPUT_OUTPUT }
 

Macro Definition Documentation

◆ UNICODE

#define UNICODE

Function Documentation

◆ qDB2Warn() [1/2]

static QString qDB2Warn ( const QDB2DriverPrivate d)
static

Definition at line 142 of file qsql_db2.cpp.

Referenced by QDB2Result::exec(), qMakeError(), and qSqlWarning().

143 {
144  return (qWarnDB2Handle(SQL_HANDLE_ENV, d->hEnv) + QLatin1Char(' ')
145  + qWarnDB2Handle(SQL_HANDLE_DBC, d->hDbc));
146 }
static QString qWarnDB2Handle(int handleType, SQLHANDLE handle)
Definition: qsql_db2.cpp:122
SQLHANDLE hDbc
Definition: qsql_db2.cpp:78
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
SQLHANDLE hEnv
Definition: qsql_db2.cpp:77

◆ qDB2Warn() [2/2]

static QString qDB2Warn ( const QDB2ResultPrivate d)
static

Definition at line 148 of file qsql_db2.cpp.

149 {
150  return (qWarnDB2Handle(SQL_HANDLE_ENV, d->dp->hEnv) + QLatin1Char(' ')
151  + qWarnDB2Handle(SQL_HANDLE_DBC, d->dp->hDbc)
152  + qWarnDB2Handle(SQL_HANDLE_STMT, d->hStmt));
153 }
static QString qWarnDB2Handle(int handleType, SQLHANDLE handle)
Definition: qsql_db2.cpp:122
const QDB2DriverPrivate * dp
Definition: qsql_db2.cpp:104
SQLHANDLE hStmt
Definition: qsql_db2.cpp:105
SQLHANDLE hDbc
Definition: qsql_db2.cpp:78
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
SQLHANDLE hEnv
Definition: qsql_db2.cpp:77

◆ qDecodeDB2Type()

static QVariant::Type qDecodeDB2Type ( SQLSMALLINT  sqltype)
static

Definition at line 179 of file qsql_db2.cpp.

Referenced by qMakeFieldInfo().

180 {
182  switch (sqltype) {
183  case SQL_REAL:
184  case SQL_FLOAT:
185  case SQL_DOUBLE:
186  case SQL_DECIMAL:
187  case SQL_NUMERIC:
188  type = QVariant::Double;
189  break;
190  case SQL_SMALLINT:
191  case SQL_INTEGER:
192  case SQL_BIT:
193  case SQL_TINYINT:
194  type = QVariant::Int;
195  break;
196  case SQL_BIGINT:
197  type = QVariant::LongLong;
198  break;
199  case SQL_BLOB:
200  case SQL_BINARY:
201  case SQL_VARBINARY:
202  case SQL_LONGVARBINARY:
203  case SQL_CLOB:
204  case SQL_DBCLOB:
205  type = QVariant::ByteArray;
206  break;
207  case SQL_DATE:
208  case SQL_TYPE_DATE:
209  type = QVariant::Date;
210  break;
211  case SQL_TIME:
212  case SQL_TYPE_TIME:
213  type = QVariant::Time;
214  break;
215  case SQL_TIMESTAMP:
216  case SQL_TYPE_TIMESTAMP:
217  type = QVariant::DateTime;
218  break;
219  case SQL_WCHAR:
220  case SQL_WVARCHAR:
221  case SQL_WLONGVARCHAR:
222  case SQL_CHAR:
223  case SQL_VARCHAR:
224  case SQL_LONGVARCHAR:
225  type = QVariant::String;
226  break;
227  default:
228  type = QVariant::ByteArray;
229  break;
230  }
231  return type;
232 }
int type
Definition: qmetatype.cpp:239
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95

◆ qFromTChar()

static QString qFromTChar ( SQLTCHAR *  str)
static

Definition at line 110 of file qsql_db2.cpp.

Referenced by qGetStringData(), qMakeFieldInfo(), and qWarnDB2Handle().

111 {
112  return QString((const QChar *)str);
113 }
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

◆ qGetBigIntData()

static SQLBIGINT qGetBigIntData ( SQLHANDLE  hStmt,
int  column,
bool &  isNull 
)
static

Definition at line 307 of file qsql_db2.cpp.

Referenced by QDB2Result::data().

308 {
309  SQLBIGINT lngbuf = Q_INT64_C(0);
310  isNull = false;
311  SQLINTEGER lengthIndicator = 0;
312  SQLRETURN r = SQLGetData(hStmt,
313  column+1,
314  SQL_C_SBIGINT,
315  (SQLPOINTER) &lngbuf,
316  0,
317  &lengthIndicator);
318  if ((r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) || lengthIndicator == SQL_NULL_DATA)
319  isNull = true;
320 
321  return lngbuf;
322 }
#define Q_INT64_C(c)
Definition: qglobal.h:940
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

◆ qGetBinaryData()

static QByteArray qGetBinaryData ( SQLHANDLE  hStmt,
int  column,
SQLINTEGER &  lengthIndicator,
bool &  isNull 
)
static

Definition at line 364 of file qsql_db2.cpp.

Referenced by QDB2Result::data().

365 {
366  QByteArray fieldVal;
367  SQLSMALLINT colNameLen;
368  SQLSMALLINT colType;
369  SQLUINTEGER colSize;
370  SQLSMALLINT colScale;
371  SQLSMALLINT nullable;
372  SQLRETURN r = SQL_ERROR;
373 
374  SQLTCHAR colName[COLNAMESIZE];
375  r = SQLDescribeCol(hStmt,
376  column+1,
377  colName,
378  COLNAMESIZE,
379  &colNameLen,
380  &colType,
381  &colSize,
382  &colScale,
383  &nullable);
384  if (r != SQL_SUCCESS)
385  qWarning("qGetBinaryData: Unable to describe column %d", column);
386  // SQLDescribeCol may return 0 if size cannot be determined
387  if (!colSize)
388  colSize = 255;
389  else if (colSize > 65536) // read the field in 64 KB chunks
390  colSize = 65536;
391  char * buf = new char[colSize];
392  while (true) {
393  r = SQLGetData(hStmt,
394  column+1,
395  colType == SQL_DBCLOB ? SQL_C_CHAR : SQL_C_BINARY,
396  (SQLPOINTER) buf,
397  colSize,
398  &lengthIndicator);
399  if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
400  if (lengthIndicator == SQL_NULL_DATA) {
401  isNull = true;
402  break;
403  } else {
404  int rSize;
405  r == SQL_SUCCESS ? rSize = lengthIndicator : rSize = colSize;
406  if (lengthIndicator == SQL_NO_TOTAL) // size cannot be determined
407  rSize = colSize;
408  fieldVal.append(QByteArray(buf, rSize));
409  if (r == SQL_SUCCESS) // the whole field was read in one chunk
410  break;
411  }
412  } else {
413  break;
414  }
415  }
416  delete [] buf;
417  return fieldVal;
418 }
QByteArray & append(char c)
Appends the character ch to this byte array.
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
Q_CORE_EXPORT void qWarning(const char *,...)
static const int COLNAMESIZE
Definition: qsql_db2.cpp:70
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

◆ qGetDoubleData()

static double qGetDoubleData ( SQLHANDLE  hStmt,
int  column,
bool &  isNull 
)
static

Definition at line 288 of file qsql_db2.cpp.

Referenced by QDB2Result::data().

289 {
290  SQLDOUBLE dblbuf;
291  isNull = false;
292  SQLINTEGER lengthIndicator = 0;
293  SQLRETURN r = SQLGetData(hStmt,
294  column+1,
295  SQL_C_DOUBLE,
296  (SQLPOINTER) &dblbuf,
297  0,
298  &lengthIndicator);
299  if ((r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) || lengthIndicator == SQL_NULL_DATA) {
300  isNull = true;
301  return 0.0;
302  }
303 
304  return (double) dblbuf;
305 }
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

◆ qGetIntData()

static int qGetIntData ( SQLHANDLE  hStmt,
int  column,
bool &  isNull 
)
static

Definition at line 270 of file qsql_db2.cpp.

Referenced by QDB2Result::data(), and qMakeFieldInfo().

271 {
272  SQLINTEGER intbuf;
273  isNull = false;
274  SQLINTEGER lengthIndicator = 0;
275  SQLRETURN r = SQLGetData(hStmt,
276  column + 1,
277  SQL_C_SLONG,
278  (SQLPOINTER) &intbuf,
279  0,
280  &lengthIndicator);
281  if ((r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) || lengthIndicator == SQL_NULL_DATA) {
282  isNull = true;
283  return 0;
284  }
285  return int(intbuf);
286 }
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

◆ qGetStringData()

static QString qGetStringData ( SQLHANDLE  hStmt,
int  column,
int  colSize,
bool &  isNull 
)
static

Definition at line 324 of file qsql_db2.cpp.

Referenced by QDB2Result::data(), QDB2Driver::primaryIndex(), qMakeFieldInfo(), and QDB2Driver::tables().

325 {
326  QString fieldVal;
327  SQLRETURN r = SQL_ERROR;
328  SQLINTEGER lengthIndicator = 0;
329 
330  if (colSize <= 0)
331  colSize = 255;
332  else if (colSize > 65536) // limit buffer size to 64 KB
333  colSize = 65536;
334  else
335  colSize++; // make sure there is room for more than the 0 termination
336  SQLTCHAR* buf = new SQLTCHAR[colSize];
337 
338  while (true) {
339  r = SQLGetData(hStmt,
340  column + 1,
341  SQL_C_WCHAR,
342  (SQLPOINTER)buf,
343  colSize * sizeof(SQLTCHAR),
344  &lengthIndicator);
345  if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) {
346  if (lengthIndicator == SQL_NULL_DATA || lengthIndicator == SQL_NO_TOTAL) {
347  fieldVal.clear();
348  isNull = true;
349  break;
350  }
351  fieldVal += qFromTChar(buf);
352  } else if (r == SQL_NO_DATA) {
353  break;
354  } else {
355  qWarning("qGetStringData: Error while fetching data (%d)", r);
356  fieldVal.clear();
357  break;
358  }
359  }
360  delete[] buf;
361  return fieldVal;
362 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
Q_CORE_EXPORT void qWarning(const char *,...)
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723
static QString qFromTChar(SQLTCHAR *str)
Definition: qsql_db2.cpp:110
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

◆ qMakeError() [1/2]

static QSqlError qMakeError ( const QString err,
QSqlError::ErrorType  type,
const QDB2DriverPrivate p 
)
static

Definition at line 167 of file qsql_db2.cpp.

Referenced by QDB2Driver::commitTransaction(), QDB2Result::exec(), QDB2Result::fetch(), QDB2Result::fetchFirst(), QDB2Result::fetchNext(), QDB2Result::nextResult(), QDB2Driver::open(), QDB2Result::prepare(), QDB2Result::reset(), QDB2Driver::rollbackTransaction(), and QDB2Driver::setAutoCommit().

169 {
170  return QSqlError(QLatin1String("QDB2: ") + err, qDB2Warn(p), type);
171 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
int type
Definition: qmetatype.cpp:239
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QString qDB2Warn(const QDB2DriverPrivate *d)
Definition: qsql_db2.cpp:142

◆ qMakeError() [2/2]

static QSqlError qMakeError ( const QString err,
QSqlError::ErrorType  type,
const QDB2ResultPrivate p 
)
static

Definition at line 173 of file qsql_db2.cpp.

175 {
176  return QSqlError(QLatin1String("QDB2: ") + err, qDB2Warn(p), type);
177 }
The QSqlError class provides SQL database error information.
Definition: qsqlerror.h:53
int type
Definition: qmetatype.cpp:239
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static QString qDB2Warn(const QDB2DriverPrivate *d)
Definition: qsql_db2.cpp:142

◆ qMakeFieldInfo() [1/2]

static QSqlField qMakeFieldInfo ( const QDB2ResultPrivate d,
int  i 
)
static

Definition at line 234 of file qsql_db2.cpp.

Referenced by QDB2Result::exec(), QDB2Result::nextResult(), QDB2Driver::record(), and QDB2Result::reset().

235 {
236  SQLSMALLINT colNameLen;
237  SQLSMALLINT colType;
238  SQLUINTEGER colSize;
239  SQLSMALLINT colScale;
240  SQLSMALLINT nullable;
241  SQLRETURN r = SQL_ERROR;
242  SQLTCHAR colName[COLNAMESIZE];
243  r = SQLDescribeCol(d->hStmt,
244  i+1,
245  colName,
246  (SQLSMALLINT) COLNAMESIZE,
247  &colNameLen,
248  &colType,
249  &colSize,
250  &colScale,
251  &nullable);
252 
253  if (r != SQL_SUCCESS) {
254  qSqlWarning(QString::fromLatin1("qMakeFieldInfo: Unable to describe column %1").arg(i), d);
255  return QSqlField();
256  }
257  QSqlField f(qFromTChar(colName), qDecodeDB2Type(colType));
258  // nullable can be SQL_NO_NULLS, SQL_NULLABLE or SQL_NULLABLE_UNKNOWN
259  if (nullable == SQL_NO_NULLS)
260  f.setRequired(true);
261  else if (nullable == SQL_NULLABLE)
262  f.setRequired(false);
263  // else required is unknown
264  f.setLength(colSize == 0 ? -1 : int(colSize));
265  f.setPrecision(colScale == 0 ? -1 : int(colScale));
266  f.setSqlType(int(colType));
267  return f;
268 }
static void qSqlWarning(const QString &message, const QDB2DriverPrivate *d)
Definition: qsql_db2.cpp:155
SQLHANDLE hStmt
Definition: qsql_db2.cpp:105
static QVariant::Type qDecodeDB2Type(SQLSMALLINT sqltype)
Definition: qsql_db2.cpp:179
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
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
static const int COLNAMESIZE
Definition: qsql_db2.cpp:70
static QString qFromTChar(SQLTCHAR *str)
Definition: qsql_db2.cpp:110

◆ qMakeFieldInfo() [2/2]

static QSqlField qMakeFieldInfo ( const SQLHANDLE  hStmt)
static

Definition at line 453 of file qsql_db2.cpp.

454 {
455  bool isNull;
456  int type = qGetIntData(hStmt, 4, isNull);
457  QSqlField f(qGetStringData(hStmt, 3, -1, isNull), qDecodeDB2Type(type));
458  int required = qGetIntData(hStmt, 10, isNull); // nullable-flag
459  // required can be SQL_NO_NULLS, SQL_NULLABLE or SQL_NULLABLE_UNKNOWN
460  if (required == SQL_NO_NULLS)
461  f.setRequired(true);
462  else if (required == SQL_NULLABLE)
463  f.setRequired(false);
464  // else we don't know.
465  f.setLength(qGetIntData(hStmt, 6, isNull)); // column size
466  f.setPrecision(qGetIntData(hStmt, 8, isNull)); // precision
467  f.setSqlType(type);
468  return f;
469 }
int type
Definition: qmetatype.cpp:239
static QVariant::Type qDecodeDB2Type(SQLSMALLINT sqltype)
Definition: qsql_db2.cpp:179
static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool &isNull)
Definition: qsql_db2.cpp:324
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
static int qGetIntData(SQLHANDLE hStmt, int column, bool &isNull)
Definition: qsql_db2.cpp:270
static bool isNull(const QVariant::Private *d)
Definition: qvariant.cpp:300

◆ qMakeStatement()

static bool qMakeStatement ( QDB2ResultPrivate d,
bool  forwardOnly,
bool  setForwardOnly = true 
)
static

Definition at line 471 of file qsql_db2.cpp.

Referenced by QDB2Result::exec(), QDB2Result::prepare(), and QDB2Result::reset().

472 {
473  SQLRETURN r;
474  if (!d->hStmt) {
475  r = SQLAllocHandle(SQL_HANDLE_STMT,
476  d->dp->hDbc,
477  &d->hStmt);
478  if (r != SQL_SUCCESS) {
479  qSqlWarning(QLatin1String("QDB2Result::reset: Unable to allocate statement handle"), d);
480  return false;
481  }
482  } else {
483  r = SQLFreeStmt(d->hStmt, SQL_CLOSE);
484  if (r != SQL_SUCCESS) {
485  qSqlWarning(QLatin1String("QDB2Result::reset: Unable to close statement handle"), d);
486  return false;
487  }
488  }
489 
490  if (!setForwardOnly)
491  return true;
492 
493  if (forwardOnly) {
494  r = SQLSetStmtAttr(d->hStmt,
495  SQL_ATTR_CURSOR_TYPE,
496  (SQLPOINTER) SQL_CURSOR_FORWARD_ONLY,
497  SQL_IS_UINTEGER);
498  } else {
499  r = SQLSetStmtAttr(d->hStmt,
500  SQL_ATTR_CURSOR_TYPE,
501  (SQLPOINTER) SQL_CURSOR_STATIC,
502  SQL_IS_UINTEGER);
503  }
504  if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) {
505  qSqlWarning(QString::fromLatin1("QDB2Result::reset: Unable to set %1 attribute.").arg(
506  forwardOnly ? QLatin1String("SQL_CURSOR_FORWARD_ONLY")
507  : QLatin1String("SQL_CURSOR_STATIC")), d);
508  return false;
509  }
510  return true;
511 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
const QDB2DriverPrivate * dp
Definition: qsql_db2.cpp:104
static void qSqlWarning(const QString &message, const QDB2DriverPrivate *d)
Definition: qsql_db2.cpp:155
SQLHANDLE hStmt
Definition: qsql_db2.cpp:105
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
SQLHANDLE hDbc
Definition: qsql_db2.cpp:78

◆ qSplitTableQualifier()

static void qSplitTableQualifier ( const QString qualifier,
QString catalog,
QString schema,
QString table 
)
static

Definition at line 420 of file qsql_db2.cpp.

Referenced by QDB2Driver::primaryIndex(), and QDB2Driver::record().

422 {
423  if (!catalog || !schema || !table)
424  return;
425  QStringList l = qualifier.split(QLatin1Char('.'));
426  if (l.count() > 3)
427  return; // can't possibly be a valid table qualifier
428  int i = 0, n = l.count();
429  if (n == 1) {
430  *table = qualifier;
431  } else {
432  for (QStringList::Iterator it = l.begin(); it != l.end(); ++it) {
433  if (n == 3) {
434  if (i == 0)
435  *catalog = *it;
436  else if (i == 1)
437  *schema = *it;
438  else if (i == 2)
439  *table = *it;
440  } else if (n == 2) {
441  if (i == 0)
442  *schema = *it;
443  else if (i == 1)
444  *table = *it;
445  }
446  i++;
447  }
448  }
449 }
#define it(className, varName)
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
iterator Iterator
Qt-style synonym for QList::iterator.
Definition: qlist.h:278
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
Definition: qlist.h:270
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
QFactoryLoader * l
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
Definition: qstring.cpp:6526
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ qSqlWarning() [1/2]

static void qSqlWarning ( const QString message,
const QDB2DriverPrivate d 
)
static

Definition at line 155 of file qsql_db2.cpp.

Referenced by QDB2Driver::close(), QDB2Result::numRowsAffected(), QDB2Driver::open(), QDB2Driver::primaryIndex(), qMakeFieldInfo(), qMakeStatement(), QDB2Driver::record(), QDB2Driver::tables(), and QDB2Result::~QDB2Result().

156 {
157  qWarning("%s\tError: %s", message.toLocal8Bit().constData(),
159 }
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
static QString qDB2Warn(const QDB2DriverPrivate *d)
Definition: qsql_db2.cpp:142
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433

◆ qSqlWarning() [2/2]

static void qSqlWarning ( const QString message,
const QDB2ResultPrivate d 
)
static

Definition at line 161 of file qsql_db2.cpp.

162 {
163  qWarning("%s\tError: %s", message.toLocal8Bit().constData(),
165 }
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
static QString qDB2Warn(const QDB2DriverPrivate *d)
Definition: qsql_db2.cpp:142
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433

◆ qToTChar()

static SQLTCHAR* qToTChar ( const QString str)
static

Definition at line 117 of file qsql_db2.cpp.

Referenced by QDB2Driver::open(), QDB2Result::prepare(), QDB2Driver::primaryIndex(), QDB2Driver::record(), QDB2Result::reset(), and QDB2Driver::tables().

118 {
119  return (SQLTCHAR*)str.utf16();
120 }
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ qWarnDB2Handle()

static QString qWarnDB2Handle ( int  handleType,
SQLHANDLE  handle 
)
static

Definition at line 122 of file qsql_db2.cpp.

Referenced by qDB2Warn().

123 {
124  SQLINTEGER nativeCode;
125  SQLSMALLINT msgLen;
126  SQLRETURN r = SQL_ERROR;
127  SQLTCHAR state[SQL_SQLSTATE_SIZE + 1];
128  SQLTCHAR description[SQL_MAX_MESSAGE_LENGTH];
129  r = SQLGetDiagRec(handleType,
130  handle,
131  1,
132  (SQLTCHAR*) state,
133  &nativeCode,
134  (SQLTCHAR*) description,
135  SQL_MAX_MESSAGE_LENGTH - 1, /* in bytes, not in characters */
136  &msgLen);
137  if (r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO)
138  return QString(qFromTChar(description));
139  return QString();
140 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QString qFromTChar(SQLTCHAR *str)
Definition: qsql_db2.cpp:110

Variable Documentation

◆ COLNAMESIZE

const int COLNAMESIZE = 255
static

Definition at line 70 of file qsql_db2.cpp.

Referenced by qGetBinaryData(), and qMakeFieldInfo().

◆ qParamType

const SQLSMALLINT qParamType[4] = { SQL_PARAM_INPUT, SQL_PARAM_INPUT, SQL_PARAM_OUTPUT, SQL_PARAM_INPUT_OUTPUT }
static

Definition at line 71 of file qsql_db2.cpp.

Referenced by QDB2Result::exec().