SQL/OCI: misc cleanup

Do some cleanup:
 - use qsizetype instead int
 - use default member init instead in ctor
 - remove unneeded functions
 - make a getter const

This is a follow-up of 7005630a9b735f2e59e3345fee0305e0277c0208-

Change-Id: Ibb02bd93a130c5d60bf431608666a5ad1fe71ead
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
(cherry picked from commit 4bf7cc2440bb09578d95e8eea51ebfbddd2897e4)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2024-08-23 13:14:38 +02:00 committed by Qt Cherry-pick Bot
parent 65b6de2a20
commit 0b328b6b00

View File

@ -792,13 +792,13 @@ qulonglong qMakeULongLong(const char* ociNumber, OCIError* err)
class QOCICols class QOCICols
{ {
public: public:
QOCICols(int size, QOCIResultPrivate* dp); QOCICols(qsizetype size, QOCIResultPrivate* dp);
~QOCICols();
int readPiecewise(QVariantList &values, int index = 0); int readPiecewise(QVariantList &values, int index = 0);
int readLOBs(QVariantList &values, int index = 0); int readLOBs(QVariantList &values, int index = 0);
int fieldFromDefine(OCIDefine* d); qsizetype fieldFromDefine(OCIDefine *d) const;
void getValues(QVariantList &v, int index); void getValues(QVariantList &v, int index);
inline int size() { return fieldInf.size(); } inline qsizetype size() const { return fieldInf.size(); }
static bool execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool arrayBind); static bool execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool arrayBind);
QSqlRecord rec; QSqlRecord rec;
@ -808,20 +808,18 @@ private:
OCILobLocator ** createLobLocator(int position, OCIEnv* env); OCILobLocator ** createLobLocator(int position, OCIEnv* env);
OraFieldInfo qMakeOraField(const QOCIResultPrivate* p, OCIParam* param) const; OraFieldInfo qMakeOraField(const QOCIResultPrivate* p, OCIParam* param) const;
class OraFieldInf struct OraFieldInf
{ {
public:
OraFieldInf() : data(0), len(0), ind(0), oraType(0), def(0), lob(0), dataPtr(nullptr)
{}
~OraFieldInf(); ~OraFieldInf();
char *data;
int len; char *data = nullptr;
sb2 ind; int len = 0;
sb2 ind = 0;
QMetaType typ; QMetaType typ;
ub4 oraType; ub4 oraType = 0;
OCIDefine *def; OCIDefine *def = nullptr;
OCILobLocator *lob; OCILobLocator *lob = nullptr;
void *dataPtr; void *dataPtr = nullptr;
}; };
QList<OraFieldInf> fieldInf; QList<OraFieldInf> fieldInf;
@ -852,7 +850,7 @@ QOCICols::OraFieldInf::~OraFieldInf()
} }
} }
QOCICols::QOCICols(int size, QOCIResultPrivate* dp) QOCICols::QOCICols(qsizetype size, QOCIResultPrivate* dp)
: fieldInf(size), d(dp) : fieldInf(size), d(dp)
{ {
ub4 dataSize = 0; ub4 dataSize = 0;
@ -1046,10 +1044,6 @@ QOCICols::QOCICols(int size, QOCIResultPrivate* dp)
} }
} }
QOCICols::~QOCICols()
{
}
char* QOCICols::create(int position, int size) char* QOCICols::create(int position, int size)
{ {
char* c = new char[size+1]; char* c = new char[size+1];
@ -1085,7 +1079,6 @@ int QOCICols::readPiecewise(QVariantList &values, int index)
ub1 piecep; ub1 piecep;
sword status; sword status;
text col [QOCI_DYNAMIC_CHUNK_SIZE+1]; text col [QOCI_DYNAMIC_CHUNK_SIZE+1];
int fieldNum = -1;
int r = 0; int r = 0;
bool nullField; bool nullField;
@ -1094,7 +1087,7 @@ int QOCICols::readPiecewise(QVariantList &values, int index)
&in_outp, &iterp, &idxp, &piecep); &in_outp, &iterp, &idxp, &piecep);
if (r != OCI_SUCCESS) if (r != OCI_SUCCESS)
qOraWarning("OCIResultPrivate::readPiecewise: unable to get piece info:", d->err); qOraWarning("OCIResultPrivate::readPiecewise: unable to get piece info:", d->err);
fieldNum = fieldFromDefine(dfn); qsizetype fieldNum = fieldFromDefine(dfn);
bool isStringField = fieldInf.at(fieldNum).oraType == SQLT_LNG; bool isStringField = fieldInf.at(fieldNum).oraType == SQLT_LNG;
ub4 chunkSize = QOCI_DYNAMIC_CHUNK_SIZE; ub4 chunkSize = QOCI_DYNAMIC_CHUNK_SIZE;
nullField = false; nullField = false;
@ -1267,19 +1260,15 @@ OraFieldInfo QOCICols::qMakeOraField(const QOCIResultPrivate* p, OCIParam* param
struct QOCIBatchColumn struct QOCIBatchColumn
{ {
inline QOCIBatchColumn() OCIBind* bindh = nullptr;
: bindh(0), bindAs(0), maxLen(0), recordCount(0), ub2 bindAs = 0;
data(0), lengths(0), indicators(0), maxarr_len(0), curelep(0) {} ub4 maxLen = 0;
ub4 recordCount = 0;
OCIBind* bindh; char* data = nullptr;
ub2 bindAs; ub4* lengths = nullptr;
ub4 maxLen; sb2* indicators = nullptr;
ub4 recordCount; ub4 maxarr_len = 0;
char* data; ub4 curelep = 0;
ub4* lengths;
sb2* indicators;
ub4 maxarr_len;
ub4 curelep;
}; };
struct QOCIBatchCleanupHandler struct QOCIBatchCleanupHandler
@ -1302,7 +1291,7 @@ struct QOCIBatchCleanupHandler
bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool arrayBind) bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool arrayBind)
{ {
int columnCount = boundValues.count(); qsizetype columnCount = boundValues.count();
if (boundValues.isEmpty() || columnCount == 0) if (boundValues.isEmpty() || columnCount == 0)
return false; return false;
@ -1310,11 +1299,10 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
qCDebug(lcOci) << "columnCount:" << columnCount << boundValues; qCDebug(lcOci) << "columnCount:" << columnCount << boundValues;
#endif #endif
int i;
sword r; sword r;
QVarLengthArray<QMetaType> fieldTypes; QVarLengthArray<QMetaType> fieldTypes;
for (i = 0; i < columnCount; ++i) { for (qsizetype i = 0; i < columnCount; ++i) {
QMetaType tp = boundValues.at(i).metaType(); QMetaType tp = boundValues.at(i).metaType();
fieldTypes.append(tp.id() == QMetaType::QVariantList ? boundValues.at(i).toList().value(0).metaType() : tp); fieldTypes.append(tp.id() == QMetaType::QVariantList ? boundValues.at(i).toList().value(0).metaType() : tp);
} }
@ -1324,7 +1312,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
TempStorage tmpStorage; TempStorage tmpStorage;
// figuring out buffer sizes // figuring out buffer sizes
for (i = 0; i < columnCount; ++i) { for (qsizetype i = 0; i < columnCount; ++i) {
if (boundValues.at(i).typeId() != QMetaType::QVariantList) { if (boundValues.at(i).typeId() != QMetaType::QVariantList) {
@ -1458,7 +1446,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
{ {
columns[i].lengths[row] = columns[i].maxLen; columns[i].lengths[row] = columns[i].maxLen;
const QByteArray ba = qMakeOCINumber(val.toLongLong(), d->err); const QByteArray ba = qMakeOCINumber(val.toLongLong(), d->err);
Q_ASSERT(ba.size() == int(columns[i].maxLen)); Q_ASSERT(ba.size() == columns[i].maxLen);
memcpy(dataPtr, ba.constData(), columns[i].maxLen); memcpy(dataPtr, ba.constData(), columns[i].maxLen);
break; break;
} }
@ -1466,7 +1454,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
{ {
columns[i].lengths[row] = columns[i].maxLen; columns[i].lengths[row] = columns[i].maxLen;
const QByteArray ba = qMakeOCINumber(val.toULongLong(), d->err); const QByteArray ba = qMakeOCINumber(val.toULongLong(), d->err);
Q_ASSERT(ba.size() == int(columns[i].maxLen)); Q_ASSERT(ba.size() == columns[i].maxLen);
memcpy(dataPtr, ba.constData(), columns[i].maxLen); memcpy(dataPtr, ba.constData(), columns[i].maxLen);
break; break;
} }
@ -1572,7 +1560,7 @@ bool QOCICols::execBatch(QOCIResultPrivate *d, QVariantList &boundValues, bool a
} }
// for out parameters we copy data back to value list // for out parameters we copy data back to value list
for (i = 0; i < columnCount; ++i) { for (qsizetype i = 0; i < columnCount; ++i) {
if (!d->isOutValue(i)) if (!d->isOutValue(i))
continue; continue;
@ -1702,7 +1690,7 @@ int QOCICols::readLOBs(QVariantList &values, int index)
OCILobLocator *lob; OCILobLocator *lob;
int r = OCI_SUCCESS; int r = OCI_SUCCESS;
for (int i = 0; i < size(); ++i) { for (qsizetype i = 0; i < size(); ++i) {
const OraFieldInf &fi = fieldInf.at(i); const OraFieldInf &fi = fieldInf.at(i);
if (fi.ind == -1 || !(lob = fi.lob)) if (fi.ind == -1 || !(lob = fi.lob))
continue; continue;
@ -1727,9 +1715,9 @@ int QOCICols::readLOBs(QVariantList &values, int index)
return r; return r;
} }
int QOCICols::fieldFromDefine(OCIDefine* d) qsizetype QOCICols::fieldFromDefine(OCIDefine *d) const
{ {
for (int i = 0; i < fieldInf.count(); ++i) { for (qsizetype i = 0; i < fieldInf.size(); ++i) {
if (fieldInf.at(i).def == d) if (fieldInf.at(i).def == d)
return i; return i;
} }
@ -1738,7 +1726,7 @@ int QOCICols::fieldFromDefine(OCIDefine* d)
void QOCICols::getValues(QVariantList &v, int index) void QOCICols::getValues(QVariantList &v, int index)
{ {
for (int i = 0; i < fieldInf.size(); ++i) { for (qsizetype i = 0; i < fieldInf.size(); ++i) {
const OraFieldInf &fld = fieldInf.at(i); const OraFieldInf &fld = fieldInf.at(i);
if (fld.ind == -1) { if (fld.ind == -1) {