kernel/qsqldriver.cpp

Switch to Source codePreprocessed file
LineSource CodeCoverage
1 -
2 -
3 -
4 -
5static 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)
TRUEFALSE
yes
Evaluation Count:1121
no
Evaluation Count:0
0-1121
11 ret = driver->escapeIdentifier(identifier, type); -
12 }
executed: }
Execution Count:1121
1121
13 return ret;
executed: return ret;
Execution Count:1121
1121
14} -
15 -
16class QSqlDriverPrivate : public QObjectPrivate -
17{ -
18public: -
19 QSqlDriverPrivate(); -
20 virtual ~QSqlDriverPrivate(); -
21 -
22public: -
23 -
24 QSqlDriver *q_func(); -
25 uint isOpen : 1; -
26 uint isOpenError : 1; -
27 QSqlError error; -
28 QSql::NumericalPrecisionPolicy precisionPolicy; -
29}; -
30 -
31inline QSqlDriverPrivate::QSqlDriverPrivate() -
32 : QObjectPrivate(), isOpen(false), isOpenError(false), precisionPolicy(QSql::LowPrecisionDouble) -
33{ -
34}
executed: }
Execution Count:52
52
35 -
36QSqlDriverPrivate::~QSqlDriverPrivate() -
37{ -
38} -
39QSqlDriver::QSqlDriver(QObject *parent) -
40 : QObject(*new QSqlDriverPrivate, parent) -
41{ -
42}
executed: }
Execution Count:52
52
43 -
44 -
45 -
46 -
47 -
48QSqlDriver::~QSqlDriver() -
49{ -
50} -
51bool QSqlDriver::isOpen() const -
52{ -
53 return d_func()->isOpen;
executed: return d_func()->isOpen;
Execution Count:7900
7900
54} -
55 -
56 -
57 -
58 -
59 -
60 -
61bool QSqlDriver::isOpenError() const -
62{ -
63 return d_func()->isOpenError;
executed: return d_func()->isOpenError;
Execution Count:5238
5238
64} -
65void QSqlDriver::setOpen(bool open) -
66{ -
67 d_func()->isOpen = open; -
68}
executed: }
Execution Count:90
90
69void QSqlDriver::setOpenError(bool error) -
70{ -
71 d_func()->isOpenError = error; -
72 if (error)
evaluated: error
TRUEFALSE
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
75bool QSqlDriver::beginTransaction() -
76{ -
77 return false;
never executed: return false;
0
78} -
79bool QSqlDriver::commitTransaction() -
80{ -
81 return false;
never executed: return false;
0
82} -
83bool QSqlDriver::rollbackTransaction() -
84{ -
85 return false;
never executed: return false;
0
86} -
87void QSqlDriver::setLastError(const QSqlError &error) -
88{ -
89 d_func()->error = error; -
90}
executed: }
Execution Count:37
37
91 -
92 -
93 -
94 -
95 -
96 -
97QSqlError QSqlDriver::lastError() const -
98{ -
99 return d_func()->error;
executed: return d_func()->error;
Execution Count:29
29
100} -
101QStringList QSqlDriver::tables(QSql::TableType) const -
102{ -
103 return QStringList();
executed: return QStringList();
Execution Count:1
1
104} -
105 -
106 -
107 -
108 -
109 -
110 -
111 -
112QSqlIndex QSqlDriver::primaryIndex(const QString&) const -
113{ -
114 return QSqlIndex();
never executed: return QSqlIndex();
0
115} -
116QSqlRecord QSqlDriver::record(const QString & ) const -
117{ -
118 return QSqlRecord();
never executed: return QSqlRecord();
0
119} -
120QString QSqlDriver::escapeIdentifier(const QString &identifier, IdentifierType) const -
121{ -
122 return identifier;
never executed: return identifier;
0
123} -
124bool QSqlDriver::isIdentifierEscaped(const QString &identifier, IdentifierType type) const -
125{ -
126 (void)type;; -
127 return identifier.size() > 2 2551
128 && identifier.startsWith(QLatin1Char('"')) 2551
129 && identifier.endsWith(QLatin1Char('"'));
executed: return identifier.size() > 2 && identifier.startsWith(QLatin1Char('"')) && identifier.endsWith(QLatin1Char('"'));
Execution Count:2551
2551
130} -
131QString QSqlDriver::stripDelimiters(const QString &identifier, IdentifierType type) const -
132{ -
133 QString ret; -
134 if (isIdentifierEscaped(identifier, type)) {
partially evaluated: isIdentifierEscaped(identifier, type)
TRUEFALSE
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 }
never executed: }
0
140 return ret;
executed: return ret;
Execution Count:99
99
141} -
142QString 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()
TRUEFALSE
yes
Evaluation Count:677
yes
Evaluation Count:269
269-677
151 if (rec.isGenerated(i))
partially evaluated: rec.isGenerated(i)
TRUEFALSE
yes
Evaluation Count:677
no
Evaluation Count:0
0-677
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:677
677
153 }
executed: }
Execution Count:677
677
154 if (s.isEmpty())
partially evaluated: s.isEmpty()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:269
0-269
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:269
269
159 case WhereStatement: -
160 if (preparedStatement) {
evaluated: preparedStatement
TRUEFALSE
yes
Evaluation Count:66
yes
Evaluation Count:57
57-66
161 for (int i = 0; i < rec.count(); ++i) {
evaluated: i < rec.count()
TRUEFALSE
yes
Evaluation Count:148
yes
Evaluation Count:66
66-148
162 s.append(prepareIdentifier(rec.fieldName(i), FieldName,this)); -
163 if (rec.isNull(i))
evaluated: rec.isNull(i)
TRUEFALSE
yes
Evaluation Count:7
yes
Evaluation Count:141
7-141
164 s.append(QLatin1String(" IS NULL"));
executed: s.append(QLatin1String(" IS NULL"));
Execution Count:7
7
165 else -
166 s.append(QLatin1String(" = ?"));
executed: s.append(QLatin1String(" = ?"));
Execution Count:141
141
167 s.append(QLatin1String(" AND ")); -
168 }
executed: }
Execution Count:148
148
169 } else {
executed: }
Execution Count:66
66
170 for (i = 0; i < rec.count(); ++i) {
evaluated: i < rec.count()
TRUEFALSE
yes
Evaluation Count:120
yes
Evaluation Count:57
57-120
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")
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:109
11-109
174 s.append(QLatin1String(" IS NULL"));
executed: s.append(QLatin1String(" IS NULL"));
Execution Count:11
11
175 else -
176 s.append(QLatin1String(" = ")).append(val);
executed: s.append(QLatin1String(" = ")).append(val);
Execution Count:109
109
177 s.append(QLatin1String(" AND ")); -
178 }
executed: }
Execution Count:120
120
179 }
executed: }
Execution Count:57
57
180 if (!s.isEmpty()) {
partially evaluated: !s.isEmpty()
TRUEFALSE
yes
Evaluation Count:123
no
Evaluation Count:0
0-123
181 s.prepend(QLatin1String("WHERE ")); -
182 s.chop(5); -
183 }
executed: }
Execution Count:123
123
184 break;
executed: break;
Execution Count:123
123
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()
TRUEFALSE
yes
Evaluation Count:143
yes
Evaluation Count:45
45-143
189 if (!rec.isGenerated(i))
evaluated: !rec.isGenerated(i)
TRUEFALSE
yes
Evaluation Count:83
yes
Evaluation Count:60
60-83
190 continue;
executed: continue;
Execution Count:83
83
191 s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1Char('=')); -
192 if (preparedStatement)
partially evaluated: preparedStatement
TRUEFALSE
yes
Evaluation Count:60
no
Evaluation Count:0
0-60
193 s.append(QLatin1Char('?'));
executed: s.append(QLatin1Char('?'));
Execution Count:60
60
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:60
60
198 if (s.endsWith(QLatin1String(", ")))
partially evaluated: s.endsWith(QLatin1String(", "))
TRUEFALSE
yes
Evaluation Count:45
no
Evaluation Count:0
0-45
199 s.chop(2);
executed: s.chop(2);
Execution Count:45
45
200 else -
201 s.clear();
never executed: s.clear();
0
202 break;
executed: break;
Execution Count:45
45
203 case DeleteStatement: -
204 s.append(QLatin1String("DELETE FROM ")).append(tableName); -
205 break;
executed: break;
Execution Count:20
20
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()
TRUEFALSE
yes
Evaluation Count:124
yes
Evaluation Count:43
43-124
210 if (!rec.isGenerated(i))
evaluated: !rec.isGenerated(i)
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:116
8-116
211 continue;
executed: continue;
Execution Count:8
8
212 s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this)).append(QLatin1String(", ")); -
213 if (preparedStatement)
partially evaluated: preparedStatement
TRUEFALSE
yes
Evaluation Count:116
no
Evaluation Count:0
0-116
214 vals.append(QLatin1Char('?'));
executed: vals.append(QLatin1Char('?'));
Execution Count:116
116
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:116
116
219 if (vals.isEmpty()) {
evaluated: vals.isEmpty()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:42
1-42
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:42
42
226 break; }
executed: break;
Execution Count:43
43
227 } -
228 return s;
executed: return s;
Execution Count:500
500
229} -
230QString 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()
TRUEFALSE
yes
Evaluation Count:11
yes
Evaluation Count:115
11-115
236 r = nullTxt;
executed: r = nullTxt;
Execution Count:11
11
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
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:73
0-73
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:73
73
245 break;
executed: break;
Execution Count:73
73
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;
never executed: 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;
never executed: 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;
never executed: break;
0
268 -
269 case QVariant::String: -
270 case QVariant::Char: -
271 { -
272 QString result = field.value().toString(); -
273 if (trimStrings) {
evaluated: trimStrings
TRUEFALSE
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
TRUEFALSE
yes
Evaluation Count:13
yes
Evaluation Count:2
evaluated: result.at(end-1).isSpace()
TRUEFALSE
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;
never executed: 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 }
never executed: }
0
297 r = QLatin1Char('\'') + res + QLatin1Char('\''); -
298 break;
never executed: break;
0
299 } -
300 } -
301 default:
code before this statement never executed: default:
0
302 r = field.value().toString(); -
303 break;
never executed: break;
0
304 } -
305 }
executed: }
Execution Count:115
115
306 return r;
executed: return r;
Execution Count:126
126
307} -
308QVariant QSqlDriver::handle() const -
309{ -
310 return QVariant();
never executed: return QVariant();
0
311} -
312bool QSqlDriver::subscribeToNotification(const QString &name) -
313{ -
314 (void)name;; -
315 return false;
never executed: return false;
0
316} -
317bool QSqlDriver::unsubscribeFromNotification(const QString &name) -
318{ -
319 (void)name;; -
320 return false;
never executed: return false;
0
321} -
322QStringList QSqlDriver::subscribedToNotifications() const -
323{ -
324 return QStringList();
never executed: return QStringList();
0
325} -
326void QSqlDriver::setNumericalPrecisionPolicy(QSql::NumericalPrecisionPolicy precisionPolicy) -
327{ -
328 d_func()->precisionPolicy = precisionPolicy; -
329}
executed: }
Execution Count:2
2
330QSql::NumericalPrecisionPolicy QSqlDriver::numericalPrecisionPolicy() const -
331{ -
332 return d_func()->precisionPolicy;
executed: return d_func()->precisionPolicy;
Execution Count:2112
2112
333} -
334bool QSqlDriver::cancelQuery() -
335{ -
336 return false;
never executed: return false;
0
337} -
338 -
339 -
340 -
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial