Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ end_of_line = lf
# 2 space indentation for CI configuration
[*.yml]
indent_style = space
indent_size = 4
indent_size = 2
68 changes: 42 additions & 26 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,47 +16,60 @@ matrix:
# GCC on Linux
##########################################################################

# GCC Debug build with GCov for coverage build
- dist: bionic
env:
- cc=gcc
- cxx=g++
- CXXFLAGS=""
- cc=gcc cxx=g++
- BUILD_TYPE=Debug
- ASAN=ON GCOV=ON
- COVERALLS=true


# GCC Debug build with Valgrind instead of Address Sanitizer
- dist: bionic
env:
- cc=gcc cxx=g++
- BUILD_TYPE=Debug
- VALGRIND=true

# GCC Release build
- dist: bionic
env:
- cc=gcc cxx=g++
- BUILD_TYPE=Release

- dist: xenial
env:
- cc=gcc
- cxx=g++
- CXXFLAGS=""
- cc=gcc cxx=g++
- BUILD_TYPE=Debug
- ASAN=ON

- dist: trusty
env:
- cc=gcc
- cxx=g++
- CXXFLAGS=""
- cc=gcc cxx=g++
- BUILD_TYPE=Debug
- ASAN=ON

##########################################################################
# Clang on Linux
##########################################################################

- dist: bionic
env:
- cc=clang
- cxx=clang++
- CXXFLAGS=""
- cc=clang cxx=clang++
- BUILD_TYPE=Debug
- ASAN=ON

- dist: xenial
env:
- cc=clang
- cxx=clang++
- CXXFLAGS=""
- cc=clang cxx=clang++
- BUILD_TYPE=Debug
- ASAN=ON

- dist: trusty
env:
- cc=clang
- cxx=clang++
- CXXFLAGS=""
- cc=clang cxx=clang++
- BUILD_TYPE=Debug
- ASAN=ON

##########################################################################
# Clang on OSX
Expand All @@ -65,24 +78,25 @@ matrix:
# Latest XCode
- os: osx
env:
- cc=clang
- cxx=clang++
- CXXFLAGS=""
- cc=clang cxx=clang++
- BUILD_TYPE=Debug
- ASAN=ON

# XCode 8.3
- os: osx
osx_image: xcode8.3
env:
- cc=clang
- cxx=clang++
- CXXFLAGS=""
- cc=clang cxx=clang++
- BUILD_TYPE=Debug
- ASAN=ON

before_install:
# Set the compiler environment variables properly
- export CC=${cc}
- export CXX=${cxx}
- ${CC} --version
- ${CXX} --version
- if [[ "$VALGRIND" == "true" ]]; then sudo apt-get install -qq valgrind ; fi

install:
# coveralls test coverage:
Expand All @@ -92,13 +106,15 @@ install:
before_script:
- mkdir build
- cd build
- cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=Debug -DSQLITECPP_USE_ASAN=ON -DSQLITECPP_USE_GCOV=ON -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..
- cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DSQLITECPP_USE_ASAN=$ASAN -DSQLITECPP_USE_GCOV=$GCOV -DSQLITECPP_BUILD_EXAMPLES=ON -DSQLITECPP_BUILD_TESTS=ON ..

# build examples, and run tests (ie make & make test)
script:
- cmake --build .
- export ASAN_OPTIONS=verbosity=1:debug=1
- ctest --verbose --output-on-failure
- if [[ "$VALGRIND" == "true" ]]; then valgrind --leak-check=full --error-exitcode=1 ./SQLiteCpp_example1 ; fi
- if [[ "$VALGRIND" == "true" ]]; then valgrind --leak-check=full --error-exitcode=1 ./SQLiteCpp_tests ; fi

# generate and publish GCov coveralls results
after_success:
Expand Down
14 changes: 8 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ Mar 30 2012
- Start of a new thin C++ SQLite wrapper

Apr 2 2012
- The wrapper is functionnal
- The wrapper is functional
- Added documentation and examples
- Publication on GitHub

Version 0.1.0 - Apr 4 2012
- Added a Database::exec() methode to execute simple SQL statement
- Added a Database::exec() method to execute simple SQL statement
- Added a version number like in sqlite3.h, starting with 0.1.0

Version 0.2.0 - Apr 11 2012
Expand Down Expand Up @@ -75,7 +75,7 @@ Version 1.3.0 - November 1 2015
- Added Backup class

Version 1.3.1 - February 10 2016
- Swith Linux/Mac build to the provided SQLite3 C library
- Switch Linux/Mac build to the provided SQLite3 C library
- Update SQLite3 from 3.8.8.3 to latest 3.10.2 (2016-01-20)
- Remove warnings
- Remove biicode support (defunct service, servers will shutdown the 16th of February 2016)
Expand Down Expand Up @@ -157,9 +157,11 @@ Version 2.5.0 - December 31 2019
- #251 Added example for getHeaderInfo()

Version 3.0.0 - January 1 2020
- C++11 minimum
- C++11 is now required
- CMake 3.1 minimum
- Visual Studio 2015 minimum
- Googletest 1.10
- Remove Statement::isOk() deprecated in 2.2.0 when renamed to Statement::hasRow()
- Update Googletest to latest release 1.10
- Add Github Actions continuous integration solution
- Add Valgrind memcheck tool to Travis CI
- Remove Statement::isOk() deprecated in 2.2.0 when renamed to Statement::hasRow()
- Replace Database::backup() "C" implementation by calling the Backup class
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ 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 -Wpedantic -Wno-long-long -Wswitch-enum -Wshadow -Winline)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-c++0x-compat") # C++ only
add_compile_options(-fstack-protector)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wswitch-enum -Wshadow -Wno-long-long") # C++ only, don't bother with sqlite3
if (CMAKE_COMPILER_IS_GNUCXX)
# GCC flags
option(SQLITECPP_USE_GCOV "USE GCov instrumentation." OFF)
if (SQLITECPP_USE_GCOV)
message (STATUS "Using GCov instrumentation")
add_compile_options (-coverage) # NOTE -fkeep-inline-functions would be usefull but not working with current google test and gcc 4.8
add_compile_options (-coverage) # NOTE -fkeep-inline-functions would be useful but not working with current Google test and GCC 4.8
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -coverage")
endif ()
endif (CMAKE_COMPILER_IS_GNUCXX)
Expand Down Expand Up @@ -83,7 +83,7 @@ endif ()

## Build the C++ Wrapper ##

# adding a new file require explicittly modifing the CMakeLists.txt
# adding a new file require explicitly modifying the CMakeLists.txt
# so that CMake knows that it should rebuild the project (it is best practice)

# list of sources files of the library
Expand Down Expand Up @@ -307,7 +307,7 @@ if (SQLITECPP_BUILD_EXAMPLES)
# add the basic example executable
add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES})
target_link_libraries(SQLiteCpp_example1 SQLiteCpp sqlite3)
# Link target with pthread and dl for linux
# Link target with pthread and dl for Linux
if (UNIX)
target_link_libraries(SQLiteCpp_example1 pthread)
if (NOT APPLE)
Expand All @@ -329,12 +329,12 @@ if (SQLITECPP_BUILD_TESTS)
if (GTEST_FOUND)
target_link_libraries(SQLiteCpp_tests GTest::GTest GTest::Main SQLiteCpp sqlite3)
else (GTEST_FOUND)
# deactivate some warnings for compiling the gtest library
# deactivate some warnings for compiling the googletest library
if (NOT MSVC)
add_compile_options(-Wno-variadic-macros -Wno-long-long -Wno-switch-enum -Wno-float-equal -Wno-conversion-null -Wno-switch-default -Wno-pedantic)
endif (NOT MSVC)

# add the subdirectory containing the CMakeLists.txt for the gtest library
# add the subdirectory containing the CMakeLists.txt for the googletest library
if (NOT EXISTS "${PROJECT_SOURCE_DIR}/googletest/CMakeLists.txt")
message(FATAL_ERROR "Missing 'googletest' submodule! Either use 'git submodule init' and 'git submodule update' to get googletest according to the README, or deactivate unit tests with -DSQLITECPP_BUILD_TESTS=OFF")
endif ()
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Developments and tests are done under the following OSs:
- Windows 10, and Windows Server 2012 R2 & Windows Server 2016 (AppVeyor)
- OS X 10.11 (Travis CI)
- Github Actions
- Valgrind memcheck tool

And the following IDEs/Compilers
- GCC 4.8.4, 5.3.0 and 7.1.1 (C++11, C++14, C++17)
Expand Down
2 changes: 0 additions & 2 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Switch to C++11 for v3.0.0

Add a Tutorial for SQLite newbies
Add a real example in the form of a small interactive console application

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt
# or copy at http://opensource.org/licenses/MIT)

# exit on firts error
# exit on first error
set -e

mkdir -p build
Expand Down
6 changes: 6 additions & 0 deletions include/SQLiteCpp/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,12 @@ class Database
*/
static Header getHeaderInfo(const std::string& aFilename);

// Parse SQLite header data from a database file.
Header getHeaderInfo()
{
return getHeaderInfo(mFilename);
}

/**
* @brief BackupType for the backup() method
*/
Expand Down
32 changes: 18 additions & 14 deletions src/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,28 +287,32 @@ Header Database::getHeaderInfo(const std::string& aFilename)

if (aFilename.empty())
{
throw SQLite::Exception("Could not open database, the aFilename parameter was empty.");
throw SQLite::Exception("Filename parameter is empty");
}

std::ifstream fileBuffer(aFilename.c_str(), std::ios::in | std::ios::binary);

if (fileBuffer.is_open())
{
fileBuffer.seekg(0, std::ios::beg);
fileBuffer.read(pBuf, 100);
fileBuffer.close();
strncpy(pHeaderStr, pBuf, 16);
}

else
{
throw SQLite::Exception("Error opening file: " + aFilename);
std::ifstream fileBuffer(aFilename.c_str(), std::ios::in | std::ios::binary);
if (fileBuffer.is_open())
{
fileBuffer.seekg(0, std::ios::beg);
fileBuffer.read(pBuf, 100);
fileBuffer.close();
if (fileBuffer.gcount() < 100)
{
throw SQLite::Exception("File " + aFilename + " is too short");
}
}
else
{
throw SQLite::Exception("Error opening file " + aFilename);
}
}

// If the "magic string" can't be found then header is invalid, corrupt or unreadable
strncpy(pHeaderStr, pBuf, 16);
if (!strncmp(pHeaderStr, "SQLite format 3", 15) == 0)
{
throw SQLite::Exception("Invalid or encrypted SQLite header");
throw SQLite::Exception("Invalid or encrypted SQLite header in file " + aFilename);
}

h.pageSizeBytes = (buf[16] << 8) | buf[17];
Expand Down
Loading