summaryrefslogtreecommitdiffstats
path: root/src/library/queryutil.h
diff options
context:
space:
mode:
authorUwe Klotz <uwe_klotz@web.de>2017-01-31 19:21:21 +0100
committerUwe Klotz <uwe_klotz@web.de>2017-01-31 19:30:25 +0100
commit372a2784a84891cc1134ac8c072fb264c5b5ddfa (patch)
tree7e2df6a0ef080d1731056a67408a18bc502bd80d /src/library/queryutil.h
parent845994e3ff64ccb50b35e3605b4b405833e3f6fe (diff)
Reduce code duplication
Diffstat (limited to 'src/library/queryutil.h')
-rw-r--r--src/library/queryutil.h28
1 files changed, 4 insertions, 24 deletions
diff --git a/src/library/queryutil.h b/src/library/queryutil.h
index 878772fb5e..a0742ac83b 100644
--- a/src/library/queryutil.h
+++ b/src/library/queryutil.h
@@ -4,6 +4,7 @@
#include <QtDebug>
#include <QtSql>
+
#define LOG_FAILED_QUERY(query) qDebug() << __FILE__ << __LINE__ << "FAILED QUERY [" \
<< (query).executedQuery() << "]" << (query).lastError()
@@ -65,14 +66,12 @@ class ScopedTransaction {
bool m_active;
};
-class FieldEscaper {
+class FieldEscaper final {
public:
FieldEscaper(const QSqlDatabase& database)
: m_database(database),
m_stringField("string", QVariant::String) {
}
- virtual ~FieldEscaper() {
- }
// Escapes a string for use in a SQL query by wrapping with quotes and
// escaping embedded quote characters.
@@ -87,6 +86,7 @@ class FieldEscaper {
return result;
}
+ private:
void escapeStringsInPlace(QStringList* pEscapeStrings) const {
QMutableStringListIterator it(*pEscapeStrings);
while (it.hasNext()) {
@@ -94,28 +94,8 @@ class FieldEscaper {
}
}
- // Escapes a string for use in a LIKE operation by prefixing instances of
- // LIKE wildcard characters (% and _) with escapeCharacter. This allows the
- // caller to then attach wildcard characters to the string. This does NOT
- // escape the string in the same way that escapeString() does.
- QString escapeStringForLike(const QString& escapeString, const QChar escapeCharacter) const {
- QString escapeCharacterStr(escapeCharacter);
- QString result = escapeString;
- // Replace instances of escapeCharacter with two escapeCharacters.
- result = result.replace(
- escapeCharacter, escapeCharacterStr + escapeCharacterStr);
- // Replace instances of % or _ with $escapeCharacter%.
- if (escapeCharacter != '%') {
- result = result.replace("%", escapeCharacterStr + "%");
- }
- if (escapeCharacter != '_') {
- result = result.replace("_", escapeCharacterStr + "_");
- }
- return result;
- }
-
- private:
const QSqlDatabase& m_database;
mutable QSqlField m_stringField;
};
+
#endif /* QUERYUTIL_H */