Qt 4.8
Classes | Macros | Typedefs | Enumerations | Functions
qsql_ibase.cpp File Reference
#include "qsql_ibase.h"
#include <qcoreapplication.h>
#include <qdatetime.h>
#include <qvariant.h>
#include <qsqlerror.h>
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <qlist.h>
#include <qvector.h>
#include <qtextcodec.h>
#include <qmutex.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
#include <qdebug.h>
#include <QVarLengthArray>

Go to the source code of this file.

Classes

class  QIBaseDriverPrivate
 
struct  QIBaseEventBuffer
 
class  QIBaseResultPrivate
 

Macros

#define FBVERSION   SQL_DIALECT_V6
 
#define SQLDA_CURRENT_VERSION   SQLDA_VERSION1
 

Typedefs

typedef QMap< void *, QIBaseDriver * > QIBaseBufferDriverMap
 

Enumerations

enum  { QIBaseChunkSize = SHRT_MAX / 2 }
 

Functions

static char * createArrayBuffer (char *buffer, const QList< QVariant > &list, QVariant::Type type, short curDim, ISC_ARRAY_DESC *arrayDesc, QString &error, QTextCodec *tc)
 
static void createDA (XSQLDA *&sqlda)
 
static void delDA (XSQLDA *&sqlda)
 
static QByteArray encodeString (QTextCodec *tc, const QString &str)
 
static void enlargeDA (XSQLDA *&sqlda, int n)
 
template<typename T >
static char * fillList (char *buffer, const QList< QVariant > &list, T *=0)
 
template<>
char * fillList< float > (char *buffer, const QList< QVariant > &list, float *)
 
static QDate fromDate (char *buffer)
 
static QTime fromTime (char *buffer)
 
static QDateTime fromTimeStamp (char *buffer)
 
static bool getIBaseError (QString &msg, ISC_STATUS *status, ISC_LONG &sqlcode, QTextCodec *tc)
 
static void initDA (XSQLDA *sqlda)
 
 Q_GLOBAL_STATIC (QMutex, qMutex)
 
static isc_callback qEventCallback (char *result, short length, char *updated)
 
static char * qFillBufferWithString (char *buffer, const QString &string, short buflen, bool varying, bool array, QTextCodec *tc)
 
static void qFreeEventBuffer (QIBaseEventBuffer *eBuffer)
 
static QVariant::Type qIBaseTypeName (int iType, bool hasScale)
 
static QVariant::Type qIBaseTypeName2 (int iType, bool hasScale)
 
static char * readArrayBuffer (QList< QVariant > &list, char *buffer, short curDim, short *numElements, ISC_ARRAY_DESC *arrayDesc, QTextCodec *tc)
 
static ISC_DATE toDate (const QDate &t)
 
template<typename T >
static QList< QVarianttoList (char **buf, int count, T *=0)
 
template<>
QList< QVarianttoList< long > (char **buf, int count, long *)
 
static ISC_TIME toTime (const QTime &t)
 
static ISC_TIMESTAMP toTimeStamp (const QDateTime &dt)
 

Macro Definition Documentation

◆ FBVERSION

#define FBVERSION   SQL_DIALECT_V6

◆ SQLDA_CURRENT_VERSION

#define SQLDA_CURRENT_VERSION   SQLDA_VERSION1

Definition at line 65 of file qsql_ibase.cpp.

Referenced by createDA(), and enlargeDA().

Typedef Documentation

◆ QIBaseBufferDriverMap

Definition at line 337 of file qsql_ibase.cpp.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
QIBaseChunkSize 

Definition at line 68 of file qsql_ibase.cpp.

68 { QIBaseChunkSize = SHRT_MAX / 2 };

Function Documentation

◆ createArrayBuffer()

static char* createArrayBuffer ( char *  buffer,
const QList< QVariant > &  list,
QVariant::Type  type,
short  curDim,
ISC_ARRAY_DESC *  arrayDesc,
QString error,
QTextCodec tc 
)
static

Definition at line 675 of file qsql_ibase.cpp.

Referenced by QIBaseResultPrivate::writeArray().

678 {
679  int i;
680  ISC_ARRAY_BOUND *bounds = arrayDesc->array_desc_bounds;
681  short dim = arrayDesc->array_desc_dimensions - 1;
682 
683  int elements = (bounds[curDim].array_bound_upper -
684  bounds[curDim].array_bound_lower + 1);
685 
686  if (list.size() != elements) { // size mismatch
687  error = QLatin1String("Expected size: %1. Supplied size: %2");
688  error = QLatin1String("Array size mismatch. Fieldname: %1 ")
689  + error.arg(elements).arg(list.size());
690  return 0;
691  }
692 
693  if (curDim != dim) {
694  for(i = 0; i < list.size(); ++i) {
695 
696  if (list.at(i).type() != QVariant::List) { // dimensions mismatch
697  error = QLatin1String("Array dimensons mismatch. Fieldname: %1");
698  return 0;
699  }
700 
701  buffer = createArrayBuffer(buffer, list.at(i).toList(), type, curDim + 1,
702  arrayDesc, error, tc);
703  if (!buffer)
704  return 0;
705  }
706  } else {
707  switch(type) {
708  case QVariant::Int:
709  case QVariant::UInt:
710  if (arrayDesc->array_desc_dtype == blr_short)
711  buffer = fillList<short>(buffer, list);
712  else
713  buffer = fillList<int>(buffer, list);
714  break;
715  case QVariant::Double:
716  if (arrayDesc->array_desc_dtype == blr_float)
717  buffer = fillList<float>(buffer, list, static_cast<float *>(0));
718  else
719  buffer = fillList<double>(buffer, list);
720  break;
721  case QVariant::LongLong:
722  buffer = fillList<qint64>(buffer, list);
723  break;
724  case QVariant::ULongLong:
725  buffer = fillList<quint64>(buffer, list);
726  break;
727  case QVariant::String:
728  for (i = 0; i < list.size(); ++i)
729  buffer = qFillBufferWithString(buffer, list.at(i).toString(),
730  arrayDesc->array_desc_length,
731  arrayDesc->array_desc_dtype == blr_varying,
732  true, tc);
733  break;
734  case QVariant::Date:
735  for (i = 0; i < list.size(); ++i) {
736  *((ISC_DATE*)buffer) = toDate(list.at(i).toDate());
737  buffer += sizeof(ISC_DATE);
738  }
739  break;
740  case QVariant::Time:
741  for (i = 0; i < list.size(); ++i) {
742  *((ISC_TIME*)buffer) = toTime(list.at(i).toTime());
743  buffer += sizeof(ISC_TIME);
744  }
745  break;
746 
747  case QVariant::DateTime:
748  for (i = 0; i < list.size(); ++i) {
749  *((ISC_TIMESTAMP*)buffer) = toTimeStamp(list.at(i).toDateTime());
750  buffer += sizeof(ISC_TIMESTAMP);
751  }
752  break;
753  default:
754  break;
755  }
756  }
757  return buffer;
758 }
int type
Definition: qmetatype.cpp:239
static ISC_DATE toDate(const QDate &t)
Definition: qsql_ibase.cpp:268
char * fillList< float >(char *buffer, const QList< QVariant > &list, float *)
Definition: qsql_ibase.cpp:637
static char * qFillBufferWithString(char *buffer, const QString &string, short buflen, bool varying, bool array, QTextCodec *tc)
Definition: qsql_ibase.cpp:650
#define error(msg)
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
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
QList< QVariant > toList() const
Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise return...
Definition: qvariant.cpp:2751
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static ISC_TIMESTAMP toTimeStamp(const QDateTime &dt)
Definition: qsql_ibase.cpp:228
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2311
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
static const QTextHtmlElement elements[Html_NumElements]
static ISC_TIME toTime(const QTime &t)
Definition: qsql_ibase.cpp:252
QTime toTime() const
Returns the variant as a QTime if the variant has type() Time , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2330

◆ createDA()

static void createDA ( XSQLDA *&  sqlda)
static

Definition at line 97 of file qsql_ibase.cpp.

Referenced by QIBaseResult::prepare().

98 {
99  sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(1));
100  if (sqlda == (XSQLDA*)0) return;
101  sqlda->sqln = 1;
102  sqlda->sqld = 0;
103  sqlda->version = SQLDA_CURRENT_VERSION;
104  sqlda->sqlvar[0].sqlind = 0;
105  sqlda->sqlvar[0].sqldata = 0;
106 }
#define SQLDA_CURRENT_VERSION
Definition: qsql_ibase.cpp:65

◆ delDA()

static void delDA ( XSQLDA *&  sqlda)
static

Definition at line 155 of file qsql_ibase.cpp.

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

156 {
157  if (!sqlda)
158  return;
159  for (int i = 0; i < sqlda->sqld; ++i) {
160  delete [] sqlda->sqlvar[i].sqlind;
161  delete [] sqlda->sqlvar[i].sqldata;
162  }
163  free(sqlda);
164  sqlda = 0;
165 }

◆ encodeString()

static QByteArray encodeString ( QTextCodec tc,
const QString str 
)
static

Definition at line 289 of file qsql_ibase.cpp.

Referenced by QKeySequence::operator>=(), QIBaseResult::prepare(), and qFillBufferWithString().

290 {
291  if (tc)
292  return tc->fromUnicode(str);
293  return str.toUtf8();
294 }
QByteArray toUtf8() const Q_REQUIRED_RESULT
Returns a UTF-8 representation of the string as a QByteArray.
Definition: qstring.cpp:4074
QByteArray fromUnicode(const QString &uc) const
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray...

◆ enlargeDA()

static void enlargeDA ( XSQLDA *&  sqlda,
int  n 
)
static

Definition at line 108 of file qsql_ibase.cpp.

Referenced by QIBaseResult::prepare().

109 {
110  if (sqlda != (XSQLDA*)0)
111  free(sqlda);
112  sqlda = (XSQLDA *) malloc(XSQLDA_LENGTH(n));
113  if (sqlda == (XSQLDA*)0) return;
114  sqlda->sqln = n;
115  sqlda->version = SQLDA_CURRENT_VERSION;
116 }
#define SQLDA_CURRENT_VERSION
Definition: qsql_ibase.cpp:65

◆ fillList()

template<typename T >
static char* fillList ( char *  buffer,
const QList< QVariant > &  list,
T *  = 0 
)
static

Definition at line 625 of file qsql_ibase.cpp.

626 {
627  for (int i = 0; i < list.size(); ++i) {
628  T val;
629  val = qvariant_cast<T>(list.at(i));
630  memcpy(buffer, &val, sizeof(T));
631  buffer += sizeof(T);
632  }
633  return buffer;
634 }
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571

◆ fillList< float >()

template<>
char* fillList< float > ( char *  buffer,
const QList< QVariant > &  list,
float *   
)

Definition at line 637 of file qsql_ibase.cpp.

Referenced by createArrayBuffer().

638 {
639  for (int i = 0; i < list.size(); ++i) {
640  double val;
641  float val2 = 0;
642  val = qvariant_cast<double>(list.at(i));
643  val2 = (float)val;
644  memcpy(buffer, &val2, sizeof(float));
645  buffer += sizeof(float);
646  }
647  return buffer;
648 }
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
int size() const
Returns the number of items in the list.
Definition: qlist.h:137
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571

◆ fromDate()

static QDate fromDate ( char *  buffer)
static

Definition at line 277 of file qsql_ibase.cpp.

Referenced by QIBaseResult::gotoNext(), and readArrayBuffer().

278 {
279  static const QDate bd(1858, 11, 17);
280  QDate d;
281 
282  // have to demangle the structure ourselves because isc_decode_time
283  // strips the msecs
284  d = bd.addDays(int(((ISC_TIMESTAMP*)buffer)->timestamp_date));
285 
286  return d;
287 }
double d
Definition: qnumeric_p.h:62
The QDate class provides date functions.
Definition: qdatetime.h:55
QDate addDays(int days) const
Returns a QDate object containing a date ndays later than the date of this object (or earlier if nday...
Definition: qdatetime.cpp:989

◆ fromTime()

static QTime fromTime ( char *  buffer)
static

Definition at line 258 of file qsql_ibase.cpp.

Referenced by QIBaseResult::gotoNext(), and readArrayBuffer().

259 {
260  QTime t;
261  // have to demangle the structure ourselves because isc_decode_time
262  // strips the msecs
263  t = t.addMSecs(int((*(ISC_TIME*)buffer) / 10));
264 
265  return t;
266 }
The QTime class provides clock time functions.
Definition: qdatetime.h:148
QTime addMSecs(int ms) const
Returns a QTime object containing a time ms milliseconds later than the time of this object (or earli...
Definition: qdatetime.cpp:1803

◆ fromTimeStamp()

static QDateTime fromTimeStamp ( char *  buffer)
static

Definition at line 238 of file qsql_ibase.cpp.

Referenced by QIBaseResult::gotoNext(), and readArrayBuffer().

239 {
240  static const QDate bd(1858, 11, 17);
241  QTime t;
242  QDate d;
243 
244  // have to demangle the structure ourselves because isc_decode_time
245  // strips the msecs
246  t = t.addMSecs(int(((ISC_TIMESTAMP*)buffer)->timestamp_time / 10));
247  d = bd.addDays(int(((ISC_TIMESTAMP*)buffer)->timestamp_date));
248 
249  return QDateTime(d, t);
250 }
double d
Definition: qnumeric_p.h:62
The QDate class provides date functions.
Definition: qdatetime.h:55
The QTime class provides clock time functions.
Definition: qdatetime.h:148
QDate addDays(int days) const
Returns a QDate object containing a date ndays later than the date of this object (or earlier if nday...
Definition: qdatetime.cpp:989
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
QTime addMSecs(int ms) const
Returns a QTime object containing a time ms milliseconds later than the time of this object (or earli...
Definition: qdatetime.cpp:1803

◆ getIBaseError()

static bool getIBaseError ( QString msg,
ISC_STATUS *  status,
ISC_LONG &  sqlcode,
QTextCodec tc 
)
static

Definition at line 73 of file qsql_ibase.cpp.

Referenced by QIBaseDriverPrivate::isError(), and QIBaseResultPrivate::isError().

75 {
76  if (status[0] != 1 || status[1] <= 0)
77  return false;
78 
79  msg.clear();
80  sqlcode = isc_sqlcode(status);
81  char buf[512];
82 #if defined(FB_API_VER) && FB_API_VER >= 20
83  while(fb_interpret(buf, 512, &status)) {
84 #else
85  while(isc_interprete(buf, &status)) {
86 #endif
87  if(!msg.isEmpty())
88  msg += QLatin1String(" - ");
89  if (tc)
90  msg += tc->toUnicode(buf);
91  else
92  msg += QString::fromUtf8(buf);
93  }
94  return true;
95 }
static LibLoadStatus status
Definition: qlocale_icu.cpp:69
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
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
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
void clear()
Clears the contents of the string and makes it empty.
Definition: qstring.h:723

◆ initDA()

static void initDA ( XSQLDA *  sqlda)
static

Definition at line 118 of file qsql_ibase.cpp.

Referenced by QIBaseResult::prepare().

119 {
120  for (int i = 0; i < sqlda->sqld; ++i) {
121  switch (sqlda->sqlvar[i].sqltype & ~1) {
122  case SQL_INT64:
123  case SQL_LONG:
124  case SQL_SHORT:
125  case SQL_FLOAT:
126  case SQL_DOUBLE:
127  case SQL_TIMESTAMP:
128  case SQL_TYPE_TIME:
129  case SQL_TYPE_DATE:
130  case SQL_TEXT:
131  case SQL_BLOB:
132  sqlda->sqlvar[i].sqldata = new char[sqlda->sqlvar[i].sqllen];
133  break;
134  case SQL_ARRAY:
135  sqlda->sqlvar[i].sqldata = new char[sizeof(ISC_QUAD)];
136  memset(sqlda->sqlvar[i].sqldata, 0, sizeof(ISC_QUAD));
137  break;
138  case SQL_VARYING:
139  sqlda->sqlvar[i].sqldata = new char[sqlda->sqlvar[i].sqllen + sizeof(short)];
140  break;
141  default:
142  // not supported - do not bind.
143  sqlda->sqlvar[i].sqldata = 0;
144  break;
145  }
146  if (sqlda->sqlvar[i].sqltype & 1) {
147  sqlda->sqlvar[i].sqlind = new short[1];
148  *(sqlda->sqlvar[i].sqlind) = 0;
149  } else {
150  sqlda->sqlvar[i].sqlind = 0;
151  }
152  }
153 }

◆ Q_GLOBAL_STATIC()

Q_GLOBAL_STATIC ( QMutex  ,
qMutex   
)

◆ qEventCallback()

static isc_callback qEventCallback ( char *  result,
short  length,
char *  updated 
)
static

Definition at line 1727 of file qsql_ibase.cpp.

Referenced by QIBaseDriver::handle(), QIBaseDriver::qHandleEventNotification(), and QIBaseDriver::subscribeToNotificationImplementation().

1729 {
1730  if (!updated)
1731  return 0;
1732 
1733 
1734  memcpy(result, updated, length);
1735  qMutex()->lock();
1736  QIBaseDriver *driver = qBufferDriverMap()->value(result);
1737  qMutex()->unlock();
1738 
1739  // We use an asynchronous call (i.e., queued connection) because the event callback
1740  // is executed in a different thread than the one in which the driver lives.
1741  if (driver)
1742  QMetaObject::invokeMethod(driver, "qHandleEventNotification", Qt::QueuedConnection, Q_ARG(void *, reinterpret_cast<void *>(result)));
1743 
1744  return 0;
1745 }
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.

◆ qFillBufferWithString()

static char* qFillBufferWithString ( char *  buffer,
const QString string,
short  buflen,
bool  varying,
bool  array,
QTextCodec tc 
)
static

Definition at line 650 of file qsql_ibase.cpp.

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

653 {
654  QByteArray str = encodeString(tc, string); // keep a copy of the string alive in this scope
655  if (varying) {
656  short tmpBuflen = buflen;
657  if (str.length() < buflen)
658  buflen = str.length();
659  if (array) { // interbase stores varying arrayelements different than normal varying elements
660  memcpy(buffer, str.data(), buflen);
661  memset(buffer + buflen, 0, tmpBuflen - buflen);
662  } else {
663  *(short*)buffer = buflen; // first two bytes is the length
664  memcpy(buffer + sizeof(short), str.data(), buflen);
665  }
666  buffer += tmpBuflen;
667  } else {
668  str = str.leftJustified(buflen, ' ', true);
669  memcpy(buffer, str.data(), buflen);
670  buffer += buflen;
671  }
672  return buffer;
673 }
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
static QByteArray encodeString(QTextCodec *tc, const QString &str)
Definition: qsql_ibase.cpp:289
QByteArray leftJustified(int width, char fill=' ', bool truncate=false) const
Returns a byte array of size width that contains this byte array padded by the fill character...
int length() const
Same as size().
Definition: qbytearray.h:356

◆ qFreeEventBuffer()

static void qFreeEventBuffer ( QIBaseEventBuffer eBuffer)
static

Definition at line 341 of file qsql_ibase.cpp.

Referenced by QIBaseDriver::close(), QIBaseDriver::subscribeToNotificationImplementation(), and QIBaseDriver::unsubscribeFromNotificationImplementation().

342 {
343  qMutex()->lock();
344  qBufferDriverMap()->remove(reinterpret_cast<void *>(eBuffer->resultBuffer));
345  qMutex()->unlock();
346  delete eBuffer;
347 }

◆ qIBaseTypeName()

static QVariant::Type qIBaseTypeName ( int  iType,
bool  hasScale 
)
static

Definition at line 167 of file qsql_ibase.cpp.

Referenced by QIBaseDriver::primaryIndex(), QIBaseDriver::record(), and QIBaseResultPrivate::writeArray().

168 {
169  switch (iType) {
170  case blr_varying:
171  case blr_varying2:
172  case blr_text:
173  case blr_cstring:
174  case blr_cstring2:
175  return QVariant::String;
176  case blr_sql_time:
177  return QVariant::Time;
178  case blr_sql_date:
179  return QVariant::Date;
180  case blr_timestamp:
181  return QVariant::DateTime;
182  case blr_blob:
183  return QVariant::ByteArray;
184  case blr_quad:
185  case blr_short:
186  case blr_long:
187  return (hasScale ? QVariant::Double : QVariant::Int);
188  case blr_int64:
189  return (hasScale ? QVariant::Double : QVariant::LongLong);
190  case blr_float:
191  case blr_d_float:
192  case blr_double:
193  return QVariant::Double;
194  }
195  qWarning("qIBaseTypeName: unknown datatype: %d", iType);
196  return QVariant::Invalid;
197 }
#define iType(varName, parent)
Q_CORE_EXPORT void qWarning(const char *,...)

◆ qIBaseTypeName2()

static QVariant::Type qIBaseTypeName2 ( int  iType,
bool  hasScale 
)
static

Definition at line 199 of file qsql_ibase.cpp.

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

200 {
201  switch(iType & ~1) {
202  case SQL_VARYING:
203  case SQL_TEXT:
204  return QVariant::String;
205  case SQL_LONG:
206  case SQL_SHORT:
207  return (hasScale ? QVariant::Double : QVariant::Int);
208  case SQL_INT64:
209  return (hasScale ? QVariant::Double : QVariant::LongLong);
210  case SQL_FLOAT:
211  case SQL_DOUBLE:
212  return QVariant::Double;
213  case SQL_TIMESTAMP:
214  return QVariant::DateTime;
215  case SQL_TYPE_TIME:
216  return QVariant::Time;
217  case SQL_TYPE_DATE:
218  return QVariant::Date;
219  case SQL_ARRAY:
220  return QVariant::List;
221  case SQL_BLOB:
222  return QVariant::ByteArray;
223  default:
224  return QVariant::Invalid;
225  }
226 }
#define iType(varName, parent)

◆ readArrayBuffer()

static char* readArrayBuffer ( QList< QVariant > &  list,
char *  buffer,
short  curDim,
short *  numElements,
ISC_ARRAY_DESC *  arrayDesc,
QTextCodec tc 
)
static

Definition at line 496 of file qsql_ibase.cpp.

Referenced by QIBaseResultPrivate::fetchArray().

499 {
500  const short dim = arrayDesc->array_desc_dimensions - 1;
501  const unsigned char dataType = arrayDesc->array_desc_dtype;
502  QList<QVariant> valList;
503  unsigned short strLen = arrayDesc->array_desc_length;
504 
505  if (curDim != dim) {
506  for(int i = 0; i < numElements[curDim]; ++i)
507  buffer = readArrayBuffer(list, buffer, curDim + 1, numElements,
508  arrayDesc, tc);
509  } else {
510  switch(dataType) {
511  case blr_varying:
512  case blr_varying2:
513  strLen += 2; // for the two terminating null values
514  case blr_text:
515  case blr_text2: {
516  int o;
517  for (int i = 0; i < numElements[dim]; ++i) {
518  for(o = 0; o < strLen && buffer[o]!=0; ++o )
519  ;
520 
521  if (tc)
522  valList.append(tc->toUnicode(buffer, o));
523  else
524  valList.append(QString::fromUtf8(buffer, o));
525 
526  buffer += strLen;
527  }
528  break; }
529  case blr_long:
530  valList = toList<long>(&buffer, numElements[dim], static_cast<long *>(0));
531  break;
532  case blr_short:
533  valList = toList<short>(&buffer, numElements[dim]);
534  break;
535  case blr_int64:
536  valList = toList<qint64>(&buffer, numElements[dim]);
537  break;
538  case blr_float:
539  valList = toList<float>(&buffer, numElements[dim]);
540  break;
541  case blr_double:
542  valList = toList<double>(&buffer, numElements[dim]);
543  break;
544  case blr_timestamp:
545  for(int i = 0; i < numElements[dim]; ++i) {
546  valList.append(fromTimeStamp(buffer));
547  buffer += sizeof(ISC_TIMESTAMP);
548  }
549  break;
550  case blr_sql_time:
551  for(int i = 0; i < numElements[dim]; ++i) {
552  valList.append(fromTime(buffer));
553  buffer += sizeof(ISC_TIME);
554  }
555  break;
556  case blr_sql_date:
557  for(int i = 0; i < numElements[dim]; ++i) {
558  valList.append(fromDate(buffer));
559  buffer += sizeof(ISC_DATE);
560  }
561  break;
562  }
563  }
564  if (dim > 0)
565  list.append(valList);
566  else
567  list += valList;
568  return buffer;
569 }
QList< QVariant > toList< long >(char **buf, int count, long *)
Definition: qsql_ibase.cpp:483
static char * readArrayBuffer(QList< QVariant > &list, char *buffer, short curDim, short *numElements, ISC_ARRAY_DESC *arrayDesc, QTextCodec *tc)
Definition: qsql_ibase.cpp:496
static QDateTime fromTimeStamp(char *buffer)
Definition: qsql_ibase.cpp:238
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
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
QString toUnicode(const QByteArray &) const
Converts a from the encoding of this codec to Unicode, and returns the result in a QString...
static QDate fromDate(char *buffer)
Definition: qsql_ibase.cpp:277

◆ toDate()

static ISC_DATE toDate ( const QDate t)
static

Definition at line 268 of file qsql_ibase.cpp.

Referenced by createArrayBuffer(), QIBaseResult::exec(), and QVariant::swap().

269 {
270  static const QDate basedate(1858, 11, 17);
271  ISC_DATE date;
272 
273  date = basedate.daysTo(t);
274  return date;
275 }
The QDate class provides date functions.
Definition: qdatetime.h:55

◆ toList()

template<typename T >
static QList<QVariant> toList ( char **  buf,
int  count,
T *  = 0 
)
static

Definition at line 472 of file qsql_ibase.cpp.

Referenced by Maemo::appendVariantToDBusMessage(), QEventDispatcherWin32::createInternalHwnd(), operator<<(), QVector< QPoint >::operator<<(), QTreeModel::sortItems(), and QVariant::swap().

473 {
474  QList<QVariant> res;
475  for (int i = 0; i < count; ++i) {
476  res.append(*(T*)(*buf));
477  *buf += sizeof(T);
478  }
479  return res;
480 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507

◆ toList< long >()

template<>
QList<QVariant> toList< long > ( char **  buf,
int  count,
long *   
)

Definition at line 483 of file qsql_ibase.cpp.

Referenced by readArrayBuffer().

484 {
485  QList<QVariant> res;
486  for (int i = 0; i < count; ++i) {
487  if (sizeof(int) == sizeof(long))
488  res.append(int((*(long*)(*buf))));
489  else
490  res.append((qint64)(*(long*)(*buf)));
491  *buf += sizeof(long);
492  }
493  return res;
494 }
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
__int64 qint64
Definition: qglobal.h:942

◆ toTime()

static ISC_TIME toTime ( const QTime t)
static

Definition at line 252 of file qsql_ibase.cpp.

Referenced by createArrayBuffer(), QIBaseResult::exec(), and QVariant::swap().

253 {
254  static const QTime midnight(0, 0, 0, 0);
255  return (ISC_TIME)midnight.msecsTo(t) * 10;
256 }
The QTime class provides clock time functions.
Definition: qdatetime.h:148

◆ toTimeStamp()

static ISC_TIMESTAMP toTimeStamp ( const QDateTime dt)
static

Definition at line 228 of file qsql_ibase.cpp.

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

229 {
230  static const QTime midnight(0, 0, 0, 0);
231  static const QDate basedate(1858, 11, 17);
232  ISC_TIMESTAMP ts;
233  ts.timestamp_time = midnight.msecsTo(dt.time()) * 10;
234  ts.timestamp_date = basedate.daysTo(dt.date());
235  return ts;
236 }
The QDate class provides date functions.
Definition: qdatetime.h:55
The QTime class provides clock time functions.
Definition: qdatetime.h:148
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368