--- qsql_oci_org.cpp	2014-12-05 19:27:16.000000000 +0100
+++ qsql_oci.cpp	2015-01-30 11:00:10.192236502 +0100
@@ -76,9 +76,11 @@
 
 //#define QOCI_DEBUG
 
-Q_DECLARE_OPAQUE_POINTER(OCIEnv*);
+Q_DECLARE_OPAQUE_POINTER(QOCIResult*)
+Q_DECLARE_METATYPE(QOCIResult*)
+Q_DECLARE_OPAQUE_POINTER(OCIEnv*)
 Q_DECLARE_METATYPE(OCIEnv*)
-Q_DECLARE_OPAQUE_POINTER(OCIStmt*);
+Q_DECLARE_OPAQUE_POINTER(OCIStmt*)
 Q_DECLARE_METATYPE(OCIStmt*)
 
 QT_BEGIN_NAMESPACE
@@ -156,33 +158,6 @@
 QT_END_INCLUDE_NAMESPACE
 
 class QOCICols;
-struct QOCIResultPrivate;
-
-class Q_EXPORT_SQLDRIVER_OCI QOCIResult : public QSqlCachedResult
-{
-    friend class QOCIDriver;
-    friend struct QOCIResultPrivate;
-    friend class QOCICols;
-public:
-    QOCIResult(const QOCIDriver * db, const QOCIDriverPrivate* p);
-    ~QOCIResult();
-    bool prepare(const QString& query);
-    bool exec();
-    QVariant handle() const;
-
-protected:
-    bool gotoNext(ValueCache &values, int index);
-    bool reset (const QString& query);
-    int size();
-    int numRowsAffected();
-    QSqlRecord record() const;
-    QVariant lastInsertId() const;
-    bool execBatch(bool arrayBind = false);
-    void virtual_hook(int id, void *data);
-
-private:
-    QOCIResultPrivate *d;
-};
 
 struct QOCIResultPrivate
 {
@@ -363,6 +338,18 @@
                              const_cast<OCIRowid **>(&rptr->id),
                              -1,
                              SQLT_RDD, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
+        } else if (val.canConvert<QOCIResult *>() && isOutValue(pos)) {
+            QOCIResult *res = qvariant_cast<QOCIResult *>(val);
+
+            if (res->internal_prepare()) {
+                r = OCIBindByPos(sql, hbnd, err,
+                                 pos + 1,
+                                 const_cast<OCIStmt **>(&res->d->sql),
+                                 (sb4)0,
+                                 SQLT_RSET, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
+
+                res->isCursor = true;
+            }
         } else {
             qWarning("Unknown bind variable");
             r = OCI_ERROR;
@@ -1820,6 +1807,7 @@
     : QSqlCachedResult(db)
 {
     d = new QOCIResultPrivate(this, p);
+    isCursor = false;
 }
 
 QOCIResult::~QOCIResult()
@@ -1915,12 +1903,15 @@
     return rowCount;
 }
 
-bool QOCIResult::prepare(const QString& query)
+bool QOCIResult::internal_prepare()
 {
     int r = 0;
-    QSqlResult::prepare(query);
+    QString noStr;
+    QSqlResult::prepare(noStr);
+
+    if (d->cols)
+        delete d->cols;
 
-    delete d->cols;
     d->cols = 0;
     QSqlCachedResult::cleanup();
 
@@ -1929,8 +1920,7 @@
         if (r != OCI_SUCCESS)
             qOraWarning("QOCIResult::prepare: unable to free statement handle:", d->err);
     }
-    if (query.isEmpty())
-        return false;
+
     r = OCIHandleAlloc(d->env,
                        reinterpret_cast<void **>(&d->sql),
                        OCI_HTYPE_STMT,
@@ -1942,7 +1932,21 @@
                      "Unable to alloc statement"), QSqlError::StatementError, d->err));
         return false;
     }
+
     d->setStatementAttributes();
+
+    return true;
+}
+
+bool QOCIResult::prepare(const QString& query)
+{
+    if (query.isEmpty())
+        return false;
+
+    if (!internal_prepare())
+        return false;
+
+    int r;
     const OraText *txt = reinterpret_cast<const OraText *>(query.utf16());
     const int len = query.length() * sizeof(QChar);
     r = OCIStmtPrepare(d->sql,
@@ -2002,23 +2006,26 @@
         return false;
     }
 
-    // execute
-    r = OCIStmtExecute(d->svc,
-                       d->sql,
-                       d->err,
-                       iters,
-                       0,
-                       0,
-                       0,
-                       mode);
-    if (r != OCI_SUCCESS && r != OCI_SUCCESS_WITH_INFO) {
-        qOraWarning("QOCIResult::exec: unable to execute statement:", d->err);
-        setLastError(qMakeError(QCoreApplication::translate("QOCIResult",
-                     "Unable to execute statement"), QSqlError::StatementError, d->err));
-#ifdef QOCI_DEBUG
-        qDebug() << "lastQuery()" << lastQuery();
-#endif
-        return false;
+    if (!isCursor)
+    {
+        // execute
+        r = OCIStmtExecute(d->svc,
+                           d->sql,
+                           d->err,
+                           iters,
+                           0,
+                           0,
+                           0,
+                           mode);
+        if (r != OCI_SUCCESS && r != OCI_SUCCESS_WITH_INFO) {
+            qOraWarning("QOCIResult::exec: unable to execute statement:", d->err);
+            setLastError(qMakeError(QCoreApplication::translate("QOCIResult",
+                         "Unable to execute statement"), QSqlError::StatementError, d->err));
+    #ifdef QOCI_DEBUG
+            qDebug() << "lastQuery()" << lastQuery();
+    #endif
+            return false;
+        }
     }
 
     if (stmtType == OCI_STMT_SELECT) {
