Cleanup remaining QVariant::Type uses in Qt Sql
Change-Id: Ibcaa678cd9f9c957392a75b477fa6821f9a69127 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
parent
008343a05e
commit
2732231182
@ -85,24 +85,24 @@ static QString _q_escapeIdentifier(const QString &identifier)
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QVariant::Type qGetColumnType(const QString &tpName)
|
static int qGetColumnType(const QString &tpName)
|
||||||
{
|
{
|
||||||
const QString typeName = tpName.toLower();
|
const QString typeName = tpName.toLower();
|
||||||
|
|
||||||
if (typeName == QLatin1String("integer")
|
if (typeName == QLatin1String("integer")
|
||||||
|| typeName == QLatin1String("int"))
|
|| typeName == QLatin1String("int"))
|
||||||
return QVariant::Int;
|
return QMetaType::Int;
|
||||||
if (typeName == QLatin1String("double")
|
if (typeName == QLatin1String("double")
|
||||||
|| typeName == QLatin1String("float")
|
|| typeName == QLatin1String("float")
|
||||||
|| typeName == QLatin1String("real")
|
|| typeName == QLatin1String("real")
|
||||||
|| typeName.startsWith(QLatin1String("numeric")))
|
|| typeName.startsWith(QLatin1String("numeric")))
|
||||||
return QVariant::Double;
|
return QMetaType::Double;
|
||||||
if (typeName == QLatin1String("blob"))
|
if (typeName == QLatin1String("blob"))
|
||||||
return QVariant::ByteArray;
|
return QMetaType::QByteArray;
|
||||||
if (typeName == QLatin1String("boolean")
|
if (typeName == QLatin1String("boolean")
|
||||||
|| typeName == QLatin1String("bool"))
|
|| typeName == QLatin1String("bool"))
|
||||||
return QVariant::Bool;
|
return QMetaType::Bool;
|
||||||
return QVariant::String;
|
return QMetaType::QString;
|
||||||
}
|
}
|
||||||
|
|
||||||
static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type,
|
static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type,
|
||||||
@ -214,7 +214,7 @@ void QSQLiteResultPrivate::initColumns(bool emptyResultset)
|
|||||||
// sqlite3_column_type is documented to have undefined behavior if the result set is empty
|
// sqlite3_column_type is documented to have undefined behavior if the result set is empty
|
||||||
int stp = emptyResultset ? -1 : sqlite3_column_type(stmt, i);
|
int stp = emptyResultset ? -1 : sqlite3_column_type(stmt, i);
|
||||||
|
|
||||||
QVariant::Type fieldType;
|
int fieldType;
|
||||||
|
|
||||||
if (!typeName.isEmpty()) {
|
if (!typeName.isEmpty()) {
|
||||||
fieldType = qGetColumnType(typeName);
|
fieldType = qGetColumnType(typeName);
|
||||||
@ -222,25 +222,25 @@ void QSQLiteResultPrivate::initColumns(bool emptyResultset)
|
|||||||
// Get the proper type for the field based on stp value
|
// Get the proper type for the field based on stp value
|
||||||
switch (stp) {
|
switch (stp) {
|
||||||
case SQLITE_INTEGER:
|
case SQLITE_INTEGER:
|
||||||
fieldType = QVariant::Int;
|
fieldType = QMetaType::Int;
|
||||||
break;
|
break;
|
||||||
case SQLITE_FLOAT:
|
case SQLITE_FLOAT:
|
||||||
fieldType = QVariant::Double;
|
fieldType = QMetaType::Double;
|
||||||
break;
|
break;
|
||||||
case SQLITE_BLOB:
|
case SQLITE_BLOB:
|
||||||
fieldType = QVariant::ByteArray;
|
fieldType = QMetaType::QByteArray;
|
||||||
break;
|
break;
|
||||||
case SQLITE_TEXT:
|
case SQLITE_TEXT:
|
||||||
fieldType = QVariant::String;
|
fieldType = QMetaType::QString;
|
||||||
break;
|
break;
|
||||||
case SQLITE_NULL:
|
case SQLITE_NULL:
|
||||||
default:
|
default:
|
||||||
fieldType = QVariant::Invalid;
|
fieldType = QMetaType::UnknownType;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSqlField fld(colName, fieldType, tableName);
|
QSqlField fld(colName, QMetaType(fieldType), tableName);
|
||||||
fld.setSqlType(stp);
|
fld.setSqlType(stp);
|
||||||
rInf.append(fld);
|
rInf.append(fld);
|
||||||
}
|
}
|
||||||
@ -502,37 +502,37 @@ bool QSQLiteResult::exec()
|
|||||||
res = sqlite3_bind_null(d->stmt, i + 1);
|
res = sqlite3_bind_null(d->stmt, i + 1);
|
||||||
} else {
|
} else {
|
||||||
switch (value.userType()) {
|
switch (value.userType()) {
|
||||||
case QVariant::ByteArray: {
|
case QMetaType::QByteArray: {
|
||||||
const QByteArray *ba = static_cast<const QByteArray*>(value.constData());
|
const QByteArray *ba = static_cast<const QByteArray*>(value.constData());
|
||||||
res = sqlite3_bind_blob(d->stmt, i + 1, ba->constData(),
|
res = sqlite3_bind_blob(d->stmt, i + 1, ba->constData(),
|
||||||
ba->size(), SQLITE_STATIC);
|
ba->size(), SQLITE_STATIC);
|
||||||
break; }
|
break; }
|
||||||
case QVariant::Int:
|
case QMetaType::Int:
|
||||||
case QVariant::Bool:
|
case QMetaType::Bool:
|
||||||
res = sqlite3_bind_int(d->stmt, i + 1, value.toInt());
|
res = sqlite3_bind_int(d->stmt, i + 1, value.toInt());
|
||||||
break;
|
break;
|
||||||
case QVariant::Double:
|
case QMetaType::Double:
|
||||||
res = sqlite3_bind_double(d->stmt, i + 1, value.toDouble());
|
res = sqlite3_bind_double(d->stmt, i + 1, value.toDouble());
|
||||||
break;
|
break;
|
||||||
case QVariant::UInt:
|
case QMetaType::UInt:
|
||||||
case QVariant::LongLong:
|
case QMetaType::LongLong:
|
||||||
res = sqlite3_bind_int64(d->stmt, i + 1, value.toLongLong());
|
res = sqlite3_bind_int64(d->stmt, i + 1, value.toLongLong());
|
||||||
break;
|
break;
|
||||||
case QVariant::DateTime: {
|
case QMetaType::QDateTime: {
|
||||||
const QDateTime dateTime = value.toDateTime();
|
const QDateTime dateTime = value.toDateTime();
|
||||||
const QString str = dateTime.toString(Qt::ISODateWithMs);
|
const QString str = dateTime.toString(Qt::ISODateWithMs);
|
||||||
res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
|
res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
|
||||||
str.size() * sizeof(ushort), SQLITE_TRANSIENT);
|
str.size() * sizeof(ushort), SQLITE_TRANSIENT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QVariant::Time: {
|
case QMetaType::QTime: {
|
||||||
const QTime time = value.toTime();
|
const QTime time = value.toTime();
|
||||||
const QString str = time.toString(u"hh:mm:ss.zzz");
|
const QString str = time.toString(u"hh:mm:ss.zzz");
|
||||||
res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
|
res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
|
||||||
str.size() * sizeof(ushort), SQLITE_TRANSIENT);
|
str.size() * sizeof(ushort), SQLITE_TRANSIENT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QVariant::String: {
|
case QMetaType::QString: {
|
||||||
// lifetime of string == lifetime of its qvariant
|
// lifetime of string == lifetime of its qvariant
|
||||||
const QString *str = static_cast<const QString*>(value.constData());
|
const QString *str = static_cast<const QString*>(value.constData());
|
||||||
res = sqlite3_bind_text16(d->stmt, i + 1, str->utf16(),
|
res = sqlite3_bind_text16(d->stmt, i + 1, str->utf16(),
|
||||||
@ -925,7 +925,7 @@ static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool only
|
|||||||
defVal = defVal.mid(1, end - 1);
|
defVal = defVal.mid(1, end - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSqlField fld(q.value(1).toString(), qGetColumnType(typeName), tableName);
|
QSqlField fld(q.value(1).toString(), QMetaType(qGetColumnType(typeName)), tableName);
|
||||||
if (isPk && (typeName == QLatin1String("integer")))
|
if (isPk && (typeName == QLatin1String("integer")))
|
||||||
// INTEGER PRIMARY KEY fields are auto-generated in sqlite
|
// INTEGER PRIMARY KEY fields are auto-generated in sqlite
|
||||||
// INT PRIMARY KEY is not the same as INTEGER PRIMARY KEY!
|
// INT PRIMARY KEY is not the same as INTEGER PRIMARY KEY!
|
||||||
|
@ -54,7 +54,7 @@ class Q_SQL_EXPORT QSqlField
|
|||||||
public:
|
public:
|
||||||
enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
|
enum RequiredStatus { Unknown = -1, Optional = 0, Required = 1 };
|
||||||
|
|
||||||
#if QT_DEPRECATED_SINCE(6,0)
|
#if QT_DEPRECATED_SINCE(6, 0)
|
||||||
QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
|
QT_DEPRECATED_VERSION_X_6_0("Use the constructor using a QMetaType instead")
|
||||||
QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString())
|
QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString())
|
||||||
: QSqlField(fieldName, QMetaType(type), tableName)
|
: QSqlField(fieldName, QMetaType(type), tableName)
|
||||||
@ -84,12 +84,14 @@ public:
|
|||||||
|
|
||||||
QMetaType metaType() const;
|
QMetaType metaType() const;
|
||||||
void setMetaType(QMetaType type);
|
void setMetaType(QMetaType type);
|
||||||
#if QT_DEPRECATED_SINCE(6,0)
|
|
||||||
|
#if QT_DEPRECATED_SINCE(6, 0)
|
||||||
QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead")
|
QT_DEPRECATED_VERSION_X_6_0("Use metaType() instead")
|
||||||
QVariant::Type type() const { return QVariant::Type(metaType().id()); };
|
QVariant::Type type() const { return QVariant::Type(metaType().id()); };
|
||||||
QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead")
|
QT_DEPRECATED_VERSION_X_6_0("Use setMetaType() instead")
|
||||||
void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); }
|
void setType(QVariant::Type type) { setMetaType(QMetaType(int(type))); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void setRequiredStatus(RequiredStatus status);
|
void setRequiredStatus(RequiredStatus status);
|
||||||
inline void setRequired(bool required)
|
inline void setRequired(bool required)
|
||||||
{ setRequiredStatus(required ? Required : Optional); }
|
{ setRequiredStatus(required ? Required : Optional); }
|
||||||
|
@ -220,7 +220,7 @@ static const int ITERATION_COUNT = 2;
|
|||||||
//helper class for database specific tests
|
//helper class for database specific tests
|
||||||
struct FieldDef {
|
struct FieldDef {
|
||||||
FieldDef(QString tn = QString(),
|
FieldDef(QString tn = QString(),
|
||||||
QVariant::Type t = QVariant::Invalid,
|
int t = QMetaType::UnknownType,
|
||||||
QVariant v = QVariant(),
|
QVariant v = QVariant(),
|
||||||
bool nl = true):
|
bool nl = true):
|
||||||
typeName(tn), type(t), val(v), nullable(nl) {}
|
typeName(tn), type(t), val(v), nullable(nl) {}
|
||||||
@ -237,7 +237,7 @@ struct FieldDef {
|
|||||||
return "t_" + rt.left(i);
|
return "t_" + rt.left(i);
|
||||||
}
|
}
|
||||||
QString typeName;
|
QString typeName;
|
||||||
QVariant::Type type;
|
int type;
|
||||||
QVariant val;
|
QVariant val;
|
||||||
bool nullable;
|
bool nullable;
|
||||||
};
|
};
|
||||||
@ -656,8 +656,8 @@ void tst_QSqlDatabase::record()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
static const FieldDef fieldDefs[] = {
|
static const FieldDef fieldDefs[] = {
|
||||||
FieldDef("char(20)", QMetaType(QMetaType::String), QString("blah1"), false),
|
FieldDef("char(20)", QMetaType(QMetaType::QString), QString("blah1"), false),
|
||||||
FieldDef("varchar(20)", QMetaType(QMetaType::String), QString("blah2"), false),
|
FieldDef("varchar(20)", QMetaType(QMetaType::QString), QString("blah2"), false),
|
||||||
FieldDef()
|
FieldDef()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -675,7 +675,7 @@ 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"));
|
QVERIFY2(inf.field(i).isAutoValue(), qPrintable(inf.field(i).name() + " should be reporting as an autovalue"));
|
||||||
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) {
|
for (i = 0; !fieldDefs[ i ].typeName.isNull(); ++i) {
|
||||||
QCOMPARE(inf.field(i+1).name().toUpper(), fieldDefs[ i ].fieldName().toUpper());
|
QCOMPARE(inf.field(i+1).name().toUpper(), fieldDefs[ i ].fieldName().toUpper());
|
||||||
if (inf.field(i+1).metaType().id() != int(fieldDefs[ i ].type)) {
|
if (inf.field(i+1).metaType().id() != fieldDefs[ i ].type) {
|
||||||
QFAIL(qPrintable(QString(" Expected: '%1' Received: '%2' for field %3 in testRecord").arg(
|
QFAIL(qPrintable(QString(" Expected: '%1' Received: '%2' for field %3 in testRecord").arg(
|
||||||
QMetaType(fieldDefs[ i ].type).name()).arg(
|
QMetaType(fieldDefs[ i ].type).name()).arg(
|
||||||
inf.field(i+1).metaType().name()).arg(
|
inf.field(i+1).metaType().name()).arg(
|
||||||
@ -713,26 +713,26 @@ void tst_QSqlDatabase::recordTDS()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
static const FieldDef fieldDefs[] = {
|
static const FieldDef fieldDefs[] = {
|
||||||
FieldDef("tinyint", QVariant::Int, 255),
|
FieldDef("tinyint", QMetaType::Int, 255),
|
||||||
FieldDef("smallint", QVariant::Int, 32767),
|
FieldDef("smallint", QMetaType::Int, 32767),
|
||||||
FieldDef("int", QVariant::Int, 2147483647),
|
FieldDef("int", QMetaType::Int, 2147483647),
|
||||||
FieldDef("numeric(10,9)", QVariant::Double, 1.23456789),
|
FieldDef("numeric(10,9)", QMetaType::Double, 1.23456789),
|
||||||
FieldDef("decimal(10,9)", QVariant::Double, 1.23456789),
|
FieldDef("decimal(10,9)", QMetaType::Double, 1.23456789),
|
||||||
FieldDef("float(4)", QVariant::Double, 1.23456789),
|
FieldDef("float(4)", QMetaType::Double, 1.23456789),
|
||||||
FieldDef("double precision", QVariant::Double, 1.23456789),
|
FieldDef("double precision", QMetaType::Double, 1.23456789),
|
||||||
FieldDef("real", QVariant::Double, 1.23456789),
|
FieldDef("real", QMetaType::Double, 1.23456789),
|
||||||
FieldDef("smallmoney", QVariant::Double, 100.42),
|
FieldDef("smallmoney", QMetaType::Double, 100.42),
|
||||||
FieldDef("money", QVariant::Double, 200.42),
|
FieldDef("money", QMetaType::Double, 200.42),
|
||||||
// accuracy is that of a minute
|
// accuracy is that of a minute
|
||||||
FieldDef("smalldatetime", QVariant::DateTime, QDateTime(QDate::currentDate(), QTime(1, 2, 0, 0))),
|
FieldDef("smalldatetime", QMetaType::QDateTime, QDateTime(QDate::currentDate(), QTime(1, 2, 0, 0))),
|
||||||
// accuracy is that of a second
|
// accuracy is that of a second
|
||||||
FieldDef("datetime", QVariant::DateTime, QDateTime(QDate::currentDate(), QTime(1, 2, 3, 0))),
|
FieldDef("datetime", QMetaType::QDateTime, QDateTime(QDate::currentDate(), QTime(1, 2, 3, 0))),
|
||||||
FieldDef("char(20)", QVariant::String, "blah1"),
|
FieldDef("char(20)", QMetaType::QString, "blah1"),
|
||||||
FieldDef("varchar(20)", QVariant::String, "blah2"),
|
FieldDef("varchar(20)", QMetaType::QString, "blah2"),
|
||||||
FieldDef("nchar(20)", QVariant::String, "blah3"),
|
FieldDef("nchar(20)", QMetaType::QString, "blah3"),
|
||||||
FieldDef("nvarchar(20)", QVariant::String, "blah4"),
|
FieldDef("nvarchar(20)", QMetaType::QString, "blah4"),
|
||||||
FieldDef("text", QVariant::String, "blah5"),
|
FieldDef("text", QMetaType::QString, "blah5"),
|
||||||
FieldDef("bit", QVariant::Int, 1, false),
|
FieldDef("bit", QMetaType::Int, 1, false),
|
||||||
|
|
||||||
FieldDef()
|
FieldDef()
|
||||||
};
|
};
|
||||||
@ -764,26 +764,26 @@ void tst_QSqlDatabase::recordOCI()
|
|||||||
static const QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0));
|
static const QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0));
|
||||||
|
|
||||||
if (hasTimeStamp) {
|
if (hasTimeStamp) {
|
||||||
tsdef = FieldDef("timestamp", QVariant::DateTime, dt);
|
tsdef = FieldDef("timestamp", QMetaType::QDateTime, dt);
|
||||||
tstzdef = FieldDef("timestamp with time zone", QVariant::DateTime, dt);
|
tstzdef = FieldDef("timestamp with time zone", QMetaType::QDateTime, dt);
|
||||||
tsltzdef = FieldDef("timestamp with local time zone", QVariant::DateTime, dt);
|
tsltzdef = FieldDef("timestamp with local time zone", QMetaType::QDateTime, dt);
|
||||||
intytm = FieldDef("interval year to month", QVariant::String, QString("+01-01"));
|
intytm = FieldDef("interval year to month", QMetaType::QString, QString("+01-01"));
|
||||||
intdts = FieldDef("interval day to second", QVariant::String, QString("+01 00:00:01.000000"));
|
intdts = FieldDef("interval day to second", QMetaType::QString, QString("+01 00:00:01.000000"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const FieldDef fieldDefs[] = {
|
const FieldDef fieldDefs[] = {
|
||||||
FieldDef("char(20)", QVariant::String, QString("blah1")),
|
FieldDef("char(20)", QMetaType::QString, QString("blah1")),
|
||||||
FieldDef("varchar(20)", QVariant::String, QString("blah2")),
|
FieldDef("varchar(20)", QMetaType::QString, QString("blah2")),
|
||||||
FieldDef("nchar(20)", QVariant::String, QString("blah3")),
|
FieldDef("nchar(20)", QMetaType::QString, QString("blah3")),
|
||||||
FieldDef("nvarchar2(20)", QVariant::String, QString("blah4")),
|
FieldDef("nvarchar2(20)", QMetaType::QString, QString("blah4")),
|
||||||
FieldDef("number(10,5)", QVariant::Double, 1.1234567),
|
FieldDef("number(10,5)", QMetaType::Double, 1.1234567),
|
||||||
FieldDef("date", QVariant::DateTime, dt),
|
FieldDef("date", QMetaType::QDateTime, dt),
|
||||||
FieldDef("long raw", QVariant::ByteArray, QByteArray("blah5")),
|
FieldDef("long raw", QMetaType::QByteArray, QByteArray("blah5")),
|
||||||
FieldDef("raw(2000)", QVariant::ByteArray, QByteArray("blah6"), false),
|
FieldDef("raw(2000)", QMetaType::QByteArray, QByteArray("blah6"), false),
|
||||||
FieldDef("blob", QVariant::ByteArray, QByteArray("blah7")),
|
FieldDef("blob", QMetaType::QByteArray, QByteArray("blah7")),
|
||||||
FieldDef("clob", QVariant::ByteArray, QByteArray("blah8")),
|
FieldDef("clob", QMetaType::QByteArray, QByteArray("blah8")),
|
||||||
FieldDef("nclob", QVariant::ByteArray, QByteArray("blah9")),
|
FieldDef("nclob", QMetaType::QByteArray, QByteArray("blah9")),
|
||||||
// FieldDef("bfile", QVariant::ByteArray, QByteArray("blah10")),
|
// FieldDef("bfile", QMetaType::QByteArray, QByteArray("blah10")),
|
||||||
|
|
||||||
intytm,
|
intytm,
|
||||||
intdts,
|
intdts,
|
||||||
@ -819,39 +819,39 @@ void tst_QSqlDatabase::recordPSQL()
|
|||||||
|
|
||||||
FieldDef byteadef;
|
FieldDef byteadef;
|
||||||
if (db.driver()->hasFeature(QSqlDriver::BLOB))
|
if (db.driver()->hasFeature(QSqlDriver::BLOB))
|
||||||
byteadef = FieldDef("bytea", QVariant::ByteArray, QByteArray("bl\\ah"));
|
byteadef = FieldDef("bytea", QMetaType::QByteArray, QByteArray("bl\\ah"));
|
||||||
static FieldDef fieldDefs[] = {
|
static FieldDef fieldDefs[] = {
|
||||||
FieldDef("bigint", QVariant::LongLong, Q_INT64_C(9223372036854775807)),
|
FieldDef("bigint", QMetaType::LongLong, Q_INT64_C(9223372036854775807)),
|
||||||
FieldDef("bigserial", QVariant::LongLong, 100, false),
|
FieldDef("bigserial", QMetaType::LongLong, 100, false),
|
||||||
FieldDef("bit", QVariant::String, "1"), // a bit in postgres is a bit-string
|
FieldDef("bit", QMetaType::QString, "1"), // a bit in postgres is a bit-string
|
||||||
FieldDef("box", QVariant::String, "(5,6),(1,2)"),
|
FieldDef("box", QMetaType::QString, "(5,6),(1,2)"),
|
||||||
FieldDef("char(20)", QVariant::String, "blah5678901234567890"),
|
FieldDef("char(20)", QMetaType::QString, "blah5678901234567890"),
|
||||||
FieldDef("varchar(20)", QVariant::String, "blah5678901234567890"),
|
FieldDef("varchar(20)", QMetaType::QString, "blah5678901234567890"),
|
||||||
FieldDef("cidr", QVariant::String, "12.123.0.0/24"),
|
FieldDef("cidr", QMetaType::QString, "12.123.0.0/24"),
|
||||||
FieldDef("circle", QVariant::String, "<(1,2),3>"),
|
FieldDef("circle", QMetaType::QString, "<(1,2),3>"),
|
||||||
FieldDef("date", QVariant::Date, QDate::currentDate()),
|
FieldDef("date", QMetaType::QDate, QDate::currentDate()),
|
||||||
FieldDef("float8", QVariant::Double, 1.12345678912),
|
FieldDef("float8", QMetaType::Double, 1.12345678912),
|
||||||
FieldDef("inet", QVariant::String, "12.123.12.23"),
|
FieldDef("inet", QMetaType::QString, "12.123.12.23"),
|
||||||
FieldDef("integer", QVariant::Int, 2147483647),
|
FieldDef("integer", QMetaType::Int, 2147483647),
|
||||||
FieldDef("interval", QVariant::String, "1 day 12:59:10"),
|
FieldDef("interval", QMetaType::QString, "1 day 12:59:10"),
|
||||||
// LOL... you can create a "line" datatype in PostgreSQL <= 7.2.x but
|
// LOL... you can create a "line" datatype in PostgreSQL <= 7.2.x but
|
||||||
// as soon as you want to insert data you get a "not implemented yet" error
|
// as soon as you want to insert data you get a "not implemented yet" error
|
||||||
// FieldDef("line", QVariant::Polygon, QPolygon(QRect(1, 2, 3, 4))),
|
// FieldDef("line", QMetaType::Polygon, QPolygon(QRect(1, 2, 3, 4))),
|
||||||
FieldDef("lseg", QVariant::String, "[(1,1),(2,2)]"),
|
FieldDef("lseg", QMetaType::QString, "[(1,1),(2,2)]"),
|
||||||
FieldDef("macaddr", QVariant::String, "08:00:2b:01:02:03"),
|
FieldDef("macaddr", QMetaType::QString, "08:00:2b:01:02:03"),
|
||||||
FieldDef("money", QVariant::String, "$12.23"),
|
FieldDef("money", QMetaType::QString, "$12.23"),
|
||||||
FieldDef("numeric", QVariant::Double, 1.2345678912),
|
FieldDef("numeric", QMetaType::Double, 1.2345678912),
|
||||||
FieldDef("path", QVariant::String, "((1,2),(3,2),(3,5),(1,5))"),
|
FieldDef("path", QMetaType::QString, "((1,2),(3,2),(3,5),(1,5))"),
|
||||||
FieldDef("point", QVariant::String, "(1,2)"),
|
FieldDef("point", QMetaType::QString, "(1,2)"),
|
||||||
FieldDef("polygon", QVariant::String, "((1,2),(3,2),(3,5),(1,5))"),
|
FieldDef("polygon", QMetaType::QString, "((1,2),(3,2),(3,5),(1,5))"),
|
||||||
FieldDef("real", QVariant::Double, 1.1234),
|
FieldDef("real", QMetaType::Double, 1.1234),
|
||||||
FieldDef("smallint", QVariant::Int, 32767),
|
FieldDef("smallint", QMetaType::Int, 32767),
|
||||||
FieldDef("serial", QVariant::Int, 100, false),
|
FieldDef("serial", QMetaType::Int, 100, false),
|
||||||
FieldDef("text", QVariant::String, "blah"),
|
FieldDef("text", QMetaType::QString, "blah"),
|
||||||
FieldDef("time(6)", QVariant::Time, QTime(1, 2, 3)),
|
FieldDef("time(6)", QMetaType::QTime, QTime(1, 2, 3)),
|
||||||
FieldDef("timetz", QVariant::Time, QTime(1, 2, 3)),
|
FieldDef("timetz", QMetaType::QTime, QTime(1, 2, 3)),
|
||||||
FieldDef("timestamp(6)", QVariant::DateTime, QDateTime::currentDateTime()),
|
FieldDef("timestamp(6)", QMetaType::QDateTime, QDateTime::currentDateTime()),
|
||||||
FieldDef("timestamptz", QVariant::DateTime, QDateTime::currentDateTime()),
|
FieldDef("timestamptz", QMetaType::QDateTime, QDateTime::currentDateTime()),
|
||||||
byteadef,
|
byteadef,
|
||||||
|
|
||||||
FieldDef()
|
FieldDef()
|
||||||
@ -901,37 +901,37 @@ void tst_QSqlDatabase::recordMySQL()
|
|||||||
with space on insert, and trailing spaces are removed on select.
|
with space on insert, and trailing spaces are removed on select.
|
||||||
*/
|
*/
|
||||||
if( vernum >= ((5 << 16) + 15) ) {
|
if( vernum >= ((5 << 16) + 15) ) {
|
||||||
bin10 = FieldDef("binary(10)", QVariant::ByteArray, QString("123abc "));
|
bin10 = FieldDef("binary(10)", QMetaType::QByteArray, QString("123abc "));
|
||||||
varbin10 = FieldDef("varbinary(10)", QVariant::ByteArray, QString("123abcv "));
|
varbin10 = FieldDef("varbinary(10)", QMetaType::QByteArray, QString("123abcv "));
|
||||||
}
|
}
|
||||||
|
|
||||||
static QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0));
|
static QDateTime dt(QDate::currentDate(), QTime(1, 2, 3, 0));
|
||||||
static const FieldDef fieldDefs[] = {
|
static const FieldDef fieldDefs[] = {
|
||||||
FieldDef("tinyint", static_cast<QVariant::Type>(QMetaType::Char), 127),
|
FieldDef("tinyint", QMetaType::Char, 127),
|
||||||
FieldDef("tinyint unsigned", static_cast<QVariant::Type>(QMetaType::UChar), 255),
|
FieldDef("tinyint unsigned", QMetaType::UChar, 255),
|
||||||
FieldDef("smallint", static_cast<QVariant::Type>(QMetaType::Short), 32767),
|
FieldDef("smallint", QMetaType::Short, 32767),
|
||||||
FieldDef("smallint unsigned", static_cast<QVariant::Type>(QMetaType::UShort), 65535),
|
FieldDef("smallint unsigned", QMetaType::UShort, 65535),
|
||||||
FieldDef("mediumint", QVariant::Int, 8388607),
|
FieldDef("mediumint", QMetaType::Int, 8388607),
|
||||||
FieldDef("mediumint unsigned", QVariant::UInt, 16777215),
|
FieldDef("mediumint unsigned", QMetaType::UInt, 16777215),
|
||||||
FieldDef("integer", QVariant::Int, 2147483647),
|
FieldDef("integer", QMetaType::Int, 2147483647),
|
||||||
FieldDef("integer unsigned", QVariant::UInt, 4294967295u),
|
FieldDef("integer unsigned", QMetaType::UInt, 4294967295u),
|
||||||
FieldDef("bigint", QVariant::LongLong, Q_INT64_C(9223372036854775807)),
|
FieldDef("bigint", QMetaType::LongLong, Q_INT64_C(9223372036854775807)),
|
||||||
FieldDef("bigint unsigned", QVariant::ULongLong, Q_UINT64_C(18446744073709551615)),
|
FieldDef("bigint unsigned", QMetaType::ULongLong, Q_UINT64_C(18446744073709551615)),
|
||||||
FieldDef("float", QVariant::Double, 1.12345),
|
FieldDef("float", QMetaType::Double, 1.12345),
|
||||||
FieldDef("double", QVariant::Double, 1.123456789),
|
FieldDef("double", QMetaType::Double, 1.123456789),
|
||||||
FieldDef("decimal(10, 9)", QVariant::Double, 1.123456789),
|
FieldDef("decimal(10, 9)", QMetaType::Double, 1.123456789),
|
||||||
FieldDef("numeric(5, 2)", QVariant::Double, 123.67),
|
FieldDef("numeric(5, 2)", QMetaType::Double, 123.67),
|
||||||
FieldDef("date", QVariant::Date, QDate::currentDate()),
|
FieldDef("date", QMetaType::QDate, QDate::currentDate()),
|
||||||
FieldDef("datetime", QVariant::DateTime, dt),
|
FieldDef("datetime", QMetaType::QDateTime, dt),
|
||||||
FieldDef("timestamp", QVariant::DateTime, dt, false),
|
FieldDef("timestamp", QMetaType::QDateTime, dt, false),
|
||||||
FieldDef("time", QVariant::String, dt.time()),
|
FieldDef("time", QMetaType::QString, dt.time()),
|
||||||
FieldDef("year", QVariant::Int, 2003),
|
FieldDef("year", QMetaType::Int, 2003),
|
||||||
FieldDef("char(20)", QVariant::String, "Blah"),
|
FieldDef("char(20)", QMetaType::QString, "Blah"),
|
||||||
FieldDef("varchar(20)", QVariant::String, "BlahBlah"),
|
FieldDef("varchar(20)", QMetaType::QString, "BlahBlah"),
|
||||||
FieldDef("tinytext", QVariant::String, QString("blah5")),
|
FieldDef("tinytext", QMetaType::QString, QString("blah5")),
|
||||||
FieldDef("text", QVariant::String, QString("blah6")),
|
FieldDef("text", QMetaType::QString, QString("blah6")),
|
||||||
FieldDef("mediumtext", QVariant::String, QString("blah7")),
|
FieldDef("mediumtext", QMetaType::QString, QString("blah7")),
|
||||||
FieldDef("longtext", QVariant::String, QString("blah8")),
|
FieldDef("longtext", QMetaType::QString, QString("blah8")),
|
||||||
// SET OF?
|
// SET OF?
|
||||||
|
|
||||||
FieldDef()
|
FieldDef()
|
||||||
@ -955,26 +955,26 @@ void tst_QSqlDatabase::recordDB2()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
static const FieldDef fieldDefs[] = {
|
static const FieldDef fieldDefs[] = {
|
||||||
FieldDef("char(20)", QVariant::String, QString("Blah1")),
|
FieldDef("char(20)", QMetaType::QString, QString("Blah1")),
|
||||||
FieldDef("varchar(20)", QVariant::String, QString("Blah2")),
|
FieldDef("varchar(20)", QMetaType::QString, QString("Blah2")),
|
||||||
FieldDef("long varchar", QVariant::String, QString("Blah3")),
|
FieldDef("long varchar", QMetaType::QString, QString("Blah3")),
|
||||||
// using BOOLEAN results in "SQL0486N The BOOLEAN data type is currently only supported internally."
|
// using BOOLEAN results in "SQL0486N The BOOLEAN data type is currently only supported internally."
|
||||||
//X FieldDef("boolean" , QVariant::Bool, QVariant(true, 1)),
|
//X FieldDef("boolean" , QMetaType::Bool, QVariant(true, 1)),
|
||||||
FieldDef("smallint", QVariant::Int, 32767),
|
FieldDef("smallint", QMetaType::Int, 32767),
|
||||||
FieldDef("integer", QVariant::Int, 2147483647),
|
FieldDef("integer", QMetaType::Int, 2147483647),
|
||||||
FieldDef("bigint", QVariant::LongLong, Q_INT64_C(9223372036854775807)),
|
FieldDef("bigint", QMetaType::LongLong, Q_INT64_C(9223372036854775807)),
|
||||||
FieldDef("real", QVariant::Double, 1.12345),
|
FieldDef("real", QMetaType::Double, 1.12345),
|
||||||
FieldDef("double", QVariant::Double, 1.23456789),
|
FieldDef("double", QMetaType::Double, 1.23456789),
|
||||||
FieldDef("float", QVariant::Double, 1.23456789),
|
FieldDef("float", QMetaType::Double, 1.23456789),
|
||||||
FieldDef("decimal(10,9)", QVariant::Double, 1.234567891),
|
FieldDef("decimal(10,9)", QMetaType::Double, 1.234567891),
|
||||||
FieldDef("numeric(10,9)", QVariant::Double, 1.234567891),
|
FieldDef("numeric(10,9)", QMetaType::Double, 1.234567891),
|
||||||
FieldDef("date", QVariant::Date, QDate::currentDate()),
|
FieldDef("date", QMetaType::QDate, QDate::currentDate()),
|
||||||
FieldDef("time", QVariant::Time, QTime(1, 2, 3)),
|
FieldDef("time", QMetaType::QTime, QTime(1, 2, 3)),
|
||||||
FieldDef("timestamp", QVariant::DateTime, QDateTime::currentDateTime()),
|
FieldDef("timestamp", QMetaType::QDateTime, QDateTime::currentDateTime()),
|
||||||
// FieldDef("graphic(20)", QVariant::String, QString("Blah4")),
|
// FieldDef("graphic(20)", QMetaType::QString, QString("Blah4")),
|
||||||
// FieldDef("vargraphic(20)", QVariant::String, QString("Blah5")),
|
// FieldDef("vargraphic(20)", QMetaType::QString, QString("Blah5")),
|
||||||
// FieldDef("long vargraphic", QVariant::String, QString("Blah6")),
|
// FieldDef("long vargraphic", QMetaType::QString, QString("Blah6")),
|
||||||
//X FieldDef("datalink", QVariant::String, QString("DLVALUE('Blah10')")),
|
//X FieldDef("datalink", QMetaType::QString, QString("DLVALUE('Blah10')")),
|
||||||
FieldDef()
|
FieldDef()
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -991,16 +991,16 @@ void tst_QSqlDatabase::recordIBase()
|
|||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
|
|
||||||
static const FieldDef fieldDefs[] = {
|
static const FieldDef fieldDefs[] = {
|
||||||
FieldDef("char(20)", QVariant::String, QString("Blah1"), false),
|
FieldDef("char(20)", QMetaType::QString, QString("Blah1"), false),
|
||||||
FieldDef("varchar(20)", QVariant::String, QString("Blah2")),
|
FieldDef("varchar(20)", QMetaType::QString, QString("Blah2")),
|
||||||
FieldDef("smallint", QVariant::Int, 32767),
|
FieldDef("smallint", QMetaType::Int, 32767),
|
||||||
FieldDef("float", QVariant::Double, 1.2345),
|
FieldDef("float", QMetaType::Double, 1.2345),
|
||||||
FieldDef("double precision", QVariant::Double, 1.2345678),
|
FieldDef("double precision", QMetaType::Double, 1.2345678),
|
||||||
FieldDef("timestamp", QVariant::DateTime, QDateTime::currentDateTime()),
|
FieldDef("timestamp", QMetaType::QDateTime, QDateTime::currentDateTime()),
|
||||||
FieldDef("time", QVariant::Time, QTime::currentTime()),
|
FieldDef("time", QMetaType::QTime, QTime::currentTime()),
|
||||||
FieldDef("decimal(18)", QVariant::LongLong, Q_INT64_C(9223372036854775807)),
|
FieldDef("decimal(18)", QMetaType::LongLong, Q_INT64_C(9223372036854775807)),
|
||||||
FieldDef("numeric(5,2)", QVariant::Double, 123.45),
|
FieldDef("numeric(5,2)", QMetaType::Double, 123.45),
|
||||||
FieldDef("boolean", QVariant::Bool, true),
|
FieldDef("boolean", QMetaType::Bool, true),
|
||||||
|
|
||||||
FieldDef()
|
FieldDef()
|
||||||
};
|
};
|
||||||
@ -1019,14 +1019,14 @@ void tst_QSqlDatabase::recordSQLite()
|
|||||||
|
|
||||||
static const FieldDef fieldDefs[] = {
|
static const FieldDef fieldDefs[] = {
|
||||||
// The affinity of these fields are TEXT so SQLite should give us strings, not ints or doubles.
|
// The affinity of these fields are TEXT so SQLite should give us strings, not ints or doubles.
|
||||||
FieldDef("char(20)", QVariant::String, QString("123")),
|
FieldDef("char(20)", QMetaType::QString, QString("123")),
|
||||||
FieldDef("varchar(20)", QVariant::String, QString("123.4")),
|
FieldDef("varchar(20)", QMetaType::QString, QString("123.4")),
|
||||||
FieldDef("clob", QVariant::String, QString("123.45")),
|
FieldDef("clob", QMetaType::QString, QString("123.45")),
|
||||||
FieldDef("text", QVariant::String, QString("123.456")),
|
FieldDef("text", QMetaType::QString, QString("123.456")),
|
||||||
|
|
||||||
FieldDef("integer", QVariant::Int, QVariant(13)),
|
FieldDef("integer", QMetaType::Int, QVariant(13)),
|
||||||
FieldDef("int", QVariant::Int, QVariant(12)),
|
FieldDef("int", QMetaType::Int, QVariant(12)),
|
||||||
FieldDef("real", QVariant::Double, QVariant(1.234567890123456)),
|
FieldDef("real", QMetaType::Double, QVariant(1.234567890123456)),
|
||||||
|
|
||||||
FieldDef()
|
FieldDef()
|
||||||
};
|
};
|
||||||
@ -1049,13 +1049,13 @@ void tst_QSqlDatabase::recordSQLServer()
|
|||||||
|
|
||||||
// ### TODO: Add the rest of the fields
|
// ### TODO: Add the rest of the fields
|
||||||
static const FieldDef fieldDefs[] = {
|
static const FieldDef fieldDefs[] = {
|
||||||
FieldDef("varchar(20)", QVariant::String, QString("Blah1")),
|
FieldDef("varchar(20)", QMetaType::QString, QString("Blah1")),
|
||||||
FieldDef("bigint", QVariant::LongLong, 12345),
|
FieldDef("bigint", QMetaType::LongLong, 12345),
|
||||||
FieldDef("int", QVariant::Int, 123456),
|
FieldDef("int", QMetaType::Int, 123456),
|
||||||
FieldDef("tinyint", QVariant::UInt, 255),
|
FieldDef("tinyint", QMetaType::UInt, 255),
|
||||||
FieldDef("float", QVariant::Double, 1.12345),
|
FieldDef("float", QMetaType::Double, 1.12345),
|
||||||
FieldDef("numeric(5,2)", QVariant::Double, 123.45),
|
FieldDef("numeric(5,2)", QMetaType::Double, 123.45),
|
||||||
FieldDef("uniqueidentifier", QVariant::String,
|
FieldDef("uniqueidentifier", QMetaType::QString,
|
||||||
QString("AA7DF450-F119-11CD-8465-00AA00425D90")),
|
QString("AA7DF450-F119-11CD-8465-00AA00425D90")),
|
||||||
|
|
||||||
FieldDef()
|
FieldDef()
|
||||||
@ -1082,12 +1082,12 @@ void tst_QSqlDatabase::recordAccess()
|
|||||||
|
|
||||||
// ### TODO: Add the rest of the fields
|
// ### TODO: Add the rest of the fields
|
||||||
static const FieldDef fieldDefs[] = {
|
static const FieldDef fieldDefs[] = {
|
||||||
FieldDef("varchar(20)", QVariant::String, QString("Blah1")),
|
FieldDef("varchar(20)", QMetaType::QString, QString("Blah1")),
|
||||||
FieldDef("single", QVariant::Double, 1.12345),
|
FieldDef("single", QMetaType::Double, 1.12345),
|
||||||
FieldDef("double", QVariant::Double, 1.123456),
|
FieldDef("double", QMetaType::Double, 1.123456),
|
||||||
FieldDef("byte", QVariant::UInt, 255),
|
FieldDef("byte", QMetaType::UInt, 255),
|
||||||
FieldDef("long", QVariant::Int, 2147483647),
|
FieldDef("long", QMetaType::Int, 2147483647),
|
||||||
FieldDef("memo", QVariant::String, memo),
|
FieldDef("memo", QMetaType::QString, memo),
|
||||||
FieldDef()
|
FieldDef()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -534,7 +534,7 @@ void tst_QSqlQuery::oraRowId()
|
|||||||
QSqlQuery q( db );
|
QSqlQuery q( db );
|
||||||
QVERIFY_SQL( q, exec( "select rowid from " + qtest ) );
|
QVERIFY_SQL( q, exec( "select rowid from " + qtest ) );
|
||||||
QVERIFY( q.next() );
|
QVERIFY( q.next() );
|
||||||
QCOMPARE( q.value( 0 ).type(), QVariant::String );
|
QCOMPARE( q.value( 0 ).metaType().id(), QMetaType::QString );
|
||||||
QVERIFY( !q.value( 0 ).toString().isEmpty() );
|
QVERIFY( !q.value( 0 ).toString().isEmpty() );
|
||||||
|
|
||||||
QVERIFY_SQL( q, exec( "create table " + oraRowId + " (id char(1))" ) );
|
QVERIFY_SQL( q, exec( "create table " + oraRowId + " (id char(1))" ) );
|
||||||
@ -676,7 +676,7 @@ void tst_QSqlQuery::oraOutValues()
|
|||||||
QCOMPARE( q.boundValue( 0 ).toInt(), 42 );
|
QCOMPARE( q.boundValue( 0 ).toInt(), 42 );
|
||||||
|
|
||||||
// bind a null value, make sure the OCI driver resets the null flag
|
// bind a null value, make sure the OCI driver resets the null flag
|
||||||
q.addBindValue( QVariant( QVariant::Int ), QSql::Out );
|
q.addBindValue( QVariant(QMetaType(QMetaType::Int)), QSql::Out );
|
||||||
QVERIFY_SQL( q, exec() );
|
QVERIFY_SQL( q, exec() );
|
||||||
QCOMPARE( q.boundValue( 0 ).toInt(), 42 );
|
QCOMPARE( q.boundValue( 0 ).toInt(), 42 );
|
||||||
QVERIFY( !q.boundValue( 0 ).isNull() );
|
QVERIFY( !q.boundValue( 0 ).isNull() );
|
||||||
@ -766,7 +766,7 @@ void tst_QSqlQuery::oraOutValues()
|
|||||||
QVERIFY(q.prepare("call " + tst_outValues + "(?, ?)"));
|
QVERIFY(q.prepare("call " + tst_outValues + "(?, ?)"));
|
||||||
const QDateTime dt = QDateTime::currentDateTime();
|
const QDateTime dt = QDateTime::currentDateTime();
|
||||||
q.addBindValue(dt, QSql::In);
|
q.addBindValue(dt, QSql::In);
|
||||||
q.addBindValue(QVariant(QVariant::DateTime), QSql::Out);
|
q.addBindValue(QVariant(QMetaType(QMetaType::QDateTime)), QSql::Out);
|
||||||
QVERIFY_SQL(q, exec());
|
QVERIFY_SQL(q, exec());
|
||||||
QCOMPARE(q.boundValue(1).toDateTime(), dt);
|
QCOMPARE(q.boundValue(1).toDateTime(), dt);
|
||||||
}
|
}
|
||||||
@ -2497,15 +2497,15 @@ void tst_QSqlQuery::batchExec()
|
|||||||
"dtstamp ") + timeStampString +
|
"dtstamp ") + timeStampString +
|
||||||
QStringLiteral(", extraId int, extraName varchar(20))")));
|
QStringLiteral(", extraId int, extraName varchar(20))")));
|
||||||
|
|
||||||
const QVariantList intCol = { 1, 2, QVariant(QVariant::Int) };
|
const QVariantList intCol = { 1, 2, QVariant(QMetaType(QMetaType::Int)) };
|
||||||
const QVariantList charCol = { QStringLiteral("harald"), QStringLiteral("boris"),
|
const QVariantList charCol = { QStringLiteral("harald"), QStringLiteral("boris"),
|
||||||
QVariant(QVariant::String) };
|
QVariant(QMetaType(QMetaType::QString)) };
|
||||||
const QDateTime currentDateTime = QDateTime(QDateTime::currentDateTime());
|
const QDateTime currentDateTime = QDateTime(QDateTime::currentDateTime());
|
||||||
const QVariantList dateCol = { currentDateTime.date(), currentDateTime.date().addDays(-1),
|
const QVariantList dateCol = { currentDateTime.date(), currentDateTime.date().addDays(-1),
|
||||||
QVariant(QVariant::Date) };
|
QVariant(QMetaType(QMetaType::QDate)) };
|
||||||
const QVariantList numCol = { 2.3, 3.4, QVariant(QVariant::Double) };
|
const QVariantList numCol = { 2.3, 3.4, QVariant(QMetaType(QMetaType::Double)) };
|
||||||
const QVariantList timeStampCol = { currentDateTime, currentDateTime.addDays(-1),
|
const QVariantList timeStampCol = { currentDateTime, currentDateTime.addDays(-1),
|
||||||
QVariant(QVariant::DateTime) };
|
QVariant(QMetaType(QMetaType::QDateTime)) };
|
||||||
|
|
||||||
// Test with positional placeholders
|
// Test with positional placeholders
|
||||||
QVERIFY_SQL(q, prepare(QStringLiteral("insert into ") + tableName +
|
QVERIFY_SQL(q, prepare(QStringLiteral("insert into ") + tableName +
|
||||||
@ -2720,18 +2720,18 @@ void tst_QSqlQuery::record_sqlite()
|
|||||||
QSqlRecord rec = db.record(qTableName("record_sqlite", __FILE__, db));
|
QSqlRecord rec = db.record(qTableName("record_sqlite", __FILE__, db));
|
||||||
|
|
||||||
QCOMPARE( rec.count(), 3 );
|
QCOMPARE( rec.count(), 3 );
|
||||||
QCOMPARE( rec.field( 0 ).metaType().id(), QVariant::Int );
|
QCOMPARE( rec.field( 0 ).metaType().id(), QMetaType::Int );
|
||||||
QCOMPARE( rec.field( 1 ).metaType().id(), QVariant::String );
|
QCOMPARE( rec.field( 1 ).metaType().id(), QMetaType::QString );
|
||||||
QCOMPARE( rec.field( 2 ).metaType().id(), QVariant::Int );
|
QCOMPARE( rec.field( 2 ).metaType().id(), QMetaType::Int );
|
||||||
|
|
||||||
/* important - select from an empty table */
|
/* important - select from an empty table */
|
||||||
QVERIFY_SQL(q, exec("select id, name, title from " + qTableName("record_sqlite", __FILE__, db)));
|
QVERIFY_SQL(q, exec("select id, name, title from " + qTableName("record_sqlite", __FILE__, db)));
|
||||||
|
|
||||||
rec = q.record();
|
rec = q.record();
|
||||||
QCOMPARE( rec.count(), 3 );
|
QCOMPARE( rec.count(), 3 );
|
||||||
QCOMPARE( rec.field( 0 ).metaType().id(), QVariant::Int );
|
QCOMPARE( rec.field( 0 ).metaType().id(), QMetaType::Int );
|
||||||
QCOMPARE( rec.field( 1 ).metaType().id(), QVariant::String );
|
QCOMPARE( rec.field( 1 ).metaType().id(), QMetaType::QString );
|
||||||
QCOMPARE( rec.field( 2 ).metaType().id(), QVariant::Int );
|
QCOMPARE( rec.field( 2 ).metaType().id(), QMetaType::Int );
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QSqlQuery::oraLong()
|
void tst_QSqlQuery::oraLong()
|
||||||
@ -3118,7 +3118,7 @@ void tst_QSqlQuery::nextResult()
|
|||||||
|
|
||||||
QCOMPARE( q.record().field( 0 ).name().toUpper(), QString( "ID" ) );
|
QCOMPARE( q.record().field( 0 ).name().toUpper(), QString( "ID" ) );
|
||||||
|
|
||||||
QCOMPARE( q.record().field( 0 ).metaType().id(), QVariant::Int );
|
QCOMPARE( q.record().field( 0 ).metaType().id(), QMetaType::Int );
|
||||||
|
|
||||||
QVERIFY( q.nextResult() ); // Discards first result set and move to the next
|
QVERIFY( q.nextResult() ); // Discards first result set and move to the next
|
||||||
|
|
||||||
@ -3126,10 +3126,10 @@ void tst_QSqlQuery::nextResult()
|
|||||||
|
|
||||||
QCOMPARE( q.record().field( 0 ).name().toUpper(), QString( "TEXT" ) );
|
QCOMPARE( q.record().field( 0 ).name().toUpper(), QString( "TEXT" ) );
|
||||||
|
|
||||||
QCOMPARE( q.record().field( 0 ).metaType().id(), QVariant::String );
|
QCOMPARE( q.record().field( 0 ).metaType().id(), QMetaType::QString );
|
||||||
|
|
||||||
QCOMPARE( q.record().field( 1 ).name().toUpper(), QString( "NUM" ) );
|
QCOMPARE( q.record().field( 1 ).name().toUpper(), QString( "NUM" ) );
|
||||||
QCOMPARE(q.record().field(1).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(1).metaType().id(), QMetaType::Double);
|
||||||
|
|
||||||
QVERIFY( q.next() ); // Move to first row of the second result set
|
QVERIFY( q.next() ); // Move to first row of the second result set
|
||||||
|
|
||||||
@ -3946,14 +3946,14 @@ void tst_QSqlQuery::QTBUG_23895()
|
|||||||
QVERIFY_SQL(q, exec(sql));
|
QVERIFY_SQL(q, exec(sql));
|
||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
|
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Int);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Int);
|
||||||
QCOMPARE(q.value(0).metaType().id(), QVariant::LongLong);
|
QCOMPARE(q.value(0).metaType().id(), QMetaType::LongLong);
|
||||||
QCOMPARE(q.value(0).toInt(), 1);
|
QCOMPARE(q.value(0).toInt(), 1);
|
||||||
QCOMPARE(q.record().field(1).metaType().id(), QVariant::Bool);
|
QCOMPARE(q.record().field(1).metaType().id(), QMetaType::Bool);
|
||||||
QCOMPARE(q.value(1).metaType().id(), QVariant::LongLong);
|
QCOMPARE(q.value(1).metaType().id(), QMetaType::LongLong);
|
||||||
QCOMPARE(q.value(1).toBool(), true);
|
QCOMPARE(q.value(1).toBool(), true);
|
||||||
QCOMPARE(q.record().field(2).metaType().id(), QVariant::Bool);
|
QCOMPARE(q.record().field(2).metaType().id(), QMetaType::Bool);
|
||||||
QCOMPARE(q.value(2).metaType().id(), QVariant::LongLong);
|
QCOMPARE(q.value(2).metaType().id(), QMetaType::LongLong);
|
||||||
QCOMPARE(q.value(2).toBool(), false);
|
QCOMPARE(q.value(2).toBool(), false);
|
||||||
|
|
||||||
q.prepare("insert into " + tableName + "(id, val1, val2) values(?, ?, ?);");
|
q.prepare("insert into " + tableName + "(id, val1, val2) values(?, ?, ?);");
|
||||||
@ -4002,14 +4002,14 @@ void tst_QSqlQuery::QTBUG_14904()
|
|||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
|
|
||||||
QCOMPARE(q.record().indexOf("value1"), 0);
|
QCOMPARE(q.record().indexOf("value1"), 0);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Bool);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Bool);
|
||||||
QCOMPARE(q.value(0).toBool(), true);
|
QCOMPARE(q.value(0).toBool(), true);
|
||||||
|
|
||||||
sql="select val1 AS 'value.one' from " + tableName;
|
sql="select val1 AS 'value.one' from " + tableName;
|
||||||
QVERIFY_SQL(q, exec(sql));
|
QVERIFY_SQL(q, exec(sql));
|
||||||
QVERIFY_SQL(q, next());
|
QVERIFY_SQL(q, next());
|
||||||
QCOMPARE(q.record().indexOf("value.one"), 0); // was -1 before bug fix
|
QCOMPARE(q.record().indexOf("value.one"), 0); // was -1 before bug fix
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Bool);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Bool);
|
||||||
QCOMPARE(q.value(0).toBool(), true);
|
QCOMPARE(q.value(0).toBool(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4135,7 +4135,7 @@ void tst_QSqlQuery::gisPointDatatype()
|
|||||||
QVERIFY(sqlQuery.exec(sqlCommand));
|
QVERIFY(sqlQuery.exec(sqlCommand));
|
||||||
sqlCommand = QStringLiteral("SELECT * FROM %1;").arg(tableName);
|
sqlCommand = QStringLiteral("SELECT * FROM %1;").arg(tableName);
|
||||||
QVERIFY(sqlQuery.exec(sqlCommand));
|
QVERIFY(sqlQuery.exec(sqlCommand));
|
||||||
QCOMPARE(sqlQuery.record().field(0).metaType().id(), QVariant::Type::ByteArray);
|
QCOMPARE(sqlQuery.record().field(0).metaType().id(), QMetaType::QByteArray);
|
||||||
QVERIFY(sqlQuery.next());
|
QVERIFY(sqlQuery.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4281,7 +4281,7 @@ void tst_QSqlQuery::sqlite_real()
|
|||||||
QVERIFY_SQL(q, exec("SELECT realVal FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT realVal FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
QCOMPARE(q.value(0).toDouble(), 2.3);
|
QCOMPARE(q.value(0).toDouble(), 2.3);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
|
|
||||||
q.prepare("INSERT INTO " + tableName + " (id, realVal) VALUES (?, ?)");
|
q.prepare("INSERT INTO " + tableName + " (id, realVal) VALUES (?, ?)");
|
||||||
QVariant var((double)5.6);
|
QVariant var((double)5.6);
|
||||||
@ -4299,18 +4299,18 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QFETCH(QString, dbName);
|
QFETCH(QString, dbName);
|
||||||
QSqlDatabase db = QSqlDatabase::database(dbName);
|
QSqlDatabase db = QSqlDatabase::database(dbName);
|
||||||
CHECK_DATABASE(db);
|
CHECK_DATABASE(db);
|
||||||
QVariant::Type intType = QVariant::Int;
|
int intType = QMetaType::Int;
|
||||||
QVariant::Type sumType = intType;
|
int sumType = intType;
|
||||||
QVariant::Type countType = intType;
|
int countType = intType;
|
||||||
// QPSQL uses LongLong for manipulation of integers
|
// QPSQL uses LongLong for manipulation of integers
|
||||||
const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
const QSqlDriver::DbmsType dbType = tst_Databases::getDatabaseType(db);
|
||||||
if (dbType == QSqlDriver::PostgreSQL || dbType == QSqlDriver::Interbase) {
|
if (dbType == QSqlDriver::PostgreSQL || dbType == QSqlDriver::Interbase) {
|
||||||
sumType = countType = QVariant::LongLong;
|
sumType = countType = QMetaType::LongLong;
|
||||||
} else if (dbType == QSqlDriver::Oracle) {
|
} else if (dbType == QSqlDriver::Oracle) {
|
||||||
intType = sumType = countType = QVariant::Double;
|
intType = sumType = countType = QMetaType::Double;
|
||||||
} else if (dbType == QSqlDriver::MySqlServer) {
|
} else if (dbType == QSqlDriver::MySqlServer) {
|
||||||
sumType = QVariant::Double;
|
sumType = QMetaType::Double;
|
||||||
countType = QVariant::LongLong;
|
countType = QMetaType::LongLong;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const QString tableName(qTableName("numericFunctionsWithIntValues", __FILE__, db));
|
const QString tableName(qTableName("numericFunctionsWithIntValues", __FILE__, db));
|
||||||
@ -4323,7 +4323,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
if (dbType == QSqlDriver::SQLite)
|
if (dbType == QSqlDriver::SQLite)
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Invalid);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::UnknownType);
|
||||||
else
|
else
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), sumType);
|
QCOMPARE(q.record().field(0).metaType().id(), sumType);
|
||||||
|
|
||||||
@ -4340,10 +4340,10 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
if (dbType == QSqlDriver::SQLite || dbType == QSqlDriver::PostgreSQL || dbType == QSqlDriver::MySqlServer
|
if (dbType == QSqlDriver::SQLite || dbType == QSqlDriver::PostgreSQL || dbType == QSqlDriver::MySqlServer
|
||||||
|| dbType == QSqlDriver::Oracle) {
|
|| dbType == QSqlDriver::Oracle) {
|
||||||
QCOMPARE(q.value(0).toDouble(), 1.5);
|
QCOMPARE(q.value(0).toDouble(), 1.5);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
} else {
|
} else {
|
||||||
QCOMPARE(q.value(0).toInt(), 1);
|
QCOMPARE(q.value(0).toInt(), 1);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), (dbType == QSqlDriver::Interbase ? QVariant::LongLong : QVariant::Int));
|
QCOMPARE(q.record().field(0).metaType().id(), (dbType == QSqlDriver::Interbase ? QMetaType::LongLong : QMetaType::Int));
|
||||||
}
|
}
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName));
|
||||||
@ -4372,9 +4372,9 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
if (dbType == QSqlDriver::SQLite)
|
if (dbType == QSqlDriver::SQLite)
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Invalid);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::UnknownType);
|
||||||
else
|
else
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (1.5)"));
|
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (1.5)"));
|
||||||
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (2.5)"));
|
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id) VALUES (2.5)"));
|
||||||
@ -4382,12 +4382,12 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT SUM(id) FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
QCOMPARE(q.value(0).toDouble(), 4.0);
|
QCOMPARE(q.value(0).toDouble(), 4.0);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("SELECT AVG(id) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT AVG(id) FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
QCOMPARE(q.value(0).toDouble(), 2.0);
|
QCOMPARE(q.value(0).toDouble(), 2.0);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT COUNT(id) FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
@ -4397,12 +4397,12 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT MIN(id) FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
QCOMPARE(q.value(0).toDouble(), 1.5);
|
QCOMPARE(q.value(0).toDouble(), 1.5);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("SELECT MAX(id) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT MAX(id) FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
QCOMPARE(q.value(0).toDouble(), 2.5);
|
QCOMPARE(q.value(0).toDouble(), 2.5);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
|
|
||||||
QString field = "id";
|
QString field = "id";
|
||||||
|
|
||||||
@ -4414,7 +4414,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QVERIFY_SQL(q, exec("SELECT ROUND(" + field + ", 1) FROM " + tableName + " WHERE id=1.5"));
|
QVERIFY_SQL(q, exec("SELECT ROUND(" + field + ", 1) FROM " + tableName + " WHERE id=1.5"));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
QCOMPARE(q.value(0).toDouble(), 1.5);
|
QCOMPARE(q.value(0).toDouble(), 1.5);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("SELECT ROUND(" + field + ", 0) FROM " + tableName + " WHERE id=2.5"));
|
QVERIFY_SQL(q, exec("SELECT ROUND(" + field + ", 0) FROM " + tableName + " WHERE id=2.5"));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
@ -4422,7 +4422,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QCOMPARE(q.value(0).toDouble(), 2.0);
|
QCOMPARE(q.value(0).toDouble(), 2.0);
|
||||||
else
|
else
|
||||||
QCOMPARE(q.value(0).toDouble(), 3.0);
|
QCOMPARE(q.value(0).toDouble(), 3.0);
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Double);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::Double);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const QString tableName(qTableName("stringFunctions", __FILE__, db));
|
const QString tableName(qTableName("stringFunctions", __FILE__, db));
|
||||||
@ -4434,9 +4434,9 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QVERIFY_SQL(q, exec("SELECT MAX(txt) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT MAX(txt) FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
if (dbType == QSqlDriver::SQLite)
|
if (dbType == QSqlDriver::SQLite)
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::Invalid);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::UnknownType);
|
||||||
else
|
else
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::String);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::QString);
|
||||||
|
|
||||||
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, txt) VALUES (1, 'lower')"));
|
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, txt) VALUES (1, 'lower')"));
|
||||||
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, txt) VALUES (2, 'upper')"));
|
QVERIFY_SQL(q, exec("INSERT INTO " + tableName + " (id, txt) VALUES (2, 'upper')"));
|
||||||
@ -4444,7 +4444,7 @@ void tst_QSqlQuery::aggregateFunctionTypes()
|
|||||||
QVERIFY_SQL(q, exec("SELECT MAX(txt) FROM " + tableName));
|
QVERIFY_SQL(q, exec("SELECT MAX(txt) FROM " + tableName));
|
||||||
QVERIFY(q.next());
|
QVERIFY(q.next());
|
||||||
QCOMPARE(q.value(0).toString(), QLatin1String("upper"));
|
QCOMPARE(q.value(0).toString(), QLatin1String("upper"));
|
||||||
QCOMPARE(q.record().field(0).metaType().id(), QVariant::String);
|
QCOMPARE(q.record().field(0).metaType().id(), QMetaType::QString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,10 +111,10 @@ void tst_QSqlRecord::createTestRecord()
|
|||||||
{
|
{
|
||||||
delete rec;
|
delete rec;
|
||||||
rec = new QSqlRecord();
|
rec = new QSqlRecord();
|
||||||
fields[0] = new QSqlField(QStringLiteral("string"), QVariant::String, QStringLiteral("stringtable"));
|
fields[0] = new QSqlField(QStringLiteral("string"), QMetaType(QMetaType::QString), QStringLiteral("stringtable"));
|
||||||
fields[1] = new QSqlField(QStringLiteral("int"), QVariant::Int, QStringLiteral("inttable"));
|
fields[1] = new QSqlField(QStringLiteral("int"), QMetaType(QMetaType::Int), QStringLiteral("inttable"));
|
||||||
fields[2] = new QSqlField(QStringLiteral("double"), QVariant::Double, QStringLiteral("doubletable"));
|
fields[2] = new QSqlField(QStringLiteral("double"), QMetaType(QMetaType::Double), QStringLiteral("doubletable"));
|
||||||
fields[3] = new QSqlField(QStringLiteral("bool"), QVariant::Bool);
|
fields[3] = new QSqlField(QStringLiteral("bool"), QMetaType(QMetaType::Bool));
|
||||||
for ( int i = 0; i < NUM_FIELDS; ++i )
|
for ( int i = 0; i < NUM_FIELDS; ++i )
|
||||||
rec->append( *(fields[ i ] ) );
|
rec->append( *(fields[ i ] ) );
|
||||||
}
|
}
|
||||||
@ -124,19 +124,19 @@ void tst_QSqlRecord::append()
|
|||||||
{
|
{
|
||||||
delete rec;
|
delete rec;
|
||||||
rec = new QSqlRecord();
|
rec = new QSqlRecord();
|
||||||
rec->append(QSqlField("string", QVariant::String, QStringLiteral("stringtable")));
|
rec->append(QSqlField("string", QMetaType(QMetaType::QString), QStringLiteral("stringtable")));
|
||||||
QCOMPARE( rec->field( 0 ).name(), (QString) "string" );
|
QCOMPARE( rec->field( 0 ).name(), (QString) "string" );
|
||||||
QCOMPARE(rec->field(0).tableName(), QStringLiteral("stringtable"));
|
QCOMPARE(rec->field(0).tableName(), QStringLiteral("stringtable"));
|
||||||
QVERIFY( !rec->isEmpty() );
|
QVERIFY( !rec->isEmpty() );
|
||||||
QCOMPARE( (int)rec->count(), 1 );
|
QCOMPARE( (int)rec->count(), 1 );
|
||||||
rec->append(QSqlField("int", QVariant::Int, QStringLiteral("inttable")));
|
rec->append(QSqlField("int", QMetaType(QMetaType::Int), QStringLiteral("inttable")));
|
||||||
QCOMPARE( rec->field( 1 ).name(), (QString) "int" );
|
QCOMPARE( rec->field( 1 ).name(), (QString) "int" );
|
||||||
QCOMPARE(rec->field(1).tableName(), QStringLiteral("inttable"));
|
QCOMPARE(rec->field(1).tableName(), QStringLiteral("inttable"));
|
||||||
QCOMPARE( (int)rec->count(), 2 );
|
QCOMPARE( (int)rec->count(), 2 );
|
||||||
rec->append( QSqlField( "double", QVariant::Double ) );
|
rec->append( QSqlField( "double", QMetaType(QMetaType::Double) ) );
|
||||||
QCOMPARE( rec->field( 2 ).name(), (QString) "double" );
|
QCOMPARE( rec->field( 2 ).name(), (QString) "double" );
|
||||||
QCOMPARE( (int)rec->count(), 3 );
|
QCOMPARE( (int)rec->count(), 3 );
|
||||||
rec->append( QSqlField( "bool", QVariant::Bool ) );
|
rec->append( QSqlField( "bool", QMetaType(QMetaType::Bool) ) );
|
||||||
QCOMPARE( rec->field( 3 ).name(), (QString) "bool" );
|
QCOMPARE( rec->field( 3 ).name(), (QString) "bool" );
|
||||||
QCOMPARE( (int)rec->count(), 4 );
|
QCOMPARE( (int)rec->count(), 4 );
|
||||||
QCOMPARE( rec->indexOf( "string" ), 0 );
|
QCOMPARE( rec->indexOf( "string" ), 0 );
|
||||||
@ -186,17 +186,17 @@ void tst_QSqlRecord::clearValues()
|
|||||||
delete rec;
|
delete rec;
|
||||||
|
|
||||||
rec = new QSqlRecord();
|
rec = new QSqlRecord();
|
||||||
rec->append( QSqlField( "string", QVariant::String ) );
|
rec->append( QSqlField( "string", QMetaType(QMetaType::QString) ) );
|
||||||
QCOMPARE( rec->field(0).name(), (QString) "string" );
|
QCOMPARE( rec->field(0).name(), (QString) "string" );
|
||||||
QVERIFY( !rec->isEmpty() );
|
QVERIFY( !rec->isEmpty() );
|
||||||
QCOMPARE( (int)rec->count(), 1 );
|
QCOMPARE( (int)rec->count(), 1 );
|
||||||
rec->append( QSqlField( "int", QVariant::Int ) );
|
rec->append( QSqlField( "int", QMetaType(QMetaType::Int) ) );
|
||||||
QCOMPARE( rec->field(1).name(), (QString) "int" );
|
QCOMPARE( rec->field(1).name(), (QString) "int" );
|
||||||
QCOMPARE( (int)rec->count(), 2 );
|
QCOMPARE( (int)rec->count(), 2 );
|
||||||
rec->append( QSqlField( "double", QVariant::Double ) );
|
rec->append( QSqlField( "double", QMetaType(QMetaType::Double) ) );
|
||||||
QCOMPARE( rec->field(2).name(), (QString) "double" );
|
QCOMPARE( rec->field(2).name(), (QString) "double" );
|
||||||
QCOMPARE( (int)rec->count(), 3 );
|
QCOMPARE( (int)rec->count(), 3 );
|
||||||
rec->append( QSqlField( "bool", QVariant::Bool ) );
|
rec->append( QSqlField( "bool", QMetaType(QMetaType::Bool) ) );
|
||||||
QCOMPARE( rec->field(3).name(), (QString) "bool" );
|
QCOMPARE( rec->field(3).name(), (QString) "bool" );
|
||||||
QCOMPARE( (int)rec->count(), 4 );
|
QCOMPARE( (int)rec->count(), 4 );
|
||||||
QCOMPARE( rec->indexOf( "string" ), 0 );
|
QCOMPARE( rec->indexOf( "string" ), 0 );
|
||||||
@ -268,29 +268,29 @@ void tst_QSqlRecord::insert()
|
|||||||
QSqlRecord iRec;
|
QSqlRecord iRec;
|
||||||
int i;
|
int i;
|
||||||
for ( i = 0; i <= 100; ++i ) {
|
for ( i = 0; i <= 100; ++i ) {
|
||||||
iRec.insert( i, QSqlField( QString::number( i ), QVariant::Int ) );
|
iRec.insert( i, QSqlField( QString::number( i ), QMetaType(QMetaType::Int) ) );
|
||||||
}
|
}
|
||||||
for ( i = 0; i <= 100; ++i ) {
|
for ( i = 0; i <= 100; ++i ) {
|
||||||
QCOMPARE( iRec.fieldName( i ), QString::number( i ) );
|
QCOMPARE( iRec.fieldName( i ), QString::number( i ) );
|
||||||
}
|
}
|
||||||
// iRec.insert( 505, QSqlField( "Harry", QVariant::Double ) );
|
// iRec.insert( 505, QSqlField( "Harry", QMetaType(QMetaType::Double) ) );
|
||||||
// QCOMPARE( iRec.fieldName( 505 ), (QString)"Harry" );
|
// QCOMPARE( iRec.fieldName( 505 ), (QString)"Harry" );
|
||||||
// QVERIFY( iRec.field( 505 ).type() == QVariant::Double );
|
// QVERIFY( iRec.field( 505 ).type() == QMetaType(QMetaType::Double) );
|
||||||
|
|
||||||
iRec.insert( 42, QSqlField( "Everything", QVariant::String ) );
|
iRec.insert( 42, QSqlField( "Everything", QMetaType(QMetaType::QString) ) );
|
||||||
QCOMPARE( iRec.fieldName( 42 ), (QString)"Everything" );
|
QCOMPARE( iRec.fieldName( 42 ), (QString)"Everything" );
|
||||||
QVERIFY( iRec.field( 42 ).type() == QVariant::String );
|
QVERIFY( iRec.field( 42 ).metaType() == QMetaType(QMetaType::QString) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QSqlRecord::isEmpty()
|
void tst_QSqlRecord::isEmpty()
|
||||||
{
|
{
|
||||||
QSqlRecord eRec;
|
QSqlRecord eRec;
|
||||||
QVERIFY( eRec.isEmpty() );
|
QVERIFY( eRec.isEmpty() );
|
||||||
eRec.append( QSqlField( "Harry", QVariant::String ) );
|
eRec.append( QSqlField( "Harry", QMetaType(QMetaType::QString) ) );
|
||||||
QVERIFY( !eRec.isEmpty() );
|
QVERIFY( !eRec.isEmpty() );
|
||||||
eRec.remove( 0 );
|
eRec.remove( 0 );
|
||||||
QVERIFY( eRec.isEmpty() );
|
QVERIFY( eRec.isEmpty() );
|
||||||
eRec.insert( 0, QSqlField( "Harry", QVariant::String ) );
|
eRec.insert( 0, QSqlField( "Harry", QMetaType(QMetaType::QString) ) );
|
||||||
QVERIFY( !eRec.isEmpty() );
|
QVERIFY( !eRec.isEmpty() );
|
||||||
eRec.clear();
|
eRec.clear();
|
||||||
QVERIFY( eRec.isEmpty() );
|
QVERIFY( eRec.isEmpty() );
|
||||||
@ -383,7 +383,7 @@ void tst_QSqlRecord::operator_Assign()
|
|||||||
buf3.remove( NUM_FIELDS - 1 );
|
buf3.remove( NUM_FIELDS - 1 );
|
||||||
QSqlRecord buf5 = buf3;
|
QSqlRecord buf5 = buf3;
|
||||||
for ( i = 0; i < NUM_FIELDS - 1; ++i ) {
|
for ( i = 0; i < NUM_FIELDS - 1; ++i ) {
|
||||||
QSqlField fi(fields[i]->name(), fields[i]->type(), fields[i]->tableName());
|
QSqlField fi(fields[i]->name(), fields[i]->metaType(), fields[i]->tableName());
|
||||||
fi.clear();
|
fi.clear();
|
||||||
QVERIFY( buf5.field( i ) == fi );
|
QVERIFY( buf5.field( i ) == fi );
|
||||||
QVERIFY( buf5.isGenerated( i ) );
|
QVERIFY( buf5.isGenerated( i ) );
|
||||||
@ -413,7 +413,7 @@ void tst_QSqlRecord::remove()
|
|||||||
}
|
}
|
||||||
rec->remove( NUM_FIELDS * 2 ); // nothing should happen
|
rec->remove( NUM_FIELDS * 2 ); // nothing should happen
|
||||||
for ( i = 0; i < NUM_FIELDS; ++i ) {
|
for ( i = 0; i < NUM_FIELDS; ++i ) {
|
||||||
rec->insert( i, QSqlField( fields[ i ]->name(), fields[ i ]->type() ) );
|
rec->insert( i, QSqlField( fields[ i ]->name(), fields[ i ]->metaType() ) );
|
||||||
QVERIFY( rec->isGenerated( i ) );
|
QVERIFY( rec->isGenerated( i ) );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -439,17 +439,17 @@ void tst_QSqlRecord::setValue()
|
|||||||
|
|
||||||
delete rec;
|
delete rec;
|
||||||
rec = new QSqlRecord();
|
rec = new QSqlRecord();
|
||||||
rec->append( QSqlField( "string", QVariant::String ) );
|
rec->append( QSqlField( "string", QMetaType(QMetaType::QString) ) );
|
||||||
QCOMPARE( rec->field( 0 ).name(), (QString) "string" );
|
QCOMPARE( rec->field( 0 ).name(), (QString) "string" );
|
||||||
QVERIFY( !rec->isEmpty() );
|
QVERIFY( !rec->isEmpty() );
|
||||||
QCOMPARE( (int)rec->count(), 1 );
|
QCOMPARE( (int)rec->count(), 1 );
|
||||||
rec->append( QSqlField( "int", QVariant::Int ) );
|
rec->append( QSqlField( "int", QMetaType(QMetaType::Int) ) );
|
||||||
QCOMPARE( rec->field( 1 ).name(), (QString) "int" );
|
QCOMPARE( rec->field( 1 ).name(), (QString) "int" );
|
||||||
QCOMPARE( (int)rec->count(), 2 );
|
QCOMPARE( (int)rec->count(), 2 );
|
||||||
rec->append( QSqlField( "double", QVariant::Double ) );
|
rec->append( QSqlField( "double", QMetaType(QMetaType::Double) ) );
|
||||||
QCOMPARE( rec->field( 2 ).name(), (QString) "double" );
|
QCOMPARE( rec->field( 2 ).name(), (QString) "double" );
|
||||||
QCOMPARE( (int)rec->count(), 3 );
|
QCOMPARE( (int)rec->count(), 3 );
|
||||||
rec->append( QSqlField( "bool", QVariant::Bool ) );
|
rec->append( QSqlField( "bool", QMetaType(QMetaType::Bool) ) );
|
||||||
QCOMPARE( rec->field( 3 ).name(), (QString) "bool" );
|
QCOMPARE( rec->field( 3 ).name(), (QString) "bool" );
|
||||||
QCOMPARE( (int)rec->count(), 4 );
|
QCOMPARE( (int)rec->count(), 4 );
|
||||||
QCOMPARE( rec->indexOf( "string" ), 0 );
|
QCOMPARE( rec->indexOf( "string" ), 0 );
|
||||||
@ -498,7 +498,7 @@ void tst_QSqlRecord::value()
|
|||||||
{
|
{
|
||||||
// this test is already covered in setValue()
|
// this test is already covered in setValue()
|
||||||
QSqlRecord rec2;
|
QSqlRecord rec2;
|
||||||
rec2.append( QSqlField( "string", QVariant::String ) );
|
rec2.append( QSqlField( "string", QMetaType(QMetaType::QString) ) );
|
||||||
rec2.setValue( "string", "Harry" );
|
rec2.setValue( "string", "Harry" );
|
||||||
QCOMPARE(rec2.value("string").toString(), QLatin1String("Harry"));
|
QCOMPARE(rec2.value("string").toString(), QLatin1String("Harry"));
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public:
|
|||||||
: QSqlResult(driver) {}
|
: QSqlResult(driver) {}
|
||||||
~TestSqlDriverResult() {}
|
~TestSqlDriverResult() {}
|
||||||
|
|
||||||
bool savePrepare(const QString& sqlquery)
|
bool savePrepare(const QString& sqlquery) override
|
||||||
{
|
{
|
||||||
return QSqlResult::savePrepare(sqlquery);
|
return QSqlResult::savePrepare(sqlquery);
|
||||||
}
|
}
|
||||||
@ -49,15 +49,15 @@ public:
|
|||||||
QList<QVariant> boundValues() const { return QSqlResult::boundValues(); }
|
QList<QVariant> boundValues() const { return QSqlResult::boundValues(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QVariant data(int /* index */) { return QVariant(); }
|
QVariant data(int /* index */) override { return QVariant(); }
|
||||||
bool isNull(int /* index */) { return false; }
|
bool isNull(int /* index */) override { return false; }
|
||||||
bool reset(const QString & /* query */) { return false; }
|
bool reset(const QString & /* query */) override { return false; }
|
||||||
bool fetch(int /* index */) { return false; }
|
bool fetch(int /* index */) override { return false; }
|
||||||
bool fetchFirst() { return false; }
|
bool fetchFirst() override { return false; }
|
||||||
bool fetchLast() { return false; }
|
bool fetchLast() override { return false; }
|
||||||
int size() { return 0; }
|
int size() override { return 0; }
|
||||||
int numRowsAffected() { return 0; }
|
int numRowsAffected() override { return 0; }
|
||||||
QSqlRecord record() const { return QSqlRecord(); }
|
QSqlRecord record() const override { return QSqlRecord(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class TestSqlDriver : public QSqlDriver
|
class TestSqlDriver : public QSqlDriver
|
||||||
@ -68,7 +68,7 @@ public:
|
|||||||
TestSqlDriver() {}
|
TestSqlDriver() {}
|
||||||
~TestSqlDriver() {}
|
~TestSqlDriver() {}
|
||||||
|
|
||||||
bool hasFeature(DriverFeature f) const {
|
bool hasFeature(DriverFeature f) const override {
|
||||||
switch (f) {
|
switch (f) {
|
||||||
case QSqlDriver::PreparedQueries:
|
case QSqlDriver::PreparedQueries:
|
||||||
case QSqlDriver::NamedPlaceholders:
|
case QSqlDriver::NamedPlaceholders:
|
||||||
@ -80,11 +80,11 @@ public:
|
|||||||
}
|
}
|
||||||
bool open(const QString & /* db */, const QString & /* user */,
|
bool open(const QString & /* db */, const QString & /* user */,
|
||||||
const QString & /* password */, const QString & /* host */,
|
const QString & /* password */, const QString & /* host */,
|
||||||
int /* port */, const QString & /* options */)
|
int /* port */, const QString & /* options */) override
|
||||||
{ return false; }
|
{ return false; }
|
||||||
void close() {}
|
void close() override {}
|
||||||
|
|
||||||
QSqlResult *createResult() const { return new TestSqlDriverResult(this); }
|
QSqlResult *createResult() const override { return new TestSqlDriverResult(this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TESTSQLDRIVER_H
|
#endif // TESTSQLDRIVER_H
|
||||||
|
@ -402,7 +402,7 @@ class SelectRowOverrideTestModel: public QSqlTableModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SelectRowOverrideTestModel(QObject *parent, QSqlDatabase db):QSqlTableModel(parent, db) { }
|
SelectRowOverrideTestModel(QObject *parent, QSqlDatabase db):QSqlTableModel(parent, db) { }
|
||||||
bool selectRow(int row)
|
bool selectRow(int row) override
|
||||||
{
|
{
|
||||||
Q_UNUSED(row);
|
Q_UNUSED(row);
|
||||||
return select();
|
return select();
|
||||||
@ -551,9 +551,9 @@ void tst_QSqlTableModel::setData()
|
|||||||
|
|
||||||
// change 0 to NULL
|
// change 0 to NULL
|
||||||
idx = model.index(0, 0);
|
idx = model.index(0, 0);
|
||||||
QVERIFY_SQL(model, setData(idx, QVariant(QVariant::Int)));
|
QVERIFY_SQL(model, setData(idx, QVariant(QMetaType(QMetaType::Int))));
|
||||||
val = model.data(idx);
|
val = model.data(idx);
|
||||||
QCOMPARE(val, QVariant(QVariant::Int));
|
QCOMPARE(val, QVariant(QMetaType(QMetaType::Int)));
|
||||||
QVERIFY(val.isNull());
|
QVERIFY(val.isNull());
|
||||||
QVERIFY_SQL(model, isDirty(idx));
|
QVERIFY_SQL(model, isDirty(idx));
|
||||||
QVERIFY_SQL(model, submitAll());
|
QVERIFY_SQL(model, submitAll());
|
||||||
@ -580,13 +580,13 @@ void tst_QSqlTableModel::setData()
|
|||||||
// initial state
|
// initial state
|
||||||
idx = model.index(0, 0);
|
idx = model.index(0, 0);
|
||||||
QSqlRecord rec = model.record(0);
|
QSqlRecord rec = model.record(0);
|
||||||
QCOMPARE(rec.value(0), QVariant(QVariant::Int));
|
QCOMPARE(rec.value(0), QVariant(QMetaType(QMetaType::Int)));
|
||||||
QVERIFY(rec.isNull(0));
|
QVERIFY(rec.isNull(0));
|
||||||
QVERIFY(!rec.isGenerated(0));
|
QVERIFY(!rec.isGenerated(0));
|
||||||
// unchanged value, but causes column to be included in INSERT
|
// unchanged value, but causes column to be included in INSERT
|
||||||
QVERIFY_SQL(model, setData(idx, QVariant(QVariant::Int)));
|
QVERIFY_SQL(model, setData(idx, QVariant(QMetaType(QMetaType::Int))));
|
||||||
rec = model.record(0);
|
rec = model.record(0);
|
||||||
QCOMPARE(rec.value(0), QVariant(QVariant::Int));
|
QCOMPARE(rec.value(0), QVariant(QMetaType(QMetaType::Int)));
|
||||||
QVERIFY(rec.isNull(0));
|
QVERIFY(rec.isNull(0));
|
||||||
QVERIFY(rec.isGenerated(0));
|
QVERIFY(rec.isGenerated(0));
|
||||||
QVERIFY_SQL(model, submitAll());
|
QVERIFY_SQL(model, submitAll());
|
||||||
@ -657,7 +657,7 @@ class SetRecordReimplModel: public QSqlTableModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
SetRecordReimplModel(QObject *parent, QSqlDatabase db):QSqlTableModel(parent, db) {}
|
SetRecordReimplModel(QObject *parent, QSqlDatabase db):QSqlTableModel(parent, db) {}
|
||||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
|
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override
|
||||||
{
|
{
|
||||||
Q_UNUSED(value);
|
Q_UNUSED(value);
|
||||||
return QSqlTableModel::setData(index, QString("Qt"), role);
|
return QSqlTableModel::setData(index, QString("Qt"), role);
|
||||||
@ -693,7 +693,7 @@ class RecordReimplModel: public QSqlTableModel
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
RecordReimplModel(QObject *parent, QSqlDatabase db):QSqlTableModel(parent, db) {}
|
RecordReimplModel(QObject *parent, QSqlDatabase db):QSqlTableModel(parent, db) {}
|
||||||
QVariant data(const QModelIndex &index, int role = Qt::EditRole) const
|
QVariant data(const QModelIndex &index, int role = Qt::EditRole) const override
|
||||||
{
|
{
|
||||||
if (role == Qt::EditRole)
|
if (role == Qt::EditRole)
|
||||||
return QString("Qt");
|
return QString("Qt");
|
||||||
@ -2139,7 +2139,7 @@ class SqlThread : public QThread
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SqlThread() : QThread() {}
|
SqlThread() : QThread() {}
|
||||||
void run()
|
void run() override
|
||||||
{
|
{
|
||||||
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "non-default-connection");
|
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE", "non-default-connection");
|
||||||
QSqlTableModel stm(nullptr, db);
|
QSqlTableModel stm(nullptr, db);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user