Qt 4.8
Classes | Macros | Typedefs | Functions
qsql_tds.cpp File Reference
#include <qglobal.h>
#include "qsql_tds.h"
#include <qvariant.h>
#include <qdatetime.h>
#include <qhash.h>
#include <qregexp.h>
#include <qsqlerror.h>
#include <qsqlfield.h>
#include <qsqlindex.h>
#include <qsqlquery.h>
#include <qstringlist.h>
#include <qvector.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

class  QTDSDriverPrivate
 
class  QTDSResultPrivate
 

Macros

#define CS_PUBLIC
 
#define Q_USE_SYBASE
 
#define QERRHANDLE   EHANDLEFUNC
 
#define QMSGHANDLE   MHANDLEFUNC
 
#define QTDSBINARY   SYBBINARY
 
#define QTDSBIT   SYBBIT
 
#define QTDSCHAR   SYBCHAR
 
#define QTDSDATETIME   SYBDATETIME
 
#define QTDSDATETIME4   SYBDATETIME4
 
#define QTDSDATETIME_N   SYBDATETIMN
 
#define QTDSDECIMAL   SYBDECIMAL
 
#define QTDSDECIMAL_2   55
 
#define QTDSFLT4   SYBREAL
 
#define QTDSFLT8   SYBFLT8
 
#define QTDSFLT8_N   SYBFLTN
 
#define QTDSIMAGE   SYBIMAGE
 
#define QTDSINT1   SYBINT1
 
#define QTDSINT2   SYBINT2
 
#define QTDSINT4   SYBINT4
 
#define QTDSINT4_N   SYBINTN
 
#define QTDSMONEY   SYBMONEY
 
#define QTDSMONEY4   SYBMONEY4
 
#define QTDSMONEY_N   SYBMONEYN
 
#define QTDSNUMERIC   SYBNUMERIC
 
#define QTDSNUMERIC_2   63
 
#define QTDSTEXT   SYBTEXT
 
#define QTDSVARBINARY   SYBVARBINARY
 
#define QTDSVARCHAR   SYBVARCHAR
 
#define TDS_CURSOR_SIZE   50
 

Typedefs

typedef QHash< DBPROCESS *, QTDSResultPrivate * > QTDSErrorHash
 

Functions

QVariant::Type qDecodeTDSType (int type)
 
QVariant::Type qFieldType (QTDSResultPrivate *d, int i)
 
static bool qIsNull (const void *ind)
 
QSqlError qMakeError (const QString &err, QSqlError::ErrorType type, int errNo=-1)
 
static int CS_PUBLIC qTdsErrHandler (DBPROCESS *dbproc, int, int dberr, int, char *dberrstr, char *oserrstr)
 
static int CS_PUBLIC qTdsMsgHandler (DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *, int line)
 

Macro Definition Documentation

◆ CS_PUBLIC

#define CS_PUBLIC

Definition at line 127 of file qsql_tds.cpp.

◆ Q_USE_SYBASE

#define Q_USE_SYBASE

Definition at line 48 of file qsql_tds.cpp.

◆ QERRHANDLE

#define QERRHANDLE   EHANDLEFUNC

Definition at line 95 of file qsql_tds.cpp.

Referenced by QTDSDriver::init().

◆ QMSGHANDLE

#define QMSGHANDLE   MHANDLEFUNC

Definition at line 94 of file qsql_tds.cpp.

Referenced by QTDSDriver::init().

◆ QTDSBINARY

#define QTDSBINARY   SYBBINARY

Definition at line 115 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSBIT

#define QTDSBIT   SYBBIT

Definition at line 114 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSCHAR

#define QTDSCHAR   SYBCHAR

Definition at line 96 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSDATETIME

#define QTDSDATETIME   SYBDATETIME

Definition at line 98 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSDATETIME4

#define QTDSDATETIME4   SYBDATETIME4

Definition at line 97 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSDATETIME_N

#define QTDSDATETIME_N   SYBDATETIMN

Definition at line 99 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSDECIMAL

#define QTDSDECIMAL   SYBDECIMAL

Definition at line 100 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSDECIMAL_2

#define QTDSDECIMAL_2   55

Definition at line 119 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSFLT4

#define QTDSFLT4   SYBREAL

Definition at line 103 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSFLT8

#define QTDSFLT8   SYBFLT8

Definition at line 101 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSFLT8_N

#define QTDSFLT8_N   SYBFLTN

Definition at line 102 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSIMAGE

#define QTDSIMAGE   SYBIMAGE

Definition at line 117 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSINT1

#define QTDSINT1   SYBINT1

Definition at line 104 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSINT2

#define QTDSINT2   SYBINT2

Definition at line 105 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSINT4

#define QTDSINT4   SYBINT4

Definition at line 106 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSINT4_N

#define QTDSINT4_N   SYBINTN

Definition at line 107 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSMONEY

#define QTDSMONEY   SYBMONEY

Definition at line 109 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSMONEY4

#define QTDSMONEY4   SYBMONEY4

Definition at line 108 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSMONEY_N

#define QTDSMONEY_N   SYBMONEYN

Definition at line 110 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSNUMERIC

#define QTDSNUMERIC   SYBNUMERIC

Definition at line 111 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSNUMERIC_2

#define QTDSNUMERIC_2   63

Definition at line 120 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSTEXT

#define QTDSTEXT   SYBTEXT

Definition at line 112 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSVARBINARY

#define QTDSVARBINARY   SYBVARBINARY

Definition at line 116 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ QTDSVARCHAR

#define QTDSVARCHAR   SYBVARCHAR

Definition at line 113 of file qsql_tds.cpp.

Referenced by qDecodeTDSType().

◆ TDS_CURSOR_SIZE

#define TDS_CURSOR_SIZE   50

Definition at line 123 of file qsql_tds.cpp.

Typedef Documentation

◆ QTDSErrorHash

typedef QHash<DBPROCESS *, QTDSResultPrivate *> QTDSErrorHash

Definition at line 163 of file qsql_tds.cpp.

Function Documentation

◆ qDecodeTDSType()

QVariant::Type qDecodeTDSType ( int  type)

Definition at line 238 of file qsql_tds.cpp.

Referenced by qFieldType(), QTDSDriver::record(), and QTDSResult::reset().

239 {
241  switch (type) {
242  case QTDSCHAR:
243  case QTDSTEXT:
244  case QTDSVARCHAR:
245  t = QVariant::String;
246  break;
247  case QTDSINT1:
248  case QTDSINT2:
249  case QTDSINT4:
250  case QTDSINT4_N:
251  case QTDSBIT:
252  t = QVariant::Int;
253  break;
254  case QTDSFLT4:
255  case QTDSFLT8:
256  case QTDSFLT8_N:
257  case QTDSMONEY4:
258  case QTDSMONEY:
259  case QTDSDECIMAL:
260  case QTDSNUMERIC:
261 #ifdef QTDSNUMERIC_2
262  case QTDSNUMERIC_2:
263 #endif
264 #ifdef QTDSDECIMAL_2
265  case QTDSDECIMAL_2:
266 #endif
267  case QTDSMONEY_N:
268  t = QVariant::Double;
269  break;
270  case QTDSDATETIME4:
271  case QTDSDATETIME:
272  case QTDSDATETIME_N:
273  t = QVariant::DateTime;
274  break;
275  case QTDSBINARY:
276  case QTDSVARBINARY:
277  case QTDSIMAGE:
279  break;
280  default:
281  t = QVariant::Invalid;
282  break;
283  }
284  return t;
285 }
#define QTDSVARBINARY
Definition: qsql_tds.cpp:116
int type
Definition: qmetatype.cpp:239
#define QTDSDECIMAL_2
Definition: qsql_tds.cpp:119
#define QTDSINT4_N
Definition: qsql_tds.cpp:107
#define QTDSFLT8_N
Definition: qsql_tds.cpp:102
#define QTDSCHAR
Definition: qsql_tds.cpp:96
#define QTDSDECIMAL
Definition: qsql_tds.cpp:100
#define QTDSINT1
Definition: qsql_tds.cpp:104
#define QTDSVARCHAR
Definition: qsql_tds.cpp:113
#define QTDSMONEY4
Definition: qsql_tds.cpp:108
#define QTDSDATETIME_N
Definition: qsql_tds.cpp:99
#define QTDSINT2
Definition: qsql_tds.cpp:105
#define QTDSFLT8
Definition: qsql_tds.cpp:101
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
#define QTDSDATETIME
Definition: qsql_tds.cpp:98
#define QTDSBINARY
Definition: qsql_tds.cpp:115
#define QTDSIMAGE
Definition: qsql_tds.cpp:117
#define QTDSNUMERIC
Definition: qsql_tds.cpp:111
#define QTDSTEXT
Definition: qsql_tds.cpp:112
#define QTDSINT4
Definition: qsql_tds.cpp:106
#define QTDSBIT
Definition: qsql_tds.cpp:114
#define QTDSFLT4
Definition: qsql_tds.cpp:103
#define QTDSNUMERIC_2
Definition: qsql_tds.cpp:120
#define QTDSMONEY_N
Definition: qsql_tds.cpp:110
#define QTDSDATETIME4
Definition: qsql_tds.cpp:97
#define QTDSMONEY
Definition: qsql_tds.cpp:109

◆ qFieldType()

QVariant::Type qFieldType ( QTDSResultPrivate d,
int  i 
)

Definition at line 287 of file qsql_tds.cpp.

288 {
289  QVariant::Type type = qDecodeTDSType(dbcoltype(d->dbproc, i+1));
290  return type;
291 }
int type
Definition: qmetatype.cpp:239
QVariant::Type qDecodeTDSType(int type)
Definition: qsql_tds.cpp:238
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
DBPROCESS * dbproc
Definition: qsql_tds.cpp:151

◆ qIsNull()

static bool qIsNull ( const void *  ind)
inlinestatic

Definition at line 340 of file qsql_tds.cpp.

Referenced by QTDSResult::gotoNext().

341 {
342  return *reinterpret_cast<const DBINT *>(&ind) == -1;
343 }

◆ qMakeError()

QSqlError qMakeError ( const QString err,
QSqlError::ErrorType  type,
int  errNo = -1 
)

Definition at line 130 of file qsql_tds.cpp.

Referenced by QTDSDriver::open(), qTdsErrHandler(), and qTdsMsgHandler().

131 {
132  return QSqlError(QLatin1String("QTDS: ") + err, QString(), type, errNo);
133 }
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
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ qTdsErrHandler()

static int CS_PUBLIC qTdsErrHandler ( DBPROCESS *  dbproc,
int  ,
int  dberr,
int  ,
char *  dberrstr,
char *  oserrstr 
)
static

Definition at line 204 of file qsql_tds.cpp.

Referenced by QTDSDriver::init().

210 {
211  QTDSResultPrivate* p = errs()->value(dbproc);
212  if (!p) {
213  qWarning("QTDSDriver error (%d): [%s] [%s]", dberr, dberrstr, oserrstr);
214  return INT_CANCEL;
215  }
216  /*
217  * If the process is dead or NULL and
218  * we are not in the middle of logging in...
219  */
220  if((dbproc == NULL || DBDEAD(dbproc))) {
221  qWarning("QTDSDriver error (%d): [%s] [%s]", dberr, dberrstr, oserrstr);
222  return INT_CANCEL;
223  }
224 
225 
226  QString errMsg = QString::fromLatin1("%1 %2\n").arg(QLatin1String(dberrstr)).arg(
227  QLatin1String(oserrstr));
228  errMsg += p->getErrorMsgs();
229  p->lastError = qMakeError(errMsg, QSqlError::UnknownError, dberr);
230  p->clearErrorMsgs();
231 
232  return INT_CANCEL ;
233 }
QSqlError lastError
Definition: qsql_tds.cpp:152
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString getErrorMsgs()
Definition: qsql_tds.cpp:154
Q_CORE_EXPORT void qWarning(const char *,...)
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
void clearErrorMsgs()
Definition: qsql_tds.cpp:155
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
QSqlError qMakeError(const QString &err, QSqlError::ErrorType type, int errNo=-1)
Definition: qsql_tds.cpp:130

◆ qTdsMsgHandler()

static int CS_PUBLIC qTdsMsgHandler ( DBPROCESS *  dbproc,
DBINT  msgno,
int  msgstate,
int  severity,
char *  msgtext,
char *  srvname,
char *  ,
int  line 
)
static

Definition at line 167 of file qsql_tds.cpp.

Referenced by QTDSDriver::init().

175 {
176  QTDSResultPrivate* p = errs()->value(dbproc);
177 
178  if (!p) {
179 // ### umm... temporary disabled since this throws a lot of warnings...
180 // qWarning("QTDSDriver warning (%d): [%s] from server [%s]", msgstate, msgtext, srvname);
181  return INT_CANCEL;
182  }
183 
184  if (severity > 0) {
185  QString errMsg = QString::fromLatin1("%1 (Msg %2, Level %3, State %4, Server %5, Line %6)")
186  .arg(QString::fromAscii(msgtext))
187  .arg(msgno)
188  .arg(severity)
189  .arg(msgstate)
190  .arg(QString::fromAscii(srvname))
191  .arg(line);
192  p->addErrorMsg(errMsg);
193  if (severity > 10) {
194  // Severe messages are really errors in the sense of lastError
195  errMsg = p->getErrorMsgs();
196  p->lastError = qMakeError(errMsg, QSqlError::UnknownError, msgno);
197  p->clearErrorMsgs();
198  }
199  }
200 
201  return INT_CANCEL;
202 }
QSqlError lastError
Definition: qsql_tds.cpp:152
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
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString getErrorMsgs()
Definition: qsql_tds.cpp:154
void addErrorMsg(QString &errMsg)
Definition: qsql_tds.cpp:153
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
void clearErrorMsgs()
Definition: qsql_tds.cpp:155
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
QSqlError qMakeError(const QString &err, QSqlError::ErrorType type, int errNo=-1)
Definition: qsql_tds.cpp:130