Skip to content

Commit 1eda5c7

Browse files
committed
Minor cleanup of the codebase, mostly putting braces on their own line in unit tests
1 parent 08a73ce commit 1eda5c7

File tree

13 files changed

+140
-81
lines changed

13 files changed

+140
-81
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,6 @@ Version ?
133133
- Update SQLite3 from 3.27.2 to 3.28.0 (2019-04-16)
134134
- #191 CMake Warning line 299
135135
- #190 Implement move constructors
136-
- #192 Add wrapper for bind parameter count
136+
- #192 Add wrapper for bind parameter count
137+
- #197 Add tuple_bind and execute_many
138+
- #199 Fix #156 misleading error message in exception from Statement::exec

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ The source code use the CamelCase naming style variant where:
301301
- files (.cpp/.h) are named like the class they contain
302302
- function and variable names begin with a lower case letter
303303
- member variables begin with a 'm', function arguments begin with a 'a', booleans with a 'b', pointers with a 'p'
304-
- each file, class, method and member variable is documented using Doxygen tags
304+
- each file, class, method and member variable is documented using Doxygen tags
305+
- braces on their own line
305306
See also http://www.appinf.com/download/CppCodingStyleGuide.pdf for good guidelines
306307

307308
## See also - Some other simple C++ SQLite wrappers:

include/SQLiteCpp/ExecuteMany.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* @ingroup SQLiteCpp
44
* @brief Convenience function to execute a Statement with multiple Parameter sets
55
*
6-
* Copyright (c) 2019 Maximilian Bachmann (github@maxbachmann)
6+
* Copyright (c) 2019 Maximilian Bachmann (github maxbachmann)
7+
* Copyright (c) 2019 Sebastien Rombauts ([email protected])
78
*
89
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
910
* or copy at http://opensource.org/licenses/MIT)
@@ -39,15 +40,17 @@ namespace SQLite
3940
* \endcode
4041
* @param aDatabase Database to use
4142
* @param apQuery Query to use with all parameter sets
42-
* @param Arg first tuple with parameters
43-
* @param Types the following tuples with parameters
43+
* @param aArg first tuple with parameters
44+
* @param aParams the following tuples with parameters
4445
*/
4546
template <typename Arg, typename... Types>
46-
void execute_many(Database& aDatabase, const char* apQuery, Arg&& arg, Types&&... params) {
47+
void execute_many(Database& aDatabase, const char* apQuery, Arg&& aArg, Types&&... aParams)
48+
{
4749
SQLite::Statement query(aDatabase, apQuery);
48-
bind_exec(query, std::forward<decltype(arg)>(arg));
49-
(void)std::initializer_list<int>{
50-
((void)reset_bind_exec(query, std::forward<decltype(params)>(params)), 0)...
50+
bind_exec(query, std::forward<decltype(aArg)>(aArg));
51+
(void)std::initializer_list<int>
52+
{
53+
((void)reset_bind_exec(query, std::forward<decltype(aParams)>(aParams)), 0)...
5154
};
5255
}
5356

@@ -58,13 +61,13 @@ void execute_many(Database& aDatabase, const char* apQuery, Arg&& arg, Types&&..
5861
* This feature requires a c++14 capable compiler.
5962
*
6063
* @param apQuery Query to use
61-
* @param tuple tuple to bind
64+
* @param aTuple Tuple to bind
6265
*/
6366
template <typename ... Types>
64-
void reset_bind_exec(SQLite::Statement& query, std::tuple<Types...>&& tuple)
67+
void reset_bind_exec(SQLite::Statement& apQuery, std::tuple<Types...>&& aTuple)
6568
{
66-
query.reset();
67-
bind_exec(query, std::forward<decltype(tuple)>(tuple));
69+
apQuery.reset();
70+
bind_exec(apQuery, std::forward<decltype(aTuple)>(aTuple));
6871
}
6972

7073
/**
@@ -73,13 +76,13 @@ void reset_bind_exec(SQLite::Statement& query, std::tuple<Types...>&& tuple)
7376
* This feature requires a c++14 capable compiler.
7477
*
7578
* @param apQuery Query to use
76-
* @param tuple tuple to bind
79+
* @param aTuple Tuple to bind
7780
*/
7881
template <typename ... Types>
79-
void bind_exec(SQLite::Statement& query, std::tuple<Types...>&& tuple)
82+
void bind_exec(SQLite::Statement& apQuery, std::tuple<Types...>&& aTuple)
8083
{
81-
bind(query, std::forward<decltype(tuple)>(tuple));
82-
while (query.executeStep()) {}
84+
bind(apQuery, std::forward<decltype(aTuple)>(aTuple));
85+
while (apQuery.executeStep()) {}
8386
}
8487

8588
} // namespace SQLite

include/SQLiteCpp/VariadicBind.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Copyright (c) 2016 Paul Dreik ([email protected])
77
* Copyright (c) 2016-2019 Sebastien Rombauts ([email protected])
8-
* Copyright (c) 2019 Maximilian Bachmann (github@maxbachmann)
8+
* Copyright (c) 2019 Maximilian Bachmann (github maxbachmann)
99
*
1010
* Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
1111
* or copy at http://opensource.org/licenses/MIT)

src/Database.cpp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ void Database::createFunction(const char* apFuncName,
198198
{
199199
int TextRep = SQLITE_UTF8;
200200
// optimization if deterministic function (e.g. of nondeterministic function random())
201-
if (abDeterministic) {
201+
if (abDeterministic)
202+
{
202203
TextRep = TextRep|SQLITE_DETERMINISTIC;
203204
}
204205
const int ret = sqlite3_create_function_v2(mpSQLite, apFuncName, aNbArg, TextRep,
@@ -237,14 +238,16 @@ void Database::loadExtension(const char* apExtensionName, const char *apEntryPoi
237238
// Set the key for the current sqlite database instance.
238239
void Database::key(const std::string& aKey) const
239240
{
240-
int pass_len = static_cast<int>(aKey.length());
241+
int passLen = static_cast<int>(aKey.length());
241242
#ifdef SQLITE_HAS_CODEC
242-
if (pass_len > 0) {
243-
const int ret = sqlite3_key(mpSQLite, aKey.c_str(), pass_len);
243+
if (passLen > 0)
244+
{
245+
const int ret = sqlite3_key(mpSQLite, aKey.c_str(), passLen);
244246
check(ret);
245247
}
246248
#else // SQLITE_HAS_CODEC
247-
if (pass_len > 0) {
249+
if (passLen > 0)
250+
{
248251
const SQLite::Exception exception("No encryption support, recompile with SQLITE_HAS_CODEC to enable.");
249252
throw exception;
250253
}
@@ -255,11 +258,14 @@ void Database::key(const std::string& aKey) const
255258
void Database::rekey(const std::string& aNewKey) const
256259
{
257260
#ifdef SQLITE_HAS_CODEC
258-
int pass_len = aNewKey.length();
259-
if (pass_len > 0) {
260-
const int ret = sqlite3_rekey(mpSQLite, aNewKey.c_str(), pass_len);
261+
int passLen = aNewKey.length();
262+
if (passLen > 0)
263+
{
264+
const int ret = sqlite3_rekey(mpSQLite, aNewKey.c_str(), passLen);
261265
check(ret);
262-
} else {
266+
}
267+
else
268+
{
263269
const int ret = sqlite3_rekey(mpSQLite, nullptr, 0);
264270
check(ret);
265271
}
@@ -273,14 +279,18 @@ void Database::rekey(const std::string& aNewKey) const
273279
// Test if a file contains an unencrypted database.
274280
bool Database::isUnencrypted(const std::string& aFilename)
275281
{
276-
if (aFilename.length() > 0) {
282+
if (aFilename.length() > 0)
283+
{
277284
std::ifstream fileBuffer(aFilename.c_str(), std::ios::in | std::ios::binary);
278285
char header[16];
279-
if (fileBuffer.is_open()) {
286+
if (fileBuffer.is_open())
287+
{
280288
fileBuffer.seekg(0, std::ios::beg);
281289
fileBuffer.getline(header, 16);
282290
fileBuffer.close();
283-
} else {
291+
}
292+
else
293+
{
284294
const SQLite::Exception exception("Error opening file: " + aFilename);
285295
throw exception;
286296
}

tests/Backup_test.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
#include <cstdio>
2323

24-
TEST(Backup, initException) {
24+
TEST(Backup, initException)
25+
{
2526
remove("backup_test.db3");
2627
SQLite::Database srcDB("backup_test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
2728
srcDB.exec("CREATE TABLE backup_test (id INTEGER PRIMARY KEY, value TEXT)");
@@ -34,7 +35,8 @@ TEST(Backup, initException) {
3435
remove("backup_test.db3");
3536
}
3637

37-
TEST(Backup, executeStepOne) {
38+
TEST(Backup, executeStepOne)
39+
{
3840
remove("backup_test.db3");
3941
remove("backup_test.db3.backup");
4042
SQLite::Database srcDB("backup_test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
@@ -66,7 +68,8 @@ TEST(Backup, executeStepOne) {
6668
remove("backup_test.db3.backup");
6769
}
6870

69-
TEST(Backup, executeStepAll) {
71+
TEST(Backup, executeStepAll)
72+
{
7073
remove("backup_test.db3");
7174
remove("backup_test.db3.backup");
7275
SQLite::Database srcDB("backup_test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
@@ -94,7 +97,8 @@ TEST(Backup, executeStepAll) {
9497
remove("backup_test.db3.backup");
9598
}
9699

97-
TEST(Backup, executeStepException) {
100+
TEST(Backup, executeStepException)
101+
{
98102
remove("backup_test.db3");
99103
remove("backup_test.db3.backup");
100104
SQLite::Database srcDB("backup_test.db3", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);

tests/Column_test.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
#include <stdint.h>
2222

2323

24-
TEST(Column, basis) {
24+
TEST(Column, basis)
25+
{
2526
// Create a new database
2627
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
2728
EXPECT_EQ(SQLite::OK, db.getErrorCode());
@@ -187,7 +188,8 @@ TEST(Column, basis) {
187188
}
188189
}
189190

190-
TEST(Column, getName) {
191+
TEST(Column, getName)
192+
{
191193
// Create a new database
192194
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
193195
EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT)"));
@@ -214,7 +216,8 @@ TEST(Column, getName) {
214216
#endif
215217
}
216218

217-
TEST(Column, stream) {
219+
TEST(Column, stream)
220+
{
218221
// Create a new database
219222
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE|SQLite::OPEN_CREATE);
220223
EXPECT_EQ(0, db.exec("CREATE TABLE test (msg TEXT)"));

tests/Database_test.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ void assertion_failed(const char* apFile, const long apLine, const char* apFunc,
2929
}
3030
#endif
3131

32-
TEST(SQLiteCpp, version) {
32+
TEST(SQLiteCpp, version)
33+
{
3334
EXPECT_STREQ(SQLITE_VERSION, SQLite::VERSION);
3435
EXPECT_EQ (SQLITE_VERSION_NUMBER, SQLite::VERSION_NUMBER);
3536
EXPECT_STREQ(SQLITE_VERSION, SQLite::getLibVersion());
3637
EXPECT_EQ (SQLITE_VERSION_NUMBER, SQLite::getLibVersionNumber());
3738
}
3839

39-
TEST(Database, ctorExecCreateDropExist) {
40+
TEST(Database, ctorExecCreateDropExist)
41+
{
4042
remove("test.db3");
4143
{
4244
// Try to open a non-existing database
@@ -70,7 +72,8 @@ SQLite::Database DatabaseBuilder(const char* apName)
7072
return SQLite::Database(apName, SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE);
7173
}
7274

73-
TEST(Database, moveConstructor) {
75+
TEST(Database, moveConstructor)
76+
{
7477
remove("test.db3");
7578
{
7679
// Create a new database, using the move constructor
@@ -87,7 +90,8 @@ TEST(Database, moveConstructor) {
8790

8891
#endif
8992

90-
TEST(Database, createCloseReopen) {
93+
TEST(Database, createCloseReopen)
94+
{
9195
remove("test.db3");
9296
{
9397
// Try to open the non-existing database
@@ -107,7 +111,8 @@ TEST(Database, createCloseReopen) {
107111
remove("test.db3");
108112
}
109113

110-
TEST(Database, inMemory) {
114+
TEST(Database, inMemory)
115+
{
111116
{
112117
// Create a new database
113118
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE);
@@ -126,7 +131,8 @@ TEST(Database, inMemory) {
126131
}
127132

128133
#if SQLITE_VERSION_NUMBER >= 3007015 // SQLite v3.7.15 is first version with PRAGMA busy_timeout
129-
TEST(Database, busyTimeout) {
134+
TEST(Database, busyTimeout)
135+
{
130136
{
131137
// Create a new database with default timeout of 0ms
132138
SQLite::Database db(":memory:");
@@ -163,7 +169,8 @@ TEST(Database, busyTimeout) {
163169
}
164170
#endif // SQLITE_VERSION_NUMBER >= 3007015
165171

166-
TEST(Database, exec) {
172+
TEST(Database, exec)
173+
{
167174
// Create a new database
168175
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE);
169176

@@ -224,7 +231,8 @@ TEST(Database, exec) {
224231
#endif
225232
}
226233

227-
TEST(Database, execAndGet) {
234+
TEST(Database, execAndGet)
235+
{
228236
// Create a new database
229237
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE);
230238

@@ -242,7 +250,8 @@ TEST(Database, execAndGet) {
242250
EXPECT_EQ(3, db.execAndGet("SELECT weight FROM test WHERE value=\"first\"").getInt());
243251
}
244252

245-
TEST(Database, execException) {
253+
TEST(Database, execException)
254+
{
246255
// Create a new database
247256
SQLite::Database db(":memory:", SQLite::OPEN_READWRITE);
248257
EXPECT_EQ(SQLite::OK, db.getErrorCode());
@@ -284,7 +293,8 @@ TEST(Database, execException) {
284293
// TODO: test Database::loadExtension()
285294

286295
#ifdef SQLITE_HAS_CODEC
287-
TEST(Database, encryptAndDecrypt) {
296+
TEST(Database, encryptAndDecrypt)
297+
{
288298
remove("test.db3");
289299
{
290300
// Try to open the non-existing database
@@ -328,7 +338,8 @@ TEST(Database, encryptAndDecrypt) {
328338
remove("test.db3");
329339
}
330340
#else // SQLITE_HAS_CODEC
331-
TEST(Database, encryptAndDecrypt) {
341+
TEST(Database, encryptAndDecrypt)
342+
{
332343
remove("test.db3");
333344
{
334345
// Try to open the non-existing database
@@ -350,4 +361,4 @@ TEST(Database, encryptAndDecrypt) {
350361
} // Close DB test.db3
351362
remove("test.db3");
352363
}
353-
#endif // SQLITE_HAS_CODEC
364+
#endif // SQLITE_HAS_CODEC

0 commit comments

Comments
 (0)