diff --git a/.travis.yml b/.travis.yml index 07242b86..8b3185e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ os: - linux - osx -dist: xenial +dist: bionic sudo: required compiler: @@ -23,12 +23,15 @@ notifications: install: - g++ --version - - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew upgrade cmake; fi - - cmake --version - - git clone https://github.com/HowardHinnant/date - - cd date - - git checkout tags/v2.4 - - cd .. + - 'if [ "$TRAVIS_OS_NAME" = "osx" ]; then + brew upgrade cmake; + else + wget -O - https://apt.kitware.com/keys/kitware-archive-latest.asc 2>/dev/null | gpg --dearmor - | sudo tee /etc/apt/trusted.gpg.d/kitware.gpg >/dev/null && + sudo apt-add-repository -y "deb https://apt.kitware.com/ubuntu/ bionic main" && + sudo apt-get update -qq -y && + sudo apt-get install -y cmake && + sudo rm -r /usr/local/cmake-3.12.4/; + fi' before_script: - mkdir build diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b15323e..b8de9fa4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,19 +23,24 @@ # (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 3.2 FATAL_ERROR) +### Preamble +cmake_minimum_required(VERSION 3.14) project(sqlpp11 VERSION 0.1 LANGUAGES CXX) -enable_testing() +### Project Wide Setup +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/") -option(ENABLE_TESTS "Build unit tests" On) +include(CTest) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") -find_package(HinnantDate REQUIRED) +### Dependencies +add_subdirectory(dependencies) + +### Main targets add_library(sqlpp11 INTERFACE) +add_library(sqlpp11::sqlpp11 ALIAS sqlpp11) -target_link_libraries(sqlpp11 INTERFACE HinnantDate::Date) +target_link_libraries(sqlpp11 INTERFACE date::date) target_include_directories(sqlpp11 INTERFACE $ @@ -64,6 +69,7 @@ target_compile_features(sqlpp11 INTERFACE cxx_variadic_templates ) +### Packaging install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/sqlpp11" DESTINATION include ) @@ -96,8 +102,7 @@ configure_file(cmake/Sqlpp11Config.cmake set(ConfigPackageLocation lib/cmake/Sqlpp11) install(EXPORT Sqlpp11Targets - FILE - Sqlpp11Targets.cmake + NAMESPACE sqlpp11:: DESTINATION ${ConfigPackageLocation} ) @@ -106,12 +111,12 @@ install( FILES "cmake/Sqlpp11Config.cmake" "${CMAKE_CURRENT_BINARY_DIR}/cmake/Sqlpp11ConfigVersion.cmake" - "cmake/Modules/FindHinnantDate.cmake" DESTINATION ${ConfigPackageLocation} ) -if(ENABLE_TESTS) +### Tests +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) add_subdirectory(tests) add_subdirectory(test_types) add_subdirectory(test_serializer) diff --git a/README.md b/README.md index a2ae3ffd..10a1893c 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,8 @@ Status: ------- Branch / Compiler | clang-3.4, gcc-4.9, Xcode-7 | MSVC 2015/2017 | Test Coverage ------------------| -------------------------------|-------------|--------------- -master | [![Build Status](https://travis-ci.org/rbock/sqlpp11.svg?branch=master)](https://travis-ci.org/rbock/sqlpp11?branch=master) | [![Build status](https://ci.appveyor.com/api/projects/status/eid7mwqgavo0h61h/branch/master?svg=true)](https://ci.appveyor.com/project/rbock/sqlpp11/branch/master) | [![Coverage Status](https://coveralls.io/repos/rbock/sqlpp11/badge.svg?branch=master)](https://coveralls.io/r/rbock/sqlpp11?branch=master) -develop | [![Build Status](https://travis-ci.org/rbock/sqlpp11.svg?branch=develop)](https://travis-ci.org/rbock/sqlpp11?branch=develop) | [![Build status](https://ci.appveyor.com/api/projects/status/eid7mwqgavo0h61h/branch/develop?svg=true)](https://ci.appveyor.com/project/rbock/sqlpp11/branch/develop) | [![Coverage Status](https://coveralls.io/repos/rbock/sqlpp11/badge.svg?branch=develop)](https://coveralls.io/r/rbock/sqlpp11?branch=develop) +master | [![Build Status](https://travis-ci.com/rbock/sqlpp11.svg?branch=master)](https://travis-ci.com/rbock/sqlpp11?branch=master) | [![Build status](https://ci.appveyor.com/api/projects/status/eid7mwqgavo0h61h/branch/master?svg=true)](https://ci.appveyor.com/project/rbock/sqlpp11/branch/master) | [![Coverage Status](https://coveralls.io/repos/rbock/sqlpp11/badge.svg?branch=master)](https://coveralls.io/r/rbock/sqlpp11?branch=master) +develop | [![Build Status](https://travis-ci.com/rbock/sqlpp11.svg?branch=develop)](https://travis-ci.com/rbock/sqlpp11?branch=develop) | [![Build status](https://ci.appveyor.com/api/projects/status/eid7mwqgavo0h61h/branch/develop?svg=true)](https://ci.appveyor.com/project/rbock/sqlpp11/branch/develop) | [![Coverage Status](https://coveralls.io/repos/rbock/sqlpp11/badge.svg?branch=develop)](https://coveralls.io/r/rbock/sqlpp11?branch=develop) Additional information available: --------------------------------- @@ -135,27 +135,23 @@ To demonstrate that sqlpp11 can work with other backends as well, here is an exp * STL Container: https://github.com/rbock/sqlpp11-connector-stl __Date Library:__ -sqlpp11 requires [Howard Hinnant's date library](https://github.com/HowardHinnant/date) for `date` and `date_time` data types. Sqlpp11 includes CMake search module for this, but if you didn't install this library system-wide, you need to point cmake to it: - -``` -cmake -DHinnantDate_ROOT_DIR=/%PATH_TO_HinnantDate_SOURCE%/ -``` +sqlpp11 requires [Howard Hinnant's date library](https://github.com/HowardHinnant/date) for `date` and `date_time` data types. Sqlpp11 uses FetchContent to pull the library automatically in the project. Build and Install ----------------- + +**Note**: Depending on how you use the lib, you might not need to install it (see Basic Usage) + __Build from Source:__ Download and unpack the latest release from https://github.com/rbock/sqlpp11/releases or clone the repository. Inside the directory run the following commands: ```bash -mkdir build -cd build -cmake .. -make -make install +cmake -B build +cmake --build build --target install ``` -The last step will install the library system wide. +The last step will build the library and install it system wide, therefore it might need admins right. __Install via Homebrew (MacOS):__ @@ -186,6 +182,12 @@ The following connector libraries for sqlpp11 are maintained as a separate packa Basic usage: ------------- +__Use with cmake__: +The library officially supports two ways how it can be used with cmake. +You can find examples for both methods in the example folder. + +1. Fetch content (Recommend, no installation required) +1. Find package (installation required, see above) __Create DDL files__: ``` diff --git a/cmake/Modules/FindHinnantDate.cmake b/cmake/Modules/FindHinnantDate.cmake deleted file mode 100644 index 8a2f1deb..00000000 --- a/cmake/Modules/FindHinnantDate.cmake +++ /dev/null @@ -1,99 +0,0 @@ -#.rst: -# FindHinnantDate -# --------------- -# -# This module finds Howard Hinnant's date and time library for C++11 and beyond -# See https://github.com/HowardHinnant/date for details. -# -# This will define the following variables:: -# -# HinnantDate_FOUND - True if the system has the library -# HinnantDate_INCLUDE_DIR - The directory which includes the header -# HinnantDate_ROOT_DIR - The base directory of the library -# -# and the following imported targets:: -# -# HinnantDate::Date - The target to use date/date.h -# -# You can set HinnantDate_ROOT_DIR as hint to the location of the library. -# -# The target will enable the required C++11 standard in your compiler. You can -# use any later standard but you have to enable them explicitly. - -# Copyright (c) 2016 Christian Dávid -# 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. - -cmake_minimum_required(VERSION 3.1) - -# ensure cache entry -set(HinnantDate_ROOT_DIR "${HinnantDate_ROOT_DIR}" CACHE PATH "Root directory of Howard Hinnant's date library") -set(HinnantDate_NOT_FOUND_MESSAGE "Could NOT find HinnantDate. -Maybe you need to adjust the search paths or HinnantDate_ROOT_DIR.") - -find_file(HinnantDate_INCLUDE_FILE - date/date.h include/date/date.h - HINTS - ${HinnantDate_ROOT_DIR} - ${HinnantDate_ROOT_DIR}/include -) -mark_as_advanced(HinnantDate_INCLUDE_FILE) - -if (HinnantDate_INCLUDE_FILE) - # Validate that correct file is found - file(STRINGS ${HinnantDate_INCLUDE_FILE} check_result - LIMIT_COUNT 1 - REGEX "^ *// Copyright [(]c[)] 2015.* Howard Hinnant *$" - ) - - if("${check_result}" STREQUAL "") - string(APPEND HinnantDate_NOT_FOUND_MESSAGE "\nRejecting found '${HinnantDate_INCLUDE_FILE}', it seems to be a name twin.") - unset(HinnantDate_INCLUDE_FILE CACHE) - else() - # Check succeeded, create target - get_filename_component(HinnantDate_INCLUDE_DIR "${HinnantDate_INCLUDE_FILE}" DIRECTORY) # remove filename - get_filename_component(HinnantDate_INCLUDE_DIR "${HinnantDate_INCLUDE_DIR}" DIRECTORY) # remove date dir - mark_as_advanced(HinnantDate_INCLUDE_DIR) - set(HinnantDate_ROOT_DIR "${HinnantDate_INCLUDE_DIR}") - unset(HinnantDate_NOT_FOUND_MESSAGE) - - if(NOT TARGET HinnantDate::Date) - add_library(HinnantDate::Date INTERFACE IMPORTED) - set_target_properties(HinnantDate::Date PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${HinnantDate_INCLUDE_DIR}" - INTERFACE_COMPILE_FEATURES "cxx_auto_type;cxx_static_assert;cxx_decltype;cxx_alias_templates;cxx_strong_enums" -# Due to cmake restrictions the standard cannot be set directly to interface imported targets. Instead required compile -# features are set (list maybe incomplete). Please note that this list shall be a minimal set of required features. -# CXX_STANDARD 11 -# CXX_STANDARD_REQUIRED true - ) - endif() - endif() -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(HinnantDate - REQUIRED_VARS HinnantDate_ROOT_DIR HinnantDate_INCLUDE_DIR - FAIL_MESSAGE ${HinnantDate_NOT_FOUND_MESSAGE} -) diff --git a/cmake/Sqlpp11Config.cmake b/cmake/Sqlpp11Config.cmake index 18ea9b1b..ed7b6900 100644 --- a/cmake/Sqlpp11Config.cmake +++ b/cmake/Sqlpp11Config.cmake @@ -26,7 +26,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") include(CMakeFindDependencyMacro) -find_dependency(HinnantDate REQUIRED) +find_dependency(date REQUIRED) include("${CMAKE_CURRENT_LIST_DIR}/Sqlpp11Targets.cmake") diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt new file mode 100644 index 00000000..90010ff9 --- /dev/null +++ b/dependencies/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright (c) 2020, Leon De Andrade +# 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. + +include(FetchContent) + +FetchContent_Declare(date + GIT_REPOSITORY https://github.com/HowardHinnant/date.git + GIT_TAG v3.0.0 +) + +add_subdirectory(hinnant_date) \ No newline at end of file diff --git a/dependencies/hinnant_date/CMakeLists.txt b/dependencies/hinnant_date/CMakeLists.txt new file mode 100644 index 00000000..27a9d2b3 --- /dev/null +++ b/dependencies/hinnant_date/CMakeLists.txt @@ -0,0 +1,25 @@ +# Copyright (c) 2020, Leon De Andrade +# 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. + +FetchContent_MakeAvailable(date) \ No newline at end of file diff --git a/examples/usage_fetch_content/CMakeLists.txt b/examples/usage_fetch_content/CMakeLists.txt new file mode 100644 index 00000000..10ca104d --- /dev/null +++ b/examples/usage_fetch_content/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (c) 2020, Leon De Andrade +# 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. + +### Preamble ### +cmake_minimum_required(VERSION 3.14) +project(Test VERSION 0.1 LANGUAGES CXX) + +##### Project wide setup #### +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +### Dependencies ### +add_subdirectory(dependencies) + +### Main Targets ### +add_subdirectory(src) \ No newline at end of file diff --git a/examples/usage_fetch_content/dependencies/CMakeLists.txt b/examples/usage_fetch_content/dependencies/CMakeLists.txt new file mode 100644 index 00000000..2987e759 --- /dev/null +++ b/examples/usage_fetch_content/dependencies/CMakeLists.txt @@ -0,0 +1,32 @@ +# Copyright (c) 2020, Leon De Andrade +# 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. + +include(FetchContent) + +FetchContent_Declare(sqlpp11 + GIT_REPOSITORY https://github.com/rbock/sqlpp11 + GIT_TAG origin/develop +) + +add_subdirectory(sqlpp11) \ No newline at end of file diff --git a/examples/usage_fetch_content/dependencies/sqlpp11/CMakeLists.txt b/examples/usage_fetch_content/dependencies/sqlpp11/CMakeLists.txt new file mode 100644 index 00000000..2c86850e --- /dev/null +++ b/examples/usage_fetch_content/dependencies/sqlpp11/CMakeLists.txt @@ -0,0 +1,26 @@ +# Copyright (c) 2020, Leon De Andrade +# 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. + +# Configure before sqlpp11 +FetchContent_MakeAvailable(sqlpp11) \ No newline at end of file diff --git a/examples/usage_fetch_content/src/CMakeLists.txt b/examples/usage_fetch_content/src/CMakeLists.txt new file mode 100644 index 00000000..cf207bf3 --- /dev/null +++ b/examples/usage_fetch_content/src/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2020, Leon De Andrade +# 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. + +add_executable(Test) +target_link_libraries(Test PRIVATE sqlpp11::sqlpp11) + +target_sources(Test + PRIVATE + main.cpp +) \ No newline at end of file diff --git a/examples/usage_fetch_content/src/main.cpp b/examples/usage_fetch_content/src/main.cpp new file mode 100644 index 00000000..13f814de --- /dev/null +++ b/examples/usage_fetch_content/src/main.cpp @@ -0,0 +1,8 @@ +#include +#include + +int main() +{ + select(sqlpp::value(false).as(sqlpp::alias::a)); + return 0; +} \ No newline at end of file diff --git a/examples/usage_find_package/CMakeLists.txt b/examples/usage_find_package/CMakeLists.txt new file mode 100644 index 00000000..e3eee50c --- /dev/null +++ b/examples/usage_find_package/CMakeLists.txt @@ -0,0 +1,38 @@ +# Copyright (c) 2020, Leon De Andrade +# 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. + +### Preamble ### +cmake_minimum_required(VERSION 3.14) +project(Test VERSION 0.1 LANGUAGES CXX) + +##### Project wide setup #### +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +### Dependencies ### +find_package(Sqlpp11 REQUIRED) + +### Main Targets ### +add_subdirectory(src) \ No newline at end of file diff --git a/examples/usage_find_package/src/CMakeLists.txt b/examples/usage_find_package/src/CMakeLists.txt new file mode 100644 index 00000000..cf207bf3 --- /dev/null +++ b/examples/usage_find_package/src/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright (c) 2020, Leon De Andrade +# 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. + +add_executable(Test) +target_link_libraries(Test PRIVATE sqlpp11::sqlpp11) + +target_sources(Test + PRIVATE + main.cpp +) \ No newline at end of file diff --git a/examples/usage_find_package/src/main.cpp b/examples/usage_find_package/src/main.cpp new file mode 100644 index 00000000..13f814de --- /dev/null +++ b/examples/usage_find_package/src/main.cpp @@ -0,0 +1,8 @@ +#include +#include + +int main() +{ + select(sqlpp::value(false).as(sqlpp::alias::a)); + return 0; +} \ No newline at end of file diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index ff11ac3d..ee359f2d 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -43,6 +43,7 @@ #include #include #include // Csaba Csoma suggests: unsafe_sql instead of verbatim +#include #include #include #include diff --git a/include/sqlpp11/parameterized_verbatim.h b/include/sqlpp11/parameterized_verbatim.h new file mode 100644 index 00000000..438a89ef --- /dev/null +++ b/include/sqlpp11/parameterized_verbatim.h @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2013-2020, Roland Bock, MacDue + * 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. + */ + +#ifndef SQLPP11_PARAMETERIZED_VERBATIM_COUNT_H +#define SQLPP11_PARAMETERIZED_VERBATIM_COUNT_H + +#include +#include +#include + +#include + +namespace sqlpp +{ + template + struct parameterized_verbatim_t : public expression_operators, ValueType>, + public alias_operators> + { + using _traits = make_traits; + using _nodes = detail::type_vector; + using _can_be_null = + std::true_type; // since we do not know what's going on inside the verbatim, we assume it can be null + + parameterized_verbatim_t( + const Expr expr, std::string verbatim_lhs, std::string verbatim_rhs) + : _expr(expr), _verbatim_lhs(std::move(verbatim_lhs)), _verbatim_rhs(std::move(verbatim_rhs)) { } + + parameterized_verbatim_t(const parameterized_verbatim_t&) = default; + parameterized_verbatim_t(parameterized_verbatim_t&&) = default; + parameterized_verbatim_t& operator=(const parameterized_verbatim_t&) = default; + parameterized_verbatim_t& operator=(parameterized_verbatim_t&&) = default; + ~parameterized_verbatim_t() = default; + + Expr _expr; + std::string _verbatim_lhs, _verbatim_rhs; + }; + + template + struct serializer_t> + { + using _serialize_check = consistent_t; + using T = parameterized_verbatim_t; + + static Context& _(const T& t, Context& context) + { + context << t._verbatim_lhs; + serialize(t._expr, context); + context << t._verbatim_rhs; + return context; + } + }; + + template + auto parameterized_verbatim(std::string lhs, Expr expr, std::string rhs) + -> parameterized_verbatim_t> + { + static_assert(is_expression_t>::value, "parameterized_verbatim() requires an expression as argument"); + return {expr, lhs, rhs}; + } + +} // namespace sqlpp + +#endif diff --git a/test_serializer/CMakeLists.txt b/test_serializer/CMakeLists.txt index b17c83ef..d7d9d145 100644 --- a/test_serializer/CMakeLists.txt +++ b/test_serializer/CMakeLists.txt @@ -27,13 +27,14 @@ set(test_serializer_names Blob CustomQuery DynamicWhere - ForUpdate - From - In - Insert + ForUpdate + From + In + Insert Over - TableAlias - Where + TableAlias + Where + ParameterizedVerbatim ) create_test_sourcelist(test_serializer_sources test_serializer_main.cpp ${test_serializer_names}) diff --git a/test_serializer/ParameterizedVerbatim.cpp b/test_serializer/ParameterizedVerbatim.cpp new file mode 100644 index 00000000..1f639c45 --- /dev/null +++ b/test_serializer/ParameterizedVerbatim.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2013-2020, Roland Bock, MacDue + * 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. + */ + +#include "compare.h" +#include + +#include + +SQLPP_ALIAS_PROVIDER(quester_player_level); + +int ParameterizedVerbatim(int, char* []) +{ + // An example thing that needs parameterized verbatim (as it's database specific) + auto checking_value_in_range = sqlpp::parameterized_verbatim( + "(quests.spawn_level_range @> CAST(", parameter(sqlpp::integer(), quester_player_level), " AS integer))"); + + compare(__LINE__, checking_value_in_range, "(quests.spawn_level_range @> CAST(? AS integer))"); + + return 0; +}