From f00d69c9ad01a10b99ce146ef6fbb9aa88afd616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Tue, 31 Jan 2017 08:53:06 +0100 Subject: [PATCH 01/12] Fix #112 format error in README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 525dfc4..0d9d995 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,7 @@ Developements and tests are done under the following OSs: - Ubuntu 14.04 (Travis CI) - Windows XP/10 - OS X 10.11 (Travis CI) + And the following IDEs/Compilers - GCC 4.8.4, 4.9.3, 5.3.0 and 6.1.1 (C++03, C++11, C++14, C++1z) - Clang 3.5 and 3.8 From 92bbeccffe53e13f31867e8c93a6179944def150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Fri, 3 Feb 2017 15:09:34 +0100 Subject: [PATCH 02/12] Fix #113 SQLite 3.7.15 minimum for sqlite3_errstr() SQLite 3.7.15 was release in 2012-12-12 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0d9d995..7c0b134 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ And the following IDEs/Compilers - an STL implementation (even an old one, like the one provided with VC6 should work) - exception support (the class Exception inherits from std::runtime_error) -- the SQLite library, either by linking to it dynamicaly or statically (install the libsqlite3-dev package under Debian/Ubuntu/Mint Linux), +- the SQLite library (3.7.15 minimum from 2012-12-12) either by linking to it dynamicaly or statically (install the libsqlite3-dev package under Debian/Ubuntu/Mint Linux), or by adding its source file in your project code base (source code provided in src/sqlite3 for Windows), with the SQLITE_ENABLE_COLUMN_METADATA macro defined (see http://www.sqlite.org/compile.html#enable_column_metadata). From f01a644dc040ca37f7d3c3ac96bd353b5fbccf52 Mon Sep 17 00:00:00 2001 From: dend Date: Sun, 12 Feb 2017 22:10:29 -0500 Subject: [PATCH 03/12] Added convenience functions for constructing objects from a row --- include/SQLiteCpp/Column.h | 17 +++++++++++ include/SQLiteCpp/Statement.h | 34 +++++++++++++++++++++ tests/Statement_test.cpp | 57 +++++++++++++++++++++++++++++++++++ 3 files changed, 108 insertions(+) diff --git a/include/SQLiteCpp/Column.h b/include/SQLiteCpp/Column.h index cfafa07..be0babc 100644 --- a/include/SQLiteCpp/Column.h +++ b/include/SQLiteCpp/Column.h @@ -260,5 +260,22 @@ private: */ std::ostream& operator<<(std::ostream& aStream, const Column& aColumn); +#if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) + // Create an instance of T from the first N columns, see declaration in Statement.h for full details + template + T Statement::getColumns() + { + checkRow(); + checkIndex(N - 1); + return getColumns(std::make_integer_sequence{}); + } + + // Helper function called by getColums + template + T Statement::getColumns(const std::integer_sequence) + { + return T(Column(mStmtPtr, Is)...); + } +#endif } // namespace SQLite diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index 594ee38..6d1d319 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -427,6 +427,40 @@ public: */ Column getColumn(const char* apName); +#if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) + /** + * @brief Return an instance of T constructed from copies of the first N columns + * + * Can be used to access the data of the current row of result when applicable, + * while the executeStep() method returns true. + * + * Throw an exception if there is no row to return a Column from: + * - if provided column count is out of bound + * - before any executeStep() call + * - after the last executeStep() returned false + * - after a reset() call + * + * Throw an exception if the specified column count is out of the [0, getColumnCount()) range. + * + * @tparam T Object type to construct + * @tparam N Number of columns + * + * @note Requires std=C++14 + */ + template + T getColumns(); + +private: + /** + * @brief Helper function used by getColumns to expand an integer_sequence used to generate + * the required Column objects + */ + template + T getColumns(const std::integer_sequence); + +public: +#endif + /** * @brief Test if the column value is NULL * diff --git a/tests/Statement_test.cpp b/tests/Statement_test.cpp index 7f38b6b..8bd626c 100644 --- a/tests/Statement_test.cpp +++ b/tests/Statement_test.cpp @@ -651,3 +651,60 @@ TEST(Statement, getName) { EXPECT_EQ("msg", oname1); #endif } + +#if __cplusplus >= 201402L || (defined(_MSC_VER) && _MSC_VER >= 1900) +TEST(Statement, getColumns) { + struct GetRowTestStruct + { + int id; + std::string msg; + int integer; + double real; + GetRowTestStruct(int _id, std::string _msg, int _integer, double _real) + : id(_id), msg(_msg), integer(_integer), real(_real) + {} + + GetRowTestStruct(int _id, const std::string& _msg) + : id(_id), msg(_msg), integer(-1), real(0.0) + {} + }; + + // Create a new database + SQLite::Database db(":memory:", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE); + EXPECT_EQ(SQLite::OK, db.getErrorCode()); + EXPECT_EQ(SQLite::OK, db.getExtendedErrorCode()); + + // Create a new table + EXPECT_EQ(0, db.exec("CREATE TABLE test (id INTEGER PRIMARY KEY, msg TEXT, int INTEGER, double REAL)")); + EXPECT_EQ(SQLite::OK, db.getErrorCode()); + EXPECT_EQ(SQLite::OK, db.getExtendedErrorCode()); + + // Create a first row + EXPECT_EQ(1, db.exec("INSERT INTO test VALUES (NULL, \"first\", 123, 0.123)")); + EXPECT_EQ(1, db.getLastInsertRowid()); + EXPECT_EQ(1, db.getTotalChanges()); + + // Compile a SQL query + SQLite::Statement query(db, "SELECT * FROM test"); + EXPECT_STREQ("SELECT * FROM test", query.getQuery().c_str()); + EXPECT_EQ(4, query.getColumnCount()); + query.executeStep(); + EXPECT_TRUE(query.isOk()); + EXPECT_FALSE(query.isDone()); + + // Get all columns + auto testStruct = query.getColumns(); + EXPECT_EQ(1, testStruct.id); + EXPECT_EQ("first", testStruct.msg); + EXPECT_EQ(123, testStruct.integer); + EXPECT_EQ(0.123, testStruct.real); + + // Get only the first 2 columns + auto testStruct2 = query.getColumns(); + EXPECT_EQ(1, testStruct2.id); + EXPECT_EQ("first", testStruct2.msg); + EXPECT_EQ(-1, testStruct2.integer); + EXPECT_EQ(0.0, testStruct2.real); +} +#endif + From f4a7e7c7ea02563a1165fc764b9173ff99d171a6 Mon Sep 17 00:00:00 2001 From: dunkelfalke Date: Tue, 21 Mar 2017 17:45:39 +0100 Subject: [PATCH 04/12] Update Statement.h Missing parameter name in the documentation comment --- include/SQLiteCpp/Statement.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index 6d1d319..030eab9 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -599,7 +599,7 @@ private: /** * @brief Check if a return code equals SQLITE_OK, else throw a SQLite::Exception with the SQLite error message * - * @param[in] SQLite return code to test against the SQLITE_OK expected value + * @param[in] aRet SQLite return code to test against the SQLITE_OK expected value */ inline void check(const int aRet) const { From 8387b594eb42f089c0a5b4979bc62b152efff5db Mon Sep 17 00:00:00 2001 From: Timothy Rae Date: Mon, 27 Mar 2017 18:04:44 +0900 Subject: [PATCH 05/12] Add install step --- CMakeLists.txt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 129b819..a875e96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,12 +161,22 @@ include_directories("${PROJECT_SOURCE_DIR}/include") # add sources of the wrapper as a "SQLiteCpp" static library add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT}) -target_include_directories(SQLiteCpp PUBLIC "${PROJECT_SOURCE_DIR}/include") if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fPIC") endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) +# Allow the library to be installed via "make install" and found with "find_package" +install(TARGETS SQLiteCpp + EXPORT ${PROJECT_NAME}Config + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + COMPONENT libraries) +target_include_directories(SQLiteCpp PUBLIC + $ + $) +install(DIRECTORY include/ DESTINATION include COMPONENT headers FILES_MATCHING REGEX ".*\\.(hpp|h)$") +install(EXPORT ${PROJECT_NAME}Config DESTINATION lib/cmake/${PROJECT_NAME}) ## Build provided copy of SQLite3 C library ## From 4c339031f062c73abe0081207e4ff0cfa0e9e17c Mon Sep 17 00:00:00 2001 From: Timothy Rae Date: Fri, 31 Mar 2017 12:12:46 +0900 Subject: [PATCH 06/12] Remove const from Database::isUnencrypted() return type Compiling with gcc pedantic mode was leading to a warning: "type qualifiers ignored on function return type" --- include/SQLiteCpp/Database.h | 2 +- src/Database.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/SQLiteCpp/Database.h b/include/SQLiteCpp/Database.h index 0129809..d3184c0 100644 --- a/include/SQLiteCpp/Database.h +++ b/include/SQLiteCpp/Database.h @@ -412,7 +412,7 @@ public: * * @throw SQLite::Exception in case of error */ - static const bool isUnencrypted(const std::string& aFilename); + static bool isUnencrypted(const std::string& aFilename); private: /// @{ Database must be non-copyable diff --git a/src/Database.cpp b/src/Database.cpp index cfa5447..a63b3ff 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -265,7 +265,7 @@ void Database::rekey(const std::string& aNewKey) const } // Test if a file contains an unencrypted database. -const bool Database::isUnencrypted(const std::string& aFilename) +bool Database::isUnencrypted(const std::string& aFilename) { if (aFilename.length() > 0) { std::ifstream fileBuffer(aFilename.c_str(), std::ios::in | std::ios::binary); From b23f2e155f4de21d24cabd72fdb0d994952acf02 Mon Sep 17 00:00:00 2001 From: Timothy Rae Date: Fri, 31 Mar 2017 12:22:38 +0900 Subject: [PATCH 07/12] Use -Wextra flag with gcc From the manual: This enables some extra warning flags that are not enabled by -Wall. (This option used to be called -W. The older name is still supported, but the newer name is more descriptive.) -Wclobbered -Wempty-body -Wignored-qualifiers -Wimplicit-fallthrough=3 -Wmissing-field-initializers -Wmissing-parameter-type (C only) -Wold-style-declaration (C only) -Woverride-init -Wsign-compare (C only) -Wtype-limits -Wuninitialized -Wshift-negative-value (in C++03 and in C99 and newer) -Wunused-parameter (only with -Wunused or -Wall) -Wunused-but-set-parameter (only with -Wunused or -Wall) --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a875e96..9e0ba8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ else (MSVC) set(CPPLINT_ARG_OUTPUT "--output=eclipse") set(CPPCHECK_ARG_TEMPLATE "--template=gcc") # Useful compile flags and extra warnings - add_compile_options(-fstack-protector -Wall -Winit-self -Wswitch-enum -Wshadow -Winline) + add_compile_options(-fstack-protector -Wall -Wextra -Winit-self -Wswitch-enum -Wshadow -Winline) if (CMAKE_COMPILER_IS_GNUCXX) # GCC flags if (SQLITECPP_USE_GCOV AND CMAKE_COMPILER_IS_GNUCXX) From 400ab71fa338ac0ccd9617f24e626902e190e8a9 Mon Sep 17 00:00:00 2001 From: Timothy Rae Date: Fri, 31 Mar 2017 12:22:48 +0900 Subject: [PATCH 08/12] Fix unused parameter warning --- src/Database.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Database.cpp b/src/Database.cpp index a63b3ff..164f3e3 100644 --- a/src/Database.cpp +++ b/src/Database.cpp @@ -259,6 +259,7 @@ void Database::rekey(const std::string& aNewKey) const check(ret); } #else // SQLITE_HAS_CODEC + static_cast(aNewKey); // silence unused parameter warning const SQLite::Exception exception("No encryption support, recompile with SQLITE_HAS_CODEC to enable."); throw exception; #endif // SQLITE_HAS_CODEC From 2123ef034850039c54b47d493ec09907dedb797b Mon Sep 17 00:00:00 2001 From: Timothy Rae Date: Fri, 31 Mar 2017 12:40:58 +0900 Subject: [PATCH 09/12] Use pedantic warnings From the gcc manual: Issue all the warnings demanded by strict ISO C and ISO C++; reject all programs that use forbidden extensions, and some other programs that do not follow ISO C and ISO C++. For ISO C, follows the version of the ISO C standard specified by any -std option used. Note: ISO C++98 doesn't support the "long long" data type, so we disable that warning -Winit-self can be removed as it's enabled by -Wall --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e0ba8c..c87dee5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ else (MSVC) set(CPPLINT_ARG_OUTPUT "--output=eclipse") set(CPPCHECK_ARG_TEMPLATE "--template=gcc") # Useful compile flags and extra warnings - add_compile_options(-fstack-protector -Wall -Wextra -Winit-self -Wswitch-enum -Wshadow -Winline) + add_compile_options(-fstack-protector -Wall -Wextra -Wpedantic -Wno-long-long -Wswitch-enum -Wshadow -Winline) if (CMAKE_COMPILER_IS_GNUCXX) # GCC flags if (SQLITECPP_USE_GCOV AND CMAKE_COMPILER_IS_GNUCXX) From a537dd637530988a08b464c988d43e8ddb489bb0 Mon Sep 17 00:00:00 2001 From: Volker Braun Date: Thu, 6 Apr 2017 16:20:33 +0200 Subject: [PATCH 10/12] Make cpplint.py Python-3 compatible --- cpplint.py | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/cpplint.py b/cpplint.py index 6b97648..8fecfa9 100755 --- a/cpplint.py +++ b/cpplint.py @@ -53,6 +53,15 @@ import sys import unicodedata +try: + xrange(0,1) + PY3 = False +except NameError: + PY3 = True # Python 3 + xrange = range + unicode = str + + _USAGE = """ Syntax: cpplint.py [--verbose=#] [--output=vs7] [--filter=-x,+y,...] [--counting=total|toplevel|detailed] [--root=subdir] @@ -736,7 +745,7 @@ class _CppLintState(object): def PrintErrorCounts(self): """Print a summary of errors by category, and the total.""" # SRombauts: "cpplint:" prefix - for category, count in self.errors_by_category.iteritems(): + for category, count in self.errors_by_category.items(): sys.stderr.write('cpplint: Category \'%s\' errors found: %d\n' % (category, count)) # SRombauts: "cpplint:" prefix and error message only when appropriate @@ -3694,7 +3703,7 @@ def _GetTextInside(text, start_pattern): # Give opening punctuations to get the matching close-punctuations. matching_punctuation = {'(': ')', '{': '}', '[': ']'} - closing_punctuation = set(matching_punctuation.itervalues()) + closing_punctuation = set(matching_punctuation.values()) # Find the position to start extracting text. match = re.search(start_pattern, text, re.M) @@ -4779,10 +4788,11 @@ def main(): # Change stderr to write with replacement characters so we don't die # if we try to print something containing non-ASCII characters. - sys.stderr = codecs.StreamReaderWriter(sys.stderr, - codecs.getreader('utf8'), - codecs.getwriter('utf8'), - 'replace') + if not PY3: + sys.stderr = codecs.StreamReaderWriter(sys.stderr, + codecs.getreader('utf8'), + codecs.getwriter('utf8'), + 'replace') _cpplint_state.ResetErrorCounts() for filename in filenames: From 03b229380518367167561516acc3947a91f46c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Sat, 8 Apr 2017 14:36:18 +0200 Subject: [PATCH 11/12] Update README.md Copyright notice 2017 and PayPal.me link & logo --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7c0b134..bec4d5e 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,6 @@ SQLiteC++ [![Coveralls](https://img.shields.io/coveralls/SRombauts/SQLiteCpp.svg)](https://coveralls.io/github/SRombauts/SQLiteCpp "Coveralls test coverage") [![Join the chat at https://gitter.im/SRombauts/SQLiteCpp](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/SRombauts/SQLiteCpp?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - SQLiteC++ (SQLiteCpp) is a smart and easy to use C++ SQLite3 wrapper. See SQLiteC++ website http://srombauts.github.com/SQLiteCpp on GitHub. @@ -22,7 +21,8 @@ with a few intuitive and well documented C++ classes. ### License: -Copyright (c) 2012-2016 Sébastien Rombauts (sebastien.rombauts@gmail.com) +Copyright (c) 2012-2017 Sébastien Rombauts (sebastien.rombauts@gmail.com) +    Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt or copy at http://opensource.org/licenses/MIT) From 0938ca68a704ef4c255e6511c4536dcb38040013 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Sat, 8 Apr 2017 21:37:20 +0200 Subject: [PATCH 12/12] Set theme jekyll-theme-slate --- README.md | 4 +--- _config.yml | 1 + 2 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 _config.yml diff --git a/README.md b/README.md index bec4d5e..02b8cce 100644 --- a/README.md +++ b/README.md @@ -10,8 +10,6 @@ SQLiteC++ SQLiteC++ (SQLiteCpp) is a smart and easy to use C++ SQLite3 wrapper. -See SQLiteC++ website http://srombauts.github.com/SQLiteCpp on GitHub. - Keywords: sqlite, sqlite3, C, library, wrapper C++ ## About SQLiteC++: @@ -22,7 +20,7 @@ with a few intuitive and well documented C++ classes. ### License: Copyright (c) 2012-2017 Sébastien Rombauts (sebastien.rombauts@gmail.com) -    + Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt or copy at http://opensource.org/licenses/MIT) diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..c741881 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-slate \ No newline at end of file