| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/sql/models/qsqlquerymodel.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | - | |||||||||||||||||||||||||
| 6 | - | |||||||||||||||||||||||||
| 7 | void QSqlQueryModelPrivate::prefetch(int limit) | - | ||||||||||||||||||||||||
| 8 | { | - | ||||||||||||||||||||||||
| 9 | QSqlQueryModel * const q = q_func(); | - | ||||||||||||||||||||||||
| 10 | - | |||||||||||||||||||||||||
| 11 | if (atEnd
| 0-388 | ||||||||||||||||||||||||
| 12 | return; executed 3 times by 2 tests: return;Executed by:
| 3 | ||||||||||||||||||||||||
| 13 | - | |||||||||||||||||||||||||
| 14 | QModelIndex newBottom; | - | ||||||||||||||||||||||||
| 15 | const int oldBottomRow = qMax(bottom.row(), 0); | - | ||||||||||||||||||||||||
| 16 | - | |||||||||||||||||||||||||
| 17 | - | |||||||||||||||||||||||||
| 18 | if (query.seek(limit)
| 130-257 | ||||||||||||||||||||||||
| 19 | newBottom = q->createIndex(limit, bottom.column()); | - | ||||||||||||||||||||||||
| 20 | } executed 130 times by 3 tests: else {end of blockExecuted by:
| 130 | ||||||||||||||||||||||||
| 21 | - | |||||||||||||||||||||||||
| 22 | int i = oldBottomRow; | - | ||||||||||||||||||||||||
| 23 | if (query.seek(i)
| 11-246 | ||||||||||||||||||||||||
| 24 | while (query.next()
| 246-526 | ||||||||||||||||||||||||
| 25 | ++ executed 526 times by 4 tests: i;++i;Executed by:
executed 526 times by 4 tests: ++i;Executed by:
| 526 | ||||||||||||||||||||||||
| 26 | newBottom = q->createIndex(i, bottom.column()); | - | ||||||||||||||||||||||||
| 27 | } executed 246 times by 4 tests: else {end of blockExecuted by:
| 246 | ||||||||||||||||||||||||
| 28 | - | |||||||||||||||||||||||||
| 29 | newBottom = q->createIndex(-1, bottom.column()); | - | ||||||||||||||||||||||||
| 30 | } executed 11 times by 2 tests: end of blockExecuted by:
| 11 | ||||||||||||||||||||||||
| 31 | atEnd = true; | - | ||||||||||||||||||||||||
| 32 | } executed 257 times by 4 tests: end of blockExecuted by:
| 257 | ||||||||||||||||||||||||
| 33 | if (newBottom.row() >= 0
| 0-376 | ||||||||||||||||||||||||
| 34 | q->beginInsertRows(QModelIndex(), bottom.row() + 1, newBottom.row()); | - | ||||||||||||||||||||||||
| 35 | bottom = newBottom; | - | ||||||||||||||||||||||||
| 36 | q->endInsertRows(); | - | ||||||||||||||||||||||||
| 37 | } executed 376 times by 4 tests: else {end of blockExecuted by:
| 376 | ||||||||||||||||||||||||
| 38 | bottom = newBottom; | - | ||||||||||||||||||||||||
| 39 | } executed 11 times by 2 tests: end of blockExecuted by:
| 11 | ||||||||||||||||||||||||
| 40 | } | - | ||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | QSqlQueryModelPrivate::~QSqlQueryModelPrivate() | - | ||||||||||||||||||||||||
| 43 | { | - | ||||||||||||||||||||||||
| 44 | } | - | ||||||||||||||||||||||||
| 45 | - | |||||||||||||||||||||||||
| 46 | void QSqlQueryModelPrivate::initColOffsets(int size) | - | ||||||||||||||||||||||||
| 47 | { | - | ||||||||||||||||||||||||
| 48 | colOffsets.resize(size); | - | ||||||||||||||||||||||||
| 49 | memset(colOffsets.data(), 0, colOffsets.size() * sizeof(int)); | - | ||||||||||||||||||||||||
| 50 | } executed 438 times by 4 tests: end of blockExecuted by:
| 438 | ||||||||||||||||||||||||
| 51 | - | |||||||||||||||||||||||||
| 52 | int QSqlQueryModelPrivate::columnInQuery(int modelColumn) const | - | ||||||||||||||||||||||||
| 53 | { | - | ||||||||||||||||||||||||
| 54 | if (modelColumn < 0
| 0-3254 | ||||||||||||||||||||||||
| 55 | return executed 27 times by 1 test: -1;return -1;Executed by:
executed 27 times by 1 test: return -1;Executed by:
| 27 | ||||||||||||||||||||||||
| 56 | return executed 3242 times by 4 tests: modelColumn - colOffsets[modelColumn];return modelColumn - colOffsets[modelColumn];Executed by:
executed 3242 times by 4 tests: return modelColumn - colOffsets[modelColumn];Executed by:
| 3242 | ||||||||||||||||||||||||
| 57 | } | - | ||||||||||||||||||||||||
| 58 | QSqlQueryModel::QSqlQueryModel(QObject *parent) | - | ||||||||||||||||||||||||
| 59 | : QAbstractTableModel(*new QSqlQueryModelPrivate, parent) | - | ||||||||||||||||||||||||
| 60 | { | - | ||||||||||||||||||||||||
| 61 | } executed 113 times by 2 tests: end of blockExecuted by:
| 113 | ||||||||||||||||||||||||
| 62 | - | |||||||||||||||||||||||||
| 63 | - | |||||||||||||||||||||||||
| 64 | - | |||||||||||||||||||||||||
| 65 | QSqlQueryModel::QSqlQueryModel(QSqlQueryModelPrivate &dd, QObject *parent) | - | ||||||||||||||||||||||||
| 66 | : QAbstractTableModel(dd, parent) | - | ||||||||||||||||||||||||
| 67 | { | - | ||||||||||||||||||||||||
| 68 | } executed 174 times by 3 tests: end of blockExecuted by:
| 174 | ||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||
| 70 | - | |||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | - | |||||||||||||||||||||||||
| 73 | - | |||||||||||||||||||||||||
| 74 | - | |||||||||||||||||||||||||
| 75 | QSqlQueryModel::~QSqlQueryModel() | - | ||||||||||||||||||||||||
| 76 | { | - | ||||||||||||||||||||||||
| 77 | } | - | ||||||||||||||||||||||||
| 78 | void QSqlQueryModel::fetchMore(const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 79 | { | - | ||||||||||||||||||||||||
| 80 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 81 | if (parent.isValid()
| 0-390 | ||||||||||||||||||||||||
| 82 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 83 | d->prefetch(qMax(d->bottom.row(), 0) + 255); | - | ||||||||||||||||||||||||
| 84 | } executed 390 times by 4 tests: end of blockExecuted by:
| 390 | ||||||||||||||||||||||||
| 85 | bool QSqlQueryModel::canFetchMore(const QModelIndex &parent) const | - | ||||||||||||||||||||||||
| 86 | { | - | ||||||||||||||||||||||||
| 87 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 88 | return executed 1029 times by 2 tests: (!parent.isValid() && !d->atEnd);return (!parent.isValid() && !d->atEnd);Executed by:
executed 1029 times by 2 tests: return (!parent.isValid() && !d->atEnd);Executed by:
| 1029 | ||||||||||||||||||||||||
| 89 | } | - | ||||||||||||||||||||||||
| 90 | - | |||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | - | |||||||||||||||||||||||||
| 93 | void QSqlQueryModel::beginInsertRows(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
| 94 | { | - | ||||||||||||||||||||||||
| 95 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 96 | if (!d->nestedResetLevel
| 85-364 | ||||||||||||||||||||||||
| 97 | QAbstractTableModel::beginInsertRows(parent, first, last); executed 85 times by 4 tests: QAbstractTableModel::beginInsertRows(parent, first, last);Executed by:
| 85 | ||||||||||||||||||||||||
| 98 | } executed 449 times by 4 tests: end of blockExecuted by:
| 449 | ||||||||||||||||||||||||
| 99 | - | |||||||||||||||||||||||||
| 100 | - | |||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | void QSqlQueryModel::endInsertRows() | - | ||||||||||||||||||||||||
| 103 | { | - | ||||||||||||||||||||||||
| 104 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 105 | if (!d->nestedResetLevel
| 85-364 | ||||||||||||||||||||||||
| 106 | QAbstractTableModel::endInsertRows(); executed 85 times by 4 tests: QAbstractTableModel::endInsertRows();Executed by:
| 85 | ||||||||||||||||||||||||
| 107 | } executed 449 times by 4 tests: end of blockExecuted by:
| 449 | ||||||||||||||||||||||||
| 108 | - | |||||||||||||||||||||||||
| 109 | - | |||||||||||||||||||||||||
| 110 | - | |||||||||||||||||||||||||
| 111 | void QSqlQueryModel::beginRemoveRows(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
| 112 | { | - | ||||||||||||||||||||||||
| 113 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 114 | if (!d->nestedResetLevel
| 0-32 | ||||||||||||||||||||||||
| 115 | QAbstractTableModel::beginRemoveRows(parent, first, last); executed 32 times by 2 tests: QAbstractTableModel::beginRemoveRows(parent, first, last);Executed by:
| 32 | ||||||||||||||||||||||||
| 116 | } executed 32 times by 2 tests: end of blockExecuted by:
| 32 | ||||||||||||||||||||||||
| 117 | - | |||||||||||||||||||||||||
| 118 | - | |||||||||||||||||||||||||
| 119 | - | |||||||||||||||||||||||||
| 120 | void QSqlQueryModel::endRemoveRows() | - | ||||||||||||||||||||||||
| 121 | { | - | ||||||||||||||||||||||||
| 122 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 123 | if (!d->nestedResetLevel
| 0-32 | ||||||||||||||||||||||||
| 124 | QAbstractTableModel::endRemoveRows(); executed 32 times by 2 tests: QAbstractTableModel::endRemoveRows();Executed by:
| 32 | ||||||||||||||||||||||||
| 125 | } executed 32 times by 2 tests: end of blockExecuted by:
| 32 | ||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||
| 127 | - | |||||||||||||||||||||||||
| 128 | - | |||||||||||||||||||||||||
| 129 | void QSqlQueryModel::beginInsertColumns(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
| 130 | { | - | ||||||||||||||||||||||||
| 131 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 132 | if (!d->nestedResetLevel
| 0-10 | ||||||||||||||||||||||||
| 133 | QAbstractTableModel::beginInsertColumns(parent, first, last); executed 10 times by 2 tests: QAbstractTableModel::beginInsertColumns(parent, first, last);Executed by:
| 10 | ||||||||||||||||||||||||
| 134 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 135 | - | |||||||||||||||||||||||||
| 136 | - | |||||||||||||||||||||||||
| 137 | - | |||||||||||||||||||||||||
| 138 | void QSqlQueryModel::endInsertColumns() | - | ||||||||||||||||||||||||
| 139 | { | - | ||||||||||||||||||||||||
| 140 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 141 | if (!d->nestedResetLevel
| 0-10 | ||||||||||||||||||||||||
| 142 | QAbstractTableModel::endInsertColumns(); executed 10 times by 2 tests: QAbstractTableModel::endInsertColumns();Executed by:
| 10 | ||||||||||||||||||||||||
| 143 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 144 | - | |||||||||||||||||||||||||
| 145 | - | |||||||||||||||||||||||||
| 146 | - | |||||||||||||||||||||||||
| 147 | void QSqlQueryModel::beginRemoveColumns(const QModelIndex &parent, int first, int last) | - | ||||||||||||||||||||||||
| 148 | { | - | ||||||||||||||||||||||||
| 149 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 150 | if (!d->nestedResetLevel
| 0-4 | ||||||||||||||||||||||||
| 151 | QAbstractTableModel::beginRemoveColumns(parent, first, last); executed 4 times by 1 test: QAbstractTableModel::beginRemoveColumns(parent, first, last);Executed by:
| 4 | ||||||||||||||||||||||||
| 152 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 153 | - | |||||||||||||||||||||||||
| 154 | - | |||||||||||||||||||||||||
| 155 | - | |||||||||||||||||||||||||
| 156 | void QSqlQueryModel::endRemoveColumns() | - | ||||||||||||||||||||||||
| 157 | { | - | ||||||||||||||||||||||||
| 158 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 159 | if (!d->nestedResetLevel
| 0-4 | ||||||||||||||||||||||||
| 160 | QAbstractTableModel::endRemoveColumns(); executed 4 times by 1 test: QAbstractTableModel::endRemoveColumns();Executed by:
| 4 | ||||||||||||||||||||||||
| 161 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 162 | - | |||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | - | |||||||||||||||||||||||||
| 165 | void QSqlQueryModel::beginResetModel() | - | ||||||||||||||||||||||||
| 166 | { | - | ||||||||||||||||||||||||
| 167 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 168 | if (!d->nestedResetLevel
| 538-574 | ||||||||||||||||||||||||
| 169 | QAbstractTableModel::beginResetModel(); executed 574 times by 4 tests: QAbstractTableModel::beginResetModel();Executed by:
| 574 | ||||||||||||||||||||||||
| 170 | ++d->nestedResetLevel; | - | ||||||||||||||||||||||||
| 171 | } executed 1112 times by 4 tests: end of blockExecuted by:
| 1112 | ||||||||||||||||||||||||
| 172 | - | |||||||||||||||||||||||||
| 173 | - | |||||||||||||||||||||||||
| 174 | - | |||||||||||||||||||||||||
| 175 | void QSqlQueryModel::endResetModel() | - | ||||||||||||||||||||||||
| 176 | { | - | ||||||||||||||||||||||||
| 177 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 178 | --d->nestedResetLevel; | - | ||||||||||||||||||||||||
| 179 | if (!d->nestedResetLevel
| 538-574 | ||||||||||||||||||||||||
| 180 | QAbstractTableModel::endResetModel(); executed 574 times by 4 tests: QAbstractTableModel::endResetModel();Executed by:
| 574 | ||||||||||||||||||||||||
| 181 | } executed 1112 times by 4 tests: end of blockExecuted by:
| 1112 | ||||||||||||||||||||||||
| 182 | int QSqlQueryModel::rowCount(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 183 | { | - | ||||||||||||||||||||||||
| 184 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 185 | return executed 22178 times by 4 tests: index.isValid() ? 0 : d->bottom.row() + 1;return index.isValid() ? 0 : d->bottom.row() + 1;Executed by:
executed 22178 times by 4 tests: return index.isValid() ? 0 : d->bottom.row() + 1;Executed by:
| 22178 | ||||||||||||||||||||||||
| 186 | } | - | ||||||||||||||||||||||||
| 187 | - | |||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | - | |||||||||||||||||||||||||
| 190 | int QSqlQueryModel::columnCount(const QModelIndex &index) const | - | ||||||||||||||||||||||||
| 191 | { | - | ||||||||||||||||||||||||
| 192 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 193 | return executed 20241 times by 4 tests: index.isValid() ? 0 : d->rec.count();return index.isValid() ? 0 : d->rec.count();Executed by:
executed 20241 times by 4 tests: return index.isValid() ? 0 : d->rec.count();Executed by:
| 20241 | ||||||||||||||||||||||||
| 194 | } | - | ||||||||||||||||||||||||
| 195 | QVariant QSqlQueryModel::data(const QModelIndex &item, int role) const | - | ||||||||||||||||||||||||
| 196 | { | - | ||||||||||||||||||||||||
| 197 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 198 | if (!item.isValid()
| 519-3240 | ||||||||||||||||||||||||
| 199 | return executed 519 times by 2 tests: QVariant();return QVariant();Executed by:
executed 519 times by 2 tests: return QVariant();Executed by:
| 519 | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | QVariant v; | - | ||||||||||||||||||||||||
| 202 | if (role & ~(Qt::DisplayRole | Qt::EditRole)
| 9-3231 | ||||||||||||||||||||||||
| 203 | return executed 9 times by 1 test: v;return v;Executed by:
executed 9 times by 1 test: return v;Executed by:
| 9 | ||||||||||||||||||||||||
| 204 | - | |||||||||||||||||||||||||
| 205 | if (!d->rec.isGenerated(item.column())
| 20-3211 | ||||||||||||||||||||||||
| 206 | return executed 20 times by 2 tests: v;return v;Executed by:
executed 20 times by 2 tests: return v;Executed by:
| 20 | ||||||||||||||||||||||||
| 207 | QModelIndex dItem = indexInQuery(item); | - | ||||||||||||||||||||||||
| 208 | if (dItem.row() > d->bottom.row()
| 0-3211 | ||||||||||||||||||||||||
| 209 | const_cast< never executed: QSqlQueryModelPrivate *>(d)->prefetch(dItem.row());const_cast<QSqlQueryModelPrivate *>(d)->prefetch(dItem.row());never executed: const_cast<QSqlQueryModelPrivate *>(d)->prefetch(dItem.row()); | 0 | ||||||||||||||||||||||||
| 210 | - | |||||||||||||||||||||||||
| 211 | if (!d->query.seek(dItem.row())
| 0-3211 | ||||||||||||||||||||||||
| 212 | d->error = d->query.lastError(); | - | ||||||||||||||||||||||||
| 213 | return never executed: v;return v;never executed: return v; | 0 | ||||||||||||||||||||||||
| 214 | } | - | ||||||||||||||||||||||||
| 215 | - | |||||||||||||||||||||||||
| 216 | return executed 3211 times by 4 tests: d->query.value(dItem.column());return d->query.value(dItem.column());Executed by:
executed 3211 times by 4 tests: return d->query.value(dItem.column());Executed by:
| 3211 | ||||||||||||||||||||||||
| 217 | } | - | ||||||||||||||||||||||||
| 218 | - | |||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||
| 220 | - | |||||||||||||||||||||||||
| 221 | - | |||||||||||||||||||||||||
| 222 | - | |||||||||||||||||||||||||
| 223 | QVariant QSqlQueryModel::headerData(int section, Qt::Orientation orientation, int role) const | - | ||||||||||||||||||||||||
| 224 | { | - | ||||||||||||||||||||||||
| 225 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 226 | if (orientation == Qt::Horizontal
| 32-1601 | ||||||||||||||||||||||||
| 227 | QVariant val = d->headers.value(section).value(role); | - | ||||||||||||||||||||||||
| 228 | if (role == Qt::DisplayRole
| 0-27 | ||||||||||||||||||||||||
| 229 | val = d->headers.value(section).value(Qt::EditRole); executed 27 times by 3 tests: val = d->headers.value(section).value(Qt::EditRole);Executed by:
| 27 | ||||||||||||||||||||||||
| 230 | if (val.isValid()
| 2-30 | ||||||||||||||||||||||||
| 231 | return executed 2 times by 1 test: val;return val;Executed by:
executed 2 times by 1 test: return val;Executed by:
| 2 | ||||||||||||||||||||||||
| 232 | if (role == Qt::DisplayRole
| 4-25 | ||||||||||||||||||||||||
| 233 | return executed 16 times by 3 tests: d->rec.fieldName(section);return d->rec.fieldName(section);Executed by:
executed 16 times by 3 tests: return d->rec.fieldName(section);Executed by:
| 16 | ||||||||||||||||||||||||
| 234 | } executed 14 times by 3 tests: end of blockExecuted by:
| 14 | ||||||||||||||||||||||||
| 235 | return executed 1615 times by 3 tests: QAbstractItemModel::headerData(section, orientation, role);return QAbstractItemModel::headerData(section, orientation, role);Executed by:
executed 1615 times by 3 tests: return QAbstractItemModel::headerData(section, orientation, role);Executed by:
| 1615 | ||||||||||||||||||||||||
| 236 | } | - | ||||||||||||||||||||||||
| 237 | void QSqlQueryModel::queryChange() | - | ||||||||||||||||||||||||
| 238 | { | - | ||||||||||||||||||||||||
| 239 | - | |||||||||||||||||||||||||
| 240 | } | - | ||||||||||||||||||||||||
| 241 | void QSqlQueryModel::setQuery(const QSqlQuery &query) | - | ||||||||||||||||||||||||
| 242 | { | - | ||||||||||||||||||||||||
| 243 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 244 | beginResetModel(); | - | ||||||||||||||||||||||||
| 245 | - | |||||||||||||||||||||||||
| 246 | QSqlRecord newRec = query.record(); | - | ||||||||||||||||||||||||
| 247 | bool columnsChanged = (newRec != d->rec); | - | ||||||||||||||||||||||||
| 248 | - | |||||||||||||||||||||||||
| 249 | if (d->colOffsets.size() != newRec.count()
| 66-316 | ||||||||||||||||||||||||
| 250 | d->initColOffsets(newRec.count()); executed 253 times by 4 tests: d->initColOffsets(newRec.count());Executed by:
| 253 | ||||||||||||||||||||||||
| 251 | - | |||||||||||||||||||||||||
| 252 | d->bottom = QModelIndex(); | - | ||||||||||||||||||||||||
| 253 | d->error = QSqlError(); | - | ||||||||||||||||||||||||
| 254 | d->query = query; | - | ||||||||||||||||||||||||
| 255 | d->rec = newRec; | - | ||||||||||||||||||||||||
| 256 | d->atEnd = true; | - | ||||||||||||||||||||||||
| 257 | - | |||||||||||||||||||||||||
| 258 | if (query.isForwardOnly()
| 0-382 | ||||||||||||||||||||||||
| 259 | d->error = QSqlError(QLatin1String("Forward-only queries " | - | ||||||||||||||||||||||||
| 260 | "cannot be used in a data model"), | - | ||||||||||||||||||||||||
| 261 | QString(), QSqlError::ConnectionError); | - | ||||||||||||||||||||||||
| 262 | endResetModel(); | - | ||||||||||||||||||||||||
| 263 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 264 | } | - | ||||||||||||||||||||||||
| 265 | - | |||||||||||||||||||||||||
| 266 | if (!query.isActive()
| 7-375 | ||||||||||||||||||||||||
| 267 | d->error = query.lastError(); | - | ||||||||||||||||||||||||
| 268 | endResetModel(); | - | ||||||||||||||||||||||||
| 269 | return; executed 7 times by 2 tests: return;Executed by:
| 7 | ||||||||||||||||||||||||
| 270 | } | - | ||||||||||||||||||||||||
| 271 | - | |||||||||||||||||||||||||
| 272 | if (query.driver()->hasFeature(QSqlDriver::QuerySize)
| 0-375 | ||||||||||||||||||||||||
| 273 | d->bottom = createIndex(d->query.size() - 1, d->rec.count() - 1); | - | ||||||||||||||||||||||||
| 274 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 275 | d->bottom = createIndex(-1, d->rec.count() - 1); | - | ||||||||||||||||||||||||
| 276 | d->atEnd = false; | - | ||||||||||||||||||||||||
| 277 | } executed 375 times by 4 tests: end of blockExecuted by:
| 375 | ||||||||||||||||||||||||
| 278 | - | |||||||||||||||||||||||||
| 279 | - | |||||||||||||||||||||||||
| 280 | - | |||||||||||||||||||||||||
| 281 | fetchMore(); | - | ||||||||||||||||||||||||
| 282 | - | |||||||||||||||||||||||||
| 283 | endResetModel(); | - | ||||||||||||||||||||||||
| 284 | queryChange(); | - | ||||||||||||||||||||||||
| 285 | } executed 375 times by 4 tests: end of blockExecuted by:
| 375 | ||||||||||||||||||||||||
| 286 | void QSqlQueryModel::setQuery(const QString &query, const QSqlDatabase &db) | - | ||||||||||||||||||||||||
| 287 | { | - | ||||||||||||||||||||||||
| 288 | setQuery(QSqlQuery(query, db)); | - | ||||||||||||||||||||||||
| 289 | } executed 57 times by 2 tests: end of blockExecuted by:
| 57 | ||||||||||||||||||||||||
| 290 | - | |||||||||||||||||||||||||
| 291 | - | |||||||||||||||||||||||||
| 292 | - | |||||||||||||||||||||||||
| 293 | - | |||||||||||||||||||||||||
| 294 | void QSqlQueryModel::clear() | - | ||||||||||||||||||||||||
| 295 | { | - | ||||||||||||||||||||||||
| 296 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 297 | beginResetModel(); | - | ||||||||||||||||||||||||
| 298 | d->error = QSqlError(); | - | ||||||||||||||||||||||||
| 299 | d->atEnd = true; | - | ||||||||||||||||||||||||
| 300 | d->query.clear(); | - | ||||||||||||||||||||||||
| 301 | d->rec.clear(); | - | ||||||||||||||||||||||||
| 302 | d->colOffsets.clear(); | - | ||||||||||||||||||||||||
| 303 | d->bottom = QModelIndex(); | - | ||||||||||||||||||||||||
| 304 | d->headers.clear(); | - | ||||||||||||||||||||||||
| 305 | endResetModel(); | - | ||||||||||||||||||||||||
| 306 | } executed 191 times by 4 tests: end of blockExecuted by:
| 191 | ||||||||||||||||||||||||
| 307 | bool QSqlQueryModel::setHeaderData(int section, Qt::Orientation orientation, | - | ||||||||||||||||||||||||
| 308 | const QVariant &value, int role) | - | ||||||||||||||||||||||||
| 309 | { | - | ||||||||||||||||||||||||
| 310 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 311 | if (orientation != Qt::Horizontal
| 4-18 | ||||||||||||||||||||||||
| 312 | return executed 16 times by 2 tests: false;return false;Executed by:
executed 16 times by 2 tests: return false;Executed by:
| 16 | ||||||||||||||||||||||||
| 313 | - | |||||||||||||||||||||||||
| 314 | if (d->headers.size() <= section
| 2-4 | ||||||||||||||||||||||||
| 315 | d->headers.resize(qMax(section + 1, 16)); executed 4 times by 3 tests: d->headers.resize(qMax(section + 1, 16));Executed by:
| 4 | ||||||||||||||||||||||||
| 316 | d->headers[section][role] = value; | - | ||||||||||||||||||||||||
| 317 | headerDataChanged(orientation, section, section); | - | ||||||||||||||||||||||||
| 318 | return executed 6 times by 3 tests: true;return true;Executed by:
executed 6 times by 3 tests: return true;Executed by:
| 6 | ||||||||||||||||||||||||
| 319 | } | - | ||||||||||||||||||||||||
| 320 | - | |||||||||||||||||||||||||
| 321 | - | |||||||||||||||||||||||||
| 322 | - | |||||||||||||||||||||||||
| 323 | - | |||||||||||||||||||||||||
| 324 | - | |||||||||||||||||||||||||
| 325 | - | |||||||||||||||||||||||||
| 326 | QSqlQuery QSqlQueryModel::query() const | - | ||||||||||||||||||||||||
| 327 | { | - | ||||||||||||||||||||||||
| 328 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 329 | return never executed: d->query;return d->query;never executed: return d->query; | 0 | ||||||||||||||||||||||||
| 330 | } | - | ||||||||||||||||||||||||
| 331 | - | |||||||||||||||||||||||||
| 332 | - | |||||||||||||||||||||||||
| 333 | - | |||||||||||||||||||||||||
| 334 | - | |||||||||||||||||||||||||
| 335 | - | |||||||||||||||||||||||||
| 336 | - | |||||||||||||||||||||||||
| 337 | - | |||||||||||||||||||||||||
| 338 | QSqlError QSqlQueryModel::lastError() const | - | ||||||||||||||||||||||||
| 339 | { | - | ||||||||||||||||||||||||
| 340 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 341 | return executed 796 times by 4 tests: d->error;return d->error;Executed by:
executed 796 times by 4 tests: return d->error;Executed by:
| 796 | ||||||||||||||||||||||||
| 342 | } | - | ||||||||||||||||||||||||
| 343 | - | |||||||||||||||||||||||||
| 344 | - | |||||||||||||||||||||||||
| 345 | - | |||||||||||||||||||||||||
| 346 | - | |||||||||||||||||||||||||
| 347 | - | |||||||||||||||||||||||||
| 348 | - | |||||||||||||||||||||||||
| 349 | - | |||||||||||||||||||||||||
| 350 | void QSqlQueryModel::setLastError(const QSqlError &error) | - | ||||||||||||||||||||||||
| 351 | { | - | ||||||||||||||||||||||||
| 352 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 353 | d->error = error; | - | ||||||||||||||||||||||||
| 354 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 355 | QSqlRecord QSqlQueryModel::record(int row) const | - | ||||||||||||||||||||||||
| 356 | { | - | ||||||||||||||||||||||||
| 357 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 358 | if (row < 0
| 0-250 | ||||||||||||||||||||||||
| 359 | return never executed: d->rec;return d->rec;never executed: return d->rec; | 0 | ||||||||||||||||||||||||
| 360 | - | |||||||||||||||||||||||||
| 361 | QSqlRecord rec = d->rec; | - | ||||||||||||||||||||||||
| 362 | for (int i = 0; i < rec.count()
| 250-606 | ||||||||||||||||||||||||
| 363 | rec.setValue(i, data(createIndex(row, i), Qt::EditRole)); executed 606 times by 3 tests: rec.setValue(i, data(createIndex(row, i), Qt::EditRole));Executed by:
| 606 | ||||||||||||||||||||||||
| 364 | return executed 250 times by 3 tests: rec;return rec;Executed by:
executed 250 times by 3 tests: return rec;Executed by:
| 250 | ||||||||||||||||||||||||
| 365 | } | - | ||||||||||||||||||||||||
| 366 | QSqlRecord QSqlQueryModel::record() const | - | ||||||||||||||||||||||||
| 367 | { | - | ||||||||||||||||||||||||
| 368 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 369 | return executed 21 times by 3 tests: d->rec;return d->rec;Executed by:
executed 21 times by 3 tests: return d->rec;Executed by:
| 21 | ||||||||||||||||||||||||
| 370 | } | - | ||||||||||||||||||||||||
| 371 | bool QSqlQueryModel::insertColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 372 | { | - | ||||||||||||||||||||||||
| 373 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 374 | if (count <= 0
| 0-14 | ||||||||||||||||||||||||
| 375 | return executed 4 times by 1 test: false;return false;Executed by:
executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||||||||||||||
| 376 | - | |||||||||||||||||||||||||
| 377 | beginInsertColumns(parent, column, column + count - 1); | - | ||||||||||||||||||||||||
| 378 | for (int c = 0; c < count
| 10 | ||||||||||||||||||||||||
| 379 | QSqlField field; | - | ||||||||||||||||||||||||
| 380 | field.setReadOnly(true); | - | ||||||||||||||||||||||||
| 381 | field.setGenerated(false); | - | ||||||||||||||||||||||||
| 382 | d->rec.insert(column, field); | - | ||||||||||||||||||||||||
| 383 | if (d->colOffsets.size() < d->rec.count()
| 1-9 | ||||||||||||||||||||||||
| 384 | int nVal = d->colOffsets.isEmpty()
| 0-9 | ||||||||||||||||||||||||
| 385 | d->colOffsets.append(nVal); | - | ||||||||||||||||||||||||
| 386 | ((!(d->colOffsets.size() >= d->rec.count())) ? qt_assert("d->colOffsets.size() >= d->rec.count()",__FILE__,621) : qt_noop()); | - | ||||||||||||||||||||||||
| 387 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||||||||||||||
| 388 | for (int i = column + 1; i < d->colOffsets.count()
| 10-22 | ||||||||||||||||||||||||
| 389 | ++ executed 22 times by 2 tests: d->colOffsets[i];++d->colOffsets[i];Executed by:
executed 22 times by 2 tests: ++d->colOffsets[i];Executed by:
| 22 | ||||||||||||||||||||||||
| 390 | } executed 10 times by 2 tests: end of blockExecuted by:
| 10 | ||||||||||||||||||||||||
| 391 | endInsertColumns(); | - | ||||||||||||||||||||||||
| 392 | return executed 10 times by 2 tests: true;return true;Executed by:
executed 10 times by 2 tests: return true;Executed by:
| 10 | ||||||||||||||||||||||||
| 393 | } | - | ||||||||||||||||||||||||
| 394 | bool QSqlQueryModel::removeColumns(int column, int count, const QModelIndex &parent) | - | ||||||||||||||||||||||||
| 395 | { | - | ||||||||||||||||||||||||
| 396 | QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 397 | if (count <= 0
| 0-7 | ||||||||||||||||||||||||
| 398 | return executed 3 times by 1 test: false;return false;Executed by:
executed 3 times by 1 test: return false;Executed by:
| 3 | ||||||||||||||||||||||||
| 399 | - | |||||||||||||||||||||||||
| 400 | beginRemoveColumns(parent, column, column + count - 1); | - | ||||||||||||||||||||||||
| 401 | - | |||||||||||||||||||||||||
| 402 | int i; | - | ||||||||||||||||||||||||
| 403 | for (i = 0; i < count
| 4 | ||||||||||||||||||||||||
| 404 | d->rec.remove(column); executed 4 times by 1 test: d->rec.remove(column);Executed by:
| 4 | ||||||||||||||||||||||||
| 405 | for (i = column; i < d->colOffsets.count()
| 4-9 | ||||||||||||||||||||||||
| 406 | d->colOffsets[i] -= count; executed 9 times by 1 test: d->colOffsets[i] -= count;Executed by:
| 9 | ||||||||||||||||||||||||
| 407 | - | |||||||||||||||||||||||||
| 408 | endRemoveColumns(); | - | ||||||||||||||||||||||||
| 409 | return executed 4 times by 1 test: true;return true;Executed by:
executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||||||||
| 410 | } | - | ||||||||||||||||||||||||
| 411 | QModelIndex QSqlQueryModel::indexInQuery(const QModelIndex &item) const | - | ||||||||||||||||||||||||
| 412 | { | - | ||||||||||||||||||||||||
| 413 | const QSqlQueryModelPrivate * const d = d_func(); | - | ||||||||||||||||||||||||
| 414 | int modelColumn = d->columnInQuery(item.column()); | - | ||||||||||||||||||||||||
| 415 | if (modelColumn < 0
| 23-3226 | ||||||||||||||||||||||||
| 416 | return executed 23 times by 1 test: QModelIndex();return QModelIndex();Executed by:
executed 23 times by 1 test: return QModelIndex();Executed by:
| 23 | ||||||||||||||||||||||||
| 417 | return executed 3226 times by 4 tests: createIndex(item.row(), modelColumn, item.internalPointer());return createIndex(item.row(), modelColumn, item.internalPointer());Executed by:
executed 3226 times by 4 tests: return createIndex(item.row(), modelColumn, item.internalPointer());Executed by:
| 3226 | ||||||||||||||||||||||||
| 418 | } | - | ||||||||||||||||||||||||
| 419 | - | |||||||||||||||||||||||||
| 420 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |