0
0
mirror of https://github.com/rbock/sqlpp11.git synced 2024-11-15 20:31:16 +08:00

Merge branch 'develop' of https://github.com/purpleKarrot/sqlpp11 into purpleKarrot-develop

This commit is contained in:
rbock 2015-05-30 15:25:54 +02:00
commit 0f3c239283
27 changed files with 233 additions and 121 deletions

View File

@ -2,39 +2,46 @@ language: cpp
os:
- linux
- osx
compiler:
# - clang # disabled clang due to missing libc++
- clang
- gcc
env:
- CONFIG=Release
- CONFIG=Debug
notifications:
email:
on_success: change
on_failure: always
before_install:
# install boost 1.50 (headers only), travis currently offers 1.46 and 1.48
- wget http://sourceforge.net/projects/boost/files/boost/1.50.0/boost_1_50_0.tar.bz2/download -O /tmp/boost.tar.bz2
- mkdir -p temp
- cd temp
- tar jxf /tmp/boost.tar.bz2 boost_1_50_0/boost # extract headers only
- sudo mkdir -p /usr/local/include/
- sudo ln -s $PWD/boost_1_50_0/boost /usr/local/include
- cd ..
#install g++-4.8
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update
- if [ "$CXX" = "g++" ]; then sudo apt-get install g++-4.8; fi
- if [ "$CXX" = "g++" ]; then export CXX="g++-4.8" CC="gcc-4.8"; fi
install:
- "mkdir -p $TRAVIS_BUILD_DIR/build/scripts"
- "cd $TRAVIS_BUILD_DIR/build/scripts"
- "cmake $TRAVIS_BUILD_DIR"
- CMAKE_VERSION_MM=3.2
- CMAKE_VERSION_FULL=$CMAKE_VERSION_MM.2
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
&& sudo add-apt-repository -y ppa:apokluda/boost1.53
&& sudo apt-get update -qq
&& sudo apt-get install -qq g++-4.8 libboost1.53-dev --no-install-recommends
&& sudo update-alternatives --quiet --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 60 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.6
&& sudo update-alternatives --quiet --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 40 --slave /usr/bin/g++ g++ /usr/bin/g++-4.8 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.8
&& sudo update-alternatives --quiet --set gcc /usr/bin/gcc-4.8
&& wget http://www.cmake.org/files/v${CMAKE_VERSION_MM}/cmake-${CMAKE_VERSION_FULL}-Linux-x86_64.sh
&& sudo sh cmake-${CMAKE_VERSION_FULL}-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir;
fi
- if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install boost cmake; fi
before_script:
- mkdir build
- cd build
- if [[ "$CXX" = "g++" && "$CONFIG" = "Debug" ]]; then export CXXFLAGS="--coverage"; fi
- cmake .. -DCMAKE_BUILD_TYPE=$CONFIG
script:
- "cd $TRAVIS_BUILD_DIR/build/scripts"
- "make -j3"
# test compile-time constraints
- "make test_sqlpp_constraints"
- cmake --build . --config $CONFIG
- ctest --output-on-failure
after_script:
- ../coveralls

View File

@ -22,25 +22,21 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(sqlpp11 VERSION 0.1 LANGUAGES CXX)
# Cygwin does not define WIN32 and warn if not use with this flag
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
project (sqlpp11)
enable_testing()
message(STATUS "Using ${CMAKE_CXX_COMPILER} (compiler id: ${CMAKE_CXX_COMPILER_ID})")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall ${CMAKE_CXX_FLAGS}")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall ${CMAKE_CXX_FLAGS}")
endif ()
set(CMAKE_CXX_FLAGS "-Wconversion -Wpedantic -Wshadow ${CMAKE_CXX_FLAGS}")
add_library(sqlpp11 INTERFACE)
target_include_directories(sqlpp11 INTERFACE
$<BUILD_INTERFACE:${sqlpp11_SOURCE_DIR}/include>
)
target_compile_features(sqlpp11 INTERFACE
cxx_variadic_templates
)
set(include_dir "${PROJECT_SOURCE_DIR}/include")
file(GLOB_RECURSE sqlpp_headers "${include_dir}/*.h")
include_directories("${include_dir}")
add_subdirectory(tests)
add_subdirectory(test_constraints)
add_subdirectory(examples)

13
CREDITS
View File

@ -3,14 +3,15 @@ Credits:
This library evolved through several stages and would probably not exist without input from other people:
* Michael Gmelin: Interface and requirements discussions
* Paul Körbitz: Feedback and extensions
* Peter Knoblach: Initial ideas
* Ulrich Küttler: Feedback and extensions
* Paul Körbitz: Feedback and extensions
* Peter Knoblach: Initial ideas
* Ulrich Küttler: Feedback and extensions
* Daniel Pfeifer: Buildsystem, Travis, Coveralls
* Metafeed GmbH: Production code using a forerunner version
* PPRO Financial Ltd: Production code using sqlpp11 and a forerunner version
* The boost community: Invaluable suggestions and critiques
* Metafeed GmbH: Production code using a forerunner version
* PPRO Financial Ltd: Production code using sqlpp11 and a forerunner version
* The boost community: Invaluable suggestions and critiques
* Meeting C++ Munich: Hosted the first talk about sqlpp11

View File

@ -1,6 +1,9 @@
sqlpp11
=======
[![Build Status](https://travis-ci.org/purpleKarrot/sqlpp11.svg?branch=develop)](https://travis-ci.org/purpleKarrot/sqlpp11)
[![Coverage Status](https://coveralls.io/repos/purpleKarrot/sqlpp11/badge.svg?branch=develop)](https://coveralls.io/r/purpleKarrot/sqlpp11?branch=develop)
A type safe embedded domain specific language for SQL queries and results in C++
Extensive documentation is found in the wiki, https://github.com/rbock/sqlpp11/wiki

31
coveralls Executable file
View File

@ -0,0 +1,31 @@
#!/bin/bash
if [ 0 -eq $(find -iname *.gcda | wc -l) ]
then
exit 0
fi
gcov --source-prefix ${TRAVIS_BUILD_DIR} --preserve-paths --relative-only $(find -iname *.gcda) 1>/dev/null || exit 0
cat >coverage.json <<EOF
{
"service_job_id": "${TRAVIS_JOB_ID}",
"service_name": "travis-ci",
"source_files": [
EOF
for file in include*.gcov
do
path=$(echo ${file} | sed -re 's%#%\/%g; s%.gcov$%%')
cat >>coverage.json <<EOF
{
"name": "${path}",
"source_digest": "$(md5sum ${TRAVIS_BUILD_DIR}/${path} | awk '{ print $1 }')",
"coverage": [$(tail -n +3 ${file} | cut -d ':' -f 1 | sed -re 's%^ +%%g; s%-%null%g; s%^[#=]+$%0%;' | tr $'\n' ',' | sed -re 's%,$%%')]
},
EOF
done
mv coverage.json coverage.json.tmp
cat >coverage.json <(head -n -1 coverage.json.tmp) <(echo -e " }\n ]\n}")
curl -F json_file=@coverage.json https://coveralls.io/api/v1/jobs

View File

@ -1,23 +1,50 @@
# Copyright (c) 2013-2015, Roland Bock
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
macro (build arg)
# Add headers to sources to enable file browsing in IDEs
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../tests")
add_executable("Sqlpp11Example${arg}" "${arg}.cpp" ${sqlpp_headers} "${CMAKE_CURRENT_SOURCE_DIR}/../tests/MockDb.h" "${CMAKE_CURRENT_LIST_DIR}/Sample.h")
add_test("${arg}" "Sqlpp11Example${arg}")
endmacro ()
set(example_names
#sample
insert
update
remove
select
)
#build(sample)
build(insert)
build(update)
build(remove)
build(select)
find_package(Boost 1.50)
if(Boost_FOUND)
MESSAGE(${Boost_INCLUDE_DIRS})
include_directories(${Boost_INCLUDE_DIRS})
build(ppgen)
list(APPEND example_names ppgen)
endif()
create_test_sourcelist(example_sources example_main.cpp ${example_names})
add_executable(sqlpp11_examples ${example_sources})
target_link_libraries(sqlpp11_examples PRIVATE sqlpp11 sqlpp11_testing)
foreach(example IN LISTS example_names)
add_test(NAME sqlpp11.examples.${example}
COMMAND sqlpp11_examples ${example}
)
endforeach()
#find_package(PythonInterp REQUIRED)

View File

@ -27,7 +27,7 @@
#include "MockDb.h"
#include <sqlpp11/sqlpp11.h>
int main()
int insert(int, char**)
{
MockDb db;
@ -64,4 +64,5 @@ int main()
pi.params.feature = true;
db(pi);
return 0;
}

View File

@ -61,7 +61,7 @@ SQLPP_DECLARE_TABLE(
(fatal, bool , SQLPP_NOT_NULL )
)
int main()
int ppgen(int, char**)
{
MockDb db;
tab_person::tab_person p;
@ -97,4 +97,5 @@ int main()
pi.params.feature = true;
db(pi);
return 0;
}

View File

@ -27,7 +27,7 @@
#include "MockDb.h"
#include <sqlpp11/sqlpp11.h>
int main()
int remove(int, char**)
{
MockDb db;
@ -37,4 +37,5 @@ int main()
db(remove_from(p)
.using_(p, q)
.where(p.feature == q.id and q.fatal == true));
return 0;
}

View File

@ -36,7 +36,7 @@
SQLPP_ALIAS_PROVIDER(cheesecake)
int main()
int select(int, char**)
{
static constexpr bool some_condition = true;
static constexpr bool some_other_condition = false;
@ -153,4 +153,5 @@ int main()
return 0;
}

View File

@ -27,7 +27,7 @@
#include "MockDb.h"
#include <sqlpp11/sqlpp11.h>
int main()
int update(int, char**)
{
MockDb db;
@ -35,4 +35,5 @@ int main()
//test::TabFeature q;
db(update(p).set(p.feature = 7).where(p.id == 23));
return 0;
}

View File

@ -1,31 +1,40 @@
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../tests")
add_custom_target(test_sqlpp_constraints COMMAND true)
# Copyright (c) 2013-2015, Roland Bock
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
function(test_constraint name pattern)
set(test sqlpp11.test_constraints.${name})
set(target sqlpp11_${name})
add_executable(${target} EXCLUDE_FROM_ALL ${name}.cpp)
target_link_libraries(${target} PRIVATE sqlpp11 sqlpp11_testing)
add_test(NAME ${test}
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target ${target}
)
set_property(TEST ${test} PROPERTY PASS_REGULAR_EXPRESSION ${pattern})
endfunction()
add_executable(
"${name}"
EXCLUDE_FROM_ALL
"${name}.cpp"
)
add_custom_command(OUTPUT "${name}.out"
COMMAND "${CMAKE_MAKE_PROGRAM}" "${name}" > "${CMAKE_CURRENT_BINARY_DIR}/${name}.out" 2>&1 || true
COMMAND grep "${pattern}" "${CMAKE_CURRENT_BINARY_DIR}/${name}.out" > /dev/null
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.cpp"
COMMENT "${name}"
VERBATIM)
add_custom_target("test_${name}" DEPENDS "${name}.out" COMMAND true)
add_dependencies(test_sqlpp_constraints "test_${name}")
endfunction(test_constraint)
test_constraint(count_of_count "count() cannot be used on an aggregate function")
test_constraint(max_of_max "max() cannot be used on an aggregate function")
test_constraint(count_of_count "count\\(\\) cannot be used on an aggregate function")
test_constraint(max_of_max "max\\(\\) cannot be used on an aggregate function")
test_constraint(no_conversion_operator_if_null_not_trivial "int i = row.alpha")
test_constraint(require_insert "required column is missing")
test_constraint(must_not_insert "one assignment is prohibited")

View File

@ -29,7 +29,7 @@
#include <sqlpp11/sqlpp11.h>
int main()
int BooleanExpression(int, char**)
{
MockDb db = {};
test::TabBar t;

View File

@ -1,25 +1,57 @@
# Copyright (c) 2013-2015, Roland Bock
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
macro (build_and_run arg)
# Add headers to sources to enable file browsing in IDEs
include_directories("${CMAKE_BINARY_DIR}/tests")
add_executable("${arg}" "${arg}.cpp" ${sqlpp_headers} "${CMAKE_CURRENT_LIST_DIR}/Sample.h")
add_test("${arg}" "${CMAKE_BINARY_DIR}/tests/${arg}")
endmacro ()
add_library(sqlpp11_testing INTERFACE)
target_include_directories(sqlpp11_testing INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(sqlpp11_testing INTERFACE -Wall -Wextra -pedantic)
build_and_run(BooleanExpressionTest)
build_and_run(CustomQueryTest)
build_and_run(InterpretTest)
build_and_run(InsertTest)
build_and_run(RemoveTest)
build_and_run(UpdateTest)
build_and_run(SelectTest)
build_and_run(SelectTypeTest)
build_and_run(FunctionTest)
build_and_run(PreparedTest)
build_and_run(Minimalistic)
build_and_run(ResultTest)
build_and_run(UnionTest)
build_and_run(WithTest)
set(test_names
BooleanExpression
CustomQuery
Interpret
Insert
Remove
Update
Select
SelectType
Function
Prepared
Minimalistic
Result
Union
With
)
create_test_sourcelist(test_sources test_main.cpp ${test_names})
add_executable(sqlpp11_tests ${test_sources})
target_link_libraries(sqlpp11_tests PRIVATE sqlpp11 sqlpp11_testing)
foreach(test IN LISTS test_names)
add_test(NAME sqlpp11.tests.${test}
COMMAND sqlpp11_tests ${test}
)
endforeach()
# if you want to use the generator, you can do something like this:
#find_package(PythonInterp REQUIRED)

View File

@ -29,7 +29,7 @@
#include <sqlpp11/sqlpp11.h>
#include <sqlpp11/custom_query.h>
int main()
int CustomQuery(int, char**)
{
MockDb db = {};
MockDb::_serializer_context_t printer;

View File

@ -34,7 +34,7 @@
SQLPP_ALIAS_PROVIDER(kaesekuchen)
int main()
int Function(int, char**)
{
MockDb db = {};
test::TabFoo f;

View File

@ -31,7 +31,7 @@
#include <iostream>
int main()
int Insert(int, char**)
{
MockDb db;
MockDb::_serializer_context_t printer;

View File

@ -29,7 +29,7 @@
#include <iostream>
int main()
int Interpret(int, char**)
{
MockDb db = {};
MockDb::_serializer_context_t printer;

View File

@ -1,5 +1,6 @@
#include <sqlpp11/sqlpp11.h>
int main()
int Minimalistic(int, char**)
{
return 0;
}

View File

@ -29,7 +29,7 @@
#include <sqlpp11/functions.h>
#include <sqlpp11/select.h>
int main()
int Prepared(int, char**)
{
MockDb db = {};
//test::TabFoo f;

View File

@ -30,7 +30,7 @@
#include "is_regular.h"
int main()
int Remove(int, char**)
{
MockDb db;
MockDb::_serializer_context_t printer;

View File

@ -32,7 +32,7 @@
static_assert(not sqlpp::enforce_null_result_treatment_t<MockDb>::value, "MockDb interprets NULL as trivial");
static_assert(sqlpp::enforce_null_result_treatment_t<EnforceDb>::value, "MockDb does not interpret NULL as trivial");
int main()
int Result(int, char**)
{
MockDb db = {};
EnforceDb edb {};

View File

@ -43,7 +43,7 @@ int64_t getColumn(Db&& db, const Column& column)
return 0;
}
int main()
int Select(int, char**)
{
MockDb db = {};
MockDb::_serializer_context_t printer;

View File

@ -41,7 +41,7 @@ namespace alias
SQLPP_ALIAS_PROVIDER(right)
}
int main()
int SelectType(int, char**)
{
MockDb db = {};
MockDb::_serializer_context_t printer;

View File

@ -29,7 +29,7 @@
#include <sqlpp11/alias_provider.h>
#include <iostream>
int main()
int Union(int, char**)
{
MockDb db;
MockDb::_serializer_context_t printer;

View File

@ -29,7 +29,7 @@
#include "MockDb.h"
#include "is_regular.h"
int main()
int Update(int, char**)
{
MockDb db;
MockDb::_serializer_context_t printer;

View File

@ -29,7 +29,7 @@
#include <sqlpp11/alias_provider.h>
#include <iostream>
int main()
int With(int, char**)
{
MockDb db;
MockDb::_serializer_context_t printer;