From 0843c6ca7fe604d8c44b9a81b8fcb072ab424172 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Fri, 19 May 2017 15:31:46 +0200 Subject: QSqlField: Add a means to see what the tablename is for a given field When you are using a query that pulls from a number of different tables then it can be ambiguous as to which table a particular field belongs to. So this will make it possible to determine the table that a given field belongs to if it is set. Task-number: QTBUG-7170 Change-Id: I49b7890c0523d81272a153df3860df800ff853d5 Reviewed-by: Jesus Fernandez Reviewed-by: Edward Welbourne --- src/sql/kernel/qsqlfield.cpp | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'src/sql/kernel/qsqlfield.cpp') diff --git a/src/sql/kernel/qsqlfield.cpp b/src/sql/kernel/qsqlfield.cpp index bb810b11df..59b992e803 100644 --- a/src/sql/kernel/qsqlfield.cpp +++ b/src/sql/kernel/qsqlfield.cpp @@ -47,9 +47,9 @@ class QSqlFieldPrivate { public: QSqlFieldPrivate(const QString &name, - QVariant::Type type) : + QVariant::Type type, const QString &tableName) : ref(1), nm(name), ro(false), type(type), req(QSqlField::Unknown), - len(-1), prec(-1), tp(-1), gen(true), autoval(false) + len(-1), prec(-1), tp(-1), gen(true), autoval(false), table(tableName) { } @@ -64,7 +64,8 @@ public: def(other.def), tp(other.tp), gen(other.gen), - autoval(other.autoval) + autoval(other.autoval), + table(other.table) {} bool operator==(const QSqlFieldPrivate& other) const @@ -77,7 +78,8 @@ public: && prec == other.prec && def == other.def && gen == other.gen - && autoval == other.autoval); + && autoval == other.autoval + && table == other.table); } QAtomicInt ref; @@ -91,6 +93,7 @@ public: int tp; uint gen: 1; uint autoval: 1; + QString table; }; @@ -153,14 +156,15 @@ public: /*! Constructs an empty field called \a fieldName of variant type \a - type. + type in \a table. \sa setRequiredStatus(), setLength(), setPrecision(), setDefaultValue(), setGenerated(), setReadOnly() */ -QSqlField::QSqlField(const QString& fieldName, QVariant::Type type) +QSqlField::QSqlField(const QString &fieldName, QVariant::Type type, + const QString &table) { - d = new QSqlFieldPrivate(fieldName, type); + d = new QSqlFieldPrivate(fieldName, type, table); val = QVariant(type); } @@ -518,6 +522,7 @@ QDebug operator<<(QDebug dbg, const QSqlField &f) QDebugStateSaver saver(dbg); dbg.nospace(); dbg << "QSqlField(" << f.name() << ", " << QMetaType::typeName(f.type()); + dbg << ", tableName: " << (f.tableName().isEmpty() ? QStringLiteral("(not specified)") : f.tableName()); if (f.length() >= 0) dbg << ", length: " << f.length(); if (f.precision() >= 0) @@ -565,4 +570,27 @@ void QSqlField::setAutoValue(bool autoVal) d->autoval = autoVal; } +/*! + Sets the tableName of the field to \a table. + + \sa tableName() +*/ + +void QSqlField::setTableName(const QString &table) +{ + detach(); + d->table = table; +} + +/*! + Returns the tableName of the field. + + \sa setTableName() +*/ + +QString QSqlField::tableName() const +{ + return d->table; +} + QT_END_NAMESPACE -- cgit v1.2.3