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

#include <qsql_oci.h>

Inheritance diagram for QOCIDriver:
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) 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...
 
 QOCIDriver (QObject *parent=0)
 
 QOCIDriver (OCIEnv *env, OCISvcCtx *ctx, 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...
 
 ~QOCIDriver ()
 
- 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...
 

Properties

QOCIDriverPrivated
 

Friends

class QOCIPrivate
 
struct QOCIResultPrivate
 

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 92 of file qsql_oci.h.

Constructors and Destructors

◆ QOCIDriver() [1/2]

QOCIDriver::QOCIDriver ( QObject parent = 0)
explicit

Definition at line 2070 of file qsql_oci.cpp.

2071  : QSqlDriver(parent)
2072 {
2073  d = new QOCIDriverPrivate();
2074 
2075 #ifdef QOCI_THREADED
2076  const ub4 mode = OCI_UTF16 | OCI_OBJECT | OCI_THREADED;
2077 #else
2078  const ub4 mode = OCI_UTF16 | OCI_OBJECT;
2079 #endif
2080  int r = OCIEnvCreate(&d->env,
2081  mode,
2082  NULL,
2083  NULL,
2084  NULL,
2085  NULL,
2086  0,
2087  NULL);
2088  if (r != 0) {
2089  qWarning("QOCIDriver: unable to create environment");
2090  setLastError(qMakeError(tr("Unable to initialize", "QOCIDriver"),
2092  return;
2093  }
2094 
2095  d->allocErrorHandle();
2096 }
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
OCIError * err
Definition: qsql_oci.cpp:473
Q_CORE_EXPORT void qWarning(const char *,...)
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
QSqlDriver(QObject *parent=0)
Constructs a new driver with the given parent.
Definition: qsqldriver.cpp:112
void allocErrorHandle()
Definition: qsql_oci.cpp:489
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
static QSqlError qMakeError(const QString &errString, QSqlError::ErrorType type, OCIError *err)
Definition: qsql_oci.cpp:554

◆ QOCIDriver() [2/2]

QOCIDriver::QOCIDriver ( OCIEnv env,
OCISvcCtx ctx,
QObject parent = 0 
)

Definition at line 2098 of file qsql_oci.cpp.

2099  : QSqlDriver(parent)
2100 {
2101  d = new QOCIDriverPrivate();
2102  d->env = env;
2103  d->svc = ctx;
2104 
2105  d->allocErrorHandle();
2106 
2107  if (env && ctx) {
2108  setOpen(true);
2109  setOpenError(false);
2110  }
2111 }
OCISvcCtx * svc
Definition: qsql_oci.cpp:470
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
QSqlDriver(QObject *parent=0)
Constructs a new driver with the given parent.
Definition: qsqldriver.cpp:112
#define ctx
Definition: qgl.cpp:6094
void allocErrorHandle()
Definition: qsql_oci.cpp:489

◆ ~QOCIDriver()

QOCIDriver::~QOCIDriver ( )

Definition at line 2113 of file qsql_oci.cpp.

2114 {
2115  if (isOpen())
2116  close();
2117  int r = OCIHandleFree(d->err, OCI_HTYPE_ERROR);
2118  if (r != OCI_SUCCESS)
2119  qWarning("Unable to free Error handle: %d", r);
2120  r = OCIHandleFree(d->env, OCI_HTYPE_ENV);
2121  if (r != OCI_SUCCESS)
2122  qWarning("Unable to free Environment handle: %d", r);
2123 
2124  delete d;
2125 }
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_oci.cpp:2271
OCIError * err
Definition: qsql_oci.cpp:473
Q_CORE_EXPORT void qWarning(const char *,...)
QOCIDriverPrivate * d
Definition: qsql_oci.h:123

Functions

◆ beginTransaction()

bool QOCIDriver::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 2293 of file qsql_oci.cpp.

2294 {
2295  if (!isOpen()) {
2296  qWarning("QOCIDriver::beginTransaction: Database not open");
2297  return false;
2298  }
2299  int r = OCITransStart(d->svc,
2300  d->err,
2301  2,
2302  OCI_TRANS_READWRITE);
2303  if (r == OCI_ERROR) {
2304  qOraWarning("QOCIDriver::beginTransaction: ", d->err);
2306  "Unable to begin transaction"), QSqlError::TransactionError, d->err));
2307  return false;
2308  }
2309  d->transaction = true;
2310  return true;
2311 }
OCISvcCtx * svc
Definition: qsql_oci.cpp:470
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
OCIError * err
Definition: qsql_oci.cpp:473
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
Q_CORE_EXPORT void qWarning(const char *,...)
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
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
static QSqlError qMakeError(const QString &errString, QSqlError::ErrorType type, OCIError *err)
Definition: qsql_oci.cpp:554
static void qOraWarning(const char *msg, OCIError *err)
Definition: qsql_oci.cpp:531

◆ close()

void QOCIDriver::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 2271 of file qsql_oci.cpp.

Referenced by open(), and ~QOCIDriver().

2272 {
2273  if (!isOpen())
2274  return;
2275 
2276  OCISessionEnd(d->svc, d->err, d->authp, OCI_DEFAULT);
2277  OCIServerDetach(d->srvhp, d->err, OCI_DEFAULT);
2278  OCIHandleFree(d->authp, OCI_HTYPE_SESSION);
2279  d->authp = 0;
2280  OCIHandleFree(d->srvhp, OCI_HTYPE_SERVER);
2281  d->srvhp = 0;
2282  OCIHandleFree(d->svc, OCI_HTYPE_SVCCTX);
2283  d->svc = 0;
2284  setOpen(false);
2285  setOpenError(false);
2286 }
OCISvcCtx * svc
Definition: qsql_oci.cpp:470
OCISession * authp
Definition: qsql_oci.cpp:472
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
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
OCIError * err
Definition: qsql_oci.cpp:473
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
OCIServer * srvhp
Definition: qsql_oci.cpp:471

◆ commitTransaction()

bool QOCIDriver::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 2313 of file qsql_oci.cpp.

2314 {
2315  if (!isOpen()) {
2316  qWarning("QOCIDriver::commitTransaction: Database not open");
2317  return false;
2318  }
2319  int r = OCITransCommit(d->svc,
2320  d->err,
2321  0);
2322  if (r == OCI_ERROR) {
2323  qOraWarning("QOCIDriver::commitTransaction:", d->err);
2325  "Unable to commit transaction"), QSqlError::TransactionError, d->err));
2326  return false;
2327  }
2328  d->transaction = false;
2329  return true;
2330 }
OCISvcCtx * svc
Definition: qsql_oci.cpp:470
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
OCIError * err
Definition: qsql_oci.cpp:473
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
Q_CORE_EXPORT void qWarning(const char *,...)
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
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
static QSqlError qMakeError(const QString &errString, QSqlError::ErrorType type, OCIError *err)
Definition: qsql_oci.cpp:554
static void qOraWarning(const char *msg, OCIError *err)
Definition: qsql_oci.cpp:531

◆ createResult()

QSqlResult * QOCIDriver::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 2288 of file qsql_oci.cpp.

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

2289 {
2290  return new QOCIResult(this, d);
2291 }
QOCIDriverPrivate * d
Definition: qsql_oci.h:123

◆ escapeIdentifier()

QString QOCIDriver::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 2654 of file qsql_oci.cpp.

2655 {
2656  QString res = identifier;
2657  if(!identifier.isEmpty() && !isIdentifierEscaped(identifier, type)) {
2658  res.replace(QLatin1Char('"'), QLatin1String("\"\""));
2659  res.prepend(QLatin1Char('"')).append(QLatin1Char('"'));
2660  res.replace(QLatin1Char('.'), QLatin1String("\".\""));
2661  }
2662  return res;
2663 }
int type
Definition: qmetatype.cpp:239
QString & replace(int i, int len, QChar after)
Definition: qstring.cpp:2005
QString & prepend(QChar c)
Definition: qstring.h:261
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
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
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
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ formatValue()

QString QOCIDriver::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 2596 of file qsql_oci.cpp.

2597 {
2598  switch (field.type()) {
2599  case QVariant::DateTime: {
2600  QDateTime datetime = field.value().toDateTime();
2601  QString datestring;
2602  if (datetime.isValid()) {
2603  datestring = QLatin1String("TO_DATE('") + QString::number(datetime.date().year())
2604  + QLatin1Char('-')
2605  + QString::number(datetime.date().month()) + QLatin1Char('-')
2606  + QString::number(datetime.date().day()) + QLatin1Char(' ')
2607  + QString::number(datetime.time().hour()) + QLatin1Char(':')
2608  + QString::number(datetime.time().minute()) + QLatin1Char(':')
2609  + QString::number(datetime.time().second())
2610  + QLatin1String("','YYYY-MM-DD HH24:MI:SS')");
2611  } else {
2612  datestring = QLatin1String("NULL");
2613  }
2614  return datestring;
2615  }
2616  case QVariant::Time: {
2617  QDateTime datetime = field.value().toDateTime();
2618  QString datestring;
2619  if (datetime.isValid()) {
2620  datestring = QLatin1String("TO_DATE('")
2621  + QString::number(datetime.time().hour()) + QLatin1Char(':')
2622  + QString::number(datetime.time().minute()) + QLatin1Char(':')
2623  + QString::number(datetime.time().second())
2624  + QLatin1String("','HH24:MI:SS')");
2625  } else {
2626  datestring = QLatin1String("NULL");
2627  }
2628  return datestring;
2629  }
2630  case QVariant::Date: {
2631  QDate date = field.value().toDate();
2632  QString datestring;
2633  if (date.isValid()) {
2634  datestring = QLatin1String("TO_DATE('") + QString::number(date.year()) +
2635  QLatin1Char('-') +
2636  QString::number(date.month()) + QLatin1Char('-') +
2637  QString::number(date.day()) + QLatin1String("','YYYY-MM-DD')");
2638  } else {
2639  datestring = QLatin1String("NULL");
2640  }
2641  return datestring;
2642  }
2643  default:
2644  break;
2645  }
2646  return QSqlDriver::formatValue(field, trimStrings);
2647 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
bool isValid() const
Returns true if this date is valid; otherwise returns false.
Definition: qdatetime.cpp:340
QVariant value() const
Returns the value of the field as a QVariant.
Definition: qsqlfield.h:71
int month() const
Returns the number corresponding to the month of this date, using the following convention: ...
Definition: qdatetime.cpp:382
QDateTime toDateTime() const
Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise ...
Definition: qvariant.cpp:2349
int day() const
Returns the day of the month (1 to 31) of this date.
Definition: qdatetime.cpp:395
bool isValid() const
Returns true if both the date and the time are valid; otherwise returns false.
Definition: qdatetime.cpp:2346
The QDate class provides date functions.
Definition: qdatetime.h:55
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
int second() const
Returns the second part (0 to 59) of the time.
Definition: qdatetime.cpp:1600
int minute() const
Returns the minute part (0 to 59) of the time.
Definition: qdatetime.cpp:1589
QVariant::Type type() const
Returns the field&#39;s type as stored in the database.
Definition: qsqlfield.cpp:394
QDate date() const
Returns the date part of the datetime.
Definition: qdatetime.cpp:2357
QDate toDate() const
Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise retu...
Definition: qvariant.cpp:2311
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
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 year() const
Returns the year of this date.
Definition: qdatetime.cpp:353
QTime time() const
Returns the time part of the datetime.
Definition: qdatetime.cpp:2368
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
int hour() const
Returns the hour part (0 to 23) of the time.
Definition: qdatetime.cpp:1578

◆ handle()

QVariant QOCIDriver::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 2649 of file qsql_oci.cpp.

2650 {
2651  return QVariant::fromValue(d->env);
2652 }
static QVariant fromValue(const T &value)
Returns a QVariant containing a copy of value.
Definition: qvariant.h:336
QOCIDriverPrivate * d
Definition: qsql_oci.h:123

◆ hasFeature()

bool QOCIDriver::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 2127 of file qsql_oci.cpp.

2128 {
2129  switch (f) {
2130  case Transactions:
2131  case LastInsertId:
2132  case BLOB:
2133  case PreparedQueries:
2134  case NamedPlaceholders:
2135  case BatchOperations:
2136  case LowPrecisionNumbers:
2137  return true;
2138  case QuerySize:
2140  case SimpleLocking:
2141  case EventNotifications:
2142  case FinishQuery:
2143  case MultipleResultSets:
2144  return false;
2145  case Unicode:
2146  return d->serverVersion >= 9;
2147  }
2148  return false;
2149 }
QOCIDriverPrivate * d
Definition: qsql_oci.h:123

◆ open()

bool QOCIDriver::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 2180 of file qsql_oci.cpp.

2186 {
2187  int r;
2188 
2189  if (isOpen())
2190  close();
2191 
2192  qParseOpts(opts, d);
2193 
2194  // Connect without tnsnames.ora if a hostname is given
2195  QString connectionString = db;
2196  if (!hostname.isEmpty())
2197  connectionString =
2198  QString::fromLatin1("(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=%1)(Port=%2))"
2199  "(CONNECT_DATA=(SID=%3)))").arg(hostname).arg((port > -1 ? port : 1521)).arg(db);
2200 
2201  r = OCIHandleAlloc(d->env, reinterpret_cast<void **>(&d->srvhp), OCI_HTYPE_SERVER, 0, 0);
2202  if (r == OCI_SUCCESS)
2203  r = OCIServerAttach(d->srvhp, d->err, reinterpret_cast<const OraText *>(connectionString.utf16()),
2204  connectionString.length() * sizeof(QChar), OCI_DEFAULT);
2205  if (r == OCI_SUCCESS || r == OCI_SUCCESS_WITH_INFO)
2206  r = OCIHandleAlloc(d->env, reinterpret_cast<void **>(&d->svc), OCI_HTYPE_SVCCTX, 0, 0);
2207  if (r == OCI_SUCCESS)
2208  r = OCIAttrSet(d->svc, OCI_HTYPE_SVCCTX, d->srvhp, 0, OCI_ATTR_SERVER, d->err);
2209  if (r == OCI_SUCCESS)
2210  r = OCIHandleAlloc(d->env, reinterpret_cast<void **>(&d->authp), OCI_HTYPE_SESSION, 0, 0);
2211  if (r == OCI_SUCCESS)
2212  r = OCIAttrSet(d->authp, OCI_HTYPE_SESSION, const_cast<ushort *>(user.utf16()),
2213  user.length() * sizeof(QChar), OCI_ATTR_USERNAME, d->err);
2214  if (r == OCI_SUCCESS)
2215  r = OCIAttrSet(d->authp, OCI_HTYPE_SESSION, const_cast<ushort *>(password.utf16()),
2216  password.length() * sizeof(QChar), OCI_ATTR_PASSWORD, d->err);
2217 
2218  OCITrans* trans;
2219  if (r == OCI_SUCCESS)
2220  r = OCIHandleAlloc(d->env, reinterpret_cast<void **>(&trans), OCI_HTYPE_TRANS, 0, 0);
2221  if (r == OCI_SUCCESS)
2222  r = OCIAttrSet(d->svc, OCI_HTYPE_SVCCTX, trans, 0, OCI_ATTR_TRANS, d->err);
2223 
2224  if (r == OCI_SUCCESS) {
2225  if (user.isEmpty() && password.isEmpty())
2226  r = OCISessionBegin(d->svc, d->err, d->authp, OCI_CRED_EXT, OCI_DEFAULT);
2227  else
2228  r = OCISessionBegin(d->svc, d->err, d->authp, OCI_CRED_RDBMS, OCI_DEFAULT);
2229  }
2230  if (r == OCI_SUCCESS || r == OCI_SUCCESS_WITH_INFO)
2231  r = OCIAttrSet(d->svc, OCI_HTYPE_SVCCTX, d->authp, 0, OCI_ATTR_SESSION, d->err);
2232 
2233  if (r != OCI_SUCCESS) {
2234  setLastError(qMakeError(tr("Unable to logon"), QSqlError::ConnectionError, d->err));
2235  setOpenError(true);
2236  if (d->authp)
2237  OCIHandleFree(d->authp, OCI_HTYPE_SESSION);
2238  d->authp = 0;
2239  if (d->srvhp)
2240  OCIHandleFree(d->srvhp, OCI_HTYPE_SERVER);
2241  d->srvhp = 0;
2242  return false;
2243  }
2244 
2245  // get server version
2246  char vertxt[512];
2247  r = OCIServerVersion(d->svc,
2248  d->err,
2249  reinterpret_cast<OraText *>(vertxt),
2250  sizeof(vertxt),
2251  OCI_HTYPE_SVCCTX);
2252  if (r != 0) {
2253  qWarning("QOCIDriver::open: could not get Oracle server version.");
2254  } else {
2255  QString versionStr;
2256  versionStr = QString(reinterpret_cast<const QChar *>(vertxt));
2257  QRegExp vers(QLatin1String("([0-9]+)\\.[0-9\\.]+[0-9]"));
2258  if (vers.indexIn(versionStr) >= 0)
2259  d->serverVersion = vers.cap(1).toInt();
2260  if (d->serverVersion == 0)
2261  d->serverVersion = -1;
2262  }
2263 
2264  setOpen(true);
2265  setOpenError(false);
2266  d->user = user;
2267 
2268  return true;
2269 }
OCISvcCtx * svc
Definition: qsql_oci.cpp:470
OCISession * authp
Definition: qsql_oci.cpp:472
virtual void setOpen(bool o)
This function sets the open state of the database to open.
Definition: qsqldriver.cpp:283
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
virtual void setOpenError(bool e)
This function sets the open error state of the database to error.
Definition: qsqldriver.cpp:297
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
static void qParseOpts(const QString &options, QOCIDriverPrivate *d)
Definition: qsql_oci.cpp:2151
static QString tr(const char *sourceText, const char *comment=0, int n=-1)
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
void close()
Derived classes must reimplement this pure virtual function in order to close the database connection...
Definition: qsql_oci.cpp:2271
OCIError * err
Definition: qsql_oci.cpp:473
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
Q_CORE_EXPORT void qWarning(const char *,...)
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
OCIServer * srvhp
Definition: qsql_oci.cpp:471
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
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
static QSqlError qMakeError(const QString &errString, QSqlError::ErrorType type, OCIError *err)
Definition: qsql_oci.cpp:554
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290

◆ primaryIndex()

QSqlIndex QOCIDriver::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 2529 of file qsql_oci.cpp.

2530 {
2531  QSqlIndex idx(tablename);
2532  if (!isOpen())
2533  return idx;
2534  QSqlQuery t(createResult());
2535  QString stmt(QLatin1String("select b.column_name, b.index_name, a.table_name, a.owner "
2536  "from all_constraints a, all_ind_columns b "
2537  "where a.constraint_type='P' "
2538  "and b.index_name = a.constraint_name "
2539  "and b.index_owner = a.owner"));
2540 
2541  bool buildIndex = false;
2542  QString table, owner, tmpStmt;
2543  qSplitTableAndOwner(tablename, &table, &owner);
2544 
2546  table = stripDelimiters(table, QSqlDriver::TableName);
2547  else
2548  table = table.toUpper();
2549 
2550  tmpStmt = stmt + QLatin1String(" and a.table_name='") + table + QLatin1Char('\'');
2551  if (owner.isEmpty()) {
2552  owner = d->user;
2553  }
2554 
2556  owner = stripDelimiters(owner, QSqlDriver::TableName);
2557  else
2558  owner = owner.toUpper();
2559 
2560  tmpStmt += QLatin1String(" and a.owner='") + owner + QLatin1Char('\'');
2561  t.setForwardOnly(true);
2562  t.exec(tmpStmt);
2563 
2564  if (!t.next()) {
2565  stmt += QLatin1String(" and a.table_name=(select tname from sys.synonyms "
2566  "where sname='") + table + QLatin1String("' and creator=a.owner)");
2567  t.setForwardOnly(true);
2568  t.exec(stmt);
2569  if (t.next()) {
2570  owner = t.value(3).toString();
2571  buildIndex = true;
2572  }
2573  } else {
2574  buildIndex = true;
2575  }
2576  if (buildIndex) {
2577  QSqlQuery tt(createResult());
2578  tt.setForwardOnly(true);
2579  idx.setName(t.value(1).toString());
2580  do {
2581  tt.exec(QLatin1String("select data_type from all_tab_columns where table_name='") +
2582  t.value(2).toString() + QLatin1String("' and column_name='") +
2583  t.value(0).toString() + QLatin1String("' and owner='") +
2584  owner + QLatin1Char('\''));
2585  if (!tt.next()) {
2586  return QSqlIndex();
2587  }
2588  QSqlField f(t.value(0).toString(), qDecodeOCIType(tt.value(0).toString(), t.numericalPrecisionPolicy()));
2589  idx.append(f);
2590  } while (t.next());
2591  return idx;
2592  }
2593  return QSqlIndex();
2594 }
The QSqlIndex class provides functions to manipulate and describe database indexes.
Definition: qsqlindex.h:55
QVariant::Type qDecodeOCIType(const QString &ocitype, QSql::NumericalPrecisionPolicy precisionPolicy)
Definition: qsql_oci.cpp:561
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
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 QString class provides a Unicode character string.
Definition: qstring.h:83
static QWidget * owner
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
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
void qSplitTableAndOwner(const QString &tname, QString *tbl, QString *owner)
Definition: qsql_oci.cpp:2444
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
QSqlResult * createResult() const
Creates an empty SQL result on the database.
Definition: qsql_oci.cpp:2288
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ record()

QSqlRecord QOCIDriver::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 2456 of file qsql_oci.cpp.

2457 {
2458  QSqlRecord fil;
2459  if (!isOpen())
2460  return fil;
2461 
2462  QSqlQuery t(createResult());
2463  // using two separate queries for this is A LOT faster than using
2464  // eg. a sub-query on the sys.synonyms table
2465  QString stmt(QLatin1String("select column_name, data_type, data_length, "
2466  "data_precision, data_scale, nullable, data_default%1"
2467  "from all_tab_columns a "
2468  "where a.table_name=%2"));
2469  if (d->serverVersion >= 9)
2470  stmt = stmt.arg(QLatin1String(", char_length "));
2471  else
2472  stmt = stmt.arg(QLatin1String(" "));
2473  bool buildRecordInfo = false;
2474  QString table, owner, tmpStmt;
2475  qSplitTableAndOwner(tablename, &table, &owner);
2476 
2478  table = stripDelimiters(table, QSqlDriver::TableName);
2479  else
2480  table = table.toUpper();
2481 
2482  tmpStmt = stmt.arg(QLatin1Char('\'') + table + QLatin1Char('\''));
2483  if (owner.isEmpty()) {
2484  owner = d->user;
2485  }
2486 
2488  owner = stripDelimiters(owner, QSqlDriver::TableName);
2489  else
2490  owner = owner.toUpper();
2491 
2492  tmpStmt += QLatin1String(" and a.owner='") + owner + QLatin1Char('\'');
2493  t.setForwardOnly(true);
2494  t.exec(tmpStmt);
2495  if (!t.next()) { // try and see if the tablename is a synonym
2496  stmt = stmt + QLatin1String(" join all_synonyms b "
2497  "on a.owner=b.table_owner and a.table_name=b.table_name "
2498  "where b.owner='") + owner +
2499  QLatin1String("' and b.synonym_name='") + table +
2500  QLatin1Char('\'');
2501  t.setForwardOnly(true);
2502  t.exec(stmt);
2503  if (t.next())
2504  buildRecordInfo = true;
2505  } else {
2506  buildRecordInfo = true;
2507  }
2508  QStringList keywords = QStringList() << QLatin1String("NUMBER") << QLatin1String("FLOAT") << QLatin1String("BINARY_FLOAT")
2509  << QLatin1String("BINARY_DOUBLE");
2510  if (buildRecordInfo) {
2511  do {
2512  QVariant::Type ty = qDecodeOCIType(t.value(1).toString(), t.numericalPrecisionPolicy());
2513  QSqlField f(t.value(0).toString(), ty);
2514  f.setRequired(t.value(5).toString() == QLatin1String("N"));
2515  f.setPrecision(t.value(4).toInt());
2516  if (d->serverVersion >= 9 && (ty == QVariant::String) && !t.isNull(3) && !keywords.contains(t.value(1).toString())) {
2517  // Oracle9: data_length == size in bytes, char_length == amount of characters
2518  f.setLength(t.value(7).toInt());
2519  } else {
2520  f.setLength(t.value(t.isNull(3) ? 2 : 3).toInt());
2521  }
2522  f.setDefaultValue(t.value(6));
2523  fil.append(f);
2524  } while (t.next());
2525  }
2526  return fil;
2527 }
QVariant::Type qDecodeOCIType(const QString &ocitype, QSql::NumericalPrecisionPolicy precisionPolicy)
Definition: qsql_oci.cpp:561
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
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
static QWidget * owner
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
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
static int toInt(const QByteArray &str)
Definition: generator.cpp:167
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
void setRequired(bool required)
Sets the required status of this field to Required if required is true; otherwise sets it to Optional...
Definition: qsqlfield.h:84
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
void qSplitTableAndOwner(const QString &tname, QString *tbl, QString *owner)
Definition: qsql_oci.cpp:2444
static const char *const keywords[MAX_KEYWORD]
void append(const QSqlField &field)
Append a copy of field field to the end of the record.
Definition: qsqlrecord.cpp:312
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
QSqlResult * createResult() const
Creates an empty SQL result on the database.
Definition: qsql_oci.cpp:2288
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ rollbackTransaction()

bool QOCIDriver::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 2332 of file qsql_oci.cpp.

2333 {
2334  if (!isOpen()) {
2335  qWarning("QOCIDriver::rollbackTransaction: Database not open");
2336  return false;
2337  }
2338  int r = OCITransRollback(d->svc,
2339  d->err,
2340  0);
2341  if (r == OCI_ERROR) {
2342  qOraWarning("QOCIDriver::rollbackTransaction:", d->err);
2344  "Unable to rollback transaction"), QSqlError::TransactionError, d->err));
2345  return false;
2346  }
2347  d->transaction = false;
2348  return true;
2349 }
OCISvcCtx * svc
Definition: qsql_oci.cpp:470
virtual bool isOpen() const
Returns true if the database connection is open; otherwise returns false.
Definition: qsqldriver.cpp:182
OCIError * err
Definition: qsql_oci.cpp:473
static QString translate(const char *context, const char *key, const char *disambiguation=0, Encoding encoding=CodecForTr)
Q_CORE_EXPORT void qWarning(const char *,...)
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
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
static QSqlError qMakeError(const QString &errString, QSqlError::ErrorType type, OCIError *err)
Definition: qsql_oci.cpp:554
static void qOraWarning(const char *msg, OCIError *err)
Definition: qsql_oci.cpp:531

◆ tables()

QStringList QOCIDriver::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 2351 of file qsql_oci.cpp.

2352 {
2353  QStringList tl;
2354  QStringList sysUsers = QStringList() << QLatin1String("MDSYS")
2355  << QLatin1String("LBACSYS")
2356  << QLatin1String("SYS")
2357  << QLatin1String("SYSTEM")
2358  << QLatin1String("WKSYS")
2359  << QLatin1String("CTXSYS")
2360  << QLatin1String("WMSYS");
2361 
2362  QString user = d->user;
2364  user = stripDelimiters(user, QSqlDriver::TableName);
2365  else
2366  user = user.toUpper();
2367 
2368  if(sysUsers.contains(user))
2369  sysUsers.removeAll(user);;
2370 
2371  if (!isOpen())
2372  return tl;
2373 
2374  QSqlQuery t(createResult());
2375  t.setForwardOnly(true);
2376  if (type & QSql::Tables) {
2377  QString query = QLatin1String("select owner, table_name from all_tables where ");
2378  QStringList whereList;
2379  foreach(const QString &sysUserName, sysUsers)
2380  whereList << QLatin1String("owner != '") + sysUserName + QLatin1String("' ");
2381  t.exec(query + whereList.join(QLatin1String(" and ")));
2382 
2383  while (t.next()) {
2384  if (t.value(0).toString().toUpper() != user.toUpper())
2385  tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
2386  else
2387  tl.append(t.value(1).toString());
2388  }
2389 
2390  // list all table synonyms as well
2391  query = QLatin1String("select owner, synonym_name from all_synonyms where ");
2392  t.exec(query + whereList.join(QLatin1String(" and ")));
2393  while (t.next()) {
2394  if (t.value(0).toString() != d->user)
2395  tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
2396  else
2397  tl.append(t.value(1).toString());
2398  }
2399  }
2400  if (type & QSql::Views) {
2401  QString query = QLatin1String("select owner, view_name from all_views where ");
2402  QStringList whereList;
2403  foreach(const QString &sysUserName, sysUsers)
2404  whereList << QLatin1String("owner != '") + sysUserName + QLatin1String("' ");
2405  t.exec(query + whereList.join(QLatin1String(" and ")));
2406  while (t.next()) {
2407  if (t.value(0).toString().toUpper() != d->user.toUpper())
2408  tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
2409  else
2410  tl.append(t.value(1).toString());
2411  }
2412  }
2413  if (type & QSql::SystemTables) {
2414  t.exec(QLatin1String("select table_name from dictionary"));
2415  while (t.next()) {
2416  tl.append(t.value(0).toString());
2417  }
2418  QString query = QLatin1String("select owner, table_name from all_tables where ");
2419  QStringList whereList;
2420  foreach(const QString &sysUserName, sysUsers)
2421  whereList << QLatin1String("owner = '") + sysUserName + QLatin1String("' ");
2422  t.exec(query + whereList.join(QLatin1String(" or ")));
2423 
2424  while (t.next()) {
2425  if (t.value(0).toString().toUpper() != user.toUpper())
2426  tl.append(t.value(0).toString() + QLatin1Char('.') + t.value(1).toString());
2427  else
2428  tl.append(t.value(1).toString());
2429  }
2430 
2431  // list all table synonyms as well
2432  query = QLatin1String("select owner, synonym_name from all_synonyms where ");
2433  t.exec(query + whereList.join(QLatin1String(" or ")));
2434  while (t.next()) {
2435  if (t.value(0).toString() != d->user)
2436  tl.append(t.value(0).toString() + QLatin1String(".") + t.value(1).toString());
2437  else
2438  tl.append(t.value(1).toString());
2439  }
2440  }
2441  return tl;
2442 }
int type
Definition: qmetatype.cpp:239
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
Definition: qstring.cpp:5483
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 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 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
QBool contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the list contains the string str; otherwise returns false.
Definition: qstringlist.h:172
QOCIDriverPrivate * d
Definition: qsql_oci.h:123
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
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
QSqlResult * createResult() const
Creates an empty SQL result on the database.
Definition: qsql_oci.cpp:2288
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
int removeAll(const T &t)
Removes all occurrences of value in the list and returns the number of entries removed.
Definition: qlist.h:770

Friends and Related Functions

◆ QOCIPrivate

friend class QOCIPrivate
friend

Definition at line 96 of file qsql_oci.h.

◆ QOCIResultPrivate

friend struct QOCIResultPrivate
friend

Definition at line 95 of file qsql_oci.h.

Properties

◆ d

QOCIDriverPrivate* QOCIDriver::d
private

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