43 #ifdef Q_OS_WIN32 // We assume that MS SQL Server is used. Set Q_USE_SYBASE to force Sybase. 69 #define QMSGHANDLE DBMSGHANDLE_PROC 70 #define QERRHANDLE DBERRHANDLE_PROC 71 #define QTDSCHAR SQLCHAR 72 #define QTDSDATETIME4 SQLDATETIM4 73 #define QTDSDATETIME SQLDATETIME 74 #define QTDSDATETIME_N SQLDATETIMN 75 #define QTDSDECIMAL SQLDECIMAL 76 #define QTDSFLT4 SQLFLT4 77 #define QTDSFLT8 SQLFLT8 78 #define QTDSFLT8_N SQLFLTN 79 #define QTDSINT1 SQLINT1 80 #define QTDSINT2 SQLINT2 81 #define QTDSINT4 SQLINT4 82 #define QTDSINT4_N SQLINTN 83 #define QTDSMONEY4 SQLMONEY4 84 #define QTDSMONEY SQLMONEY 85 #define QTDSMONEY_N SQLMONEYN 86 #define QTDSNUMERIC SQLNUMERIC 87 #define QTDSTEXT SQLTEXT 88 #define QTDSVARCHAR SQLVARCHAR 89 #define QTDSBIT SQLBIT 90 #define QTDSBINARY SQLBINARY 91 #define QTDSVARBINARY SQLVARBINARY 92 #define QTDSIMAGE SQLIMAGE 94 #define QMSGHANDLE MHANDLEFUNC 95 #define QERRHANDLE EHANDLEFUNC 96 #define QTDSCHAR SYBCHAR 97 #define QTDSDATETIME4 SYBDATETIME4 98 #define QTDSDATETIME SYBDATETIME 99 #define QTDSDATETIME_N SYBDATETIMN 100 #define QTDSDECIMAL SYBDECIMAL 101 #define QTDSFLT8 SYBFLT8 102 #define QTDSFLT8_N SYBFLTN 103 #define QTDSFLT4 SYBREAL 104 #define QTDSINT1 SYBINT1 105 #define QTDSINT2 SYBINT2 106 #define QTDSINT4 SYBINT4 107 #define QTDSINT4_N SYBINTN 108 #define QTDSMONEY4 SYBMONEY4 109 #define QTDSMONEY SYBMONEY 110 #define QTDSMONEY_N SYBMONEYN 111 #define QTDSNUMERIC SYBNUMERIC 112 #define QTDSTEXT SYBTEXT 113 #define QTDSVARCHAR SYBVARCHAR 114 #define QTDSBIT SYBBIT 115 #define QTDSBINARY SYBBINARY 116 #define QTDSVARBINARY SYBVARBINARY 117 #define QTDSIMAGE SYBIMAGE 119 #define QTDSDECIMAL_2 55 120 #define QTDSNUMERIC_2 63 123 #define TDS_CURSOR_SIZE 50 213 qWarning(
"QTDSDriver error (%d): [%s] [%s]", dberr, dberrstr, oserrstr);
220 if((dbproc == NULL || DBDEAD(dbproc))) {
221 qWarning(
"QTDSDriver error (%d): [%s] [%s]", dberr, dberrstr, oserrstr);
308 dbcmd(
d->
dbproc,
"set quoted_identifier on");
325 for (
int i = 0; i <
d->
buffer.size() / 2; ++i)
337 return QVariant(qRegisterMetaType<DBPROCESS *>(
"DBPROCESS*"), &
d->
dbproc);
342 return *
reinterpret_cast<const DBINT *
>(&ind) == -1;
348 if (stat == NO_MORE_ROWS) {
352 if ((stat == FAIL) || (stat == BUF_FULL)) {
360 for (
int i = 0; i <
d->
rec.
count(); ++i) {
367 DBDATETIME *bdt = (DBDATETIME*)
d->
buffer.at(i * 2);
377 values[idx] = *((
int*)
d->
buffer.at(i * 2));
416 if (dbsqlexec(
d->
dbproc) == FAIL) {
421 if (dbresults(
d->
dbproc) != SUCCEED) {
428 int numCols = dbnumcols(
d->
dbproc);
433 for (
int i = 0; i < numCols; ++i) {
434 int dbType = dbcoltype(
d->
dbproc, i+1);
446 ret = dbbind(
d->
dbproc, i+1, INTBIND, (DBINT) 4, (
unsigned char *)p);
451 ret = dbbind(
d->
dbproc, i+1, STRINGBIND, 50, (
unsigned char *)p);
454 p = malloc(dbcollen(
d->
dbproc, i+1) + 1);
455 ret = dbbind(
d->
dbproc, i+1, STRINGBIND, DBINT(dbcollen(
d->
dbproc, i+1) + 1), (
unsigned char *)p);
459 ret = dbbind(
d->
dbproc, i+1, DATETIMEBIND, (DBINT) 8, (
unsigned char *)p);
462 p = malloc(dbcollen(
d->
dbproc, i+1) + 1);
463 ret = dbbind(
d->
dbproc, i+1, BINARYBIND, DBINT(dbcollen(
d->
dbproc, i+1) + 1), (
unsigned char *)p);
466 qWarning(
"QTDSResult::reset: Unsupported type for field \"%s\"", dbcolname(
d->
dbproc, i+1));
469 if (ret == SUCCEED) {
471 ret = dbnullbind(
d->
dbproc, i+1, (DBINT*)(&
d->
buffer[i * 2 + 1]));
477 if ((ret != SUCCEED) && (ret != -1)) {
532 return QVariant(qRegisterMetaType<LOGINREC *>(
"LOGINREC*"), &
d->
login);
722 "where id = (select id from sysobjects where name = '%1')"));
778 static const char hexchars[] =
"0123456789abcdef";
779 for (
int i = 0; i < ba.
size(); ++i) {
The QVariant class acts like a union for the most common Qt data types.
The QSqlError class provides SQL database error information.
The QSqlIndex class provides functions to manipulate and describe database indexes.
const QSqlDriver * driver() const
Returns the driver associated with the result.
static QString fromLocal8Bit(const char *, int size=-1)
Returns a QString initialized with the first size characters of the 8-bit string str.
static mach_timebase_info_data_t info
QString cap(int nth=0) const
Returns the text captured by the nth subexpression.
bool commitTransaction()
This function is called to commit a transaction.
#define QT_END_NAMESPACE
This macro expands to.
virtual void setOpen(bool o)
This function sets the open state of the database to open.
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
QVariant::Type qDecodeTDSType(int type)
The QRegExp class provides pattern matching using regular expressions.
DriverFeature
This enum contains a list of features a driver might support.
bool beginTransaction()
This function is called to begin a transaction.
#define it(className, varName)
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
void append(const QSqlField &field)
Appends the field field to the list of indexed fields.
QVariant value() const
Returns the value of the field as a QVariant.
QString & replace(int i, int len, QChar after)
The QByteArray class provides an array of bytes.
QString & prepend(QChar c)
The QSqlQuery class provides a means of executing and manipulating SQL statements.
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
QString toString() const
Returns the variant as a QString if the variant has type() String , Bool , ByteArray ...
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
void setPrecision(int precision)
Sets the field's precision.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
The QDate class provides date functions.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
The QSqlRecord class encapsulates a database record.
The QSqlDriver class is an abstract base class for accessing specific SQL databases.
The QString class provides a Unicode character string.
The QHash class is a template class that provides a hash-table-based dictionary.
The QVector class is a template class that provides a dynamic array.
The QObject class is the base class of all Qt objects.
QStringList tables(QSql::TableType) const
Returns a list of the names of the tables in the database.
bool hasFeature(DriverFeature f) const
Returns true if the driver supports feature feature; otherwise returns false.
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
iterator Iterator
Qt-style synonym for QList::iterator.
virtual void setAt(int at)
This function is provided for derived classes to set the internal (zero-based) row position to index...
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
virtual void setLastError(const QSqlError &e)
This function is provided for derived classes to set the last error to error.
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
int toInt(bool *ok=0) const
Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char ...
ErrorType
This enum type describes the context in which the error occurred, e.
void append(const T &t)
Inserts value at the end of the list.
The QTime class provides clock time functions.
void close()
Derived classes must reimplement this pure virtual function in order to close the database connection...
#define QT_BEGIN_NAMESPACE
This macro expands to.
virtual void setSelect(bool s)
This function is provided for derived classes to indicate whether or not the current statement is a S...
int indexIn(const QString &str, int offset=0, CaretMode caretMode=CaretAtZero) const
Attempts to find a match in str from position offset (0 by default).
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
bool gotoNext(QSqlCachedResult::ValueCache &values, int index)
iterator end()
Returns an STL-style iterator pointing to the imaginary item after the last item in the list...
QHash< DBPROCESS *, QTDSResultPrivate * > QTDSErrorHash
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
QVariant::Type qFieldType(QTDSResultPrivate *d, int i)
The QStringList class provides a list of strings.
void setLength(int fieldLength)
Sets the field's length to fieldLength.
QString escapeIdentifier(const QString &identifier, IdentifierType type) const
Returns the identifier escaped according to the database rules.
Q_CORE_EXPORT void qWarning(const char *,...)
void addErrorMsg(QString &errMsg)
void setName(const QString &name)
Sets the name of the index to name.
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Type
This enum type defines the types of variable that a QVariant can contain.
QVariant handle() const
Returns the low-level database handle wrapped in a QVariant or an invalid variant if there is no hand...
QSqlIndex primaryIndex(const QString &tablename) const
Returns the primary index for table tableName.
QDate addDays(int days) const
Returns a QDate object containing a date ndays later than the date of this object (or earlier if nday...
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
QVariant::Type type() const
Returns the field's type as stored in the database.
QTDSResult(const QTDSDriver *db)
QSqlRecord record() const
Returns the current record if the query is active; otherwise returns an empty QSqlRecord.
int numRowsAffected()
Returns the number of rows affected by the last query executed, or -1 if it cannot be determined or i...
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
QSqlField field(int i) const
Returns the field at position index.
void setForwardOnly(bool forward)
Sets forward only mode to forward.
static QTime fromString(const QString &s, Qt::DateFormat f=Qt::TextDate)
Returns the time represented in the string as a QTime using the format given, or an invalid time if t...
const char * constData() const
Returns a pointer to the data stored in the byte array.
QSqlRecord record(const QString &tablename) const
Returns a QSqlRecord populated with the names of the fields in table tableName.
QString join(const QString &sep) const
Joins all the string list's strings into a single string with each element separated by the given sep...
int count() const
Returns the number of fields in the record.
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
QString & append(QChar c)
The QDateTime class provides date and time functions.
QString trimmed(QString source)
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...
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
QObject * parent() const
Returns a pointer to the parent object.
bool open(const QString &db, const QString &user, const QString &password, const QString &host, int port, const QString &connOpts)
Derived classes must reimplement this pure virtual function to open a database connection on database...
bool isNull() const
Returns true if the field's value is NULL; otherwise returns false.
virtual QString formatValue(const QSqlField &field, bool trimStrings=false) const
Returns a string representation of the field value for the database.
QString toLower() const Q_REQUIRED_RESULT
Returns a lowercase copy of the string.
static QDate fromString(const QString &s, Qt::DateFormat f=Qt::TextDate)
Returns the QDate represented by the string, using the format given, or an invalid date if the string...
bool reset(const QString &query)
Sets the result to use the SQL statement query for subsequent data retrieval.
bool rollbackTransaction()
This function is called to rollback a transaction.
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
QVariant handle() const
Returns the low-level database handle for this result set wrapped in a QVariant or an invalid QVarian...
static bool qIsNull(const void *ind)
int size() const
Returns the number of bytes in this byte array.
virtual void setActive(bool a)
This function is provided for derived classes to set the internal active state to active...
void clear()
Removes all the record's fields.
QSqlResult * createResult() const
Creates an empty SQL result on the database.
QTime addMSecs(int ms) const
Returns a QTime object containing a time ms milliseconds later than the time of this object (or earli...
static int CS_PUBLIC qTdsErrHandler(DBPROCESS *dbproc, int, int dberr, int, char *dberrstr, char *oserrstr)
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...
The QSqlField class manipulates the fields in SQL database tables and views.
bool exec(const QString &query)
Executes the SQL in query.
virtual void setLastError(const QSqlError &e)
This function is used to set the value of the last error, error, that occurred on the database...
QTDSDriver(QObject *parent=0)
QString stripDelimiters(const QString &identifier, IdentifierType type) const
Returns the identifier with the leading and trailing delimiters removed, identifier can either be a t...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
int size()
Returns the size of the SELECT result, or -1 if it cannot be determined or if the query is not a SELE...
QSqlError qMakeError(const QString &err, QSqlError::ErrorType type, int errNo=-1)
QVariant value(int i) const
Returns the value of field index in the current record.
bool next()
Retrieves the next record in the result, if available, and positions the query on the retrieved recor...
The QSqlResult class provides an abstract interface for accessing data from specific SQL databases...
static int CS_PUBLIC qTdsMsgHandler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *, int line)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
IdentifierType
This enum contains a list of SQL identifier types.
QString formatValue(const QSqlField &field, bool trimStrings) const
Returns a string representation of the field value for the database.
void setSqlType(int type)