Deprecate QVariant::Type uses in QSqlField

Add metaType()/setMetaType() methods to be used instead
of the type() methods taking a QVariant::Type.

Change-Id: Ieaba35b73f8061cd83288dd6b50d58322db3c7ed
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
This commit is contained in:
Lars Knoll 2020-06-15 09:31:31 +02:00
parent 8929c0a355
commit 67f04fa060
16 changed files with 279 additions and 219 deletions

View File

@ -117,9 +117,9 @@ int Dialog::addNewArtist(const QString &name)
int id = generateArtistId();
QSqlField f1("id", QVariant::Int);
QSqlField f2("artist", QVariant::String);
QSqlField f3("albumcount", QVariant::Int);
QSqlField f1("id", QMetaType(QMetaType::Int));
QSqlField f2("artist", QMetaType(QMetaType::QString));
QSqlField f3("albumcount", QMetaType(QMetaType::Int));
f1.setValue(QVariant(id));
f2.setValue(QVariant(name));
@ -137,10 +137,10 @@ int Dialog::addNewAlbum(const QString &title, int artistId)
int id = generateAlbumId();
QSqlRecord record;
QSqlField f1("albumid", QVariant::Int);
QSqlField f2("title", QVariant::String);
QSqlField f3("artistid", QVariant::Int);
QSqlField f4("year", QVariant::Int);
QSqlField f1("albumid", QMetaType(QMetaType::Int));
QSqlField f2("title", QMetaType(QMetaType::QString));
QSqlField f3("artistid", QMetaType(QMetaType::Int));
QSqlField f4("year", QMetaType(QMetaType::Int));
f1.setValue(QVariant(id));
f2.setValue(QVariant(title));

View File

@ -702,7 +702,7 @@ bool QDB2Result::exec()
if (bindValueType(i) & QSql::Out)
values[i].detach();
switch (values.at(i).type()) {
switch (values.at(i).metaType().id()) {
case QVariant::Date: {
QByteArray ba;
ba.resize(sizeof(DATE_STRUCT));
@ -894,7 +894,7 @@ bool QDB2Result::exec()
return true;
for (i = 0; i < values.count(); ++i) {
switch (values[i].type()) {
switch (values[i].metaType().id()) {
case QVariant::Date: {
DATE_STRUCT ds = *((DATE_STRUCT *)tmpStorage.takeFirst().constData());
values[i] = QVariant(QDate(ds.year, ds.month, ds.day));
@ -921,7 +921,7 @@ bool QDB2Result::exec()
break; }
}
if (indicators[i] == SQL_NULL_DATA)
values[i] = QVariant(values[i].type());
values[i] = QVariant(values[i].metaType());
}
return true;
}
@ -1053,7 +1053,7 @@ QVariant QDB2Result::data(int field)
QVariant* v = 0;
switch (info.type()) {
switch (info.metaType().id()) {
case QVariant::LongLong:
v = new QVariant((qint64) qGetBigIntData(d->hStmt, field, isNull));
break;
@ -1135,7 +1135,7 @@ QVariant QDB2Result::data(int field)
break;
}
if (isNull)
*v = QVariant(info.type());
*v = QVariant(info.metaType());
d->valueCache[field] = v;
return *v;
}
@ -1687,7 +1687,7 @@ QString QDB2Driver::formatValue(const QSqlField &field, bool trimStrings) const
if (field.isNull())
return QLatin1String("NULL");
switch (field.type()) {
switch (field.metaType().id()) {
case QVariant::DateTime: {
// Use an escape sequence for the datetime fields
if (field.value().toDateTime().isValid()) {

View File

@ -173,7 +173,7 @@ public:
{
char *outField = nullptr;
MYSQL_FIELD *myField = nullptr;
QMetaType::Type type = QMetaType::UnknownType;
QMetaType type = QMetaType();
my_bool nullIndicator = false;
ulong bufLength = 0ul;
};
@ -201,7 +201,7 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type,
}
static QMetaType::Type qDecodeMYSQLType(int mysqltype, uint flags)
static QMetaType qDecodeMYSQLType(int mysqltype, uint flags)
{
QMetaType::Type type;
switch (mysqltype) {
@ -256,13 +256,13 @@ static QMetaType::Type qDecodeMYSQLType(int mysqltype, uint flags)
type = QMetaType::QString;
break;
}
return type;
return QMetaType(type);
}
static QSqlField qToField(MYSQL_FIELD *field)
{
QSqlField f(QString::fromUtf8(field->name),
QVariant::Type(qDecodeMYSQLType(int(field->type), field->flags)),
qDecodeMYSQLType(int(field->type), field->flags),
QString::fromUtf8(field->table));
f.setRequired(IS_NOT_NULL(field->flags));
f.setLength(field->length);
@ -344,7 +344,7 @@ bool QMYSQLResultPrivate::bindInValues()
// after mysql_stmt_exec() in QMYSQLResult::exec()
fieldInfo->length = 0;
hasBlobs = true;
} else if (qIsInteger(f.type)) {
} else if (qIsInteger(f.type.id())) {
fieldInfo->length = 8;
} else {
fieldInfo->type = MYSQL_TYPE_STRING;
@ -541,33 +541,33 @@ QVariant QMYSQLResult::data(int field)
QString val;
if (d->preparedQuery) {
if (f.nullIndicator)
return QVariant(QVariant::Type(f.type));
return QVariant(f.type);
if (qIsInteger(f.type)) {
QVariant variant(QMetaType(f.type), f.outField);
if (qIsInteger(f.type.id())) {
QVariant variant(f.type, f.outField);
// we never want to return char variants here, see QTBUG-53397
if (static_cast<int>(f.type) == QMetaType::UChar)
if (f.type.id() == QMetaType::UChar)
return variant.toUInt();
else if (static_cast<int>(f.type) == QMetaType::Char)
else if (f.type.id() == QMetaType::Char)
return variant.toInt();
return variant;
}
if (f.type != QMetaType::QByteArray)
if (f.type.id() != QMetaType::QByteArray)
val = QString::fromUtf8(f.outField, f.bufLength);
} else {
if (d->row[field] == NULL) {
// NULL value
return QVariant(QVariant::Type(f.type));
return QVariant(f.type);
}
fieldLength = mysql_fetch_lengths(d->result)[field];
if (f.type != QMetaType::QByteArray)
if (f.type.id() != QMetaType::QByteArray)
val = QString::fromUtf8(d->row[field], fieldLength);
}
switch (static_cast<int>(f.type)) {
switch (f.type.id()) {
case QMetaType::LongLong:
return QVariant(val.toLongLong());
case QMetaType::ULongLong:
@ -1447,7 +1447,7 @@ QString QMYSQLDriver::formatValue(const QSqlField &field, bool trimStrings) cons
if (field.isNull()) {
r = QStringLiteral("NULL");
} else {
switch (+field.type()) {
switch (field.metaType().id()) {
case QMetaType::Double:
r = QString::number(field.value().toDouble(), 'g', field.precision());
break;

View File

@ -341,49 +341,49 @@ static QSqlError qMakeError(const QString& err, QSqlError::ErrorType type,
nativeCode != -1 ? QString::number(nativeCode) : QString());
}
static QVariant::Type qDecodeODBCType(SQLSMALLINT sqltype, bool isSigned = true)
static QMetaType qDecodeODBCType(SQLSMALLINT sqltype, bool isSigned = true)
{
QVariant::Type type = QVariant::Invalid;
int type = QMetaType::UnknownType;
switch (sqltype) {
case SQL_DECIMAL:
case SQL_NUMERIC:
case SQL_REAL:
case SQL_FLOAT:
case SQL_DOUBLE:
type = QVariant::Double;
type = QMetaType::Double;
break;
case SQL_SMALLINT:
case SQL_INTEGER:
case SQL_BIT:
type = isSigned ? QVariant::Int : QVariant::UInt;
type = isSigned ? QMetaType::Int : QMetaType::UInt;
break;
case SQL_TINYINT:
type = QVariant::UInt;
type = QMetaType::UInt;
break;
case SQL_BIGINT:
type = isSigned ? QVariant::LongLong : QVariant::ULongLong;
type = isSigned ? QMetaType::LongLong : QMetaType::ULongLong;
break;
case SQL_BINARY:
case SQL_VARBINARY:
case SQL_LONGVARBINARY:
type = QVariant::ByteArray;
type = QMetaType::QByteArray;
break;
case SQL_DATE:
case SQL_TYPE_DATE:
type = QVariant::Date;
type = QMetaType::QDate;
break;
case SQL_TIME:
case SQL_TYPE_TIME:
type = QVariant::Time;
type = QMetaType::QTime;
break;
case SQL_TIMESTAMP:
case SQL_TYPE_TIMESTAMP:
type = QVariant::DateTime;
type = QMetaType::QDateTime;
break;
case SQL_WCHAR:
case SQL_WVARCHAR:
case SQL_WLONGVARCHAR:
type = QVariant::String;
type = QMetaType::QString;
break;
case SQL_CHAR:
case SQL_VARCHAR:
@ -391,13 +391,13 @@ static QVariant::Type qDecodeODBCType(SQLSMALLINT sqltype, bool isSigned = true)
case SQL_GUID:
#endif
case SQL_LONGVARCHAR:
type = QVariant::String;
type = QMetaType::QString;
break;
default:
type = QVariant::ByteArray;
type = QMetaType::QByteArray;
break;
}
return type;
return QMetaType(type);
}
static QString qGetStringData(SQLHANDLE hStmt, int column, int colSize, bool unicode = false)
@ -554,7 +554,7 @@ static QVariant qGetBinaryData(SQLHANDLE hStmt, int column)
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO)
break;
if (lengthIndicator == SQL_NULL_DATA)
return QVariant(QVariant::ByteArray);
return QVariant(QMetaType(QVariant::ByteArray));
if (lengthIndicator > SQLLEN(colSize) || lengthIndicator == SQL_NO_TOTAL) {
read += colSize;
colSize = 65536;
@ -581,9 +581,9 @@ static QVariant qGetIntData(SQLHANDLE hStmt, int column, bool isSigned = true)
sizeof(intbuf),
&lengthIndicator);
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO)
return QVariant(QVariant::Invalid);
return QVariant();
if (lengthIndicator == SQL_NULL_DATA)
return QVariant(QVariant::Int);
return QVariant(QMetaType::fromType<int>());
if (isSigned)
return int(intbuf);
else
@ -601,10 +601,10 @@ static QVariant qGetDoubleData(SQLHANDLE hStmt, int column)
0,
&lengthIndicator);
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO) {
return QVariant(QVariant::Invalid);
return QVariant();
}
if(lengthIndicator == SQL_NULL_DATA)
return QVariant(QVariant::Double);
return QVariant(QMetaType::fromType<double>());
return (double) dblbuf;
}
@ -621,9 +621,9 @@ static QVariant qGetBigIntData(SQLHANDLE hStmt, int column, bool isSigned = true
sizeof(lngbuf),
&lengthIndicator);
if (r != SQL_SUCCESS && r != SQL_SUCCESS_WITH_INFO)
return QVariant(QVariant::Invalid);
return QVariant();
if (lengthIndicator == SQL_NULL_DATA)
return QVariant(QVariant::LongLong);
return QVariant(QMetaType::fromType<qlonglong>());
if (isSigned)
return qint64(lngbuf);
@ -717,7 +717,7 @@ static QSqlField qMakeFieldInfo(const SQLHANDLE hStmt, int i, QString *errorMess
const QString qColName(fromSQLTCHAR(colName, colNameLen));
// nullable can be SQL_NO_NULLS, SQL_NULLABLE or SQL_NULLABLE_UNKNOWN
QVariant::Type type = qDecodeODBCType(colType, unsignedFlag == SQL_FALSE);
QMetaType type = qDecodeODBCType(colType, unsignedFlag == SQL_FALSE);
QSqlField f(qColName, type);
f.setSqlType(colType);
f.setLength(colSize == 0 ? -1 : int(colSize));
@ -1212,7 +1212,7 @@ QVariant QODBCResult::data(int field)
// some servers do not support fetching column n after we already
// fetched column n+1, so cache all previous columns here
const QSqlField info = d->rInf.field(i);
switch (info.type()) {
switch (info.metaType().id()) {
case QVariant::LongLong:
d->fieldCache[i] = qGetBigIntData(d->hStmt, i);
break;
@ -1236,7 +1236,7 @@ QVariant QODBCResult::data(int field)
if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (lengthIndicator != SQL_NULL_DATA))
d->fieldCache[i] = QVariant(QDate(dbuf.year, dbuf.month, dbuf.day));
else
d->fieldCache[i] = QVariant(QVariant::Date);
d->fieldCache[i] = QVariant(QMetaType::fromType<QDate>());
break;
case QVariant::Time:
TIME_STRUCT tbuf;
@ -1249,7 +1249,7 @@ QVariant QODBCResult::data(int field)
if ((r == SQL_SUCCESS || r == SQL_SUCCESS_WITH_INFO) && (lengthIndicator != SQL_NULL_DATA))
d->fieldCache[i] = QVariant(QTime(tbuf.hour, tbuf.minute, tbuf.second));
else
d->fieldCache[i] = QVariant(QVariant::Time);
d->fieldCache[i] = QVariant(QMetaType::fromType<QTime>());
break;
case QVariant::DateTime:
TIMESTAMP_STRUCT dtbuf;
@ -1263,7 +1263,7 @@ QVariant QODBCResult::data(int field)
d->fieldCache[i] = QVariant(QDateTime(QDate(dtbuf.year, dtbuf.month, dtbuf.day),
QTime(dtbuf.hour, dtbuf.minute, dtbuf.second, dtbuf.fraction / 1000000)));
else
d->fieldCache[i] = QVariant(QVariant::DateTime);
d->fieldCache[i] = QVariant(QMetaType::fromType<QDateTime>());
break;
case QVariant::ByteArray:
d->fieldCache[i] = qGetBinaryData(d->hStmt, i);
@ -1730,7 +1730,7 @@ bool QODBCResult::exec()
break; }
}
if (indicators[i] == SQL_NULL_DATA)
values[i] = QVariant(QVariant::Type(values[i].userType()));
values[i] = QVariant(values[i].metaType());
}
return true;
}
@ -2583,7 +2583,7 @@ QString QODBCDriver::formatValue(const QSqlField &field,
QString r;
if (field.isNull()) {
r = QLatin1String("NULL");
} else if (field.type() == QVariant::DateTime) {
} else if (field.metaType().id() == QVariant::DateTime) {
// Use an escape sequence for the datetime fields
if (field.value().toDateTime().isValid()){
QDate dt = field.value().toDateTime().date();
@ -2599,7 +2599,7 @@ QString QODBCDriver::formatValue(const QSqlField &field,
QLatin1String("' }");
} else
r = QLatin1String("NULL");
} else if (field.type() == QVariant::ByteArray) {
} else if (field.metaType().id() == QVariant::ByteArray) {
QByteArray ba = field.value().toByteArray();
QString res;
static const char hexchars[] = "0123456789abcdef";

View File

@ -634,7 +634,7 @@ QVariant QPSQLResult::data(int i)
int ptype = PQftype(d->result, i);
QVariant::Type type = qDecodePSQLType(ptype);
if (PQgetisnull(d->result, currentRow, i))
return QVariant(type);
return QVariant(QMetaType(type), nullptr);
const char *val = PQgetvalue(d->result, currentRow, i);
switch (type) {
case QVariant::Bool:
@ -805,8 +805,8 @@ QSqlRecord QPSQLResult::record() const
f.setTableName(QString());
}
int ptype = PQftype(d->result, i);
f.setType(qDecodePSQLType(ptype));
f.setValue(QVariant(f.type())); // only set in setType() when it's invalid before
f.setMetaType(QMetaType(qDecodePSQLType(ptype)));
f.setValue(QVariant(f.metaType())); // only set in setType() when it's invalid before
int len = PQfsize(d->result, i);
int precision = PQfmod(d->result, i);
@ -856,7 +856,7 @@ static QString qCreateParamString(const QList<QVariant> &boundValues, const QSql
QString params;
QSqlField f;
for (const QVariant &val : boundValues) {
f.setType(val.type());
f.setMetaType(val.metaType());
if (val.isNull())
f.clear();
else
@ -1476,7 +1476,7 @@ QString QPSQLDriver::formatValue(const QSqlField &field, bool trimStrings) const
if (field.isNull()) {
r = nullStr();
} else {
switch (int(field.type())) {
switch (field.metaType().id()) {
case QVariant::DateTime:
#if QT_CONFIG(datestring)
if (field.value().toDateTime().isValid()) {

View File

@ -309,7 +309,7 @@ bool QSQLiteResultPrivate::fetchNext(QSqlCachedResult::ValueCache &values, int i
};
break;
case SQLITE_NULL:
values[i + idx] = QVariant(QVariant::String);
values[i + idx] = QVariant(QMetaType::fromType<QString>());
break;
default:
values[i + idx] = QString(reinterpret_cast<const QChar *>(

View File

@ -599,7 +599,7 @@ QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const
if (field.isNull())
r = nullTxt;
else {
switch (+field.type()) {
switch (field.metaType().id()) {
case QMetaType::Int:
case QMetaType::UInt:
if (field.value().userType() == QMetaType::Bool)

View File

@ -47,8 +47,8 @@ class QSqlFieldPrivate
{
public:
QSqlFieldPrivate(const QString &name,
QVariant::Type type, const QString &tableName) :
ref(1), nm(name), table(tableName), def(QVariant()), type(QMetaType::Type(type)),
QMetaType type, const QString &tableName) :
ref(1), nm(name), table(tableName), def(QVariant()), type(type),
req(QSqlField::Unknown), len(-1), prec(-1), tp(-1),
ro(false), gen(true), autoval(false)
{}
@ -86,7 +86,7 @@ public:
QString nm;
QString table;
QVariant def;
QMetaType::Type type;
QMetaType type;
QSqlField::RequiredStatus req;
int len;
int prec;
@ -155,18 +155,17 @@ public:
*/
/*!
\fn QSqlField::QSqlField(const QString &fieldName, QVariant::Type type)
Constructs an empty field called \a fieldName of variant type \a type.
\sa setRequiredStatus(), setLength(), setPrecision(), setDefaultValue(),
setGenerated(), setReadOnly()
*/
QSqlField::QSqlField(const QString &fieldName, QVariant::Type type)
{
d = new QSqlFieldPrivate(fieldName, type, QString());
val = QVariant(type);
}
/*!
\fn QSqlField::QSqlField(const QString &fieldName, QVariant::Type type, const QString &table)
\overload
Constructs an empty field called \a fieldName of variant type \a
type in \a table.
@ -174,11 +173,35 @@ QSqlField::QSqlField(const QString &fieldName, QVariant::Type type)
\sa setRequiredStatus(), setLength(), setPrecision(), setDefaultValue(),
setGenerated(), setReadOnly()
*/
QSqlField::QSqlField(const QString &fieldName, QVariant::Type type,
const QString &table)
/*!
\fn QSqlField::QSqlField(const QString &fieldName, QVariant::Type type)
Constructs an empty field called \a fieldName of type \a type.
\sa setRequiredStatus(), setLength(), setPrecision(), setDefaultValue(),
setGenerated(), setReadOnly()
*/
QSqlField::QSqlField(const QString &fieldName, QMetaType type)
{
d = new QSqlFieldPrivate(fieldName, type, QString());
val = QVariant(QMetaType(type), nullptr);
}
/*!
\fn QSqlField::QSqlField(const QString &fieldName, QVariant::Type type, const QString &table)
\overload
Constructs an empty field called \a fieldName of type \a
type in \a table.
\sa setRequiredStatus(), setLength(), setPrecision(), setDefaultValue(),
setGenerated(), setReadOnly()
*/
QSqlField::QSqlField(const QString &fieldName, QMetaType type, const QString &table)
{
d = new QSqlFieldPrivate(fieldName, type, table);
val = QVariant(type);
val = QVariant(QMetaType(type), nullptr);
}
/*!
@ -344,7 +367,7 @@ void QSqlField::clear()
{
if (isReadOnly())
return;
val = QVariant(type());
val = QVariant(d->type, nullptr);
}
/*!
@ -397,9 +420,9 @@ QString QSqlField::name() const
\sa setType()
*/
QVariant::Type QSqlField::type() const
QMetaType QSqlField::metaType() const
{
return QVariant::Type(d->type);
return d->type;
}
/*!
@ -408,14 +431,36 @@ QVariant::Type QSqlField::type() const
\sa type(), setRequiredStatus(), setLength(), setPrecision(),
setDefaultValue(), setGenerated(), setReadOnly()
*/
void QSqlField::setType(QVariant::Type type)
void QSqlField::setMetaType(QMetaType type)
{
detach();
d->type = QMetaType::Type(type);
d->type = type;
if (!val.isValid())
val = QVariant(type);
val = QVariant(type, nullptr);
}
/*!
\fn QVariant::Type QSqlField::type() const
\obsolete Use metaType() instead.
Returns the field's type as stored in the database.
Note that the actual value might have a different type,
Numerical values that are too large to store in a long
int or double are usually stored as strings to prevent
precision loss.
\sa metaType()
*/
/*!
\fn void QSqlField::setType(QVariant::Type type)
\obsolete Use setMetaType() instead.
Set's the field's variant type to \a type.
\sa setMetaType()
*/
/*!
Returns \c true if the field's value is read-only; otherwise returns
false.
@ -525,7 +570,7 @@ bool QSqlField::isGenerated() const
*/
bool QSqlField::isValid() const
{
return d->type != QMetaType::UnknownType;
return d->type.isValid();
}
#ifndef QT_NO_DEBUG_STREAM
@ -533,7 +578,7 @@ QDebug operator<<(QDebug dbg, const QSqlField &f)
{
QDebugStateSaver saver(dbg);
dbg.nospace();
dbg << "QSqlField(" << f.name() << ", " << QMetaType::typeName(f.type());
dbg << "QSqlField(" << f.name() << ", " << f.metaType().name();
dbg << ", tableName: " << (f.tableName().isEmpty() ? QStringLiteral("(not specified)") : f.tableName());
if (f.length() >= 0)
dbg << ", length: " << f.length();

View File

@ -54,10 +54,19 @@ class Q_SQL_EXPORT QSqlField
public:
enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
explicit QSqlField(const QString& fieldName = QString(),
QVariant::Type type = {});
QSqlField(const QString &fieldName, QVariant::Type type,
const QString &tableName);
#if QT_DEPRECATED_SINCE(6,0)
QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
explicit QSqlField(const QString& fieldName, QVariant::Type type)
: QSqlField(fieldName, QMetaType(type))
{}
QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
QSqlField(const QString &fieldName, QVariant::Type type, const QString &tableName)
: QSqlField(fieldName, QMetaType(type), tableName)
{}
#endif
explicit QSqlField(const QString& fieldName = QString(), QMetaType type = QMetaType());
QSqlField(const QString &fieldName, QMetaType type, const QString &tableName);
QSqlField(const QSqlField& other);
QSqlField& operator=(const QSqlField& other);
@ -76,10 +85,16 @@ public:
void setReadOnly(bool readOnly);
bool isReadOnly() const;
void clear();
QVariant::Type type() const;
bool isAutoValue() const;
void setType(QVariant::Type type);
QMetaType metaType() const;
void setMetaType(QMetaType type);
#if QT_DEPRECATED_SINCE(6,0)
QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead")
QVariant::Type type() const { return QVariant::Type(metaType().id()); };
QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead")
void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); }
#endif
void setRequiredStatus(RequiredStatus status);
inline void setRequired(bool required)
{ setRequiredStatus(required ? Required : Optional); }

View File

@ -631,7 +631,7 @@ bool QSqlResult::exec()
for (i = d->holders.count() - 1; i >= 0; --i) {
holder = d->holders.at(i).holderName;
val = d->values.value(d->indexes.value(holder).value(0,-1));
QSqlField f(QLatin1String(""), QVariant::Type(val.userType()));
QSqlField f(QLatin1String(""), val.metaType());
f.setValue(val);
query = query.replace(d->holders.at(i).holderPos,
holder.length(), driver()->formatValue(f));
@ -645,7 +645,7 @@ bool QSqlResult::exec()
if (i == -1)
continue;
QVariant var = d->values.value(idx);
QSqlField f(QLatin1String(""), QVariant::Type(var.userType()));
QSqlField f(QLatin1String(""), var.metaType());
if (var.isNull())
f.clear();
else

View File

@ -582,17 +582,17 @@ void tst_QSqlDatabase::whitespaceInIdentifiers()
QCOMPARE(rec.count(), 1);
QCOMPARE(rec.fieldName(0), QString("test test"));
if (dbType == QSqlDriver::Oracle)
QCOMPARE(rec.field(0).type(), QVariant::Double);
QCOMPARE(rec.field(0).metaType(), QMetaType(QMetaType::Double));
else
QCOMPARE(rec.field(0).type(), QVariant::Int);
QCOMPARE(rec.field(0).metaType(), QMetaType(QMetaType::Int));
QSqlIndex idx = db.primaryIndex(tableName);
QCOMPARE(idx.count(), 1);
QCOMPARE(idx.fieldName(0), QString("test test"));
if (dbType == QSqlDriver::Oracle)
QCOMPARE(idx.field(0).type(), QVariant::Double);
QCOMPARE(idx.field(0).metaType(), QMetaType(QMetaType::Double));
else
QCOMPARE(idx.field(0).type(), QVariant::Int);
QCOMPARE(idx.field(0).metaType(), QMetaType(QMetaType::Int));
} else {
QSKIP("DBMS does not support whitespaces in identifiers");
}
@ -644,8 +644,8 @@ void tst_QSqlDatabase::record()
CHECK_DATABASE(db);
static const FieldDef fieldDefs[] = {
FieldDef("char(20)", QVariant::String, QString("blah1"), false),
FieldDef("varchar(20)", QVariant::String, QString("blah2"), false),
FieldDef("char(20)", QMetaType(QMetaType::String), QString("blah1"), false),
FieldDef("varchar(20)", QMetaType(QMetaType::String), QString("blah2"), false),
FieldDef()
};
@ -663,10 +663,10 @@ void tst_QSqlDatabase::testRecord(const FieldDef fieldDefs[], const QSqlRecord&
QVERIFY2(inf.field(i).isAutoValue(), qPrintable(inf.field(i).name() + " should be reporting as an autovalue"));
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) {
QCOMPARE(inf.field(i+1).name().toUpper(), fieldDefs[ i ].fieldName().toUpper());
if (inf.field(i+1).type() != fieldDefs[ i ].type) {
if (inf.field(i+1).metaType().id() != int(fieldDefs[ i ].type)) {
QFAIL(qPrintable(QString(" Expected: '%1' Received: '%2' for field %3 in testRecord").arg(
QVariant::typeToName(fieldDefs[ i ].type)).arg(
QVariant::typeToName(inf.field(i+1).type())).arg(
QMetaType(fieldDefs[ i ].type).name()).arg(
inf.field(i+1).metaType().name()).arg(
fieldDefs[ i ].fieldName())));
}
QVERIFY(!inf.field(i+1).isAutoValue());
@ -681,7 +681,7 @@ void tst_QSqlDatabase::commonFieldTest(const FieldDef fieldDefs[], QSqlDatabase
CHECK_DATABASE(db);
const QStringList tableNames = { qTableName("qtestfields", __FILE__, db),
qTableName("qtestfields", __FILE__, db, false) };
for (const QString table : tableNames) {
for (const QString &table : tableNames) {
QSqlRecord rec = db.record(table);
QCOMPARE(rec.count(), fieldCount + 1);
testRecord(fieldDefs, rec, db);
@ -1316,8 +1316,8 @@ void tst_QSqlDatabase::psql_escapedIdentifiers()
QVERIFY(db.tables().contains(qTableName(bumpyCase, __FILE__, db, false) + '.' +
qTableName("qtest", __FILE__, db, false), Qt::CaseSensitive));
QSqlField fld1(field1Name, QVariant::Int);
QSqlField fld2(field2Name, QVariant::String);
QSqlField fld1(field1Name, QMetaType(QMetaType::Int));
QSqlField fld2(field2Name, QMetaType(QMetaType::QString));
QSqlRecord rec;
rec.append(fld1);
rec.append(fld2);
@ -1330,7 +1330,7 @@ void tst_QSqlDatabase::psql_escapedIdentifiers()
QCOMPARE(rec.count(), 2);
QCOMPARE(rec.fieldName(0), field1Name);
QCOMPARE(rec.fieldName(1), field2Name);
QCOMPARE(rec.field(0).type(), QVariant::Int);
QCOMPARE(rec.field(0).metaType(), QMetaType(QMetaType::Int));
q.exec(QString("DROP SCHEMA %1 CASCADE").arg(schemaName));
}
@ -1433,14 +1433,14 @@ void tst_QSqlDatabase::precisionPolicy()
QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
if (dbType == QSqlDriver::SQLite)
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::String);
QCOMPARE(q.value(0).metaType(), QMetaType(QMetaType::QString));
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64);
QVERIFY_SQL(q, exec(query));
QVERIFY_SQL(q, next());
if(q.value(0).type() != QVariant::LongLong)
if(q.value(0).metaType() != QMetaType(QMetaType::LongLong))
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::LongLong);
QCOMPARE(q.value(0).metaType(), QMetaType(QMetaType::LongLong));
QCOMPARE(q.value(0).toLongLong(), (qlonglong)123);
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt32);
@ -1448,7 +1448,7 @@ void tst_QSqlDatabase::precisionPolicy()
QVERIFY_SQL(q, next());
if (dbType == QSqlDriver::SQLite)
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::Int);
QCOMPARE(q.value(0).metaType(), QMetaType(QMetaType::Int));
QCOMPARE(q.value(0).toInt(), 123);
q.setNumericalPrecisionPolicy(QSql::LowPrecisionDouble);
@ -1456,7 +1456,7 @@ void tst_QSqlDatabase::precisionPolicy()
QVERIFY_SQL(q, next());
if (dbType == QSqlDriver::SQLite)
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::Double);
QCOMPARE(q.value(0).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(q.value(0).toDouble(), (double)123);
query = QString("SELECT num FROM %1 WHERE id = 2").arg(tableName);
@ -1464,7 +1464,7 @@ void tst_QSqlDatabase::precisionPolicy()
QVERIFY_SQL(q, next());
if (dbType == QSqlDriver::SQLite)
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::Double);
QCOMPARE(q.value(0).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(q.value(0).toDouble(), QString("1850000000000.0001").toDouble());
// Postgres returns invalid QVariants on overflow
@ -1473,13 +1473,13 @@ void tst_QSqlDatabase::precisionPolicy()
QVERIFY_SQL(q, next());
if (dbType == QSqlDriver::SQLite)
QEXPECT_FAIL("", "SQLite returns this value as determined by contents of the field, not the declaration", Continue);
QCOMPARE(q.value(0).type(), QVariant::String);
QCOMPARE(q.value(0).metaType(), QMetaType(QMetaType::QString));
q.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64);
QEXPECT_FAIL("QOCI", "Oracle fails here, to retrieve next", Continue);
QVERIFY_SQL(q, exec(query));
QVERIFY_SQL(q, next());
QCOMPARE(q.value(0).type(), QVariant::LongLong);
QCOMPARE(q.value(0).metaType(), QMetaType(QMetaType::LongLong));
QSql::NumericalPrecisionPolicy oldPrecision= db.numericalPrecisionPolicy();
db.setNumericalPrecisionPolicy(QSql::LowPrecisionInt64);
@ -1487,7 +1487,7 @@ void tst_QSqlDatabase::precisionPolicy()
q2.exec(QString("SELECT num FROM %1 WHERE id = 2").arg(tableName));
QVERIFY_SQL(q2, exec(query));
QVERIFY_SQL(q2, next());
QCOMPARE(q2.value(0).type(), QVariant::LongLong);
QCOMPARE(q2.value(0).metaType(), QMetaType(QMetaType::LongLong));
db.setNumericalPrecisionPolicy(oldPrecision);
}
@ -1634,11 +1634,11 @@ void tst_QSqlDatabase::ibase_numericFields()
QCOMPARE(q.value(2).toString(), QString("%1").arg(num2));
QCOMPARE(QString("%1").arg(q.value(3).toDouble()), QString("%1").arg(num3));
QCOMPARE(QString("%1").arg(q.value(4).toDouble()), QString("%1").arg(num4));
QCOMPARE(q.value(0).type(), QVariant::Int);
QCOMPARE(q.value(1).type(), QVariant::Double);
QCOMPARE(q.value(2).type(), QVariant::Double);
QCOMPARE(q.value(3).type(), QVariant::Double);
QCOMPARE(q.value(4).type(), QVariant::Double);
QCOMPARE(q.value(0).metaType(), QMetaType(QMetaType::Int));
QCOMPARE(q.value(1).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(q.value(2).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(q.value(3).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(q.value(4).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(q.record().field(1).length(), 2);
QCOMPARE(q.record().field(1).precision(), 1);
@ -1653,11 +1653,11 @@ void tst_QSqlDatabase::ibase_numericFields()
}
QSqlRecord r = db.record(tableName);
QCOMPARE(r.field(0).type(), QVariant::Int);
QCOMPARE(r.field(1).type(), QVariant::Double);
QCOMPARE(r.field(2).type(), QVariant::Double);
QCOMPARE(r.field(3).type(), QVariant::Double);
QCOMPARE(r.field(4).type(), QVariant::Double);
QCOMPARE(r.field(0).metaType(), QMetaType(QMetaType::Int));
QCOMPARE(r.field(1).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(r.field(2).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(r.field(3).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(r.field(4).metaType(), QMetaType(QMetaType::Double));
QCOMPARE(r.field(1).length(), 2);
QCOMPARE(r.field(1).precision(), 1);
QCOMPARE(r.field(2).length(), 5);
@ -2220,7 +2220,7 @@ void tst_QSqlDatabase::sqlite_bindAndFetchUInt()
// All integers in SQLite are signed, so even though we bound the value
// as an UInt it will come back as a LongLong
QCOMPARE(q.value(0).type(), QVariant::LongLong);
QCOMPARE(q.value(0).metaType(), QMetaType(QMetaType::LongLong));
QCOMPARE(q.value(0).toUInt(), 4000000000U);
}

View File

@ -134,7 +134,7 @@ void tst_QSqlField::clear_data()
void tst_QSqlField::clear()
{
QSqlField field( "Testfield", QVariant::Int );
QSqlField field( "Testfield", QMetaType(QMetaType::Int) );
QFETCH( int, val );
field.setValue( val );
field.setReadOnly(true);
@ -142,7 +142,7 @@ void tst_QSqlField::clear()
QVERIFY( field.value() == val );
QVERIFY( !field.isNull() );
QSqlField bfield( "Testfield", QVariant::Bool );
QSqlField bfield( "Testfield", QMetaType(QMetaType::Bool) );
QFETCH( bool, bval );
bfield.setValue( QVariant(bval) );
bfield.setReadOnly(true);
@ -151,7 +151,7 @@ void tst_QSqlField::clear()
QVERIFY( bfield.value() == QVariant(bval) );
QVERIFY( !bfield.isNull() );
QSqlField ffield( "Testfield", QVariant::Double );
QSqlField ffield( "Testfield", QMetaType(QMetaType::Double) );
QFETCH( double, fval );
ffield.setValue( fval );
ffield.setReadOnly(true);
@ -159,7 +159,7 @@ void tst_QSqlField::clear()
QVERIFY( ffield.value() == fval );
QVERIFY( !ffield.isNull() );
QSqlField sfield( "Testfield", QVariant::String );
QSqlField sfield( "Testfield", QMetaType(QMetaType::QString) );
QFETCH( QString, strVal );
sfield.setValue( strVal );
sfield.setReadOnly(true);
@ -170,13 +170,13 @@ void tst_QSqlField::clear()
void tst_QSqlField::isNull()
{
QSqlField field( "test", QVariant::String );
QSqlField field( "test", QMetaType(QMetaType::QString) );
QVERIFY( field.isNull() );
}
void tst_QSqlField::isReadOnly()
{
QSqlField field( "test", QVariant::String );
QSqlField field( "test", QMetaType(QMetaType::QString) );
QVERIFY( !field.isReadOnly() );
field.setReadOnly( true );
QVERIFY( field.isReadOnly() );
@ -196,7 +196,7 @@ void tst_QSqlField::name_data()
void tst_QSqlField::name()
{
QSqlField field( "test", QVariant::String );
QSqlField field( "test", QMetaType(QMetaType::QString) );
QFETCH( QString, val );
QCOMPARE(field.name(), QLatin1String("test"));
field.setName( val );
@ -205,28 +205,28 @@ void tst_QSqlField::name()
void tst_QSqlField::operator_Assign()
{
QSqlField field1( "test", QVariant::String );
QSqlField field1( "test", QMetaType(QMetaType::QString) );
field1.setValue( "Harry" );
field1.setReadOnly( true );
QSqlField field2 = field1;
QVERIFY( field1 == field2 );
QSqlField field3( "test", QVariant::Double );
QSqlField field3( "test", QMetaType(QMetaType::Double) );
field3.clear();
field1 = field3;
QVERIFY( field1 == field3 );
QSqlField field4("test", QVariant::String, "ATable");
QSqlField field4("test", QMetaType(QMetaType::QString), "ATable");
field1 = field4;
QVERIFY(field1 == field4);
}
void tst_QSqlField::operator_Equal()
{
QSqlField field1( "test", QVariant::String );
QSqlField field2( "test2", QVariant::String );
QSqlField field3( "test", QVariant::Int );
QSqlField field4("test", QVariant::String, QString("ATable"));
QSqlField field5("test2", QVariant::String, QString("ATable"));
QSqlField field6("test", QVariant::String, QString("BTable"));
QSqlField field1( "test", QMetaType(QMetaType::QString) );
QSqlField field2( "test2", QMetaType(QMetaType::QString) );
QSqlField field3( "test", QMetaType(QMetaType::Int) );
QSqlField field4("test", QMetaType(QMetaType::QString), QString("ATable"));
QSqlField field5("test2", QMetaType(QMetaType::QString), QString("ATable"));
QSqlField field6("test", QMetaType(QMetaType::QString), QString("BTable"));
QVERIFY( !(field1 == field2) );
QVERIFY( !(field1 == field3) );
@ -265,7 +265,7 @@ void tst_QSqlField::setName_data()
void tst_QSqlField::setName()
{
QSqlField field( "test", QVariant::String );
QSqlField field( "test", QMetaType(QMetaType::QString) );
QFETCH( QString, val );
QCOMPARE(field.name(), QLatin1String("test"));
field.setName( val );
@ -274,7 +274,7 @@ void tst_QSqlField::setName()
void tst_QSqlField::setNull()
{
QSqlField field( "test", QVariant::String );
QSqlField field( "test", QMetaType(QMetaType::QString) );
field.setValue( "test" );
field.clear();
QVERIFY( field.value() == QVariant().toString() );
@ -283,7 +283,7 @@ void tst_QSqlField::setNull()
void tst_QSqlField::setReadOnly()
{
QSqlField field( "test", QVariant::String );
QSqlField field( "test", QMetaType(QMetaType::QString) );
field.setValue( "test" );
field.setReadOnly( true );
field.setValue( "Harry" );
@ -317,10 +317,10 @@ void tst_QSqlField::setValue_data()
void tst_QSqlField::setValue()
{
QSqlField field1 ( "test", QVariant::Int );
QSqlField field2 ( "test", QVariant::String );
QSqlField field3 ( "test", QVariant::Bool );
QSqlField field4 ( "test", QVariant::Double );
QSqlField field1 ( "test", QMetaType(QMetaType::Int) );
QSqlField field2 ( "test", QMetaType(QMetaType::QString) );
QSqlField field3 ( "test", QMetaType(QMetaType::Bool) );
QSqlField field4 ( "test", QMetaType(QMetaType::Double) );
field1.clear();
QFETCH( int, ival );
QFETCH( QString, sval );
@ -344,12 +344,12 @@ void tst_QSqlField::setValue()
void tst_QSqlField::type()
{
QSqlField field1( "string", QVariant::String );
QSqlField field2( "string", QVariant::Bool );
QSqlField field3( "string", QVariant::Double );
QVERIFY( field1.type() == QVariant::String );
QVERIFY( field2.type() == QVariant::Bool );
QVERIFY( field3.type() == QVariant::Double );
QSqlField field1( "string", QMetaType(QMetaType::QString) );
QSqlField field2( "string", QMetaType(QMetaType::Bool) );
QSqlField field3( "string", QMetaType(QMetaType::Double) );
QVERIFY( field1.metaType() == QMetaType(QMetaType::QString) );
QVERIFY( field2.metaType() == QMetaType(QMetaType::Bool) );
QVERIFY( field3.metaType() == QMetaType(QMetaType::Double) );
}
void tst_QSqlField::setTableName_data()
@ -362,7 +362,7 @@ void tst_QSqlField::setTableName_data()
void tst_QSqlField::setTableName()
{
QSqlField field("test", QVariant::String, "test");
QSqlField field("test", QMetaType(QMetaType::QString), "test");
QFETCH(QString, tableName);
QCOMPARE(field.tableName(), QLatin1String("test"));
field.setTableName(tableName);

View File

@ -1072,9 +1072,9 @@ void tst_QSqlQuery::record()
QCOMPARE( q.record().fieldName( 0 ).toLower(), QString( "id" ) );
QCOMPARE( q.record().fieldName( 1 ).toLower(), QString( "t_varchar" ) );
QCOMPARE( q.record().fieldName( 2 ).toLower(), QString( "t_char" ) );
QCOMPARE(q.record().value(0), QVariant(q.record().field(0).type()));
QCOMPARE(q.record().value(1), QVariant(q.record().field(1).type()));
QCOMPARE(q.record().value(2), QVariant(q.record().field(2).type()));
QCOMPARE(q.record().value(0), QVariant(q.record().field(0).metaType()));
QCOMPARE(q.record().value(1), QVariant(q.record().field(1).metaType()));
QCOMPARE(q.record().value(2), QVariant(q.record().field(2).metaType()));
QVERIFY( q.next() );
QVERIFY( q.next() );
@ -2694,18 +2694,18 @@ void tst_QSqlQuery::record_sqlite()
QSqlRecord rec = db.record(qTableName("record_sqlite", __FILE__, db));
QCOMPARE( rec.count(), 3 );
QCOMPARE( rec.field( 0 ).type(), QVariant::Int );
QCOMPARE( rec.field( 1 ).type(), QVariant::String );
QCOMPARE( rec.field( 2 ).type(), QVariant::Int );
QCOMPARE( rec.field( 0 ).metaType().id(), QVariant::Int );
QCOMPARE( rec.field( 1 ).metaType().id(), QVariant::String );
QCOMPARE( rec.field( 2 ).metaType().id(), QVariant::Int );
/* important - select from an empty table */
QVERIFY_SQL(q, exec("select id, name, title from " + qTableName("record_sqlite", __FILE__, db)));
rec = q.record();
QCOMPARE( rec.count(), 3 );
QCOMPARE( rec.field( 0 ).type(), QVariant::Int );
QCOMPARE( rec.field( 1 ).type(), QVariant::String );
QCOMPARE( rec.field( 2 ).type(), QVariant::Int );
QCOMPARE( rec.field( 0 ).metaType().id(), QVariant::Int );
QCOMPARE( rec.field( 1 ).metaType().id(), QVariant::String );
QCOMPARE( rec.field( 2 ).metaType().id(), QVariant::Int );
}
void tst_QSqlQuery::oraLong()
@ -3092,7 +3092,7 @@ void tst_QSqlQuery::nextResult()
QCOMPARE( q.record().field( 0 ).name().toUpper(), QString( "ID" ) );
QCOMPARE( q.record().field( 0 ).type(), QVariant::Int );
QCOMPARE( q.record().field( 0 ).metaType().id(), QVariant::Int );
QVERIFY( q.nextResult() ); // Discards first result set and move to the next
@ -3100,10 +3100,10 @@ void tst_QSqlQuery::nextResult()
QCOMPARE( q.record().field( 0 ).name().toUpper(), QString( "TEXT" ) );
QCOMPARE( q.record().field( 0 ).type(), QVariant::String );
QCOMPARE( q.record().field( 0 ).metaType().id(), QVariant::String );
QCOMPARE( q.record().field( 1 ).name().toUpper(), QString( "NUM" ) );
QCOMPARE(q.record().field(1).type(), QVariant::Double);
QCOMPARE(q.record().field(1).metaType().id(), QVariant::Double);
QVERIFY( q.next() ); // Move to first row of the second result set
@ -3915,14 +3915,14 @@ void tst_QSqlQuery::QTBUG_23895()
QVERIFY_SQL(q, exec(sql));
QVERIFY_SQL(q, next());
QCOMPARE(q.record().field(0).type(), QVariant::Int);
QCOMPARE(q.value(0).type(), QVariant::LongLong);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Int);
QCOMPARE(q.value(0).metaType().id(), QVariant::LongLong);
QCOMPARE(q.value(0).toInt(), 1);
QCOMPARE(q.record().field(1).type(), QVariant::Bool);
QCOMPARE(q.value(1).type(), QVariant::LongLong);
QCOMPARE(q.record().field(1).metaType().id(), QVariant::Bool);
QCOMPARE(q.value(1).metaType().id(), QVariant::LongLong);
QCOMPARE(q.value(1).toBool(), true);
QCOMPARE(q.record().field(2).type(), QVariant::Bool);
QCOMPARE(q.value(2).type(), QVariant::LongLong);
QCOMPARE(q.record().field(2).metaType().id(), QVariant::Bool);
QCOMPARE(q.value(2).metaType().id(), QVariant::LongLong);
QCOMPARE(q.value(2).toBool(), false);
q.prepare("insert into " + tableName + "(id, val1, val2) values(?, ?, ?);");
@ -3971,14 +3971,14 @@ void tst_QSqlQuery::QTBUG_14904()
QVERIFY_SQL(q, next());
QCOMPARE(q.record().indexOf("value1"), 0);
QCOMPARE(q.record().field(0).type(), QVariant::Bool);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Bool);
QCOMPARE(q.value(0).toBool(), true);
sql="select val1 AS 'value.one' from " + tableName;
QVERIFY_SQL(q, exec(sql));
QVERIFY_SQL(q, next());
QCOMPARE(q.record().indexOf("value.one"), 0); // was -1 before bug fix
QCOMPARE(q.record().field(0).type(), QVariant::Bool);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Bool);
QCOMPARE(q.value(0).toBool(), true);
}
@ -4104,7 +4104,7 @@ void tst_QSqlQuery::gisPointDatatype()
QVERIFY(sqlQuery.exec(sqlCommand));
sqlCommand = QStringLiteral("SELECT * FROM %1;").arg(tableName);
QVERIFY(sqlQuery.exec(sqlCommand));
QCOMPARE(sqlQuery.record().field(0).type(), QVariant::Type::ByteArray);
QCOMPARE(sqlQuery.record().field(0).metaType().id(), QVariant::Type::ByteArray);
QVERIFY(sqlQuery.next());
}
@ -4250,7 +4250,7 @@ void tst_QSqlQuery::sqlite_real()
QVERIFY_SQL(q, exec("SELECT realVal FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toDouble(), 2.3);
QCOMPARE(q.record().field(0).type(), QVariant::Double);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
q.prepare("INSERT INTO " + tableName + " (id, realVal) VALUES (?, ?)");
QVariant var((double)5.6);
@ -4292,9 +4292,9 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
QVERIFY(q.next());
if (dbType == QSqlDriver::SQLite)
QCOMPARE(q.record().field(0).type(), QVariant::Invalid);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Invalid);
else
QCOMPARE(q.record().field(0).type(), sumType);
QCOMPARE(q.record().field(0).metaType().id(), sumType);
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (1)"));
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (2)"));
@ -4302,33 +4302,33 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toInt(), 3);
QCOMPARE(q.record().field(0).type(), sumType);
QCOMPARE(q.record().field(0).metaType().id(), sumType);
QVERIFY_SQL(q, exec("SELECT AVG(id) FROM " + tableName));
QVERIFY(q.next());
if (dbType == QSqlDriver::SQLite || dbType == QSqlDriver::PostgreSQL || dbType == QSqlDriver::MySqlServer
|| dbType == QSqlDriver::Oracle) {
QCOMPARE(q.value(0).toDouble(), 1.5);
QCOMPARE(q.record().field(0).type(), QVariant::Double);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
} else {
QCOMPARE(q.value(0).toInt(), 1);
QCOMPARE(q.record().field(0).type(), QVariant::Int);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Int);
}
QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toInt(), 2);
QCOMPARE(q.record().field(0).type(), countType);
QCOMPARE(q.record().field(0).metaType().id(), countType);
QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toInt(), 1);
QCOMPARE(q.record().field(0).type(), intType);
QCOMPARE(q.record().field(0).metaType().id(), intType);
QVERIFY_SQL(q, exec("SELECT MAX(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toInt(), 2);
QCOMPARE(q.record().field(0).type(), intType);
QCOMPARE(q.record().field(0).metaType().id(), intType);
}
{
const QString tableName(qTableName("numericFunctionsWithDoubleValues", __FILE__, db));
@ -4341,9 +4341,9 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
QVERIFY(q.next());
if (dbType == QSqlDriver::SQLite)
QCOMPARE(q.record().field(0).type(), QVariant::Invalid);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Invalid);
else
QCOMPARE(q.record().field(0).type(), QVariant::Double);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (1.5)"));
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (2.5)"));
@ -4351,27 +4351,27 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toDouble(), 4.0);
QCOMPARE(q.record().field(0).type(), QVariant::Double);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
QVERIFY_SQL(q, exec("SELECT AVG(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toDouble(), 2.0);
QCOMPARE(q.record().field(0).type(), QVariant::Double);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toInt(), 2);
QCOMPARE(q.record().field(0).type(), countType);
QCOMPARE(q.record().field(0).metaType().id(), countType);
QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toDouble(), 1.5);
QCOMPARE(q.record().field(0).type(), QVariant::Double);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
QVERIFY_SQL(q, exec("SELECT MAX(id) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toDouble(), 2.5);
QCOMPARE(q.record().field(0).type(), QVariant::Double);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
QString field = "id";
@ -4383,7 +4383,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT ROUND(" + field + ", 1) FROM " + tableName + " WHERE id=1.5"));
QVERIFY(q.next());
QCOMPARE(q.value(0).toDouble(), 1.5);
QCOMPARE(q.record().field(0).type(), QVariant::Double);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
QVERIFY_SQL(q, exec("SELECT ROUND(" + field + ", 0) FROM " + tableName + " WHERE id=2.5"));
QVERIFY(q.next());
@ -4391,7 +4391,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QCOMPARE(q.value(0).toDouble(), 2.0);
else
QCOMPARE(q.value(0).toDouble(), 3.0);
QCOMPARE(q.record().field(0).type(), QVariant::Double);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
}
{
const QString tableName(qTableName("stringFunctions", __FILE__, db));
@ -4403,9 +4403,9 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT MAX(txt) FROM " + tableName));
QVERIFY(q.next());
if (dbType == QSqlDriver::SQLite)
QCOMPARE(q.record().field(0).type(), QVariant::Invalid);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Invalid);
else
QCOMPARE(q.record().field(0).type(), QVariant::String);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::String);
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, txt) VALUES (1, 'lower')"));
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, txt) VALUES (2, 'upper')"));
@ -4413,7 +4413,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
QVERIFY_SQL(q, exec("SELECT MAX(txt) FROM " + tableName));
QVERIFY(q.next());
QCOMPARE(q.value(0).toString(), QLatin1String("upper"));
QCOMPARE(q.record().field(0).type(), QVariant::String);
QCOMPARE(q.record().field(0).metaType().id(), QVariant::String);
}
}
@ -4456,9 +4456,9 @@ void runIntegralTypesMysqlTest(QSqlDatabase &db, const QString &tableName, const
QVariant value = q.value(0);
actualVariantValues << value;
actualValues << value.value<T>();
QVERIFY(actualVariantValues.last().userType() != qMetaTypeId<char>());
QVERIFY(actualVariantValues.last().userType() != qMetaTypeId<signed char>());
QVERIFY(actualVariantValues.last().userType() != qMetaTypeId<unsigned char>());
QVERIFY(actualVariantValues.last().metaType().id() != qMetaTypeId<char>());
QVERIFY(actualVariantValues.last().metaType().id() != qMetaTypeId<signed char>());
QVERIFY(actualVariantValues.last().metaType().id() != qMetaTypeId<unsigned char>());
}
QCOMPARE(actualValues, values);
QCOMPARE(actualVariantValues, variantValues);

View File

@ -417,9 +417,9 @@ void tst_QSqlQueryModel::record()
QCOMPARE(rec.fieldName(0), isToUpper ? QString("ID") : QString("id"));
QCOMPARE(rec.fieldName(1), isToUpper ? QString("NAME") : QString("name"));
QCOMPARE(rec.fieldName(2), isToUpper ? QString("TITLE") : QString("title"));
QCOMPARE(rec.value(0), QVariant(rec.field(0).type()));
QCOMPARE(rec.value(1), QVariant(rec.field(1).type()));
QCOMPARE(rec.value(2), QVariant(rec.field(2).type()));
QCOMPARE(rec.value(0), QVariant(rec.field(0).metaType()));
QCOMPARE(rec.value(1), QVariant(rec.field(1).metaType()));
QCOMPARE(rec.value(2), QVariant(rec.field(2).metaType()));
rec = model.record(0);
QCOMPARE(rec.fieldName(0), isToUpper ? QString("ID") : QString("id"));

View File

@ -468,10 +468,10 @@ void tst_QSqlRelationalTableModel::insertRecord()
QVERIFY_SQL(model, select());
QSqlRecord rec;
QSqlField f1("id", QVariant::Int);
QSqlField f2("name", QVariant::String);
QSqlField f3("title_key", QVariant::Int);
QSqlField f4("another_title_key", QVariant::Int);
QSqlField f1("id", QMetaType(QMetaType::Int));
QSqlField f2("name", QMetaType(QMetaType::QString));
QSqlField f3("title_key", QMetaType(QMetaType::Int));
QSqlField f4("another_title_key", QMetaType(QMetaType::Int));
f1.setValue(7);
f2.setValue("test");
@ -518,10 +518,10 @@ void tst_QSqlRelationalTableModel::setRecord()
QVERIFY_SQL(model, select());
QSqlRecord rec;
QSqlField f1("id", QVariant::Int);
QSqlField f2("name", QVariant::String);
QSqlField f3("title_key", QVariant::Int);
QSqlField f4("another_title_key", QVariant::Int);
QSqlField f1("id", QMetaType(QMetaType::Int));
QSqlField f2("name", QMetaType(QMetaType::QString));
QSqlField f3("title_key", QMetaType(QMetaType::Int));
QSqlField f4("another_title_key", QMetaType(QMetaType::Int));
f1.setValue(7);
f2.setValue("tester");
@ -1417,9 +1417,9 @@ void tst_QSqlRelationalTableModel::whiteSpaceInIdentifiers()
QVERIFY_SQL(model, select());
QSqlRecord rec;
QSqlField f1("id", QVariant::Int);
QSqlField f2(db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName), QVariant::Int);
QSqlField f3(db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName), QVariant::Int);
QSqlField f1("id", QMetaType(QMetaType::Int));
QSqlField f2(db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName), QMetaType(QMetaType::Int));
QSqlField f3(db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName), QMetaType(QMetaType::Int));
f1.setValue(3);
f2.setValue(2);
@ -1445,9 +1445,9 @@ void tst_QSqlRelationalTableModel::whiteSpaceInIdentifiers()
model.setEditStrategy(QSqlTableModel::OnManualSubmit);
QSqlRecord recNew;
QSqlField f1New("id", QVariant::Int);
QSqlField f2New(db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName), QVariant::Int);
QSqlField f3New(db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName), QVariant::Int);
QSqlField f1New("id", QMetaType(QMetaType::Int));
QSqlField f2New(db.driver()->escapeIdentifier("city key", QSqlDriver::FieldName), QMetaType(QMetaType::Int));
QSqlField f3New(db.driver()->escapeIdentifier("extra field", QSqlDriver::FieldName), QMetaType(QMetaType::Int));
f1New.setValue(4);
f2New.setValue(1);

View File

@ -956,9 +956,9 @@ void tst_QSqlTableModel::insertMultiRecords()
QVERIFY(model.insertRow(2));
QCOMPARE(model.data(model.index(2, 0)), QVariant(model.record().field(0).type()));
QCOMPARE(model.data(model.index(2, 1)), QVariant(model.record().field(1).type()));
QCOMPARE(model.data(model.index(2, 2)), QVariant(model.record().field(2).type()));
QCOMPARE(model.data(model.index(2, 0)), QVariant(model.record().field(0).metaType()));
QCOMPARE(model.data(model.index(2, 1)), QVariant(model.record().field(1).metaType()));
QCOMPARE(model.data(model.index(2, 2)), QVariant(model.record().field(2).metaType()));
QVERIFY(model.insertRow(3));
QVERIFY(model.insertRow(0));