diff options
author | Uwe Klotz <uwe_klotz@web.de> | 2017-06-04 17:58:50 +0200 |
---|---|---|
committer | Uwe Klotz <uwe_klotz@web.de> | 2017-06-12 07:30:17 +0200 |
commit | bb5534f811976535815d69fd564af4c748f22ef0 (patch) | |
tree | e372518972f4ba7975d2d3c420d9948892417432 | |
parent | e0817dcb6d1d28771d17f5f4197b5bd8125c0177 (diff) |
Do not store reference in member variable
QSqlDatabase uses implicit sharing behind the scenes
-rw-r--r-- | src/library/queryutil.h | 2 | ||||
-rw-r--r-- | src/test/queryutiltest.cpp | 16 |
2 files changed, 6 insertions, 12 deletions
diff --git a/src/library/queryutil.h b/src/library/queryutil.h index bcc10b8b98..e7ab94cdfe 100644 --- a/src/library/queryutil.h +++ b/src/library/queryutil.h @@ -94,7 +94,7 @@ class FieldEscaper final { } } - const QSqlDatabase& m_database; + QSqlDatabase m_database; mutable QSqlField m_stringField; }; diff --git a/src/test/queryutiltest.cpp b/src/test/queryutiltest.cpp index 500eed3ba1..3fb2e04084 100644 --- a/src/test/queryutiltest.cpp +++ b/src/test/queryutiltest.cpp @@ -5,23 +5,17 @@ #include "library/queryutil.h" #include "util/db/sqllikewildcardescaper.h" -class QueryUtilTest : public LibraryTest { - protected: - QueryUtilTest() - : m_fieldEscaper(collection()->database()) { - } - - FieldEscaper m_fieldEscaper; -}; +class QueryUtilTest : public LibraryTest {}; TEST_F(QueryUtilTest, FieldEscaperEscapesQuotes) { + FieldEscaper fieldEscaper(collection()->database()); EXPECT_STREQ(qPrintable(QString("'foobar'")), - qPrintable(m_fieldEscaper.escapeString("foobar"))); + qPrintable(fieldEscaper.escapeString("foobar"))); EXPECT_STREQ(qPrintable(QString("'foobar''s'")), - qPrintable(m_fieldEscaper.escapeString("foobar's"))); + qPrintable(fieldEscaper.escapeString("foobar's"))); } -TEST_F(QueryUtilTest, FieldEscaperEscapesForLike) { +TEST_F(QueryUtilTest, SqlLikeWildcardEscaperEscapesForLike) { EXPECT_STREQ(qPrintable(QString("xx44xx4%yy4_yy")), qPrintable(SqlLikeWildcardEscaper::apply("xx4xx%yy_yy", '4'))); } |