Skip to content

Commit

Permalink
Cleanup remaining QVariant::Type uses in Qt Sql
Browse files Browse the repository at this point in the history
Change-Id: Ibcaa678cd9f9c957392a75b477fa6821f9a69127
Reviewed-by: Mårten Nordheim <[email protected]>
laknoll committed Oct 17, 2020
1 parent 008343a commit 2732231
Showing 7 changed files with 270 additions and 268 deletions.
46 changes: 23 additions & 23 deletions src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp
Original file line number Diff line number Diff line change
@@ -85,24 +85,24 @@ static QString _q_escapeIdentifier(const QString &identifier)
return res;
}

static QVariant::Type qGetColumnType(const QString &tpName)
static int qGetColumnType(const QString &tpName)
{
const QString typeName = tpName.toLower();

if (typeName == QLatin1String("integer")
|| typeName == QLatin1String("int"))
return QVariant::Int;
return QMetaType::Int;
if (typeName == QLatin1String("double")
|| typeName == QLatin1String("float")
|| typeName == QLatin1String("real")
|| typeName.startsWith(QLatin1String("numeric")))
return QVariant::Double;
return QMetaType::Double;
if (typeName == QLatin1String("blob"))
return QVariant::ByteArray;
return QMetaType::QByteArray;
if (typeName == QLatin1String("boolean")
|| typeName == QLatin1String("bool"))
return QVariant::Bool;
return QVariant::String;
return QMetaType::Bool;
return QMetaType::QString;
}

static QSqlError qMakeError(sqlite3 *access, const QString &descr, QSqlError::ErrorType type,
@@ -214,33 +214,33 @@ void QSQLiteResultPrivate::initColumns(bool emptyResultset)
// sqlite3_column_type is documented to have undefined behavior if the result set is empty
int stp = emptyResultset ? -1 : sqlite3_column_type(stmt, i);

QVariant::Type fieldType;
int fieldType;

if (!typeName.isEmpty()) {
fieldType = qGetColumnType(typeName);
} else {
// Get the proper type for the field based on stp value
switch (stp) {
case SQLITE_INTEGER:
fieldType = QVariant::Int;
fieldType = QMetaType::Int;
break;
case SQLITE_FLOAT:
fieldType = QVariant::Double;
fieldType = QMetaType::Double;
break;
case SQLITE_BLOB:
fieldType = QVariant::ByteArray;
fieldType = QMetaType::QByteArray;
break;
case SQLITE_TEXT:
fieldType = QVariant::String;
fieldType = QMetaType::QString;
break;
case SQLITE_NULL:
default:
fieldType = QVariant::Invalid;
fieldType = QMetaType::UnknownType;
break;
}
}

QSqlField fld(colName, fieldType, tableName);
QSqlField fld(colName, QMetaType(fieldType), tableName);
fld.setSqlType(stp);
rInf.append(fld);
}
@@ -502,37 +502,37 @@ bool QSQLiteResult::exec()
res = sqlite3_bind_null(d->stmt, i + 1);
} else {
switch (value.userType()) {
case QVariant::ByteArray: {
case QMetaType::QByteArray: {
const QByteArray *ba = static_cast<const QByteArray*>(value.constData());
res = sqlite3_bind_blob(d->stmt, i + 1, ba->constData(),
ba->size(), SQLITE_STATIC);
break; }
case QVariant::Int:
case QVariant::Bool:
case QMetaType::Int:
case QMetaType::Bool:
res = sqlite3_bind_int(d->stmt, i + 1, value.toInt());
break;
case QVariant::Double:
case QMetaType::Double:
res = sqlite3_bind_double(d->stmt, i + 1, value.toDouble());
break;
case QVariant::UInt:
case QVariant::LongLong:
case QMetaType::UInt:
case QMetaType::LongLong:
res = sqlite3_bind_int64(d->stmt, i + 1, value.toLongLong());
break;
case QVariant::DateTime: {
case QMetaType::QDateTime: {
const QDateTime dateTime = value.toDateTime();
const QString str = dateTime.toString(Qt::ISODateWithMs);
res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
str.size() * sizeof(ushort), SQLITE_TRANSIENT);
break;
}
case QVariant::Time: {
case QMetaType::QTime: {
const QTime time = value.toTime();
const QString str = time.toString(u"hh:mm:ss.zzz");
res = sqlite3_bind_text16(d->stmt, i + 1, str.utf16(),
str.size() * sizeof(ushort), SQLITE_TRANSIENT);
break;
}
case QVariant::String: {
case QMetaType::QString: {
// lifetime of string == lifetime of its qvariant
const QString *str = static_cast<const QString*>(value.constData());
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);
}

QSqlField fld(q.value(1).toString(), qGetColumnType(typeName), tableName);
QSqlField fld(q.value(1).toString(), QMetaType(qGetColumnType(typeName)), tableName);
if (isPk && (typeName == QLatin1String("integer")))
// INTEGER PRIMARY KEY fields are auto-generated in sqlite
// INT PRIMARY KEY is not the same as INTEGER PRIMARY KEY!
6 changes: 4 additions & 2 deletions src/sql/kernel/qsqlfield.h
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ class Q_SQL_EXPORT QSqlField
public:
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")
QSqlField(const QString& fieldName, QVariant::Type type, const QString &tableName = QString())
: QSqlField(fieldName, QMetaType(type), tableName)
@@ -84,12 +84,14 @@ class Q_SQL_EXPORT QSqlField

QMetaType metaType() const;
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")
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); }
Loading

0 comments on commit 2732231

Please sign in to comment.