| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/sql/models/qsqltablemodel.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||||||||
| 7 | typedef QSqlTableModelSql Sql; | - | ||||||||||||||||||||||||||||||
| 8 | - | |||||||||||||||||||||||||||||||
| 9 | - | |||||||||||||||||||||||||||||||
| 10 | - | |||||||||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||||||||
| 12 | QSqlRecord QSqlTableModelPrivate::record(const QVector<QVariant> &values) const | - | ||||||||||||||||||||||||||||||
| 13 | { | - | ||||||||||||||||||||||||||||||
| 14 | QSqlRecord r = rec; | - | ||||||||||||||||||||||||||||||
| 15 | for (int i = 0; i < r.count()
| 0 | ||||||||||||||||||||||||||||||
| 16 | r.setValue(i, values.at(i)); never executed: r.setValue(i, values.at(i)); | 0 | ||||||||||||||||||||||||||||||
| 17 | return never executed: r;return r;never executed: return r; | 0 | ||||||||||||||||||||||||||||||
| 18 | } | - | ||||||||||||||||||||||||||||||
| 19 | - | |||||||||||||||||||||||||||||||
| 20 | int QSqlTableModelPrivate::nameToIndex(const QString &name) const | - | ||||||||||||||||||||||||||||||
| 21 | { | - | ||||||||||||||||||||||||||||||
| 22 | return executed 116 times by 2 tests: rec.indexOf(strippedFieldName(name));return rec.indexOf(strippedFieldName(name));Executed by:
executed 116 times by 2 tests: return rec.indexOf(strippedFieldName(name));Executed by:
| 116 | ||||||||||||||||||||||||||||||
| 23 | } | - | ||||||||||||||||||||||||||||||
| 24 | - | |||||||||||||||||||||||||||||||
| 25 | QString QSqlTableModelPrivate::strippedFieldName(const QString &name) const | - | ||||||||||||||||||||||||||||||
| 26 | { | - | ||||||||||||||||||||||||||||||
| 27 | QString fieldname = name; | - | ||||||||||||||||||||||||||||||
| 28 | if (db.driver()->isIdentifierEscaped(fieldname, QSqlDriver::FieldName)
| 4-129 | ||||||||||||||||||||||||||||||
| 29 | fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName); executed 4 times by 1 test: fieldname = db.driver()->stripDelimiters(fieldname, QSqlDriver::FieldName);Executed by:
| 4 | ||||||||||||||||||||||||||||||
| 30 | return executed 133 times by 2 tests: fieldname;return fieldname;Executed by:
executed 133 times by 2 tests: return fieldname;Executed by:
| 133 | ||||||||||||||||||||||||||||||
| 31 | } | - | ||||||||||||||||||||||||||||||
| 32 | - | |||||||||||||||||||||||||||||||
| 33 | int QSqlTableModelPrivate::insertCount(int maxRow) const | - | ||||||||||||||||||||||||||||||
| 34 | { | - | ||||||||||||||||||||||||||||||
| 35 | int cnt = 0; | - | ||||||||||||||||||||||||||||||
| 36 | CacheMap::ConstIterator i = cache.constBegin(); | - | ||||||||||||||||||||||||||||||
| 37 | const CacheMap::ConstIterator e = cache.constEnd(); | - | ||||||||||||||||||||||||||||||
| 38 | for ( ; i != e
| 78-12805 | ||||||||||||||||||||||||||||||
| 39 | if (i.value().insert()
| 816-1278 | ||||||||||||||||||||||||||||||
| 40 | ++ executed 1278 times by 2 tests: cnt;++cnt;Executed by:
executed 1278 times by 2 tests: ++cnt;Executed by:
| 1278 | ||||||||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||||||||
| 42 | return executed 12883 times by 3 tests: cnt;return cnt;Executed by:
executed 12883 times by 3 tests: return cnt;Executed by:
| 12883 | ||||||||||||||||||||||||||||||
| 43 | } | - | ||||||||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||||||||
| 45 | void QSqlTableModelPrivate::initRecordAndPrimaryIndex() | - | ||||||||||||||||||||||||||||||
| 46 | { | - | ||||||||||||||||||||||||||||||
| 47 | rec = db.record(tableName); | - | ||||||||||||||||||||||||||||||
| 48 | primaryIndex = db.primaryIndex(tableName); | - | ||||||||||||||||||||||||||||||
| 49 | initColOffsets(rec.count()); | - | ||||||||||||||||||||||||||||||
| 50 | } executed 185 times by 3 tests: end of blockExecuted by:
| 185 | ||||||||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||||||||
| 52 | void QSqlTableModelPrivate::clear() | - | ||||||||||||||||||||||||||||||
| 53 | { | - | ||||||||||||||||||||||||||||||
| 54 | sortColumn = -1; | - | ||||||||||||||||||||||||||||||
| 55 | sortOrder = Qt::AscendingOrder; | - | ||||||||||||||||||||||||||||||
| 56 | tableName.clear(); | - | ||||||||||||||||||||||||||||||
| 57 | editQuery.clear(); | - | ||||||||||||||||||||||||||||||
| 58 | cache.clear(); | - | ||||||||||||||||||||||||||||||
| 59 | primaryIndex.clear(); | - | ||||||||||||||||||||||||||||||
| 60 | rec.clear(); | - | ||||||||||||||||||||||||||||||
| 61 | filter.clear(); | - | ||||||||||||||||||||||||||||||
| 62 | } executed 190 times by 3 tests: end of blockExecuted by:
| 190 | ||||||||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||||||||
| 64 | void QSqlTableModelPrivate::clearCache() | - | ||||||||||||||||||||||||||||||
| 65 | { | - | ||||||||||||||||||||||||||||||
| 66 | cache.clear(); | - | ||||||||||||||||||||||||||||||
| 67 | } executed 315 times by 3 tests: end of blockExecuted by:
| 315 | ||||||||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||||||||
| 69 | void QSqlTableModelPrivate::revertCachedRow(int row) | - | ||||||||||||||||||||||||||||||
| 70 | { | - | ||||||||||||||||||||||||||||||
| 71 | QSqlTableModel * const q = q_func(); | - | ||||||||||||||||||||||||||||||
| 72 | ModifiedRow r = cache.value(row); | - | ||||||||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||||||||
| 74 | switch (r.op()) { | - | ||||||||||||||||||||||||||||||
| 75 | case never executed: QSqlTableModelPrivate::None:case QSqlTableModelPrivate::None:never executed: case QSqlTableModelPrivate::None: | 0 | ||||||||||||||||||||||||||||||
| 76 | ((!(false)) ? qt_assert_x("QSqlTableModelPrivate::revertCachedRow()", "Invalid entry in cache map",__FILE__,125) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 77 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 78 | case executed 17 times by 2 tests: QSqlTableModelPrivate::Update:case QSqlTableModelPrivate::Update:Executed by:
executed 17 times by 2 tests: case QSqlTableModelPrivate::Update:Executed by:
| 17 | ||||||||||||||||||||||||||||||
| 79 | case executed 3 times by 1 test: QSqlTableModelPrivate::Delete:case QSqlTableModelPrivate::Delete:Executed by:
executed 3 times by 1 test: case QSqlTableModelPrivate::Delete:Executed by:
| 3 | ||||||||||||||||||||||||||||||
| 80 | if (!r.submitted()
| 3-17 | ||||||||||||||||||||||||||||||
| 81 | cache[row].revert(); | - | ||||||||||||||||||||||||||||||
| 82 | q->dataChanged(q->createIndex(row, 0), | - | ||||||||||||||||||||||||||||||
| 83 | q->createIndex(row, q->columnCount() - 1)); | - | ||||||||||||||||||||||||||||||
| 84 | } executed 17 times by 2 tests: end of blockExecuted by:
| 17 | ||||||||||||||||||||||||||||||
| 85 | break; executed 20 times by 2 tests: break;Executed by:
| 20 | ||||||||||||||||||||||||||||||
| 86 | case executed 32 times by 2 tests: QSqlTableModelPrivate::Insert:case QSqlTableModelPrivate::Insert:Executed by:
executed 32 times by 2 tests: {case QSqlTableModelPrivate::Insert:Executed by:
| 32 | ||||||||||||||||||||||||||||||
| 87 | QMap<int, QSqlTableModelPrivate::ModifiedRow>::Iterator it = cache.find(row); | - | ||||||||||||||||||||||||||||||
| 88 | if (it == cache.end()
| 0-32 | ||||||||||||||||||||||||||||||
| 89 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 90 | q->beginRemoveRows(QModelIndex(), row, row); | - | ||||||||||||||||||||||||||||||
| 91 | it = cache.erase(it); | - | ||||||||||||||||||||||||||||||
| 92 | while (it != cache.end()
| 5-32 | ||||||||||||||||||||||||||||||
| 93 | int oldKey = it.key(); | - | ||||||||||||||||||||||||||||||
| 94 | const QSqlTableModelPrivate::ModifiedRow oldValue = it.value(); | - | ||||||||||||||||||||||||||||||
| 95 | cache.erase(it); | - | ||||||||||||||||||||||||||||||
| 96 | it = cache.insert(oldKey - 1, oldValue); | - | ||||||||||||||||||||||||||||||
| 97 | ++it; | - | ||||||||||||||||||||||||||||||
| 98 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||||||||
| 99 | q->endRemoveRows(); | - | ||||||||||||||||||||||||||||||
| 100 | break; executed 32 times by 2 tests: }break;Executed by:
| 32 | ||||||||||||||||||||||||||||||
| 101 | } | - | ||||||||||||||||||||||||||||||
| 102 | } executed 52 times by 2 tests: end of blockExecuted by:
| 52 | ||||||||||||||||||||||||||||||
| 103 | - | |||||||||||||||||||||||||||||||
| 104 | bool QSqlTableModelPrivate::exec(const QString &stmt, bool prepStatement, | - | ||||||||||||||||||||||||||||||
| 105 | const QSqlRecord &rec, const QSqlRecord &whereValues) | - | ||||||||||||||||||||||||||||||
| 106 | { | - | ||||||||||||||||||||||||||||||
| 107 | if (stmt.isEmpty()
| 0-123 | ||||||||||||||||||||||||||||||
| 108 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 109 | - | |||||||||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||||||||
| 111 | if (editQuery.driver() != db.driver()
| 51-72 | ||||||||||||||||||||||||||||||
| 112 | editQuery = QSqlQuery(db); executed 51 times by 2 tests: editQuery = QSqlQuery(db);Executed by:
| 51 | ||||||||||||||||||||||||||||||
| 113 | - | |||||||||||||||||||||||||||||||
| 114 | - | |||||||||||||||||||||||||||||||
| 115 | - | |||||||||||||||||||||||||||||||
| 116 | if (db.driver()->hasFeature(QSqlDriver::SimpleLocking)
| 0-123 | ||||||||||||||||||||||||||||||
| 117 | const_cast< executed 123 times by 2 tests: QSqlResult *>(query.result())->detachFromResultSet();const_cast<QSqlResult *>(query.result())->detachFromResultSet();Executed by:
executed 123 times by 2 tests: const_cast<QSqlResult *>(query.result())->detachFromResultSet();Executed by:
| 123 | ||||||||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||||||||
| 119 | if (prepStatement
| 0-123 | ||||||||||||||||||||||||||||||
| 120 | if (editQuery.lastQuery() != stmt
| 44-79 | ||||||||||||||||||||||||||||||
| 121 | if (!editQuery.prepare(stmt)
| 0-79 | ||||||||||||||||||||||||||||||
| 122 | error = editQuery.lastError(); | - | ||||||||||||||||||||||||||||||
| 123 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 124 | } | - | ||||||||||||||||||||||||||||||
| 125 | } executed 79 times by 2 tests: end of blockExecuted by:
| 79 | ||||||||||||||||||||||||||||||
| 126 | int i; | - | ||||||||||||||||||||||||||||||
| 127 | for (i = 0; i < rec.count()
| 123-298 | ||||||||||||||||||||||||||||||
| 128 | if (rec.isGenerated(i)
| 106-192 | ||||||||||||||||||||||||||||||
| 129 | editQuery.addBindValue(rec.value(i)); executed 192 times by 2 tests: editQuery.addBindValue(rec.value(i));Executed by:
| 192 | ||||||||||||||||||||||||||||||
| 130 | for (i = 0; i < whereValues.count()
| 123-156 | ||||||||||||||||||||||||||||||
| 131 | if (whereValues.isGenerated(i)
| 0-156 | ||||||||||||||||||||||||||||||
| 132 | editQuery.addBindValue(whereValues.value(i)); executed 150 times by 2 tests: editQuery.addBindValue(whereValues.value(i));Executed by:
| 150 | ||||||||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||||||||
| 134 | if (!editQuery.exec()
| 6-117 | ||||||||||||||||||||||||||||||
| 135 | error = editQuery.lastError(); | - | ||||||||||||||||||||||||||||||
| 136 | return executed 6 times by 1 test: false;return false;Executed by:
executed 6 times by 1 test: return false;Executed by:
| 6 | ||||||||||||||||||||||||||||||
| 137 | } | - | ||||||||||||||||||||||||||||||
| 138 | } executed 117 times by 2 tests: else {end of blockExecuted by:
| 117 | ||||||||||||||||||||||||||||||
| 139 | if (!editQuery.exec(stmt)
| 0 | ||||||||||||||||||||||||||||||
| 140 | error = editQuery.lastError(); | - | ||||||||||||||||||||||||||||||
| 141 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 142 | } | - | ||||||||||||||||||||||||||||||
| 143 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 144 | return executed 117 times by 2 tests: true;return true;Executed by:
executed 117 times by 2 tests: return true;Executed by:
| 117 | ||||||||||||||||||||||||||||||
| 145 | } | - | ||||||||||||||||||||||||||||||
| 146 | QSqlTableModel::QSqlTableModel(QObject *parent, QSqlDatabase db) | - | ||||||||||||||||||||||||||||||
| 147 | : QSqlQueryModel(*new QSqlTableModelPrivate, parent) | - | ||||||||||||||||||||||||||||||
| 148 | { | - | ||||||||||||||||||||||||||||||
| 149 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 150 | d->db = db.isValid()
| 51-92 | ||||||||||||||||||||||||||||||
| 151 | } executed 143 times by 3 tests: end of blockExecuted by:
| 143 | ||||||||||||||||||||||||||||||
| 152 | - | |||||||||||||||||||||||||||||||
| 153 | - | |||||||||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||||||||
| 155 | QSqlTableModel::QSqlTableModel(QSqlTableModelPrivate &dd, QObject *parent, QSqlDatabase db) | - | ||||||||||||||||||||||||||||||
| 156 | : QSqlQueryModel(dd, parent) | - | ||||||||||||||||||||||||||||||
| 157 | { | - | ||||||||||||||||||||||||||||||
| 158 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 159 | d->db = db.isValid()
| 0-31 | ||||||||||||||||||||||||||||||
| 160 | } executed 31 times by 1 test: end of blockExecuted by:
| 31 | ||||||||||||||||||||||||||||||
| 161 | - | |||||||||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||||||||
| 164 | - | |||||||||||||||||||||||||||||||
| 165 | QSqlTableModel::~QSqlTableModel() | - | ||||||||||||||||||||||||||||||
| 166 | { | - | ||||||||||||||||||||||||||||||
| 167 | } | - | ||||||||||||||||||||||||||||||
| 168 | void QSqlTableModel::setTable(const QString &tableName) | - | ||||||||||||||||||||||||||||||
| 169 | { | - | ||||||||||||||||||||||||||||||
| 170 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 171 | clear(); | - | ||||||||||||||||||||||||||||||
| 172 | d->tableName = tableName; | - | ||||||||||||||||||||||||||||||
| 173 | d->initRecordAndPrimaryIndex(); | - | ||||||||||||||||||||||||||||||
| 174 | - | |||||||||||||||||||||||||||||||
| 175 | if (d->rec.count() == 0
| 1-182 | ||||||||||||||||||||||||||||||
| 176 | d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), executed 1 time by 1 test: d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), QSqlError::StatementError);Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 177 | QSqlError::StatementError); executed 1 time by 1 test: d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), QSqlError::StatementError);Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 178 | - | |||||||||||||||||||||||||||||||
| 179 | - | |||||||||||||||||||||||||||||||
| 180 | - | |||||||||||||||||||||||||||||||
| 181 | d->autoColumn.clear(); | - | ||||||||||||||||||||||||||||||
| 182 | for (int c = 0; c < d->rec.count()
| 178-450 | ||||||||||||||||||||||||||||||
| 183 | if (d->rec.field(c).isAutoValue()
| 5-445 | ||||||||||||||||||||||||||||||
| 184 | d->autoColumn = d->rec.fieldName(c); | - | ||||||||||||||||||||||||||||||
| 185 | break; executed 5 times by 2 tests: break;Executed by:
| 5 | ||||||||||||||||||||||||||||||
| 186 | } | - | ||||||||||||||||||||||||||||||
| 187 | } executed 445 times by 3 tests: end of blockExecuted by:
| 445 | ||||||||||||||||||||||||||||||
| 188 | } executed 183 times by 3 tests: end of blockExecuted by:
| 183 | ||||||||||||||||||||||||||||||
| 189 | - | |||||||||||||||||||||||||||||||
| 190 | - | |||||||||||||||||||||||||||||||
| 191 | - | |||||||||||||||||||||||||||||||
| 192 | - | |||||||||||||||||||||||||||||||
| 193 | QString QSqlTableModel::tableName() const | - | ||||||||||||||||||||||||||||||
| 194 | { | - | ||||||||||||||||||||||||||||||
| 195 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 196 | return executed 475 times by 1 test: d->tableName;return d->tableName;Executed by:
executed 475 times by 1 test: return d->tableName;Executed by:
| 475 | ||||||||||||||||||||||||||||||
| 197 | } | - | ||||||||||||||||||||||||||||||
| 198 | bool QSqlTableModel::select() | - | ||||||||||||||||||||||||||||||
| 199 | { | - | ||||||||||||||||||||||||||||||
| 200 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 201 | const QString query = selectStatement(); | - | ||||||||||||||||||||||||||||||
| 202 | if (query.isEmpty()
| 1-315 | ||||||||||||||||||||||||||||||
| 203 | return executed 1 time by 1 test: false;return false;Executed by:
executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||||||||
| 205 | beginResetModel(); | - | ||||||||||||||||||||||||||||||
| 206 | - | |||||||||||||||||||||||||||||||
| 207 | d->clearCache(); | - | ||||||||||||||||||||||||||||||
| 208 | - | |||||||||||||||||||||||||||||||
| 209 | QSqlQuery qu(query, d->db); | - | ||||||||||||||||||||||||||||||
| 210 | setQuery(qu); | - | ||||||||||||||||||||||||||||||
| 211 | - | |||||||||||||||||||||||||||||||
| 212 | if (!qu.isActive()
| 0-313 | ||||||||||||||||||||||||||||||
| 213 | - | |||||||||||||||||||||||||||||||
| 214 | d->initRecordAndPrimaryIndex(); | - | ||||||||||||||||||||||||||||||
| 215 | endResetModel(); | - | ||||||||||||||||||||||||||||||
| 216 | return executed 2 times by 1 test: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||||||||||||||
| 217 | } | - | ||||||||||||||||||||||||||||||
| 218 | endResetModel(); | - | ||||||||||||||||||||||||||||||
| 219 | return executed 313 times by 3 tests: true;return true;Executed by:
executed 313 times by 3 tests: return true;Executed by:
| 313 | ||||||||||||||||||||||||||||||
| 220 | } | - | ||||||||||||||||||||||||||||||
| 221 | bool QSqlTableModel::selectRow(int row) | - | ||||||||||||||||||||||||||||||
| 222 | { | - | ||||||||||||||||||||||||||||||
| 223 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 224 | - | |||||||||||||||||||||||||||||||
| 225 | if (row < 0
| 0-62 | ||||||||||||||||||||||||||||||
| 226 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 227 | - | |||||||||||||||||||||||||||||||
| 228 | const int table_sort_col = d->sortColumn; | - | ||||||||||||||||||||||||||||||
| 229 | d->sortColumn = -1; | - | ||||||||||||||||||||||||||||||
| 230 | const QString table_filter = d->filter; | - | ||||||||||||||||||||||||||||||
| 231 | d->filter = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, | - | ||||||||||||||||||||||||||||||
| 232 | d->tableName, | - | ||||||||||||||||||||||||||||||
| 233 | primaryValues(row), | - | ||||||||||||||||||||||||||||||
| 234 | false); | - | ||||||||||||||||||||||||||||||
| 235 | static const QString wh = Sql::where() + Sql::sp(); | - | ||||||||||||||||||||||||||||||
| 236 | if (d->filter.startsWith(wh, Qt::CaseInsensitive)
| 0-62 | ||||||||||||||||||||||||||||||
| 237 | d->filter.remove(0, wh.length()); executed 62 times by 2 tests: d->filter.remove(0, wh.length());Executed by:
| 62 | ||||||||||||||||||||||||||||||
| 238 | - | |||||||||||||||||||||||||||||||
| 239 | QString stmt; | - | ||||||||||||||||||||||||||||||
| 240 | - | |||||||||||||||||||||||||||||||
| 241 | if (!d->filter.isEmpty()
| 0-62 | ||||||||||||||||||||||||||||||
| 242 | stmt = selectStatement(); executed 62 times by 2 tests: stmt = selectStatement();Executed by:
| 62 | ||||||||||||||||||||||||||||||
| 243 | - | |||||||||||||||||||||||||||||||
| 244 | d->sortColumn = table_sort_col; | - | ||||||||||||||||||||||||||||||
| 245 | d->filter = table_filter; | - | ||||||||||||||||||||||||||||||
| 246 | - | |||||||||||||||||||||||||||||||
| 247 | if (stmt.isEmpty()
| 0-62 | ||||||||||||||||||||||||||||||
| 248 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 249 | - | |||||||||||||||||||||||||||||||
| 250 | bool exists; | - | ||||||||||||||||||||||||||||||
| 251 | QSqlRecord newValues; | - | ||||||||||||||||||||||||||||||
| 252 | - | |||||||||||||||||||||||||||||||
| 253 | { | - | ||||||||||||||||||||||||||||||
| 254 | QSqlQuery q(d->db); | - | ||||||||||||||||||||||||||||||
| 255 | q.setForwardOnly(true); | - | ||||||||||||||||||||||||||||||
| 256 | if (!q.exec(stmt)
| 0-62 | ||||||||||||||||||||||||||||||
| 257 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 258 | - | |||||||||||||||||||||||||||||||
| 259 | exists = q.next(); | - | ||||||||||||||||||||||||||||||
| 260 | newValues = q.record(); | - | ||||||||||||||||||||||||||||||
| 261 | } | - | ||||||||||||||||||||||||||||||
| 262 | - | |||||||||||||||||||||||||||||||
| 263 | bool needsAddingToCache = !exists
| 2-53 | ||||||||||||||||||||||||||||||
| 264 | - | |||||||||||||||||||||||||||||||
| 265 | if (!needsAddingToCache
| 2-60 | ||||||||||||||||||||||||||||||
| 266 | const QSqlRecord curValues = record(row); | - | ||||||||||||||||||||||||||||||
| 267 | needsAddingToCache = curValues.count() != newValues.count(); | - | ||||||||||||||||||||||||||||||
| 268 | if (!needsAddingToCache
| 0-2 | ||||||||||||||||||||||||||||||
| 269 | - | |||||||||||||||||||||||||||||||
| 270 | - | |||||||||||||||||||||||||||||||
| 271 | for (int f = curValues.count() - 1; f >= 0
| 1-3 | ||||||||||||||||||||||||||||||
| 272 | if (curValues.value(f) != newValues.value(f)
| 1-2 | ||||||||||||||||||||||||||||||
| 273 | needsAddingToCache = true; | - | ||||||||||||||||||||||||||||||
| 274 | break; executed 1 time by 1 test: break;Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 275 | } | - | ||||||||||||||||||||||||||||||
| 276 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||||||||
| 277 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||||||||
| 278 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||||||||||||||
| 279 | - | |||||||||||||||||||||||||||||||
| 280 | if (needsAddingToCache
| 1-61 | ||||||||||||||||||||||||||||||
| 281 | d->cache[row].refresh(exists, newValues); | - | ||||||||||||||||||||||||||||||
| 282 | headerDataChanged(Qt::Vertical, row, row); | - | ||||||||||||||||||||||||||||||
| 283 | dataChanged(createIndex(row, 0), createIndex(row, columnCount() - 1)); | - | ||||||||||||||||||||||||||||||
| 284 | } executed 61 times by 2 tests: end of blockExecuted by:
| 61 | ||||||||||||||||||||||||||||||
| 285 | - | |||||||||||||||||||||||||||||||
| 286 | return executed 62 times by 2 tests: true;return true;Executed by:
executed 62 times by 2 tests: return true;Executed by:
| 62 | ||||||||||||||||||||||||||||||
| 287 | } | - | ||||||||||||||||||||||||||||||
| 288 | - | |||||||||||||||||||||||||||||||
| 289 | - | |||||||||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||||||||
| 291 | - | |||||||||||||||||||||||||||||||
| 292 | QVariant QSqlTableModel::data(const QModelIndex &index, int role) const | - | ||||||||||||||||||||||||||||||
| 293 | { | - | ||||||||||||||||||||||||||||||
| 294 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 295 | if (!index.isValid()
| 9-2596 | ||||||||||||||||||||||||||||||
| 296 | return executed 327 times by 3 tests: QVariant();return QVariant();Executed by:
executed 327 times by 3 tests: return QVariant();Executed by:
| 327 | ||||||||||||||||||||||||||||||
| 297 | - | |||||||||||||||||||||||||||||||
| 298 | const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(index.row()); | - | ||||||||||||||||||||||||||||||
| 299 | if (mrow.op() != QSqlTableModelPrivate::None
| 392-2195 | ||||||||||||||||||||||||||||||
| 300 | return executed 392 times by 2 tests: mrow.rec().value(index.column());return mrow.rec().value(index.column());Executed by:
executed 392 times by 2 tests: return mrow.rec().value(index.column());Executed by:
| 392 | ||||||||||||||||||||||||||||||
| 301 | - | |||||||||||||||||||||||||||||||
| 302 | return executed 2195 times by 3 tests: QSqlQueryModel::data(index, role);return QSqlQueryModel::data(index, role);Executed by:
executed 2195 times by 3 tests: return QSqlQueryModel::data(index, role);Executed by:
| 2195 | ||||||||||||||||||||||||||||||
| 303 | } | - | ||||||||||||||||||||||||||||||
| 304 | - | |||||||||||||||||||||||||||||||
| 305 | - | |||||||||||||||||||||||||||||||
| 306 | - | |||||||||||||||||||||||||||||||
| 307 | - | |||||||||||||||||||||||||||||||
| 308 | QVariant QSqlTableModel::headerData(int section, Qt::Orientation orientation, int role) const | - | ||||||||||||||||||||||||||||||
| 309 | { | - | ||||||||||||||||||||||||||||||
| 310 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 311 | if (orientation == Qt::Vertical
| 0-4 | ||||||||||||||||||||||||||||||
| 312 | const QSqlTableModelPrivate::Op op = d->cache.value(section).op(); | - | ||||||||||||||||||||||||||||||
| 313 | if (op == QSqlTableModelPrivate::Insert
| 0 | ||||||||||||||||||||||||||||||
| 314 | return never executed: QLatin1String("*");return QLatin1String("*");never executed: return QLatin1String("*"); | 0 | ||||||||||||||||||||||||||||||
| 315 | else if (op == QSqlTableModelPrivate::Delete
| 0 | ||||||||||||||||||||||||||||||
| 316 | return never executed: QLatin1String("!");return QLatin1String("!");never executed: return QLatin1String("!"); | 0 | ||||||||||||||||||||||||||||||
| 317 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 318 | return executed 4 times by 2 tests: QSqlQueryModel::headerData(section, orientation, role);return QSqlQueryModel::headerData(section, orientation, role);Executed by:
executed 4 times by 2 tests: return QSqlQueryModel::headerData(section, orientation, role);Executed by:
| 4 | ||||||||||||||||||||||||||||||
| 319 | } | - | ||||||||||||||||||||||||||||||
| 320 | bool QSqlTableModel::isDirty() const | - | ||||||||||||||||||||||||||||||
| 321 | { | - | ||||||||||||||||||||||||||||||
| 322 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 323 | QSqlTableModelPrivate::CacheMap::ConstIterator i = d->cache.constBegin(); | - | ||||||||||||||||||||||||||||||
| 324 | const QSqlTableModelPrivate::CacheMap::ConstIterator e = d->cache.constEnd(); | - | ||||||||||||||||||||||||||||||
| 325 | for (; i != e
| 74-144 | ||||||||||||||||||||||||||||||
| 326 | if (!i.value().submitted()
| 36-38 | ||||||||||||||||||||||||||||||
| 327 | return executed 36 times by 1 test: true;return true;Executed by:
executed 36 times by 1 test: return true;Executed by:
| 36 | ||||||||||||||||||||||||||||||
| 328 | } executed 38 times by 2 tests: end of blockExecuted by:
| 38 | ||||||||||||||||||||||||||||||
| 329 | return executed 144 times by 2 tests: false;return false;Executed by:
executed 144 times by 2 tests: return false;Executed by:
| 144 | ||||||||||||||||||||||||||||||
| 330 | } | - | ||||||||||||||||||||||||||||||
| 331 | bool QSqlTableModel::isDirty(const QModelIndex &index) const | - | ||||||||||||||||||||||||||||||
| 332 | { | - | ||||||||||||||||||||||||||||||
| 333 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 334 | if (!index.isValid()
| 0-79 | ||||||||||||||||||||||||||||||
| 335 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||||||||
| 337 | const QSqlTableModelPrivate::ModifiedRow row = d->cache.value(index.row()); | - | ||||||||||||||||||||||||||||||
| 338 | if (row.submitted()
| 22-57 | ||||||||||||||||||||||||||||||
| 339 | return executed 57 times by 2 tests: false;return false;Executed by:
executed 57 times by 2 tests: return false;Executed by:
| 57 | ||||||||||||||||||||||||||||||
| 340 | - | |||||||||||||||||||||||||||||||
| 341 | return executed 22 times by 1 test: row.op() == QSqlTableModelPrivate::Insertreturn row.op() == QSqlTableModelPrivate::Insert || row.op() == QSqlTableModelPrivate::Delete || (row.op() == QSqlTableModelPrivate::Update && row.rec().isGenerated(index.column()));Executed by:
executed 22 times by 1 test: return row.op() == QSqlTableModelPrivate::Insert || row.op() == QSqlTableModelPrivate::Delete || (row.op() == QSqlTableModelPrivate::Update && row.rec().isGenerated(index.column()));Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 342 | || row.op() == QSqlTableModelPrivate::Delete executed 22 times by 1 test: return row.op() == QSqlTableModelPrivate::Insert || row.op() == QSqlTableModelPrivate::Delete || (row.op() == QSqlTableModelPrivate::Update && row.rec().isGenerated(index.column()));Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 343 | || (row.op() == QSqlTableModelPrivate::Update executed 22 times by 1 test: return row.op() == QSqlTableModelPrivate::Insert || row.op() == QSqlTableModelPrivate::Delete || (row.op() == QSqlTableModelPrivate::Update && row.rec().isGenerated(index.column()));Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 344 | && row.rec().isGenerated(index.column())); executed 22 times by 1 test: return row.op() == QSqlTableModelPrivate::Insert || row.op() == QSqlTableModelPrivate::Delete || (row.op() == QSqlTableModelPrivate::Update && row.rec().isGenerated(index.column()));Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 345 | } | - | ||||||||||||||||||||||||||||||
| 346 | bool QSqlTableModel::setData(const QModelIndex &index, const QVariant &value, int role) | - | ||||||||||||||||||||||||||||||
| 347 | { | - | ||||||||||||||||||||||||||||||
| 348 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 349 | if (d->busyInsertingRows
| 0-270 | ||||||||||||||||||||||||||||||
| 350 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 351 | - | |||||||||||||||||||||||||||||||
| 352 | if (role != Qt::EditRole
| 2-268 | ||||||||||||||||||||||||||||||
| 353 | return executed 2 times by 1 test: QSqlQueryModel::setData(index, value, role);return QSqlQueryModel::setData(index, value, role);Executed by:
executed 2 times by 1 test: return QSqlQueryModel::setData(index, value, role);Executed by:
| 2 | ||||||||||||||||||||||||||||||
| 354 | - | |||||||||||||||||||||||||||||||
| 355 | if (!index.isValid()
| 0-265 | ||||||||||||||||||||||||||||||
| 356 | return executed 3 times by 2 tests: false;return false;Executed by:
executed 3 times by 2 tests: return false;Executed by:
| 3 | ||||||||||||||||||||||||||||||
| 357 | - | |||||||||||||||||||||||||||||||
| 358 | if (!(flags(index) & Qt::ItemIsEditable)
| 3-262 | ||||||||||||||||||||||||||||||
| 359 | return executed 3 times by 1 test: false;return false;Executed by:
executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||||||||
| 361 | const QVariant oldValue = QSqlTableModel::data(index, role); | - | ||||||||||||||||||||||||||||||
| 362 | if (value == oldValue
| 33-229 | ||||||||||||||||||||||||||||||
| 363 | && value.isNull() == oldValue.isNull()
| 3-30 | ||||||||||||||||||||||||||||||
| 364 | && d->cache.value(index.row()).op() != QSqlTableModelPrivate::Insert
| 7-23 | ||||||||||||||||||||||||||||||
| 365 | return executed 23 times by 2 tests: true;return true;Executed by:
executed 23 times by 2 tests: return true;Executed by:
| 23 | ||||||||||||||||||||||||||||||
| 366 | - | |||||||||||||||||||||||||||||||
| 367 | QSqlTableModelPrivate::ModifiedRow &row = d->cache[index.row()]; | - | ||||||||||||||||||||||||||||||
| 368 | - | |||||||||||||||||||||||||||||||
| 369 | if (row.op() == QSqlTableModelPrivate::None
| 47-192 | ||||||||||||||||||||||||||||||
| 370 | row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, executed 47 times by 2 tests: row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, QSqlQueryModel::record(index.row()));Executed by:
| 47 | ||||||||||||||||||||||||||||||
| 371 | QSqlQueryModel::record(index.row())); executed 47 times by 2 tests: row = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, QSqlQueryModel::record(index.row()));Executed by:
| 47 | ||||||||||||||||||||||||||||||
| 372 | - | |||||||||||||||||||||||||||||||
| 373 | row.setValue(index.column(), value); | - | ||||||||||||||||||||||||||||||
| 374 | dataChanged(index, index); | - | ||||||||||||||||||||||||||||||
| 375 | - | |||||||||||||||||||||||||||||||
| 376 | if (d->strategy == OnFieldChange
| 7-224 | ||||||||||||||||||||||||||||||
| 377 | return executed 8 times by 2 tests: submit();return submit();Executed by:
executed 8 times by 2 tests: return submit();Executed by:
| 8 | ||||||||||||||||||||||||||||||
| 378 | - | |||||||||||||||||||||||||||||||
| 379 | return executed 231 times by 2 tests: true;return true;Executed by:
executed 231 times by 2 tests: return true;Executed by:
| 231 | ||||||||||||||||||||||||||||||
| 380 | } | - | ||||||||||||||||||||||||||||||
| 381 | void QSqlTableModel::setQuery(const QSqlQuery &query) | - | ||||||||||||||||||||||||||||||
| 382 | { | - | ||||||||||||||||||||||||||||||
| 383 | QSqlQueryModel::setQuery(query); | - | ||||||||||||||||||||||||||||||
| 384 | } executed 315 times by 3 tests: end of blockExecuted by:
| 315 | ||||||||||||||||||||||||||||||
| 385 | bool QSqlTableModel::updateRowInTable(int row, const QSqlRecord &values) | - | ||||||||||||||||||||||||||||||
| 386 | { | - | ||||||||||||||||||||||||||||||
| 387 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 388 | QSqlRecord rec(values); | - | ||||||||||||||||||||||||||||||
| 389 | beforeUpdate(row, rec); | - | ||||||||||||||||||||||||||||||
| 390 | - | |||||||||||||||||||||||||||||||
| 391 | const QSqlRecord whereValues = primaryValues(row); | - | ||||||||||||||||||||||||||||||
| 392 | const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); | - | ||||||||||||||||||||||||||||||
| 393 | const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::UpdateStatement, d->tableName, | - | ||||||||||||||||||||||||||||||
| 394 | rec, prepStatement); | - | ||||||||||||||||||||||||||||||
| 395 | const QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, d->tableName, | - | ||||||||||||||||||||||||||||||
| 396 | whereValues, prepStatement); | - | ||||||||||||||||||||||||||||||
| 397 | - | |||||||||||||||||||||||||||||||
| 398 | if (stmt.isEmpty()
| 0-49 | ||||||||||||||||||||||||||||||
| 399 | d->error = QSqlError(QLatin1String("No Fields to update"), QString(), | - | ||||||||||||||||||||||||||||||
| 400 | QSqlError::StatementError); | - | ||||||||||||||||||||||||||||||
| 401 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 402 | } | - | ||||||||||||||||||||||||||||||
| 403 | - | |||||||||||||||||||||||||||||||
| 404 | return executed 49 times by 2 tests: d->exec(Sql::concat(stmt, where), prepStatement, rec, whereValues);return d->exec(Sql::concat(stmt, where), prepStatement, rec, whereValues);Executed by:
executed 49 times by 2 tests: return d->exec(Sql::concat(stmt, where), prepStatement, rec, whereValues);Executed by:
| 49 | ||||||||||||||||||||||||||||||
| 405 | } | - | ||||||||||||||||||||||||||||||
| 406 | bool QSqlTableModel::insertRowIntoTable(const QSqlRecord &values) | - | ||||||||||||||||||||||||||||||
| 407 | { | - | ||||||||||||||||||||||||||||||
| 408 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 409 | QSqlRecord rec = values; | - | ||||||||||||||||||||||||||||||
| 410 | beforeInsert(rec); | - | ||||||||||||||||||||||||||||||
| 411 | - | |||||||||||||||||||||||||||||||
| 412 | const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); | - | ||||||||||||||||||||||||||||||
| 413 | const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::InsertStatement, d->tableName, | - | ||||||||||||||||||||||||||||||
| 414 | rec, prepStatement); | - | ||||||||||||||||||||||||||||||
| 415 | - | |||||||||||||||||||||||||||||||
| 416 | if (stmt.isEmpty()
| 1-52 | ||||||||||||||||||||||||||||||
| 417 | d->error = QSqlError(QLatin1String("No Fields to update"), QString(), | - | ||||||||||||||||||||||||||||||
| 418 | QSqlError::StatementError); | - | ||||||||||||||||||||||||||||||
| 419 | return executed 1 time by 1 test: false;return false;Executed by:
executed 1 time by 1 test: return false;Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 420 | } | - | ||||||||||||||||||||||||||||||
| 421 | - | |||||||||||||||||||||||||||||||
| 422 | return executed 52 times by 2 tests: d->exec(stmt, prepStatement, rec, QSqlRecord() );return d->exec(stmt, prepStatement, rec, QSqlRecord() );Executed by:
executed 52 times by 2 tests: return d->exec(stmt, prepStatement, rec, QSqlRecord() );Executed by:
| 52 | ||||||||||||||||||||||||||||||
| 423 | } | - | ||||||||||||||||||||||||||||||
| 424 | bool QSqlTableModel::deleteRowFromTable(int row) | - | ||||||||||||||||||||||||||||||
| 425 | { | - | ||||||||||||||||||||||||||||||
| 426 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 427 | beforeDelete(row); | - | ||||||||||||||||||||||||||||||
| 428 | - | |||||||||||||||||||||||||||||||
| 429 | const QSqlRecord whereValues = primaryValues(row); | - | ||||||||||||||||||||||||||||||
| 430 | const bool prepStatement = d->db.driver()->hasFeature(QSqlDriver::PreparedQueries); | - | ||||||||||||||||||||||||||||||
| 431 | const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::DeleteStatement, | - | ||||||||||||||||||||||||||||||
| 432 | d->tableName, | - | ||||||||||||||||||||||||||||||
| 433 | QSqlRecord(), | - | ||||||||||||||||||||||||||||||
| 434 | prepStatement); | - | ||||||||||||||||||||||||||||||
| 435 | const QString where = d->db.driver()->sqlStatement(QSqlDriver::WhereStatement, | - | ||||||||||||||||||||||||||||||
| 436 | d->tableName, | - | ||||||||||||||||||||||||||||||
| 437 | whereValues, | - | ||||||||||||||||||||||||||||||
| 438 | prepStatement); | - | ||||||||||||||||||||||||||||||
| 439 | - | |||||||||||||||||||||||||||||||
| 440 | if (stmt.isEmpty()
| 0-22 | ||||||||||||||||||||||||||||||
| 441 | d->error = QSqlError(QLatin1String("Unable to delete row"), QString(), | - | ||||||||||||||||||||||||||||||
| 442 | QSqlError::StatementError); | - | ||||||||||||||||||||||||||||||
| 443 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 444 | } | - | ||||||||||||||||||||||||||||||
| 445 | - | |||||||||||||||||||||||||||||||
| 446 | return executed 22 times by 1 test: d->exec(Sql::concat(stmt, where), prepStatement, QSqlRecord() , whereValues);return d->exec(Sql::concat(stmt, where), prepStatement, QSqlRecord() , whereValues);Executed by:
executed 22 times by 1 test: return d->exec(Sql::concat(stmt, where), prepStatement, QSqlRecord() , whereValues);Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 447 | } | - | ||||||||||||||||||||||||||||||
| 448 | bool QSqlTableModel::submitAll() | - | ||||||||||||||||||||||||||||||
| 449 | { | - | ||||||||||||||||||||||||||||||
| 450 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 451 | - | |||||||||||||||||||||||||||||||
| 452 | bool success = true; | - | ||||||||||||||||||||||||||||||
| 453 | - | |||||||||||||||||||||||||||||||
| 454 | const auto cachedKeys = d->cache.keys(); | - | ||||||||||||||||||||||||||||||
| 455 | for (int row : cachedKeys) { | - | ||||||||||||||||||||||||||||||
| 456 | - | |||||||||||||||||||||||||||||||
| 457 | QSqlTableModelPrivate::CacheMap::iterator it = d->cache.find(row); | - | ||||||||||||||||||||||||||||||
| 458 | if (it == d->cache.end()
| 0-160 | ||||||||||||||||||||||||||||||
| 459 | continue; never executed: continue; | 0 | ||||||||||||||||||||||||||||||
| 460 | - | |||||||||||||||||||||||||||||||
| 461 | QSqlTableModelPrivate::ModifiedRow &mrow = it.value(); | - | ||||||||||||||||||||||||||||||
| 462 | if (mrow.submitted()
| 36-124 | ||||||||||||||||||||||||||||||
| 463 | continue; executed 36 times by 2 tests: continue;Executed by:
| 36 | ||||||||||||||||||||||||||||||
| 464 | - | |||||||||||||||||||||||||||||||
| 465 | switch (mrow.op()) { | - | ||||||||||||||||||||||||||||||
| 466 | case executed 53 times by 2 tests: QSqlTableModelPrivate::Insert:case QSqlTableModelPrivate::Insert:Executed by:
executed 53 times by 2 tests: case QSqlTableModelPrivate::Insert:Executed by:
| 53 | ||||||||||||||||||||||||||||||
| 467 | success = insertRowIntoTable(mrow.rec()); | - | ||||||||||||||||||||||||||||||
| 468 | break; executed 53 times by 2 tests: break;Executed by:
| 53 | ||||||||||||||||||||||||||||||
| 469 | case executed 49 times by 2 tests: QSqlTableModelPrivate::Update:case QSqlTableModelPrivate::Update:Executed by:
executed 49 times by 2 tests: case QSqlTableModelPrivate::Update:Executed by:
| 49 | ||||||||||||||||||||||||||||||
| 470 | success = updateRowInTable(row, mrow.rec()); | - | ||||||||||||||||||||||||||||||
| 471 | break; executed 49 times by 2 tests: break;Executed by:
| 49 | ||||||||||||||||||||||||||||||
| 472 | case executed 22 times by 1 test: QSqlTableModelPrivate::Delete:case QSqlTableModelPrivate::Delete:Executed by:
executed 22 times by 1 test: case QSqlTableModelPrivate::Delete:Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 473 | success = deleteRowFromTable(row); | - | ||||||||||||||||||||||||||||||
| 474 | break; executed 22 times by 1 test: break;Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 475 | case never executed: QSqlTableModelPrivate::None:case QSqlTableModelPrivate::None:never executed: case QSqlTableModelPrivate::None: | 0 | ||||||||||||||||||||||||||||||
| 476 | ((!(false)) ? qt_assert_x("QSqlTableModel::submitAll()", "Invalid cache operation",__FILE__,761) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 477 | break; never executed: break; | 0 | ||||||||||||||||||||||||||||||
| 478 | } | - | ||||||||||||||||||||||||||||||
| 479 | - | |||||||||||||||||||||||||||||||
| 480 | if (success
| 7-117 | ||||||||||||||||||||||||||||||
| 481 | if (d->strategy != OnManualSubmit
| 23-60 | ||||||||||||||||||||||||||||||
| 482 | int c = mrow.rec().indexOf(d->autoColumn); | - | ||||||||||||||||||||||||||||||
| 483 | if (c != -1
| 0-17 | ||||||||||||||||||||||||||||||
| 484 | mrow.setValue(c, d->editQuery.lastInsertId()); executed 6 times by 1 test: mrow.setValue(c, d->editQuery.lastInsertId());Executed by:
| 6 | ||||||||||||||||||||||||||||||
| 485 | } executed 23 times by 2 tests: end of blockExecuted by:
| 23 | ||||||||||||||||||||||||||||||
| 486 | mrow.setSubmitted(); | - | ||||||||||||||||||||||||||||||
| 487 | if (d->strategy != OnManualSubmit
| 57-60 | ||||||||||||||||||||||||||||||
| 488 | success = selectRow(row); executed 60 times by 2 tests: success = selectRow(row);Executed by:
| 60 | ||||||||||||||||||||||||||||||
| 489 | } executed 117 times by 2 tests: end of blockExecuted by:
| 117 | ||||||||||||||||||||||||||||||
| 490 | - | |||||||||||||||||||||||||||||||
| 491 | if (!success
| 7-117 | ||||||||||||||||||||||||||||||
| 492 | break; executed 7 times by 1 test: break;Executed by:
| 7 | ||||||||||||||||||||||||||||||
| 493 | } executed 117 times by 2 tests: end of blockExecuted by:
| 117 | ||||||||||||||||||||||||||||||
| 494 | - | |||||||||||||||||||||||||||||||
| 495 | if (success
| 7-118 | ||||||||||||||||||||||||||||||
| 496 | if (d->strategy == OnManualSubmit
| 36-82 | ||||||||||||||||||||||||||||||
| 497 | success = select(); executed 36 times by 2 tests: success = select();Executed by:
| 36 | ||||||||||||||||||||||||||||||
| 498 | } executed 118 times by 2 tests: end of blockExecuted by:
| 118 | ||||||||||||||||||||||||||||||
| 499 | - | |||||||||||||||||||||||||||||||
| 500 | return executed 125 times by 2 tests: success;return success;Executed by:
executed 125 times by 2 tests: return success;Executed by:
| 125 | ||||||||||||||||||||||||||||||
| 501 | } | - | ||||||||||||||||||||||||||||||
| 502 | bool QSqlTableModel::submit() | - | ||||||||||||||||||||||||||||||
| 503 | { | - | ||||||||||||||||||||||||||||||
| 504 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 505 | if (d->strategy == OnRowChange
| 1-32 | ||||||||||||||||||||||||||||||
| 506 | return executed 56 times by 2 tests: submitAll();return submitAll();Executed by:
executed 56 times by 2 tests: return submitAll();Executed by:
| 56 | ||||||||||||||||||||||||||||||
| 507 | return executed 1 time by 1 test: true;return true;Executed by:
executed 1 time by 1 test: return true;Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 508 | } | - | ||||||||||||||||||||||||||||||
| 509 | void QSqlTableModel::revert() | - | ||||||||||||||||||||||||||||||
| 510 | { | - | ||||||||||||||||||||||||||||||
| 511 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 512 | if (d->strategy == OnRowChange
| 4-9 | ||||||||||||||||||||||||||||||
| 513 | revertAll(); executed 8 times by 1 test: revertAll();Executed by:
| 8 | ||||||||||||||||||||||||||||||
| 514 | } executed 13 times by 2 tests: end of blockExecuted by:
| 13 | ||||||||||||||||||||||||||||||
| 515 | void QSqlTableModel::setEditStrategy(EditStrategy strategy) | - | ||||||||||||||||||||||||||||||
| 516 | { | - | ||||||||||||||||||||||||||||||
| 517 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 518 | revertAll(); | - | ||||||||||||||||||||||||||||||
| 519 | d->strategy = strategy; | - | ||||||||||||||||||||||||||||||
| 520 | } executed 108 times by 3 tests: end of blockExecuted by:
| 108 | ||||||||||||||||||||||||||||||
| 521 | - | |||||||||||||||||||||||||||||||
| 522 | - | |||||||||||||||||||||||||||||||
| 523 | - | |||||||||||||||||||||||||||||||
| 524 | - | |||||||||||||||||||||||||||||||
| 525 | - | |||||||||||||||||||||||||||||||
| 526 | - | |||||||||||||||||||||||||||||||
| 527 | QSqlTableModel::EditStrategy QSqlTableModel::editStrategy() const | - | ||||||||||||||||||||||||||||||
| 528 | { | - | ||||||||||||||||||||||||||||||
| 529 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 530 | return executed 13 times by 2 tests: d->strategy;return d->strategy;Executed by:
executed 13 times by 2 tests: return d->strategy;Executed by:
| 13 | ||||||||||||||||||||||||||||||
| 531 | } | - | ||||||||||||||||||||||||||||||
| 532 | - | |||||||||||||||||||||||||||||||
| 533 | - | |||||||||||||||||||||||||||||||
| 534 | - | |||||||||||||||||||||||||||||||
| 535 | - | |||||||||||||||||||||||||||||||
| 536 | - | |||||||||||||||||||||||||||||||
| 537 | - | |||||||||||||||||||||||||||||||
| 538 | void QSqlTableModel::revertAll() | - | ||||||||||||||||||||||||||||||
| 539 | { | - | ||||||||||||||||||||||||||||||
| 540 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 541 | - | |||||||||||||||||||||||||||||||
| 542 | const QList<int> rows(d->cache.keys()); | - | ||||||||||||||||||||||||||||||
| 543 | for (int i = rows.size() - 1; i >= 0
| 35-134 | ||||||||||||||||||||||||||||||
| 544 | revertRow(rows.value(i)); executed 35 times by 2 tests: revertRow(rows.value(i));Executed by:
| 35 | ||||||||||||||||||||||||||||||
| 545 | } executed 134 times by 3 tests: end of blockExecuted by:
| 134 | ||||||||||||||||||||||||||||||
| 546 | - | |||||||||||||||||||||||||||||||
| 547 | - | |||||||||||||||||||||||||||||||
| 548 | - | |||||||||||||||||||||||||||||||
| 549 | - | |||||||||||||||||||||||||||||||
| 550 | - | |||||||||||||||||||||||||||||||
| 551 | - | |||||||||||||||||||||||||||||||
| 552 | void QSqlTableModel::revertRow(int row) | - | ||||||||||||||||||||||||||||||
| 553 | { | - | ||||||||||||||||||||||||||||||
| 554 | if (row < 0
| 0-52 | ||||||||||||||||||||||||||||||
| 555 | return; never executed: return; | 0 | ||||||||||||||||||||||||||||||
| 556 | - | |||||||||||||||||||||||||||||||
| 557 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 558 | d->revertCachedRow(row); | - | ||||||||||||||||||||||||||||||
| 559 | } executed 52 times by 2 tests: end of blockExecuted by:
| 52 | ||||||||||||||||||||||||||||||
| 560 | - | |||||||||||||||||||||||||||||||
| 561 | - | |||||||||||||||||||||||||||||||
| 562 | - | |||||||||||||||||||||||||||||||
| 563 | - | |||||||||||||||||||||||||||||||
| 564 | - | |||||||||||||||||||||||||||||||
| 565 | - | |||||||||||||||||||||||||||||||
| 566 | - | |||||||||||||||||||||||||||||||
| 567 | QSqlIndex QSqlTableModel::primaryKey() const | - | ||||||||||||||||||||||||||||||
| 568 | { | - | ||||||||||||||||||||||||||||||
| 569 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 570 | return executed 1 time by 1 test: d->primaryIndex;return d->primaryIndex;Executed by:
executed 1 time by 1 test: return d->primaryIndex;Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 571 | } | - | ||||||||||||||||||||||||||||||
| 572 | void QSqlTableModel::setPrimaryKey(const QSqlIndex &key) | - | ||||||||||||||||||||||||||||||
| 573 | { | - | ||||||||||||||||||||||||||||||
| 574 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 575 | d->primaryIndex = key; | - | ||||||||||||||||||||||||||||||
| 576 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 577 | - | |||||||||||||||||||||||||||||||
| 578 | - | |||||||||||||||||||||||||||||||
| 579 | - | |||||||||||||||||||||||||||||||
| 580 | - | |||||||||||||||||||||||||||||||
| 581 | QSqlDatabase QSqlTableModel::database() const | - | ||||||||||||||||||||||||||||||
| 582 | { | - | ||||||||||||||||||||||||||||||
| 583 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 584 | return executed 447 times by 1 test: d->db;return d->db;Executed by:
executed 447 times by 1 test: return d->db;Executed by:
| 447 | ||||||||||||||||||||||||||||||
| 585 | } | - | ||||||||||||||||||||||||||||||
| 586 | void QSqlTableModel::sort(int column, Qt::SortOrder order) | - | ||||||||||||||||||||||||||||||
| 587 | { | - | ||||||||||||||||||||||||||||||
| 588 | setSort(column, order); | - | ||||||||||||||||||||||||||||||
| 589 | select(); | - | ||||||||||||||||||||||||||||||
| 590 | } executed 12 times by 1 test: end of blockExecuted by:
| 12 | ||||||||||||||||||||||||||||||
| 591 | void QSqlTableModel::setSort(int column, Qt::SortOrder order) | - | ||||||||||||||||||||||||||||||
| 592 | { | - | ||||||||||||||||||||||||||||||
| 593 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 594 | d->sortColumn = column; | - | ||||||||||||||||||||||||||||||
| 595 | d->sortOrder = order; | - | ||||||||||||||||||||||||||||||
| 596 | } executed 72 times by 3 tests: end of blockExecuted by:
| 72 | ||||||||||||||||||||||||||||||
| 597 | - | |||||||||||||||||||||||||||||||
| 598 | - | |||||||||||||||||||||||||||||||
| 599 | - | |||||||||||||||||||||||||||||||
| 600 | - | |||||||||||||||||||||||||||||||
| 601 | - | |||||||||||||||||||||||||||||||
| 602 | - | |||||||||||||||||||||||||||||||
| 603 | - | |||||||||||||||||||||||||||||||
| 604 | QString QSqlTableModel::orderByClause() const | - | ||||||||||||||||||||||||||||||
| 605 | { | - | ||||||||||||||||||||||||||||||
| 606 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 607 | QSqlField f = d->rec.field(d->sortColumn); | - | ||||||||||||||||||||||||||||||
| 608 | if (!f.isValid()
| 138-235 | ||||||||||||||||||||||||||||||
| 609 | return executed 235 times by 3 tests: QString();return QString();Executed by:
executed 235 times by 3 tests: return QString();Executed by:
| 235 | ||||||||||||||||||||||||||||||
| 610 | - | |||||||||||||||||||||||||||||||
| 611 | - | |||||||||||||||||||||||||||||||
| 612 | - | |||||||||||||||||||||||||||||||
| 613 | QString field = d->db.driver()->escapeIdentifier(f.name(), QSqlDriver::FieldName); | - | ||||||||||||||||||||||||||||||
| 614 | field.prepend(QLatin1Char('.')).prepend(d->tableName); | - | ||||||||||||||||||||||||||||||
| 615 | field = d->sortOrder == Qt::AscendingOrder
| 5-133 | ||||||||||||||||||||||||||||||
| 616 | return executed 138 times by 3 tests: Sql::orderBy(field);return Sql::orderBy(field);Executed by:
executed 138 times by 3 tests: return Sql::orderBy(field);Executed by:
| 138 | ||||||||||||||||||||||||||||||
| 617 | } | - | ||||||||||||||||||||||||||||||
| 618 | - | |||||||||||||||||||||||||||||||
| 619 | - | |||||||||||||||||||||||||||||||
| 620 | - | |||||||||||||||||||||||||||||||
| 621 | - | |||||||||||||||||||||||||||||||
| 622 | - | |||||||||||||||||||||||||||||||
| 623 | int QSqlTableModel::fieldIndex(const QString &fieldName) const | - | ||||||||||||||||||||||||||||||
| 624 | { | - | ||||||||||||||||||||||||||||||
| 625 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 626 | return never executed: d->rec.indexOf(fieldName);return d->rec.indexOf(fieldName);never executed: return d->rec.indexOf(fieldName); | 0 | ||||||||||||||||||||||||||||||
| 627 | } | - | ||||||||||||||||||||||||||||||
| 628 | QString QSqlTableModel::selectStatement() const | - | ||||||||||||||||||||||||||||||
| 629 | { | - | ||||||||||||||||||||||||||||||
| 630 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 631 | if (d->tableName.isEmpty()
| 0-294 | ||||||||||||||||||||||||||||||
| 632 | d->error = QSqlError(QLatin1String("No table name given"), QString(), | - | ||||||||||||||||||||||||||||||
| 633 | QSqlError::StatementError); | - | ||||||||||||||||||||||||||||||
| 634 | return never executed: QString();return QString();never executed: return QString(); | 0 | ||||||||||||||||||||||||||||||
| 635 | } | - | ||||||||||||||||||||||||||||||
| 636 | if (d->rec.isEmpty()
| 1-293 | ||||||||||||||||||||||||||||||
| 637 | d->error = QSqlError(QLatin1String("Unable to find table ") + d->tableName, QString(), | - | ||||||||||||||||||||||||||||||
| 638 | QSqlError::StatementError); | - | ||||||||||||||||||||||||||||||
| 639 | return executed 1 time by 1 test: QString();return QString();Executed by:
executed 1 time by 1 test: return QString();Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 640 | } | - | ||||||||||||||||||||||||||||||
| 641 | - | |||||||||||||||||||||||||||||||
| 642 | const QString stmt = d->db.driver()->sqlStatement(QSqlDriver::SelectStatement, | - | ||||||||||||||||||||||||||||||
| 643 | d->tableName, | - | ||||||||||||||||||||||||||||||
| 644 | d->rec, | - | ||||||||||||||||||||||||||||||
| 645 | false); | - | ||||||||||||||||||||||||||||||
| 646 | if (stmt.isEmpty()
| 0-293 | ||||||||||||||||||||||||||||||
| 647 | d->error = QSqlError(QLatin1String("Unable to select fields from table ") + d->tableName, | - | ||||||||||||||||||||||||||||||
| 648 | QString(), QSqlError::StatementError); | - | ||||||||||||||||||||||||||||||
| 649 | return never executed: stmt;return stmt;never executed: return stmt; | 0 | ||||||||||||||||||||||||||||||
| 650 | } | - | ||||||||||||||||||||||||||||||
| 651 | return executed 293 times by 3 tests: Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause());return Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause());Executed by:
executed 293 times by 3 tests: return Sql::concat(Sql::concat(stmt, Sql::where(d->filter)), orderByClause());Executed by:
| 293 | ||||||||||||||||||||||||||||||
| 652 | } | - | ||||||||||||||||||||||||||||||
| 653 | bool QSqlTableModel::removeColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||||||||
| 654 | { | - | ||||||||||||||||||||||||||||||
| 655 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 656 | if (parent.isValid()
| 0-5 | ||||||||||||||||||||||||||||||
| 657 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 658 | for (int i = 0; i < count
| 5-7 | ||||||||||||||||||||||||||||||
| 659 | d->rec.remove(column); executed 7 times by 2 tests: d->rec.remove(column);Executed by:
| 7 | ||||||||||||||||||||||||||||||
| 660 | if (d->query.isActive()
| 0-5 | ||||||||||||||||||||||||||||||
| 661 | return executed 5 times by 2 tests: select();return select();Executed by:
executed 5 times by 2 tests: return select();Executed by:
| 5 | ||||||||||||||||||||||||||||||
| 662 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||||||||
| 663 | } | - | ||||||||||||||||||||||||||||||
| 664 | bool QSqlTableModel::removeRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||||||||
| 665 | { | - | ||||||||||||||||||||||||||||||
| 666 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 667 | if (parent.isValid()
| 2-41 | ||||||||||||||||||||||||||||||
| 668 | return executed 8 times by 1 test: false;return false;Executed by:
executed 8 times by 1 test: return false;Executed by:
| 8 | ||||||||||||||||||||||||||||||
| 669 | else if (row + count > rowCount()
| 2-33 | ||||||||||||||||||||||||||||||
| 670 | return executed 2 times by 1 test: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||||||||||||||
| 671 | else if (!count
| 0-33 | ||||||||||||||||||||||||||||||
| 672 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||||||||
| 673 | - | |||||||||||||||||||||||||||||||
| 674 | if (d->strategy != OnManualSubmit
| 16-17 | ||||||||||||||||||||||||||||||
| 675 | if (count > 1
| 1-16 | ||||||||||||||||||||||||||||||
| 676 | return executed 4 times by 1 test: false;return false;Executed by:
executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||||||||||||||||||||
| 677 | - | |||||||||||||||||||||||||||||||
| 678 | - | |||||||||||||||||||||||||||||||
| 679 | - | |||||||||||||||||||||||||||||||
| 680 | for (int idx = row + count - 1; idx >= row
| 29-37 | ||||||||||||||||||||||||||||||
| 681 | QSqlTableModelPrivate::ModifiedRow& mrow = d->cache[idx]; | - | ||||||||||||||||||||||||||||||
| 682 | if (mrow.op() == QSqlTableModelPrivate::Insert
| 13-24 | ||||||||||||||||||||||||||||||
| 683 | revertRow(idx); | - | ||||||||||||||||||||||||||||||
| 684 | } executed 13 times by 1 test: else {end of blockExecuted by:
| 13 | ||||||||||||||||||||||||||||||
| 685 | if (mrow.op() == QSqlTableModelPrivate::None
| 2-22 | ||||||||||||||||||||||||||||||
| 686 | mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, executed 22 times by 1 test: mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, QSqlQueryModel::record(idx));Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 687 | QSqlQueryModel::record(idx)); executed 22 times by 1 test: mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Delete, QSqlQueryModel::record(idx));Executed by:
| 22 | ||||||||||||||||||||||||||||||
| 688 | else | - | ||||||||||||||||||||||||||||||
| 689 | mrow.setOp(QSqlTableModelPrivate::Delete); executed 2 times by 1 test: mrow.setOp(QSqlTableModelPrivate::Delete);Executed by:
| 2 | ||||||||||||||||||||||||||||||
| 690 | if (d->strategy == OnManualSubmit
| 11-13 | ||||||||||||||||||||||||||||||
| 691 | headerDataChanged(Qt::Vertical, idx, idx); executed 13 times by 1 test: headerDataChanged(Qt::Vertical, idx, idx);Executed by:
| 13 | ||||||||||||||||||||||||||||||
| 692 | } executed 24 times by 1 test: end of blockExecuted by:
| 24 | ||||||||||||||||||||||||||||||
| 693 | } | - | ||||||||||||||||||||||||||||||
| 694 | - | |||||||||||||||||||||||||||||||
| 695 | if (d->strategy != OnManualSubmit
| 13-16 | ||||||||||||||||||||||||||||||
| 696 | return executed 13 times by 1 test: submit();return submit();Executed by:
executed 13 times by 1 test: return submit();Executed by:
| 13 | ||||||||||||||||||||||||||||||
| 697 | - | |||||||||||||||||||||||||||||||
| 698 | return executed 16 times by 1 test: true;return true;Executed by:
executed 16 times by 1 test: return true;Executed by:
| 16 | ||||||||||||||||||||||||||||||
| 699 | } | - | ||||||||||||||||||||||||||||||
| 700 | bool QSqlTableModel::insertRows(int row, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||||||||
| 701 | { | - | ||||||||||||||||||||||||||||||
| 702 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 703 | if (row < 0
| 0-76 | ||||||||||||||||||||||||||||||
| 704 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 705 | - | |||||||||||||||||||||||||||||||
| 706 | if (d->strategy != OnManualSubmit
| 34-42 | ||||||||||||||||||||||||||||||
| 707 | if (count != 1
| 0-34 | ||||||||||||||||||||||||||||||
| 708 | return executed 3 times by 1 test: false;return false;Executed by:
executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||||||||||||||
| 709 | - | |||||||||||||||||||||||||||||||
| 710 | d->busyInsertingRows = true; | - | ||||||||||||||||||||||||||||||
| 711 | beginInsertRows(parent, row, row + count - 1); | - | ||||||||||||||||||||||||||||||
| 712 | - | |||||||||||||||||||||||||||||||
| 713 | if (d->strategy != OnManualSubmit
| 31-42 | ||||||||||||||||||||||||||||||
| 714 | d->cache.empty(); executed 31 times by 2 tests: d->cache.empty();Executed by:
| 31 | ||||||||||||||||||||||||||||||
| 715 | - | |||||||||||||||||||||||||||||||
| 716 | if (!d->cache.isEmpty()
| 24-49 | ||||||||||||||||||||||||||||||
| 717 | QMap<int, QSqlTableModelPrivate::ModifiedRow>::Iterator it = d->cache.end(); | - | ||||||||||||||||||||||||||||||
| 718 | while (it != d->cache.begin()
| 7-28 | ||||||||||||||||||||||||||||||
| 719 | int oldKey = it.key(); | - | ||||||||||||||||||||||||||||||
| 720 | const QSqlTableModelPrivate::ModifiedRow oldValue = it.value(); | - | ||||||||||||||||||||||||||||||
| 721 | d->cache.erase(it); | - | ||||||||||||||||||||||||||||||
| 722 | it = d->cache.insert(oldKey + count, oldValue); | - | ||||||||||||||||||||||||||||||
| 723 | } executed 11 times by 2 tests: end of blockExecuted by:
| 11 | ||||||||||||||||||||||||||||||
| 724 | } executed 24 times by 2 tests: end of blockExecuted by:
| 24 | ||||||||||||||||||||||||||||||
| 725 | - | |||||||||||||||||||||||||||||||
| 726 | for (int i = 0; i < count
| 73-91 | ||||||||||||||||||||||||||||||
| 727 | d->cache[row + i] = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Insert, | - | ||||||||||||||||||||||||||||||
| 728 | d->rec); | - | ||||||||||||||||||||||||||||||
| 729 | primeInsert(row + i, d->cache[row + i].recRef()); | - | ||||||||||||||||||||||||||||||
| 730 | } executed 91 times by 2 tests: end of blockExecuted by:
| 91 | ||||||||||||||||||||||||||||||
| 731 | - | |||||||||||||||||||||||||||||||
| 732 | endInsertRows(); | - | ||||||||||||||||||||||||||||||
| 733 | d->busyInsertingRows = false; | - | ||||||||||||||||||||||||||||||
| 734 | return executed 73 times by 2 tests: true;return true;Executed by:
executed 73 times by 2 tests: return true;Executed by:
| 73 | ||||||||||||||||||||||||||||||
| 735 | } | - | ||||||||||||||||||||||||||||||
| 736 | bool QSqlTableModel::insertRecord(int row, const QSqlRecord &record) | - | ||||||||||||||||||||||||||||||
| 737 | { | - | ||||||||||||||||||||||||||||||
| 738 | if (row < 0
| 7-22 | ||||||||||||||||||||||||||||||
| 739 | row = rowCount(); executed 7 times by 2 tests: row = rowCount();Executed by:
| 7 | ||||||||||||||||||||||||||||||
| 740 | if (!insertRow(row, QModelIndex())
| 0-29 | ||||||||||||||||||||||||||||||
| 741 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 742 | if (!setRecord(row, record)
| 0-29 | ||||||||||||||||||||||||||||||
| 743 | revertRow(row); | - | ||||||||||||||||||||||||||||||
| 744 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 745 | } | - | ||||||||||||||||||||||||||||||
| 746 | return executed 29 times by 2 tests: true;return true;Executed by:
executed 29 times by 2 tests: return true;Executed by:
| 29 | ||||||||||||||||||||||||||||||
| 747 | } | - | ||||||||||||||||||||||||||||||
| 748 | - | |||||||||||||||||||||||||||||||
| 749 | - | |||||||||||||||||||||||||||||||
| 750 | - | |||||||||||||||||||||||||||||||
| 751 | int QSqlTableModel::rowCount(const QModelIndex &parent) const | - | ||||||||||||||||||||||||||||||
| 752 | { | - | ||||||||||||||||||||||||||||||
| 753 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 754 | - | |||||||||||||||||||||||||||||||
| 755 | if (parent.isValid()
| 1028-10706 | ||||||||||||||||||||||||||||||
| 756 | return executed 1028 times by 1 test: 0;return 0;Executed by:
executed 1028 times by 1 test: return 0;Executed by:
| 1028 | ||||||||||||||||||||||||||||||
| 757 | - | |||||||||||||||||||||||||||||||
| 758 | return executed 10706 times by 3 tests: QSqlQueryModel::rowCount() + d->insertCount();return QSqlQueryModel::rowCount() + d->insertCount();Executed by:
executed 10706 times by 3 tests: return QSqlQueryModel::rowCount() + d->insertCount();Executed by:
| 10706 | ||||||||||||||||||||||||||||||
| 759 | } | - | ||||||||||||||||||||||||||||||
| 760 | QModelIndex QSqlTableModel::indexInQuery(const QModelIndex &item) const | - | ||||||||||||||||||||||||||||||
| 761 | { | - | ||||||||||||||||||||||||||||||
| 762 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 763 | if (d->cache.value(item.row()).insert()
| 0-2177 | ||||||||||||||||||||||||||||||
| 764 | return never executed: QModelIndex();return QModelIndex();never executed: return QModelIndex(); | 0 | ||||||||||||||||||||||||||||||
| 765 | - | |||||||||||||||||||||||||||||||
| 766 | const int rowOffset = d->insertCount(item.row()); | - | ||||||||||||||||||||||||||||||
| 767 | return executed 2177 times by 3 tests: QSqlQueryModel::indexInQuery(createIndex(item.row() - rowOffset, item.column(), item.internalPointer()));return QSqlQueryModel::indexInQuery(createIndex(item.row() - rowOffset, item.column(), item.internalPointer()));Executed by:
executed 2177 times by 3 tests: return QSqlQueryModel::indexInQuery(createIndex(item.row() - rowOffset, item.column(), item.internalPointer()));Executed by:
| 2177 | ||||||||||||||||||||||||||||||
| 768 | } | - | ||||||||||||||||||||||||||||||
| 769 | - | |||||||||||||||||||||||||||||||
| 770 | - | |||||||||||||||||||||||||||||||
| 771 | - | |||||||||||||||||||||||||||||||
| 772 | - | |||||||||||||||||||||||||||||||
| 773 | - | |||||||||||||||||||||||||||||||
| 774 | - | |||||||||||||||||||||||||||||||
| 775 | QString QSqlTableModel::filter() const | - | ||||||||||||||||||||||||||||||
| 776 | { | - | ||||||||||||||||||||||||||||||
| 777 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 778 | return executed 86 times by 2 tests: d->filter;return d->filter;Executed by:
executed 86 times by 2 tests: return d->filter;Executed by:
| 86 | ||||||||||||||||||||||||||||||
| 779 | } | - | ||||||||||||||||||||||||||||||
| 780 | void QSqlTableModel::setFilter(const QString &filter) | - | ||||||||||||||||||||||||||||||
| 781 | { | - | ||||||||||||||||||||||||||||||
| 782 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 783 | d->filter = filter; | - | ||||||||||||||||||||||||||||||
| 784 | if (d->query.isActive()
| 3-4 | ||||||||||||||||||||||||||||||
| 785 | select(); executed 3 times by 1 test: select();Executed by:
| 3 | ||||||||||||||||||||||||||||||
| 786 | } executed 7 times by 2 tests: end of blockExecuted by:
| 7 | ||||||||||||||||||||||||||||||
| 787 | - | |||||||||||||||||||||||||||||||
| 788 | - | |||||||||||||||||||||||||||||||
| 789 | - | |||||||||||||||||||||||||||||||
| 790 | void QSqlTableModel::clear() | - | ||||||||||||||||||||||||||||||
| 791 | { | - | ||||||||||||||||||||||||||||||
| 792 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 793 | beginResetModel(); | - | ||||||||||||||||||||||||||||||
| 794 | d->clear(); | - | ||||||||||||||||||||||||||||||
| 795 | QSqlQueryModel::clear(); | - | ||||||||||||||||||||||||||||||
| 796 | endResetModel(); | - | ||||||||||||||||||||||||||||||
| 797 | } executed 190 times by 3 tests: end of blockExecuted by:
| 190 | ||||||||||||||||||||||||||||||
| 798 | - | |||||||||||||||||||||||||||||||
| 799 | - | |||||||||||||||||||||||||||||||
| 800 | - | |||||||||||||||||||||||||||||||
| 801 | Qt::ItemFlags QSqlTableModel::flags(const QModelIndex &index) const | - | ||||||||||||||||||||||||||||||
| 802 | { | - | ||||||||||||||||||||||||||||||
| 803 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 804 | if (index.internalPointer()
| 0-267 | ||||||||||||||||||||||||||||||
| 805 | || index.row() < 0
| 0-266 | ||||||||||||||||||||||||||||||
| 806 | return executed 1 time by 1 test: 0;return 0;Executed by:
executed 1 time by 1 test: return 0;Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 807 | - | |||||||||||||||||||||||||||||||
| 808 | bool editable = true; | - | ||||||||||||||||||||||||||||||
| 809 | - | |||||||||||||||||||||||||||||||
| 810 | if (d->rec.field(index.column()).isReadOnly()
| 0-266 | ||||||||||||||||||||||||||||||
| 811 | editable = false; | - | ||||||||||||||||||||||||||||||
| 812 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 813 | else { | - | ||||||||||||||||||||||||||||||
| 814 | const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(index.row()); | - | ||||||||||||||||||||||||||||||
| 815 | if (mrow.op() == QSqlTableModelPrivate::Delete
| 0-266 | ||||||||||||||||||||||||||||||
| 816 | editable = false; | - | ||||||||||||||||||||||||||||||
| 817 | } never executed: end of block | 0 | ||||||||||||||||||||||||||||||
| 818 | else if (d->strategy == OnFieldChange
| 17-249 | ||||||||||||||||||||||||||||||
| 819 | if (mrow.op() != QSqlTableModelPrivate::Insert
| 7-10 | ||||||||||||||||||||||||||||||
| 820 | if (!isDirty(index)
| 0-10 | ||||||||||||||||||||||||||||||
| 821 | editable = false; executed 1 time by 1 test: editable = false;Executed by:
| 1 | ||||||||||||||||||||||||||||||
| 822 | } executed 17 times by 2 tests: end of blockExecuted by:
| 17 | ||||||||||||||||||||||||||||||
| 823 | else if (d->strategy == OnRowChange
| 48-201 | ||||||||||||||||||||||||||||||
| 824 | if (mrow.submitted()
| 3-29 | ||||||||||||||||||||||||||||||
| 825 | editable = false; executed 3 times by 1 test: editable = false;Executed by:
| 3 | ||||||||||||||||||||||||||||||
| 826 | } executed 48 times by 2 tests: end of blockExecuted by:
| 48 | ||||||||||||||||||||||||||||||
| 827 | } executed 266 times by 2 tests: end of blockExecuted by:
| 266 | ||||||||||||||||||||||||||||||
| 828 | - | |||||||||||||||||||||||||||||||
| 829 | if (!editable
| 4-262 | ||||||||||||||||||||||||||||||
| 830 | return executed 4 times by 1 test: QSqlQueryModel::flags(index);return QSqlQueryModel::flags(index);Executed by:
executed 4 times by 1 test: return QSqlQueryModel::flags(index);Executed by:
| 4 | ||||||||||||||||||||||||||||||
| 831 | else | - | ||||||||||||||||||||||||||||||
| 832 | return executed 262 times by 2 tests: QSqlQueryModel::flags(index) | Qt::ItemIsEditable;return QSqlQueryModel::flags(index) | Qt::ItemIsEditable;Executed by:
executed 262 times by 2 tests: return QSqlQueryModel::flags(index) | Qt::ItemIsEditable;Executed by:
| 262 | ||||||||||||||||||||||||||||||
| 833 | } | - | ||||||||||||||||||||||||||||||
| 834 | QSqlRecord QSqlTableModel::record() const | - | ||||||||||||||||||||||||||||||
| 835 | { | - | ||||||||||||||||||||||||||||||
| 836 | return executed 13 times by 2 tests: QSqlQueryModel::record();return QSqlQueryModel::record();Executed by:
executed 13 times by 2 tests: return QSqlQueryModel::record();Executed by:
| 13 | ||||||||||||||||||||||||||||||
| 837 | } | - | ||||||||||||||||||||||||||||||
| 838 | QSqlRecord QSqlTableModel::record(int row) const | - | ||||||||||||||||||||||||||||||
| 839 | { | - | ||||||||||||||||||||||||||||||
| 840 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 841 | - | |||||||||||||||||||||||||||||||
| 842 | - | |||||||||||||||||||||||||||||||
| 843 | QSqlRecord rec = QSqlQueryModel::record(row); | - | ||||||||||||||||||||||||||||||
| 844 | - | |||||||||||||||||||||||||||||||
| 845 | - | |||||||||||||||||||||||||||||||
| 846 | const QSqlTableModelPrivate::ModifiedRow mrow = d->cache.value(row); | - | ||||||||||||||||||||||||||||||
| 847 | if (mrow.op() != QSqlTableModelPrivate::None
| 5-160 | ||||||||||||||||||||||||||||||
| 848 | const QSqlRecord crec = mrow.rec(); | - | ||||||||||||||||||||||||||||||
| 849 | for (int i = 0, cnt = rec.count(); i < cnt
| 5-15 | ||||||||||||||||||||||||||||||
| 850 | rec.setGenerated(i, crec.isGenerated(i)); executed 15 times by 1 test: rec.setGenerated(i, crec.isGenerated(i));Executed by:
| 15 | ||||||||||||||||||||||||||||||
| 851 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||||||||||||||||||||
| 852 | - | |||||||||||||||||||||||||||||||
| 853 | return executed 165 times by 2 tests: rec;return rec;Executed by:
executed 165 times by 2 tests: return rec;Executed by:
| 165 | ||||||||||||||||||||||||||||||
| 854 | } | - | ||||||||||||||||||||||||||||||
| 855 | bool QSqlTableModel::setRecord(int row, const QSqlRecord &values) | - | ||||||||||||||||||||||||||||||
| 856 | { | - | ||||||||||||||||||||||||||||||
| 857 | QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 858 | ((!(row >= 0)) ? qt_assert_x("QSqlTableModel::setRecord()", "Cannot set a record to a row less than 0",__FILE__,1382) : qt_noop()); | - | ||||||||||||||||||||||||||||||
| 859 | if (d->busyInsertingRows
| 0-50 | ||||||||||||||||||||||||||||||
| 860 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 861 | - | |||||||||||||||||||||||||||||||
| 862 | if (row >= rowCount()
| 0-50 | ||||||||||||||||||||||||||||||
| 863 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 864 | - | |||||||||||||||||||||||||||||||
| 865 | if (d->cache.value(row).op() == QSqlTableModelPrivate::Delete
| 0-50 | ||||||||||||||||||||||||||||||
| 866 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 867 | - | |||||||||||||||||||||||||||||||
| 868 | if (d->strategy != OnManualSubmit
| 3-26 | ||||||||||||||||||||||||||||||
| 869 | return executed 3 times by 1 test: false;return false;Executed by:
executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||||||||||||||
| 870 | - | |||||||||||||||||||||||||||||||
| 871 | - | |||||||||||||||||||||||||||||||
| 872 | typedef QMap<int, int> Map; | - | ||||||||||||||||||||||||||||||
| 873 | Map map; | - | ||||||||||||||||||||||||||||||
| 874 | for (int i = 0; i < values.count()
| 47-132 | ||||||||||||||||||||||||||||||
| 875 | int idx = d->nameToIndex(values.fieldName(i)); | - | ||||||||||||||||||||||||||||||
| 876 | if (idx == -1
| 0-132 | ||||||||||||||||||||||||||||||
| 877 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||||||||
| 878 | map[i] = idx; | - | ||||||||||||||||||||||||||||||
| 879 | } executed 132 times by 2 tests: end of blockExecuted by:
| 132 | ||||||||||||||||||||||||||||||
| 880 | - | |||||||||||||||||||||||||||||||
| 881 | QSqlTableModelPrivate::ModifiedRow &mrow = d->cache[row]; | - | ||||||||||||||||||||||||||||||
| 882 | if (mrow.op() == QSqlTableModelPrivate::None
| 13-34 | ||||||||||||||||||||||||||||||
| 883 | mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, executed 13 times by 2 tests: mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, QSqlQueryModel::record(row));Executed by:
| 13 | ||||||||||||||||||||||||||||||
| 884 | QSqlQueryModel::record(row)); executed 13 times by 2 tests: mrow = QSqlTableModelPrivate::ModifiedRow(QSqlTableModelPrivate::Update, QSqlQueryModel::record(row));Executed by:
| 13 | ||||||||||||||||||||||||||||||
| 885 | - | |||||||||||||||||||||||||||||||
| 886 | Map::const_iterator i = map.constBegin(); | - | ||||||||||||||||||||||||||||||
| 887 | const Map::const_iterator e = map.constEnd(); | - | ||||||||||||||||||||||||||||||
| 888 | for ( ; i != e
| 47-132 | ||||||||||||||||||||||||||||||
| 889 | - | |||||||||||||||||||||||||||||||
| 890 | EditStrategy strategy = d->strategy; | - | ||||||||||||||||||||||||||||||
| 891 | d->strategy = OnManualSubmit; | - | ||||||||||||||||||||||||||||||
| 892 | QModelIndex cIndex = createIndex(row, i.value()); | - | ||||||||||||||||||||||||||||||
| 893 | setData(cIndex, values.value(i.key())); | - | ||||||||||||||||||||||||||||||
| 894 | d->strategy = strategy; | - | ||||||||||||||||||||||||||||||
| 895 | - | |||||||||||||||||||||||||||||||
| 896 | if (!values.isGenerated(i.key())
| 3-129 | ||||||||||||||||||||||||||||||
| 897 | mrow.recRef().setGenerated(i.value(), false); executed 3 times by 1 test: mrow.recRef().setGenerated(i.value(), false);Executed by:
| 3 | ||||||||||||||||||||||||||||||
| 898 | } executed 132 times by 2 tests: end of blockExecuted by:
| 132 | ||||||||||||||||||||||||||||||
| 899 | - | |||||||||||||||||||||||||||||||
| 900 | if (d->strategy != OnManualSubmit
| 21-26 | ||||||||||||||||||||||||||||||
| 901 | return executed 21 times by 2 tests: submit();return submit();Executed by:
executed 21 times by 2 tests: return submit();Executed by:
| 21 | ||||||||||||||||||||||||||||||
| 902 | - | |||||||||||||||||||||||||||||||
| 903 | return executed 26 times by 2 tests: true;return true;Executed by:
executed 26 times by 2 tests: return true;Executed by:
| 26 | ||||||||||||||||||||||||||||||
| 904 | } | - | ||||||||||||||||||||||||||||||
| 905 | QSqlRecord QSqlTableModel::primaryValues(int row) const | - | ||||||||||||||||||||||||||||||
| 906 | { | - | ||||||||||||||||||||||||||||||
| 907 | const QSqlTableModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||||||||
| 908 | - | |||||||||||||||||||||||||||||||
| 909 | const QSqlRecord &pIndex = d->primaryIndex.isEmpty()
| 60-73 | ||||||||||||||||||||||||||||||
| 910 | - | |||||||||||||||||||||||||||||||
| 911 | QSqlTableModelPrivate::ModifiedRow mr = d->cache.value(row); | - | ||||||||||||||||||||||||||||||
| 912 | if (mr.op() != QSqlTableModelPrivate::None
| 2-131 | ||||||||||||||||||||||||||||||
| 913 | return executed 131 times by 2 tests: mr.primaryValues(pIndex);return mr.primaryValues(pIndex);Executed by:
executed 131 times by 2 tests: return mr.primaryValues(pIndex);Executed by:
| 131 | ||||||||||||||||||||||||||||||
| 914 | else | - | ||||||||||||||||||||||||||||||
| 915 | return executed 2 times by 1 test: QSqlQueryModel::record(row).keyValues(pIndex);return QSqlQueryModel::record(row).keyValues(pIndex);Executed by:
executed 2 times by 1 test: return QSqlQueryModel::record(row).keyValues(pIndex);Executed by:
| 2 | ||||||||||||||||||||||||||||||
| 916 | } | - | ||||||||||||||||||||||||||||||
| 917 | - | |||||||||||||||||||||||||||||||
| 918 | - | |||||||||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |