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