summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/sql/drivers/oci/qsql_oci.cpp106
-rw-r--r--tests/auto/qsqlquery/tst_qsqlquery.cpp21
2 files changed, 63 insertions, 64 deletions
diff --git a/src/sql/drivers/oci/qsql_oci.cpp b/src/sql/drivers/oci/qsql_oci.cpp
index e11cf75..3f30ea5 100644
--- a/src/sql/drivers/oci/qsql_oci.cpp
+++ b/src/sql/drivers/oci/qsql_oci.cpp
@@ -93,11 +93,13 @@ enum { QOCIEncoding = 2002 }; // AL16UTF16LE
enum { QOCIEncoding = 2000 }; // AL16UTF16
#endif
+#ifdef OCI_ATTR_CHARSET_FORM
// Always set the OCI_ATTR_CHARSET_FORM to SQLCS_NCHAR is safe
// because Oracle server will deal with the implicit Conversion
// Between CHAR and NCHAR.
// see: http://download.oracle.com/docs/cd/A91202_01/901_doc/appdev.901/a89857/oci05bnd.htm#422705
static const ub1 qOraCharsetForm = SQLCS_NCHAR;
+#endif
#if defined (OCI_UTF16ID)
static const ub2 qOraCharset = OCI_UTF16ID;
@@ -117,6 +119,8 @@ static // for some reason, Sun CC can't use qOraWarning when it's declared stati
void qOraWarning(const char* msg, OCIError *err);
static QSqlError qMakeError(const QString& errString, QSqlError::ErrorType type, OCIError *err);
+
+
class QOCIRowId: public QSharedData
{
public:
@@ -164,7 +168,6 @@ struct QOCIResultPrivate
int serverVersion;
int prefetchRows, prefetchMem;
- void setCharset(OCIBind* hbnd);
void setStatementAttributes();
int bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, int pos,
const QVariant &val, dvoid *indPtr, ub2 *tmpSize, QList<QByteArray> &tmpStorage);
@@ -176,6 +179,41 @@ struct QOCIResultPrivate
{ return q->bindValueType(i) & QSql::Out; }
inline bool isBinaryValue(int i) const
{ return q->bindValueType(i) & QSql::Binary; }
+
+ void setCharset(dvoid* handle, ub4 type) const
+ {
+ int r = 0;
+ Q_ASSERT(handle);
+
+#ifdef OCI_ATTR_CHARSET_FORM
+ r = OCIAttrSet(handle,
+ type,
+ // this const cast is safe since OCI doesn't touch
+ // the charset.
+ const_cast<void *>(static_cast<const void *>(&qOraCharsetForm)),
+ 0,
+ OCI_ATTR_CHARSET_FORM,
+ //Strange Oracle bug: some Oracle servers crash the server process with non-zero error handle (mostly for 10g).
+ //So ignore the error message here.
+ 0);
+ #ifdef QOCI_DEBUG
+ if (r != 0)
+ qWarning("QOCIResultPrivate::setCharset: Couldn't set OCI_ATTR_CHARSET_FORM.");
+ #endif
+#endif
+
+ r = OCIAttrSet(handle,
+ type,
+ // this const cast is safe since OCI doesn't touch
+ // the charset.
+ const_cast<void *>(static_cast<const void *>(&qOraCharset)),
+ 0,
+ OCI_ATTR_CHARSET_ID,
+ err);
+ if (r != 0)
+ qOraWarning("QOCIResultPrivate::setCharsetI Couldn't set OCI_ATTR_CHARSET_ID: ", err);
+
+ }
};
void QOCIResultPrivate::setStatementAttributes()
@@ -208,36 +246,6 @@ void QOCIResultPrivate::setStatementAttributes()
}
}
-void QOCIResultPrivate::setCharset(OCIBind* hbnd)
-{
- int r = 0;
-
- Q_ASSERT(hbnd);
-
- r = OCIAttrSet(hbnd,
- OCI_HTYPE_BIND,
- // this const cast is safe since OCI doesn't touch
- // the charset.
- const_cast<void *>(static_cast<const void *>(&qOraCharsetForm)),
- 0,
- OCI_ATTR_CHARSET_FORM,
- err);
- if (r != 0)
- qOraWarning("QOCIResultPrivate::setCharset: Couldn't set OCI_ATTR_CHARSET_FORM: ", err);
-
- r = OCIAttrSet(hbnd,
- OCI_HTYPE_BIND,
- // this const cast is safe since OCI doesn't touch
- // the charset.
- const_cast<void *>(static_cast<const void *>(&qOraCharset)),
- 0,
- OCI_ATTR_CHARSET_ID,
- err);
- if (r != 0)
- qOraWarning("QOCIResultPrivate::setCharset: Couldn't set OCI_ATTR_CHARSET_ID: ", err);
-
-}
-
int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, int pos,
const QVariant &val, dvoid *indPtr, ub2 *tmpSize, QList<QByteArray> &tmpStorage)
{
@@ -325,7 +333,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in
(s.length() + 1) * sizeof(QChar),
SQLT_STR, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
if (r == OCI_SUCCESS)
- setCharset(*hbnd);
+ setCharset(*hbnd, OCI_HTYPE_BIND);
break;
}
} // fall through for OUT values
@@ -349,7 +357,7 @@ int QOCIResultPrivate::bindValue(OCIStmt *sql, OCIBind **hbnd, OCIError *err, in
SQLT_STR, indPtr, 0, 0, 0, 0, OCI_DEFAULT);
}
if (r == OCI_SUCCESS)
- setCharset(*hbnd);
+ setCharset(*hbnd, OCI_HTYPE_BIND);
tmpStorage.append(ba);
break;
} // default case
@@ -688,7 +696,6 @@ class QOCICols
public:
QOCICols(int size, QOCIResultPrivate* dp);
~QOCICols();
- void setCharset(OCIDefine* dfn);
int readPiecewise(QVector<QVariant> &values, int index = 0);
int readLOBs(QVector<QVariant> &values, int index = 0);
int fieldFromDefine(OCIDefine* d);
@@ -890,7 +897,7 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp)
&(fieldInf[idx].ind),
0, 0, OCI_DEFAULT);
if (r == 0)
- setCharset(dfn);
+ d->setCharset(dfn, OCI_HTYPE_DEFINE);
}
break;
default:
@@ -950,35 +957,6 @@ OCILobLocator **QOCICols::createLobLocator(int position, OCIEnv* env)
return &lob;
}
-void QOCICols::setCharset(OCIDefine* dfn)
-{
- int r = 0;
-
- Q_ASSERT(dfn);
-
- r = OCIAttrSet(dfn,
- OCI_HTYPE_DEFINE,
- // this const cast is safe since OCI doesn't touch
- // the charset.
- const_cast<void *>(static_cast<const void *>(&qOraCharsetForm)),
- 0,
- OCI_ATTR_CHARSET_FORM,
- d->err);
- if (r != 0)
- qOraWarning("QOCIResultPrivate::setCharset: Couldn't set OCI_ATTR_CHARSET_FORM: ", d->err);
-
- r = OCIAttrSet(dfn,
- OCI_HTYPE_DEFINE,
- // this const cast is safe since OCI doesn't touch
- // the charset.
- const_cast<void *>(static_cast<const void *>(&qOraCharset)),
- 0,
- OCI_ATTR_CHARSET_ID,
- d->err);
- if (r != 0)
- qOraWarning("QOCICols::setCharset: Couldn't set OCI_ATTR_CHARSET_ID: ", d->err);
-}
-
int QOCICols::readPiecewise(QVector<QVariant> &values, int index)
{
OCIDefine* dfn;
diff --git a/tests/auto/qsqlquery/tst_qsqlquery.cpp b/tests/auto/qsqlquery/tst_qsqlquery.cpp
index c7a61a5..7c93c7a 100644
--- a/tests/auto/qsqlquery/tst_qsqlquery.cpp
+++ b/tests/auto/qsqlquery/tst_qsqlquery.cpp
@@ -209,6 +209,8 @@ private slots:
void QTBUG_6852();
void QTBUG_5765_data() { generic_data("QMYSQL"); }
void QTBUG_5765();
+ void QTBUG_14132_data() { generic_data("QOCI"); }
+ void QTBUG_14132();
void sqlite_constraint_data() { generic_data("QSQLITE"); }
void sqlite_constraint();
@@ -2933,6 +2935,25 @@ void tst_QSqlQuery::QTBUG_551()
QCOMPARE(res_outLst[2].toString(), QLatin1String("3. Value is 2"));
}
+void tst_QSqlQuery::QTBUG_14132()
+{
+ QFETCH( QString, dbName );
+ QSqlDatabase db = QSqlDatabase::database( dbName );
+ CHECK_DATABASE( db );
+ QSqlQuery q(db);
+ const QString procedureName(qTableName("procedure", __FILE__));
+ QVERIFY_SQL(q, exec("CREATE OR REPLACE PROCEDURE "+ procedureName + " (outStr OUT varchar2) \n\
+ is \n\
+ begin \n\
+ outStr := 'OUTSTRING'; \n\
+ end;"));
+ QString outValue = "XXXXXXXXX";
+ q.prepare("CALL "+procedureName+"(?)");
+ q.addBindValue(outValue, QSql::Out);
+ QVERIFY_SQL(q, exec());
+ QCOMPARE(outValue, QLatin1String("OUTSTRING"));
+}
+
void tst_QSqlQuery::QTBUG_5251()
{
QFETCH( QString, dbName );