| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | static QString prepareIdentifier(const QString &identifier, | - |
| 6 | QSqlDriver::IdentifierType type, const QSqlDriver *driver) | - |
| 7 | { | - |
| 8 | qt_noop(); | - |
| 9 | QString ret = identifier; | - |
| 10 | if (!driver->isIdentifierEscaped(identifier, type)) { partially evaluated: !driver->isIdentifierEscaped(identifier, type)| yes Evaluation Count:1199 | no Evaluation Count:0 |
| 0-1199 |
| 11 | ret = driver->escapeIdentifier(identifier, type); | - |
| 12 | } executed: }Execution Count:1199 | 1199 |
| 13 | return ret; executed: return ret;Execution Count:1199 | 1199 |
| 14 | } | - |
| 15 | | - |
| 16 | class QSqlDriverPrivate : public QObjectPrivate | - |
| 17 | { | - |
| 18 | public: | - |
| 19 | QSqlDriverPrivate(); | - |
| 20 | virtual ~QSqlDriverPrivate(); | - |
| 21 | | - |
| 22 | public: | - |
| 23 | | - |
| 24 | QSqlDriver *q_func(); | - |
| 25 | uint isOpen : 1; | - |
| 26 | uint isOpenError : 1; | - |
| 27 | QSqlError error; | - |
| 28 | QSql::NumericalPrecisionPolicy precisionPolicy; | - |
| 29 | }; | - |
| 30 | | - |
| 31 | inline QSqlDriverPrivate::QSqlDriverPrivate() | - |
| 32 | : QObjectPrivate(), isOpen(false), isOpenError(false), precisionPolicy(QSql::LowPrecisionDouble) | - |
| 33 | { | - |
| 34 | } executed: }Execution Count:53 | 53 |
| 35 | | - |
| 36 | QSqlDriverPrivate::~QSqlDriverPrivate() | - |
| 37 | { | - |
| 38 | } | - |
| 39 | QSqlDriver::QSqlDriver(QObject *parent) | - |
| 40 | : QObject(*new QSqlDriverPrivate, parent) | - |
| 41 | { | - |
| 42 | } executed: }Execution Count:53 | 53 |
| 43 | | - |
| 44 | | - |
| 45 | | - |
| 46 | | - |
| 47 | | - |
| 48 | QSqlDriver::~QSqlDriver() | - |
| 49 | { | - |
| 50 | } | - |
| 51 | bool QSqlDriver::isOpen() const | - |
| 52 | { | - |
| 53 | return d_func()->isOpen; executed: return d_func()->isOpen;Execution Count:8278 | 8278 |
| 54 | } | - |
| 55 | | - |
| 56 | | - |
| 57 | | - |
| 58 | | - |
| 59 | | - |
| 60 | | - |
| 61 | bool QSqlDriver::isOpenError() const | - |
| 62 | { | - |
| 63 | return d_func()->isOpenError; executed: return d_func()->isOpenError;Execution Count:5582 | 5582 |
| 64 | } | - |
| 65 | void QSqlDriver::setOpen(bool open) | - |
| 66 | { | - |
| 67 | d_func()->isOpen = open; | - |
| 68 | } executed: }Execution Count:90 | 90 |
| 69 | void QSqlDriver::setOpenError(bool error) | - |
| 70 | { | - |
| 71 | d_func()->isOpenError = error; | - |
| 72 | if (error) evaluated: error| yes Evaluation Count:2 | yes Evaluation Count:90 |
| 2-90 |
| 73 | d_func()->isOpen = false; executed: d_func()->isOpen = false;Execution Count:2 | 2 |
| 74 | } executed: }Execution Count:92 | 92 |
| 75 | bool QSqlDriver::beginTransaction() | - |
| 76 | { | - |
| 77 | return false; never executed: return false; | 0 |
| 78 | } | - |
| 79 | bool QSqlDriver::commitTransaction() | - |
| 80 | { | - |
| 81 | return false; never executed: return false; | 0 |
| 82 | } | - |
| 83 | bool QSqlDriver::rollbackTransaction() | - |
| 84 | { | - |
| 85 | return false; never executed: return false; | 0 |
| 86 | } | - |
| 87 | void QSqlDriver::setLastError(const QSqlError &error) | - |
| 88 | { | - |
| 89 | d_func()->error = error; | - |
| 90 | } executed: }Execution Count:37 | 37 |
| 91 | | - |
| 92 | | - |
| 93 | | - |
| 94 | | - |
| 95 | | - |
| 96 | | - |
| 97 | QSqlError QSqlDriver::lastError() const | - |
| 98 | { | - |
| 99 | return d_func()->error; executed: return d_func()->error;Execution Count:29 | 29 |
| 100 | } | - |
| 101 | QStringList QSqlDriver::tables(QSql::TableType) const | - |
| 102 | { | - |
| 103 | return QStringList(); executed: return QStringList();Execution Count:1 | 1 |
| 104 | } | - |
| 105 | | - |
| 106 | | - |
| 107 | | - |
| 108 | | - |
| 109 | | - |
| 110 | | - |
| 111 | | - |
| 112 | QSqlIndex QSqlDriver::primaryIndex(const QString&) const | - |
| 113 | { | - |
| 114 | return QSqlIndex(); never executed: return QSqlIndex(); | 0 |
| 115 | } | - |
| 116 | QSqlRecord QSqlDriver::record(const QString & ) const | - |
| 117 | { | - |
| 118 | return QSqlRecord(); never executed: return QSqlRecord(); | 0 |
| 119 | } | - |
| 120 | QString QSqlDriver::escapeIdentifier(const QString &identifier, IdentifierType) const | - |
| 121 | { | - |
| 122 | return identifier; never executed: return identifier; | 0 |
| 123 | } | - |
| 124 | bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType type) const | - |
| 125 | { | - |
| 126 | (void)type;; | - |
| 127 | return identifier.size() > 2 | 2652 |
| 128 | && identifier.startsWith(QLatin1Char('"')) | 2652 |
| 129 | && identifier.endsWith(QLatin1Char('"')); executed: return identifier.size() > 2 && identifier.startsWith(QLatin1Char('"')) && identifier.endsWith(QLatin1Char('"'));Execution Count:2652 | 2652 |
| 130 | } | - |
| 131 | QString QSqlDriver::stripDelimiters(const QString &identifier, IdentifierType type) const | - |
| 132 | { | - |
| 133 | QString ret; | - |
| 134 | if (isIdentifierEscaped(identifier, type)) { partially evaluated: isIdentifierEscaped(identifier, type)| yes Evaluation Count:99 | no Evaluation Count:0 |
| 0-99 |
| 135 | ret = identifier.mid(1); | - |
| 136 | ret.chop(1); | - |
| 137 | } else { executed: }Execution Count:99 | 99 |
| 138 | ret = identifier; | - |
| 139 | } | 0 |
| 140 | return ret; executed: return ret;Execution Count:99 | 99 |
| 141 | } | - |
| 142 | QString QSqlDriver::sqlStatement(StatementType type, const QString &tableName, | - |
| 143 | const QSqlRecord &rec, bool preparedStatement) const | - |
| 144 | { | - |
| 145 | int i; | - |
| 146 | QString s; | - |
| 147 | s.reserve(128); | - |
| 148 | switch (type) { | - |
| 149 | case SelectStatement: | - |
| 150 | for (i = 0; i < rec.count(); ++i) { evaluated: i < rec.count()| yes Evaluation Count:721 | yes Evaluation Count:293 |
| 293-721 |
| 151 | if (rec.isGenerated(i)) partially evaluated: rec.isGenerated(i)| yes Evaluation Count:721 | no Evaluation Count:0 |
| 0-721 |
| 152 | s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); executed: s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", "));Execution Count:721 | 721 |
| 153 | } executed: }Execution Count:721 | 721 |
| 154 | if (s.isEmpty()) partially evaluated: s.isEmpty()| no Evaluation Count:0 | yes Evaluation Count:293 |
| 0-293 |
| 155 | return s; never executed: return s; | 0 |
| 156 | s.chop(2); | - |
| 157 | s.prepend(QLatin1String("SELECT ")).append(QLatin1String(" FROM ")).append(tableName); | - |
| 158 | break; executed: break;Execution Count:293 | 293 |
| 159 | case WhereStatement: | - |
| 160 | if (preparedStatement) { evaluated: preparedStatement| yes Evaluation Count:72 | yes Evaluation Count:63 |
| 63-72 |
| 161 | for (int i = 0; i < rec.count(); ++i) { evaluated: i < rec.count()| yes Evaluation Count:160 | yes Evaluation Count:72 |
| 72-160 |
| 162 | s.append(prepareIdentifier(rec.fieldName(i), FieldName,this)); | - |
| 163 | if (rec.isNull(i)) evaluated: rec.isNull(i)| yes Evaluation Count:8 | yes Evaluation Count:152 |
| 8-152 |
| 164 | s.append(QLatin1String(" IS NULL")); executed: s.append(QLatin1String(" IS NULL"));Execution Count:8 | 8 |
| 165 | else | - |
| 166 | s.append(QLatin1String(" = ?")); executed: s.append(QLatin1String(" = ?"));Execution Count:152 | 152 |
| 167 | s.append(QLatin1String(" AND ")); | - |
| 168 | } executed: }Execution Count:160 | 160 |
| 169 | } else { executed: }Execution Count:72 | 72 |
| 170 | for (i = 0; i < rec.count(); ++i) { evaluated: i < rec.count()| yes Evaluation Count:126 | yes Evaluation Count:63 |
| 63-126 |
| 171 | s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)); | - |
| 172 | QString val = formatValue(rec.field(i)); | - |
| 173 | if (val == QLatin1String("NULL")) evaluated: val == QLatin1String("NULL")| yes Evaluation Count:9 | yes Evaluation Count:117 |
| 9-117 |
| 174 | s.append(QLatin1String(" IS NULL")); executed: s.append(QLatin1String(" IS NULL"));Execution Count:9 | 9 |
| 175 | else | - |
| 176 | s.append(QLatin1String(" = ")).append(val); executed: s.append(QLatin1String(" = ")).append(val);Execution Count:117 | 117 |
| 177 | s.append(QLatin1String(" AND ")); | - |
| 178 | } executed: }Execution Count:126 | 126 |
| 179 | } executed: }Execution Count:63 | 63 |
| 180 | if (!s.isEmpty()) { partially evaluated: !s.isEmpty()| yes Evaluation Count:135 | no Evaluation Count:0 |
| 0-135 |
| 181 | s.prepend(QLatin1String("WHERE ")); | - |
| 182 | s.chop(5); | - |
| 183 | } executed: }Execution Count:135 | 135 |
| 184 | break; executed: break;Execution Count:135 | 135 |
| 185 | case UpdateStatement: | - |
| 186 | s.append(QLatin1String("UPDATE ")).append(tableName).append( | - |
| 187 | QLatin1String(" SET ")); | - |
| 188 | for (i = 0; i < rec.count(); ++i) { evaluated: i < rec.count()| yes Evaluation Count:153 | yes Evaluation Count:49 |
| 49-153 |
| 189 | if (!rec.isGenerated(i)) evaluated: !rec.isGenerated(i)| yes Evaluation Count:89 | yes Evaluation Count:64 |
| 64-89 |
| 190 | continue; executed: continue;Execution Count:89 | 89 |
| 191 | s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1Char('=')); | - |
| 192 | if (preparedStatement) partially evaluated: preparedStatement| yes Evaluation Count:64 | no Evaluation Count:0 |
| 0-64 |
| 193 | s.append(QLatin1Char('?')); executed: s.append(QLatin1Char('?'));Execution Count:64 | 64 |
| 194 | else | - |
| 195 | s.append(formatValue(rec.field(i))); never executed: s.append(formatValue(rec.field(i))); | 0 |
| 196 | s.append(QLatin1String(", ")); | - |
| 197 | } executed: }Execution Count:64 | 64 |
| 198 | if (s.endsWith(QLatin1String(", "))) partially evaluated: s.endsWith(QLatin1String(", "))| yes Evaluation Count:49 | no Evaluation Count:0 |
| 0-49 |
| 199 | s.chop(2); executed: s.chop(2);Execution Count:49 | 49 |
| 200 | else | - |
| 201 | s.clear(); never executed: s.clear(); | 0 |
| 202 | break; executed: break;Execution Count:49 | 49 |
| 203 | case DeleteStatement: | - |
| 204 | s.append(QLatin1String("DELETE FROM ")).append(tableName); | - |
| 205 | break; executed: break;Execution Count:22 | 22 |
| 206 | case InsertStatement: { | - |
| 207 | s.append(QLatin1String("INSERT INTO ")).append(tableName).append(QLatin1String(" (")); | - |
| 208 | QString vals; | - |
| 209 | for (i = 0; i < rec.count(); ++i) { evaluated: i < rec.count()| yes Evaluation Count:145 | yes Evaluation Count:53 |
| 53-145 |
| 210 | if (!rec.isGenerated(i)) evaluated: !rec.isGenerated(i)| yes Evaluation Count:17 | yes Evaluation Count:128 |
| 17-128 |
| 211 | continue; executed: continue;Execution Count:17 | 17 |
| 212 | s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); | - |
| 213 | if (preparedStatement) partially evaluated: preparedStatement| yes Evaluation Count:128 | no Evaluation Count:0 |
| 0-128 |
| 214 | vals.append(QLatin1Char('?')); executed: vals.append(QLatin1Char('?'));Execution Count:128 | 128 |
| 215 | else | - |
| 216 | vals.append(formatValue(rec.field(i))); never executed: vals.append(formatValue(rec.field(i))); | 0 |
| 217 | vals.append(QLatin1String(", ")); | - |
| 218 | } executed: }Execution Count:128 | 128 |
| 219 | if (vals.isEmpty()) { evaluated: vals.isEmpty()| yes Evaluation Count:1 | yes Evaluation Count:52 |
| 1-52 |
| 220 | s.clear(); | - |
| 221 | } else { executed: }Execution Count:1 | 1 |
| 222 | vals.chop(2); | - |
| 223 | s[s.length() - 2] = QLatin1Char(')'); | - |
| 224 | s.append(QLatin1String("VALUES (")).append(vals).append(QLatin1Char(')')); | - |
| 225 | } executed: }Execution Count:52 | 52 |
| 226 | break; } executed: break;Execution Count:53 | 53 |
| 227 | } | - |
| 228 | return s; executed: return s;Execution Count:552 | 552 |
| 229 | } | - |
| 230 | QString QSqlDriver::formatValue(const QSqlField &field, bool trimStrings) const | - |
| 231 | { | - |
| 232 | const QLatin1String nullTxt("NULL"); | - |
| 233 | | - |
| 234 | QString r; | - |
| 235 | if (field.isNull()) evaluated: field.isNull()| yes Evaluation Count:9 | yes Evaluation Count:123 |
| 9-123 |
| 236 | r = nullTxt; executed: r = nullTxt;Execution Count:9 | 9 |
| 237 | else { | - |
| 238 | switch (field.type()) { | - |
| 239 | case QVariant::Int: | - |
| 240 | case QVariant::UInt: | - |
| 241 | if (field.value().type() == QVariant::Bool) partially evaluated: field.value().type() == QVariant::Bool| no Evaluation Count:0 | yes Evaluation Count:81 |
| 0-81 |
| 242 | r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0"); never evaluated: field.value().toBool() never executed: r = field.value().toBool() ? QLatin1String("1") : QLatin1String("0"); | 0 |
| 243 | else | - |
| 244 | r = field.value().toString(); executed: r = field.value().toString();Execution Count:81 | 81 |
| 245 | break; executed: break;Execution Count:81 | 81 |
| 246 | | - |
| 247 | case QVariant::Date: | - |
| 248 | if (field.value().toDate().isValid()) never evaluated: field.value().toDate().isValid() | 0 |
| 249 | r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate) | 0 |
| 250 | + QLatin1Char('\''); never executed: r = QLatin1Char('\'') + field.value().toDate().toString(Qt::ISODate) + QLatin1Char('\''); | 0 |
| 251 | else | - |
| 252 | r = nullTxt; never executed: r = nullTxt; | 0 |
| 253 | break; | 0 |
| 254 | case QVariant::Time: | - |
| 255 | if (field.value().toTime().isValid()) never evaluated: field.value().toTime().isValid() | 0 |
| 256 | r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) | 0 |
| 257 | + QLatin1Char('\''); never executed: r = QLatin1Char('\'') + field.value().toTime().toString(Qt::ISODate) + QLatin1Char('\''); | 0 |
| 258 | else | - |
| 259 | r = nullTxt; never executed: r = nullTxt; | 0 |
| 260 | break; | 0 |
| 261 | case QVariant::DateTime: | - |
| 262 | if (field.value().toDateTime().isValid()) never evaluated: field.value().toDateTime().isValid() | 0 |
| 263 | r = QLatin1Char('\'') + | 0 |
| 264 | field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\''); never executed: r = QLatin1Char('\'') + field.value().toDateTime().toString(Qt::ISODate) + QLatin1Char('\''); | 0 |
| 265 | else | - |
| 266 | r = nullTxt; never executed: r = nullTxt; | 0 |
| 267 | break; | 0 |
| 268 | | - |
| 269 | case QVariant::String: | - |
| 270 | case QVariant::Char: | - |
| 271 | { | - |
| 272 | QString result = field.value().toString(); | - |
| 273 | if (trimStrings) { evaluated: trimStrings| yes Evaluation Count:6 | yes Evaluation Count:36 |
| 6-36 |
| 274 | int end = result.length(); | - |
| 275 | while (end && result.at(end-1).isSpace()) evaluated: end| yes Evaluation Count:13 | yes Evaluation Count:2 |
evaluated: result.at(end-1).isSpace()| yes Evaluation Count:9 | yes Evaluation Count:4 |
| 2-13 |
| 276 | end--; executed: end--;Execution Count:9 | 9 |
| 277 | result.truncate(end); | - |
| 278 | } executed: }Execution Count:6 | 6 |
| 279 | | - |
| 280 | result.replace(QLatin1Char('\''), QLatin1String("''")); | - |
| 281 | r = QLatin1Char('\'') + result + QLatin1Char('\''); | - |
| 282 | break; executed: break;Execution Count:42 | 42 |
| 283 | } | - |
| 284 | case QVariant::Bool: | - |
| 285 | r = QString::number(field.value().toBool()); | - |
| 286 | break; | 0 |
| 287 | case QVariant::ByteArray : { | - |
| 288 | if (hasFeature(BLOB)) { never evaluated: hasFeature(BLOB) | 0 |
| 289 | QByteArray ba = field.value().toByteArray(); | - |
| 290 | QString res; | - |
| 291 | static const char hexchars[] = "0123456789abcdef"; | - |
| 292 | for (int i = 0; i < ba.size(); ++i) { never evaluated: i < ba.size() | 0 |
| 293 | uchar s = (uchar) ba[i]; | - |
| 294 | res += QLatin1Char(hexchars[s >> 4]); | - |
| 295 | res += QLatin1Char(hexchars[s & 0x0f]); | - |
| 296 | } | 0 |
| 297 | r = QLatin1Char('\'') + res + QLatin1Char('\''); | - |
| 298 | break; | 0 |
| 299 | } | - |
| 300 | } | - |
| 301 | default: code before this statement never executed: default: | 0 |
| 302 | r = field.value().toString(); | - |
| 303 | break; | 0 |
| 304 | } | - |
| 305 | } executed: }Execution Count:123 | 123 |
| 306 | return r; executed: return r;Execution Count:132 | 132 |
| 307 | } | - |
| 308 | QVariant QSqlDriver::handle() const | - |
| 309 | { | - |
| 310 | return QVariant(); never executed: return QVariant(); | 0 |
| 311 | } | - |
| 312 | bool QSqlDriver::subscribeToNotification(const QString &name) | - |
| 313 | { | - |
| 314 | (void)name;; | - |
| 315 | return false; never executed: return false; | 0 |
| 316 | } | - |
| 317 | bool QSqlDriver::unsubscribeFromNotification(const QString &name) | - |
| 318 | { | - |
| 319 | (void)name;; | - |
| 320 | return false; never executed: return false; | 0 |
| 321 | } | - |
| 322 | QStringList QSqlDriver::subscribedToNotifications() const | - |
| 323 | { | - |
| 324 | return QStringList(); never executed: return QStringList(); | 0 |
| 325 | } | - |
| 326 | void QSqlDriver::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy) | - |
| 327 | { | - |
| 328 | d_func()->precisionPolicy = precisionPolicy; | - |
| 329 | } executed: }Execution Count:2 | 2 |
| 330 | QSql::NumericalPrecisionPolicy QSqlDriver::numericalPrecisionPolicy() const | - |
| 331 | { | - |
| 332 | return d_func()->precisionPolicy; executed: return d_func()->precisionPolicy;Execution Count:2187 | 2187 |
| 333 | } | - |
| 334 | bool QSqlDriver::cancelQuery() | - |
| 335 | { | - |
| 336 | return false; never executed: return false; | 0 |
| 337 | } | - |
| 338 | | - |
| 339 | | - |
| 340 | | - |
| | |