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

#include <qsql_tds.h>

Inheritance diagram for QTDSDriver:
QSqlDriver QObject

Public Functions

void close ()
 Derived classes must reimplement this pure virtual function in order to close the database connection. More...
 
QSqlResultcreateResult () const
 Creates an empty SQL result on the database. More...
 
QString escapeIdentifier (const QString &identifier, IdentifierType type) const
 Returns the identifier escaped according to the database rules. More...
 
QString formatValue (const QSqlField &field, bool trimStrings) const
 Returns a string representation of the field value for the database. More...
 
QVariant handle () const
 Returns the low-level database handle wrapped in a QVariant or an invalid variant if there is no handle. More...
 
bool hasFeature (DriverFeature f) const
 Returns true if the driver supports feature feature; otherwise returns false. More...
 
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 db, using user name user, password password, host host, port port and connection options options. More...
 
QSqlIndex primaryIndex (const QString &tablename) const
 Returns the primary index for table tableName. More...
 
 QTDSDriver (QObject *parent=0)
 
 QTDSDriver (LOGINREC *rec, const QString &host, const QString &db, QObject *parent=0)
 
QSqlRecord record (const QString &tablename) const
 Returns a QSqlRecord populated with the names of the fields in table tableName. More...
 
QStringList tables (QSql::TableType) const
 Returns a list of the names of the tables in the database. More...
 
 ~QTDSDriver ()
 
- Public Functions inherited from QSqlDriver
bool isIdentifierEscaped (const QString &identifier, IdentifierType type) const
 Returns whether identifier is escaped according to the database rules. More...
 
virtual bool isOpen () const
 Returns true if the database connection is open; otherwise returns false. More...
 
bool isOpenError () const
 Returns true if the there was an error opening the database connection; otherwise returns false. More...
 
QSqlError lastError () const
 Returns a QSqlError object which contains information about the last error that occurred on the database. More...
 
QSql::NumericalPrecisionPolicy numericalPrecisionPolicy () const
 Returns the current default precision policy for the database connection. More...
 
 QSqlDriver (QObject *parent=0)
 Constructs a new driver with the given parent. More...
 
void setNumericalPrecisionPolicy (QSql::NumericalPrecisionPolicy precisionPolicy)
 Sets the default numerical precision policy used by queries created by this driver to precisionPolicy. More...
 
virtual QString sqlStatement (StatementType type, const QString &tableName, const QSqlRecord &rec, bool preparedStatement) const
 Returns a SQL statement of type type for the table tableName with the values from rec. More...
 
QString stripDelimiters (const QString &identifier, IdentifierType type) const
 Returns the identifier with the leading and trailing delimiters removed, identifier can either be a table name or field name, dependent on type. More...
 
QStringList subscribedToNotifications () const
 Returns a list of the names of the event notifications that are currently subscribed to. More...
 
bool subscribeToNotification (const QString &name)
 This function is called to subscribe to event notifications from the database. More...
 
bool unsubscribeFromNotification (const QString &name)
 This function is called to unsubscribe from event notifications from the database. More...
 
 ~QSqlDriver ()
 Destroys the object and frees any allocated resources. More...
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Protected Functions

bool beginTransaction ()
 This function is called to begin a transaction. More...
 
bool commitTransaction ()
 This function is called to commit a transaction. More...
 
bool rollbackTransaction ()
 This function is called to rollback a transaction. More...
 
- Protected Functions inherited from QSqlDriver
virtual void setLastError (const QSqlError &e)
 This function is used to set the value of the last error, error, that occurred on the database. More...
 
virtual void setOpen (bool o)
 This function sets the open state of the database to open. More...
 
virtual void setOpenError (bool e)
 This function sets the open error state of the database to error. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 

Private Functions

void init ()
 

Properties

QTDSDriverPrivated
 

Friends

class QTDSResult
 

Additional Inherited Members

- Public Types inherited from QSqlDriver
enum  DriverFeature {
  Transactions, QuerySize, BLOB, Unicode,
  PreparedQueries, NamedPlaceholders, PositionalPlaceholders, LastInsertId,
  BatchOperations, SimpleLocking, LowPrecisionNumbers, EventNotifications,
  FinishQuery, MultipleResultSets
}
 This enum contains a list of features a driver might support. More...
 
enum  IdentifierType { FieldName, TableName }
 This enum contains a list of SQL identifier types. More...
 
enum  StatementType {
  WhereStatement, SelectStatement, UpdateStatement, InsertStatement,
  DeleteStatement
}
 This enum contains a list of SQL statement (or clause) types the driver can create. More...
 
- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QSqlDriver
void notification (const QString &name)
 This signal is emitted when the database posts an event notification that the driver subscribes to. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
static bool connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Slots inherited from QSqlDriver
bool isIdentifierEscapedImplementation (const QString &identifier, IdentifierType type) const
 This slot returns whether identifier is escaped according to the database rules. More...
 
QString stripDelimitersImplementation (const QString &identifier, IdentifierType type) const
 This slot returns identifier with the leading and trailing delimiters removed, identifier can either be a tablename or field name, dependent on type. More...
 
QStringList subscribedToNotificationsImplementation () const
 Returns a list of the names of the event notifications that are currently subscribed to. More...
 
bool subscribeToNotificationImplementation (const QString &name)
 This slot is called to subscribe to event notifications from the database. More...
 
bool unsubscribeFromNotificationImplementation (const QString &name)
 This slot is called to unsubscribe from event notifications from the database. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 97 of file qsql_tds.h.

Constructors and Destructors

◆ QTDSDriver() [1/2]

QTDSDriver::QTDSDriver ( QObject parent = 0)
explicit

Definition at line 511 of file qsql_tds.cpp.

512  : QSqlDriver(parent)
513 {
514  init();
515 }
void init()
Definition: qsql_tds.cpp:535
QSqlDriver(QObject *parent=0)
Constructs a new driver with the given parent.
Definition: qsqldriver.cpp:112

◆ QTDSDriver() [2/2]

QTDSDriver::QTDSDriver ( LOGINREC *  rec,
const QString host,
const QString db,
QObject parent = 0 
)

Definition at line 517 of file qsql_tds.cpp.

518  : QSqlDriver(parent)
519 {
520  init();
521  d->login = rec;
522  d->hostName = host;
523  d->db = db;
524  if (rec) {
525  setOpen(true);
526  setOpenError(false);
527  }
528 }
LOGINREC * login
Definition: qsql_tds.cpp:139
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
QTDSDriverPrivate * d
Definition: qsql_tds.h:130
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
void init()
Definition: qsql_tds.cpp:535
QSqlDriver(QObject *parent=0)
Constructs a new driver with the given parent.
Definition: qsqldriver.cpp:112

◆ ~QTDSDriver()

QTDSDriver::~QTDSDriver ( )

Definition at line 545 of file qsql_tds.cpp.

546 {
547  dberrhandle(0);
548  dbmsghandle(0);
549  // dbexit also calls dbclose if necessary
550  dbexit();
551  delete d;
552 }
QTDSDriverPrivate * d
Definition: qsql_tds.h:130

Functions

◆ beginTransaction()

bool QTDSDriver::beginTransaction ( )
protectedvirtual

This function is called to begin a transaction.

If successful, return true, otherwise return false. The default implementation does nothing and returns false.

See also
commitTransaction(), rollbackTransaction()

Reimplemented from QSqlDriver.

Definition at line 634 of file qsql_tds.cpp.

635 {
636  return false;
637 /*
638  if (!isOpen()) {
639  qWarning("QTDSDriver::beginTransaction: Database not open");
640  return false;
641  }
642  if (dbcmd(d->dbproc, "BEGIN TRANSACTION") == FAIL) {
643  setLastError(d->lastError);
644  dbfreebuf(d->dbproc);
645  return false;
646  }
647  if (dbsqlexec(d->dbproc) == FAIL) {
648  setLastError(d->lastError);
649  dbfreebuf(d->dbproc);
650  return false;
651  }
652  while(dbresults(d->dbproc) == NO_MORE_RESULTS) {}
653  dbfreebuf(d->dbproc);
654  inTransaction = true;
655  return true;
656 */
657 }

◆ close()

void QTDSDriver::close ( )
virtual

Derived classes must reimplement this pure virtual function in order to close the database connection.

Return true on success, false on failure.

See also
open(), setOpen()

Implements QSqlDriver.

Definition at line 615 of file qsql_tds.cpp.

Referenced by open().

616 {
617  if (isOpen()) {
618 #ifdef Q_USE_SYBASE
619  dbloginfree(d->login);
620 #else
621  dbfreelogin(d->login);
622 #endif
623  d->login = 0;
624  setOpen(false);
625  setOpenError(false);
626  }
627 }
LOGINREC * login
Definition: qsql_tds.cpp:139
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
QTDSDriverPrivate * d
Definition: qsql_tds.h:130
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182

◆ commitTransaction()

bool QTDSDriver::commitTransaction ( )
protectedvirtual

This function is called to commit a transaction.

If successful, return true, otherwise return false. The default implementation does nothing and returns false.

See also
beginTransaction(), rollbackTransaction()

Reimplemented from QSqlDriver.

Definition at line 659 of file qsql_tds.cpp.

660 {
661  return false;
662 /*
663  if (!isOpen()) {
664  qWarning("QTDSDriver::commitTransaction: Database not open");
665  return false;
666  }
667  if (dbcmd(d->dbproc, "COMMIT TRANSACTION") == FAIL) {
668  setLastError(d->lastError);
669  dbfreebuf(d->dbproc);
670  return false;
671  }
672  if (dbsqlexec(d->dbproc) == FAIL) {
673  setLastError(d->lastError);
674  dbfreebuf(d->dbproc);
675  return false;
676  }
677  while(dbresults(d->dbproc) == NO_MORE_RESULTS) {}
678  dbfreebuf(d->dbproc);
679  inTransaction = false;
680  return true;
681 */
682 }

◆ createResult()

QSqlResult * QTDSDriver::createResult ( ) const
virtual

Creates an empty SQL result on the database.

Derived classes must reimplement this function and return a QSqlResult object appropriate for their database to the caller.

Implements QSqlDriver.

Definition at line 629 of file qsql_tds.cpp.

Referenced by primaryIndex(), record(), and tables().

630 {
631  return new QTDSResult(this);
632 }
friend class QTDSResult
Definition: qsql_tds.h:100

◆ escapeIdentifier()

QString QTDSDriver::escapeIdentifier ( const QString identifier,
IdentifierType  type 
) const
virtual

Returns the identifier escaped according to the database rules.

identifier can either be a table name or field name, dependent on type.

The default implementation does nothing.

See also
isIdentifierEscaped()

Reimplemented from QSqlDriver.

Definition at line 823 of file qsql_tds.cpp.

824 {
825  QString res = identifier;
826  if(!identifier.isEmpty() && !identifier.startsWith(QLatin1Char('"')) && !identifier.endsWith(QLatin1Char('"')) ) {
827  res.replace(QLatin1Char('"'), QLatin1String("\"\""));
828  res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
829  res.replace(QLatin1Char('.'), QLatin1String("\".\""));
830  }
831  return res;
832 }
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QString & prepend(QChar c)
Definition: qstring.h:261
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
QString & append(QChar c)
Definition: qstring.cpp:1777
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
Definition: qstring.cpp:3796
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ formatValue()

QString QTDSDriver::formatValue ( const QSqlField field,
bool  trimStrings 
) const
virtual

Returns a string representation of the field value for the database.

Use the other formatValue() overload instead.

This is used, for example, when constructing INSERT and UPDATE statements.

The default implementation returns the value formatted as a string according to the following rules:

  • If field is character data, the value is returned enclosed in single quotation marks, which is appropriate for many SQL databases. Any embedded single-quote characters are escaped (replaced with two single-quote characters). If trimStrings is true (the default is false), all trailing whitespace is trimmed from the field.

  • If field is date/time data, the value is formatted in ISO format and enclosed in single quotation marks. If the date/time data is invalid, "NULL" is returned.

  • If field is bytearray data, and the driver can edit binary fields, the value is formatted as a hexadecimal string.

  • For any other field type, toString() is called on its value and the result of this is returned.

See also
QVariant::toString()

Reimplemented from QSqlDriver.

Definition at line 762 of file qsql_tds.cpp.

764 {
765  QString r;
766  if (field.isNull())
767  r = QLatin1String("NULL");
768  else if (field.type() == QVariant::DateTime) {
769  if (field.value().toDateTime().isValid()){
770  r = field.value().toDateTime().toString(QLatin1String("yyyyMMdd hh:mm:ss"));
771  r.prepend(QLatin1String("'"));
772  r.append(QLatin1String("'"));
773  } else
774  r = QLatin1String("NULL");
775  } else if (field.type() == QVariant::ByteArray) {
776  QByteArray ba = field.value().toByteArray();
777  QString res;
778  static const char hexchars[] = "0123456789abcdef";
779  for (int i = 0; i < ba.size(); ++i) {
780  uchar s = (uchar) ba[i];
781  res += QLatin1Char(hexchars[s >> 4]);
782  res += QLatin1Char(hexchars[s & 0x0f]);
783  }
784  r = QLatin1String("0x") + res;
785  } else {
786  r = QSqlDriver::formatValue(field, trim);
787  }
788  return r;
789 }
QVariant value() const
Returns the value of the field as a QVariant.
Definition: qsqlfield.h:71
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QString & prepend(QChar c)
Definition: qstring.h:261
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
QString toString(Qt::DateFormat f=Qt::TextDate) const
Returns the datetime as a string in the format given.
Definition: qdatetime.cpp:2628
QByteArray toByteArray() const
Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QS...
Definition: qvariant.cpp:2383
unsigned char uchar
Definition: qglobal.h:994
QVariant::Type type() const
Returns the field&#39;s type as stored in the database.
Definition: qsqlfield.cpp:394
QString & append(QChar c)
Definition: qstring.cpp:1777
bool isNull() const
Returns true if the field&#39;s value is NULL; otherwise returns false.
Definition: qsqlfield.cpp:428
virtual QString formatValue(const QSqlField &field, bool trimStrings=false) const
Returns a string representation of the field value for the database.
Definition: qsqldriver.cpp:597
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ handle()

QVariant QTDSDriver::handle ( ) const
virtual

Returns the low-level database handle wrapped in a QVariant or an invalid variant 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 connection is modified (for example, if you close the connection).
The handle can be NULL if the connection is not open 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 connection to sqlite:

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

This snippet returns the handle for PostgreSQL or MySQL:

if (qstrcmp(v.typeName(), "PGconn*") == 0) {
PGconn *handle = *static_cast<PGconn **>(v.data());
if (handle != 0) ...
}
if (qstrcmp(v.typeName(), "MYSQL*") == 0) {
MYSQL *handle = *static_cast<MYSQL **>(v.data());
if (handle != 0) ...
}
See also
QSqlResult::handle()

Reimplemented from QSqlDriver.

Definition at line 530 of file qsql_tds.cpp.

531 {
532  return QVariant(qRegisterMetaType<LOGINREC *>("LOGINREC*"), &d->login);
533 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
LOGINREC * login
Definition: qsql_tds.cpp:139
QTDSDriverPrivate * d
Definition: qsql_tds.h:130

◆ hasFeature()

bool QTDSDriver::hasFeature ( DriverFeature  feature) const
virtual

Returns true if the driver supports feature feature; otherwise returns false.

Note that some databases need to be open() before this can be determined.

See also
DriverFeature

Implements QSqlDriver.

Definition at line 554 of file qsql_tds.cpp.

555 {
556  switch (f) {
557  case Transactions:
558  case QuerySize:
559  case Unicode:
560  case SimpleLocking:
561  case EventNotifications:
562  case MultipleResultSets:
563  return false;
564  case BLOB:
565  return true;
566  default:
567  return false;
568  }
569 }

◆ init()

void QTDSDriver::init ( )
private

Definition at line 535 of file qsql_tds.cpp.

Referenced by QTDSDriver().

536 {
537  d = new QTDSDriverPrivate();
538  d->initialized = (dbinit() == SUCCEED);
539  // the following two code-lines will fail compilation on some FreeTDS versions
540  // just comment them out if you have FreeTDS (you won't get any errors and warnings then)
541  dberrhandle((QERRHANDLE)qTdsErrHandler);
542  dbmsghandle((QMSGHANDLE)qTdsMsgHandler);
543 }
QTDSDriverPrivate * d
Definition: qsql_tds.h:130
#define QMSGHANDLE
Definition: qsql_tds.cpp:94
#define QERRHANDLE
Definition: qsql_tds.cpp:95
static int CS_PUBLIC qTdsErrHandler(DBPROCESS *dbproc, int, int dberr, int, char *dberrstr, char *oserrstr)
Definition: qsql_tds.cpp:204
static int CS_PUBLIC qTdsMsgHandler(DBPROCESS *dbproc, DBINT msgno, int msgstate, int severity, char *msgtext, char *srvname, char *, int line)
Definition: qsql_tds.cpp:167

◆ open()

bool QTDSDriver::open ( const QString db,
const QString user,
const QString password,
const QString host,
int  port,
const QString options 
)
virtual

Derived classes must reimplement this pure virtual function to open a database connection on database db, using user name user, password password, host host, port port and connection options options.

The function must return true on success and false on failure.

See also
setOpen()

Implements QSqlDriver.

Definition at line 571 of file qsql_tds.cpp.

577 {
578  if (isOpen())
579  close();
580  if (!d->initialized) {
581  setOpenError(true);
582  return false;
583  }
584  d->login = dblogin();
585  if (!d->login) {
586  setOpenError(true);
587  return false;
588  }
589  DBSETLPWD(d->login, const_cast<char*>(password.toLocal8Bit().constData()));
590  DBSETLUSER(d->login, const_cast<char*>(user.toLocal8Bit().constData()));
591 
592  // Now, try to open and use the database. If this fails, return false.
593  DBPROCESS* dbproc;
594 
595  dbproc = dbopen(d->login, const_cast<char*>(host.toLatin1().constData()));
596  if (!dbproc) {
597  setLastError(qMakeError(tr("Unable to open connection"), QSqlError::ConnectionError, -1));
598  setOpenError(true);
599  return false;
600  }
601  if (dbuse(dbproc, const_cast<char*>(db.toLatin1().constData())) == FAIL) {
602  setLastError(qMakeError(tr("Unable to use database"), QSqlError::ConnectionError, -1));
603  setOpenError(true);
604  return false;
605  }
606  dbclose( dbproc );
607 
608  setOpen(true);
609  setOpenError(false);
610  d->hostName = host;
611  d->db = db;
612  return true;
613 }
LOGINREC * login
Definition: qsql_tds.cpp:139
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
QTDSDriverPrivate * d
Definition: qsql_tds.h:130
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
void close()
Derived classes must reimplement this pure virtual function in order to close the database connection...
Definition: qsql_tds.cpp:615
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
virtual void setLastError(const QSqlError &e)
This function is used to set the value of the last error, error, that occurred on the database...
Definition: qsqldriver.cpp:350
QSqlError qMakeError(const QString &err, QSqlError::ErrorType type, int errNo=-1)
Definition: qsql_tds.cpp:130

◆ primaryIndex()

QSqlIndex QTDSDriver::primaryIndex ( const QString tableName) const
virtual

Returns the primary index for table tableName.

Returns an empty QSqlIndex if the table doesn't have a primary index. The default implementation returns an empty index.

Reimplemented from QSqlDriver.

Definition at line 791 of file qsql_tds.cpp.

792 {
793  QSqlRecord rec = record(tablename);
794 
795  QString table = tablename;
797  table = stripDelimiters(table, QSqlDriver::TableName);
798 
799  QSqlIndex idx(table);
800  if ((!isOpen()) || (table.isEmpty()))
801  return QSqlIndex();
802 
803  QSqlQuery t(createResult());
804  t.setForwardOnly(true);
805  t.exec(QString::fromLatin1("sp_helpindex '%1'").arg(table));
806  if (t.next()) {
807  QStringList fNames = t.value(2).toString().simplified().split(QLatin1Char(','));
808  QRegExp regx(QLatin1String("\\s*(\\S+)(?:\\s+(DESC|desc))?\\s*"));
809  for(QStringList::Iterator it = fNames.begin(); it != fNames.end(); ++it) {
810  regx.indexIn(*it);
811  QSqlField f(regx.cap(1), rec.field(regx.cap(1)).type());
812  if (regx.cap(2).toLower() == QLatin1String("desc")) {
813  idx.append(f, true);
814  } else {
815  idx.append(f, false);
816  }
817  }
818  idx.setName(t.value(0).toString().simplified());
819  }
820  return idx;
821 }
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition: qsqlindex.h:55
int type
Definition: qmetatype.cpp:239
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
#define it(className, varName)
void setName(const QString &name)
Sets the name of the field to name.
Definition: qsqlfield.cpp:347
The QSqlQuery class provides a means of executing and manipulating SQL statements.
Definition: qsqlquery.h:63
iterator begin()
Returns an STL-style iterator pointing to the first item in the list.
Definition: qlist.h:267
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.
Definition: qsqldriver.cpp:182
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
The QString class provides a Unicode character string.
Definition: qstring.h:83
iterator Iterator
Qt-style synonym for QList::iterator.
Definition: qlist.h:278
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
Definition: qsqldriver.cpp:429
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
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
T value(int i) const
Returns the value at index position i in the list.
Definition: qlist.h:661
QSqlField field(int i) const
Returns the field at position index.
Definition: qsqlrecord.cpp:289
QSqlRecord record(const QString &tablename) const
Returns a QSqlRecord populated with the names of the fields in table tableName.
Definition: qsql_tds.cpp:709
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
QSqlResult * createResult() const
Creates an empty SQL result on the database.
Definition: qsql_tds.cpp:629
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 QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
QString stripDelimiters(const QString &identifier, IdentifierType type) const
Returns the identifier with the leading and trailing delimiters removed, identifier can either be a t...
Definition: qsqldriver.cpp:455
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ record()

QSqlRecord QTDSDriver::record ( const QString tableName) const
virtual

Returns a QSqlRecord populated with the names of the fields in table tableName.

Use query.

If no such table exists, an empty record is returned. The default implementation returns an empty record.

record() instead.

Reimplemented from QSqlDriver.

Definition at line 709 of file qsql_tds.cpp.

Referenced by primaryIndex().

710 {
712  if (!isOpen())
713  return info;
714  QSqlQuery t(createResult());
715  t.setForwardOnly(true);
716 
717  QString table = tablename;
719  table = stripDelimiters(table, QSqlDriver::TableName);
720 
721  QString stmt (QLatin1String("select name, type, length, prec from syscolumns "
722  "where id = (select id from sysobjects where name = '%1')"));
723  t.exec(stmt.arg(table));
724  while (t.next()) {
725  QSqlField f(t.value(0).toString().simplified(), qDecodeTDSType(t.value(1).toInt()));
726  f.setLength(t.value(2).toInt());
727  f.setPrecision(t.value(3).toInt());
728  f.setSqlType(t.value(1).toInt());
729  info.append(f);
730  }
731  return info;
732 }
static mach_timebase_info_data_t info
QVariant::Type qDecodeTDSType(int type)
Definition: qsql_tds.cpp:238
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
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
The QSqlRecord class encapsulates a database record.
Definition: qsqlrecord.h:58
The QString class provides a Unicode character string.
Definition: qstring.h:83
bool isIdentifierEscaped(const QString &identifier, IdentifierType type) const
Returns whether identifier is escaped according to the database rules.
Definition: qsqldriver.cpp:429
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
Definition: qsqlrecord.cpp:312
QSqlResult * createResult() const
Creates an empty SQL result on the database.
Definition: qsql_tds.cpp:629
The QSqlField class manipulates the fields in SQL database tables and views.
Definition: qsqlfield.h:56
QString stripDelimiters(const QString &identifier, IdentifierType type) const
Returns the identifier with the leading and trailing delimiters removed, identifier can either be a t...
Definition: qsqldriver.cpp:455

◆ rollbackTransaction()

bool QTDSDriver::rollbackTransaction ( )
protectedvirtual

This function is called to rollback a transaction.

If successful, return true, otherwise return false. The default implementation does nothing and returns false.

See also
beginTransaction(), commitTransaction()

Reimplemented from QSqlDriver.

Definition at line 684 of file qsql_tds.cpp.

685 {
686  return false;
687 /*
688  if (!isOpen()) {
689  qWarning("QTDSDriver::rollbackTransaction: Database not open");
690  return false;
691  }
692  if (dbcmd(d->dbproc, "ROLLBACK TRANSACTION") == FAIL) {
693  setLastError(d->lastError);
694  dbfreebuf(d->dbproc);
695  return false;
696  }
697  if (dbsqlexec(d->dbproc) == FAIL) {
698  setLastError(d->lastError);
699  dbfreebuf(d->dbproc);
700  return false;
701  }
702  while(dbresults(d->dbproc) == NO_MORE_RESULTS) {}
703  dbfreebuf(d->dbproc);
704  inTransaction = false;
705  return true;
706 */
707 }

◆ tables()

QStringList QTDSDriver::tables ( QSql::TableType  tableType) const
virtual

Returns a list of the names of the tables in the database.

The default implementation returns an empty list.

The tableType argument describes what types of tables should be returned. Due to binary compatibility, the string contains the value of the enum QSql::TableTypes as text. An empty string should be treated as QSql::Tables for backward compatibility.

Reimplemented from QSqlDriver.

Definition at line 734 of file qsql_tds.cpp.

735 {
736  QStringList list;
737 
738  if (!isOpen())
739  return list;
740 
741  QStringList typeFilter;
742 
743  if (type & QSql::Tables)
744  typeFilter += QLatin1String("type='U'");
745  if (type & QSql::SystemTables)
746  typeFilter += QLatin1String("type='S'");
747  if (type & QSql::Views)
748  typeFilter += QLatin1String("type='V'");
749 
750  if (typeFilter.isEmpty())
751  return list;
752 
753  QSqlQuery t(createResult());
754  t.setForwardOnly(true);
755  t.exec(QLatin1String("select name from sysobjects where ") + typeFilter.join(QLatin1String(" or ")));
756  while (t.next())
757  list.append(t.value(0).toString().simplified());
758 
759  return list;
760 }
int type
Definition: qmetatype.cpp:239
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
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
bool isEmpty() const
Returns true if the list contains no items; otherwise returns false.
Definition: qlist.h:152
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString join(const QString &sep) const
Joins all the string list&#39;s strings into a single string with each element separated by the given sep...
Definition: qstringlist.h:162
QSqlResult * createResult() const
Creates an empty SQL result on the database.
Definition: qsql_tds.cpp:629

Friends and Related Functions

◆ QTDSResult

friend class QTDSResult
friend

Definition at line 100 of file qsql_tds.h.

Referenced by createResult().

Properties

◆ d

QTDSDriverPrivate* QTDSDriver::d
private

Definition at line 130 of file qsql_tds.h.

Referenced by close(), handle(), init(), open(), QTDSDriver(), QTDSResult::QTDSResult(), and ~QTDSDriver().


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