diff --git a/CMakeLists.txt b/CMakeLists.txt index 588002d0..56ee04e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,8 @@ project(sqlpp11 VERSION 0.1 LANGUAGES CXX) enable_testing() +option(ENABLE_TESTS "Build unit tests" On) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") find_package(HinnantDate REQUIRED) @@ -104,10 +106,11 @@ install( ${ConfigPackageLocation} ) -add_subdirectory(tests) -add_subdirectory(test_types) -add_subdirectory(test_serializer) -add_subdirectory(test_static_asserts) -add_subdirectory(test_constraints) -add_subdirectory(test_scripts) -add_subdirectory(examples) +if(ENABLE_TESTS) + add_subdirectory(tests) + add_subdirectory(test_types) + add_subdirectory(test_serializer) + add_subdirectory(test_static_asserts) + add_subdirectory(test_constraints) + add_subdirectory(test_scripts) +endif() \ No newline at end of file diff --git a/README.md b/README.md index 3bb6e365..81eb96a8 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,7 @@ if (const auto& row = db(select(foo.name.as(cheese)).from(foo).where(foo.id == 1 } // selecting a single row with a single result: -return db(select(count(foo.id)).from(foo).where(true)).front().count; +return db(select(count(foo.id)).from(foo).unconditionally()).front().count; Of course there are joins and subqueries, more functions, order_by, group_by etc. These will be documented soon. @@ -143,17 +143,39 @@ 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 should modify CMakeLists.txt or add some flags to compile sqlpp11: +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%/ -DHinnantDate_INCLUDE_DIR=/%PATH_TO_HinnantDate_SOURCE%/ +cmake -DHinnantDate_ROOT_DIR=/%PATH_TO_HinnantDate_SOURCE%/ ``` +Build and Install +----------------- +__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 +``` + +The last step will install the library system wide. + +__Install via Homebrew (MacOS):__ + +```bash +brew install marvin182/zapfhahn/sqlpp11 +``` + +Some connectors can be installed with the formula. See `brew info marvin182/zapfhahn/sqlpp11` for available options. + + Basic usage: ------------- -__Linux install:__ -git clone date library, needed connectors, cmake and make install them. - __Create DDL files__: ``` diff --git a/cmake/Modules/FindHinnantDate.cmake b/cmake/Modules/FindHinnantDate.cmake index 7ae59c96..d582f949 100644 --- a/cmake/Modules/FindHinnantDate.cmake +++ b/cmake/Modules/FindHinnantDate.cmake @@ -53,7 +53,7 @@ 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.h + date.h date/date.h HINTS ${HinnantDate_ROOT_DIR} ) mark_as_advanced(HinnantDate_INCLUDE_FILE) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt deleted file mode 100644 index 9046f915..00000000 --- a/examples/CMakeLists.txt +++ /dev/null @@ -1,56 +0,0 @@ -# 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. - -set(example_names - #sample - insert - update - remove - select - ) - -find_package(Boost 1.50) -if(Boost_FOUND) - include_directories(${Boost_INCLUDE_DIRS}) - 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) - -#add_custom_command( -# OUTPUT ${CMAKE_CURRENT_LIST_DIR}/Sample.h -# COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/ddl2cpp ${CMAKE_CURRENT_LIST_DIR}/sample.sql Sample test -# DEPENDS ${CMAKE_CURRENT_LIST_DIR}/sample.sql -# ) - diff --git a/examples/README.md b/examples/README.md deleted file mode 100644 index b903cdb6..00000000 --- a/examples/README.md +++ /dev/null @@ -1,5 +0,0 @@ -These examples were used for a talk at CppCon 2014 and are kept here for reference. - -They are probably not self explanatory. - -It is certainly more useful to look into the Wiki for documentation. diff --git a/examples/Sample.h b/examples/Sample.h deleted file mode 100644 index da542f0d..00000000 --- a/examples/Sample.h +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef TEST_SAMPLE_H -#define TEST_SAMPLE_H - -#include -#include -#include - -// clang-format off -namespace test -{ - namespace TabPerson_ - { - struct Id - { - struct _alias_t - { - static constexpr const char _literal[] = "id"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T id; - T& operator()() { return id; } - const T& operator()() const { return id; } - }; - }; - using _traits = sqlpp::make_traits; - }; - struct Name - { - struct _alias_t - { - static constexpr const char _literal[] = "name"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T name; - T& operator()() { return name; } - const T& operator()() const { return name; } - }; - }; - using _traits = sqlpp::make_traits; - }; - struct Feature - { - struct _alias_t - { - static constexpr const char _literal[] = "feature"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T feature; - T& operator()() { return feature; } - const T& operator()() const { return feature; } - }; - }; - using _traits = sqlpp::make_traits; - }; - } - - struct TabPerson: sqlpp::table_t - { - struct _alias_t - { - static constexpr const char _literal[] = "tab_person"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T tabPerson; - T& operator()() { return tabPerson; } - const T& operator()() const { return tabPerson; } - }; - }; - }; - namespace TabFeature_ - { - struct Id - { - struct _alias_t - { - static constexpr const char _literal[] = "id"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T id; - T& operator()() { return id; } - const T& operator()() const { return id; } - }; - }; - using _traits = sqlpp::make_traits; - }; - struct Name - { - struct _alias_t - { - static constexpr const char _literal[] = "name"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T name; - T& operator()() { return name; } - const T& operator()() const { return name; } - }; - }; - using _traits = sqlpp::make_traits; - }; - struct Fatal - { - struct _alias_t - { - static constexpr const char _literal[] = "fatal"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T fatal; - T& operator()() { return fatal; } - const T& operator()() const { return fatal; } - }; - }; - using _traits = sqlpp::make_traits; - }; - } - - struct TabFeature: sqlpp::table_t - { - struct _alias_t - { - static constexpr const char _literal[] = "tab_feature"; - using _name_t = sqlpp::make_char_sequence; - template - struct _member_t - { - T tabFeature; - T& operator()() { return tabFeature; } - const T& operator()() const { return tabFeature; } - }; - }; - }; -} -#endif diff --git a/examples/TabSample.h b/examples/TabSample.h deleted file mode 100644 index 9cadacf7..00000000 --- a/examples/TabSample.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - * 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. - */ - -#ifndef SQLPP_TAB_SAMPLE_H -#define SQLPP_TAB_SAMPLE_H - -#include -#include - -// clang-format off -namespace TabFoo_ -{ - struct Omega - { - struct _name_t - { - static constexpr const char* _get_name() { return "omega"; } - }; - template - struct _member_t - { - /* - template - _name_t(TT&&... t): omega(std::forward(t)...) {} - - template - _name_t& operator=(TT&& t) { omega = std::forward(t); return *this; } - */ - - T omega; - }; - using _value_type = sqlpp::bigint; - struct _column_type - { - }; - }; -} - -struct TabFoo: sqlpp::table_base_t< - TabFoo, - TabFoo_::Omega - > -{ - using _value_type = sqlpp::no_value_t; - struct _name_t - { - static constexpr const char* _get_name() { return "tab_foo"; } - }; - template - struct _member_t - { - T tabFoo; - }; - template - void serialize(std::ostream& os, Db& db) const - { - os << _name_t::_get_name(); - } -}; - -namespace TabSample_ -{ - struct Alpha - { - struct _name_t - { - static constexpr const char* _get_name() { return "alpha"; } - }; - template - struct _member_t - { - /* - template - _name_t(TT&&... t): alpha(std::forward(t)...) {} - - template - _name_t& operator=(TT&& t) { alpha = std::forward(t); return *this; } - */ - - T alpha; - }; - using _value_type = sqlpp::bigint; - struct _column_type - { - using _must_not_insert = sqlpp::tag_yes; - using _must_not_update = sqlpp::tag_yes; - using _can_be_null = sqlpp::tag_yes; - using _foreign_key = decltype(TabFoo::omega); - }; - }; - - struct Beta - { - struct _name_t - { - static constexpr const char* _get_name() { return "beta"; } - }; - template - struct _member_t - { - T beta; - }; - using _value_type = sqlpp::varchar; - struct _column_type - { - using _can_be_null = sqlpp::tag_yes; - using _must_not_update = sqlpp::tag_yes; - }; - }; - - struct Gamma - { - struct _name_t - { - static constexpr const char* _get_name() { return "gamma"; } - }; - template - struct _member_t - { - T gamma; - }; - using _value_type = sqlpp::boolean; - struct _column_type - { - using _require_insert = sqlpp::tag_yes; - }; - }; -} - -struct TabSample: sqlpp::table_base_t< - TabSample, - TabSample_::Alpha, - TabSample_::Beta, - TabSample_::Gamma - > -{ - using _value_type = sqlpp::no_value_t; - struct _name_t - { - static constexpr const char* _get_name() { return "tab_sample"; } - }; - template - struct _member_t - { - T tabSample; - }; - template - void serialize(std::ostream& os, Db& db) const - { - os << _name_t::_get_name(); - } -}; - -#endif diff --git a/examples/insert.cpp b/examples/insert.cpp deleted file mode 100644 index 525339f7..00000000 --- a/examples/insert.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2014-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. - */ - -#include "Sample.h" -#include "MockDb.h" -#include - -int insert(int, char* []) -{ - MockDb db{}; - - const auto p = test::TabPerson{}; - const auto f = test::TabFeature{}; - - db(insert_into(f).set(f.name = "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.nahme = "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.name == "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.name = "loves c++", f.fatal = "false")); - - // db(insert_into(p).set(f.name = "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.name = "loves c++", p.feature = 7)); - - // db(insert_into(f).set(f.id = 42, f.name = "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.name = "loves c++")); - - db(insert_into(f).default_values()); - - auto i = insert_into(p).columns(p.name, p.feature); - i.values.add(p.name = "Roland", p.feature = 1); - i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value); - db(i); - - auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature))); - pi.params.name = "likes java"; - pi.params.feature = true; - - db(pi); - return 0; -} diff --git a/examples/ppgen.cpp b/examples/ppgen.cpp deleted file mode 100644 index 7e8ca072..00000000 --- a/examples/ppgen.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com) - * 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. - */ - -#if 0 // syntax example -SQLPP_DECLARE_TABLE( - (table, \ - SQLPP_DROP_IF_EXISTS \ - ,SQLPP_CREATE_IF_NOT_EXISTS \ - ,SQLPP_ENGINE("InnoDB") \ - ,SQLPP_CHARACTER_SET("utf-8") \ - ,SQLPP_COMMENT("table comments") \ - ) - , - (id, int, SQLPP_NOT_NULL, SQLPP_PRIMARY_KEY, SQLPP_AUTO_INCREMENT) - (name, varchar(64), SQLPP_NOT_NULL, SQLPP_INDEX("name_index"), SQLPP_DEFAULT("any name")) - (age, int, SQLPP_NOT_NULL, SQLPP_INDEX("age_index"), SQLPP_UNIQUE, SQLPP_COMMENT("some comments")) -) -#endif - -#include -#include - -#include "MockDb.h" - -// clang-format off -SQLPP_DECLARE_TABLE( - (tab_person) - , - (id , int , SQLPP_PRIMARY_KEY) - (name , varchar(255), SQLPP_NOT_NULL ) - (feature, int , SQLPP_NOT_NULL ) -) - -SQLPP_DECLARE_TABLE( - (tab_feature) - , - (id , int , SQLPP_PRIMARY_KEY) - (name , varchar(255), SQLPP_NULL ) - (fatal, bool , SQLPP_NOT_NULL ) -) -// clang-format on - -int ppgen(int, char* []) -{ - MockDb db{}; - const auto p = tab_person::tab_person{}; - const auto f = tab_feature::tab_feature{}; - - db(insert_into(f).set(f.name = "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.nahme = "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.name == "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.name = "loves c++", f.fatal = "false")); - - // db(insert_into(p).set(f.name = "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.name = "loves c++", p.feature = 7)); - - // db(insert_into(f).set(f.id = 42, f.name = "loves c++", f.fatal = false)); - - // db(insert_into(f).set(f.name = "loves c++")); - - db(insert_into(f).default_values()); - - auto i = insert_into(p).columns(p.name, p.feature); - i.values.add(p.name = "Roland", p.feature = 1); - i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value); - db(i); - - auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature))); - pi.params.name = "likes java"; - pi.params.feature = true; - - db(pi); - return 0; -} diff --git a/examples/remove.cpp b/examples/remove.cpp deleted file mode 100644 index 73b7b073..00000000 --- a/examples/remove.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2014-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. - */ - -#include "Sample.h" -#include "MockDb.h" -#include - -int remove(int, char* []) -{ - MockDb db{}; - - const auto p = test::TabPerson{}; - const auto q = test::TabFeature{}; - - db(remove_from(p).using_(p, q).where(p.feature == q.id and q.fatal == true)); - return 0; -} diff --git a/examples/sample.cpp b/examples/sample.cpp deleted file mode 100644 index c356b8ec..00000000 --- a/examples/sample.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2014-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. - */ - -#include "Sample.h" -#include "MockDb.h" -#include - -int main() -{ - MockDb db{}; - - const auto p = test::TabPerson{}; - const auto f = test::TabFeature{}; - - db(insert_into(f).set(f.name = "Loves C++", p.fatal = false)); - - db(insert_into(f).set(p.name = "Roland", p.feature = 1)); - - auto s = select(all_of(p)) - .from(p, q) - .where(p.name == any(select(q.name).from(q).where(true))) - .group_by(q.name) - .having(p.name.like("%Bee%")) - .order_by(p.name.asc()) - .limit(3) - .offset(7); - - auto x = s.as(sqlpp::alias::x); - for (const auto& row : db(select(p.id, x.name).from(p.join(x).on(p.feature == x.feature)).where(true))) - { - int id = row.id; - std::string name = row.name; - } -} diff --git a/examples/sample.sql b/examples/sample.sql deleted file mode 100644 index adc255d6..00000000 --- a/examples/sample.sql +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2013, 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. - */ - -CREATE TABLE tab_person -( - id int AUTO_INCREMENT PRIMARY KEY, - name varchar(255) NOT NULL, - feature int NOT NULL -); - -CREATE TABLE tab_feature -( - id int AUTO_INCREMENT PRIMARY KEY, - name varchar(255) NULL DEFAULT "", - fatal bool NOT NULL -); - diff --git a/examples/select.cpp b/examples/select.cpp deleted file mode 100644 index d6bdfdf6..00000000 --- a/examples/select.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (c) 2014-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. - */ - -#if defined(__clang__) -#pragma clang diagnostic ignored "-Wunused-variable" -#endif -#if defined(__GNUC__) -#pragma GCC diagnostic ignored "-Wunused-variable" -#endif - -#include "Sample.h" -#include "MockDb.h" -#include - -SQLPP_ALIAS_PROVIDER(cheesecake) - -int select(int, char* []) -{ - static constexpr bool some_condition = true; - static constexpr bool some_other_condition = false; - - MockDb db{}; - - const auto p = test::TabPerson{}; -#if 0 - const auto f = test::TabFeature{}; -#endif - - for (const auto& row : db(select(all_of(p)).from(p).where(p.id > 7))) - { - int64_t id = row.id; - std::string name = row.name; - int64_t feature = row.feature; - } - -#if 0 - for (const auto& row : db(select(p.name).from(p).where(p.name.like("Herb%")))) - { - int64_t id = row.id; - std::string name = row.name; - int64_t feature = row.feature; - } -#endif - -#if 0 - for (const auto& row : db(select(p.name, f.name.as(cheesecake)).from(p,f).where(p.id > 7 and p.feature == 3))) - { - //int64_t id = row.id; - //std::string a = row.a; - std::string name = row.name; - std::string feature = row.cheesecake; - } -#endif - -#if 0 - for (const auto& row : db(select(multi_column(all_of(p)).as(p), multi_column(f.name, f.id).as(f)).from(p,f).where(true))) - { - //int64_t id = row.id; - //std::string a = row.a; - std::string name = row.tabPerson.name; - std::string name1 = row.tabFeature.name; - //int64_t feature = row.feature; - } -#endif - -#if 0 - auto s = select(p.id, p.name, f.id.as(cheesecake)) - .from(p, f) - .where(p.name == any(select(f.name) - .from(f) - .where(true))) - .group_by(f.name) - .having(p.name.like("%Bee%")) - .order_by(p.name.asc()) - .limit(3).offset(7); - - auto x = s.as(sqlpp::alias::x); - for (const auto& row : db(select(p.id, p.name, all_of(x).as(x)) - .from(p.join(x).on(p.feature == x.cheesecake)) - .where(true))) - { - int64_t id = row.id; - std::string name = row.name; - std::string x_name = row.x.name; - int cheesecake = row.x.cheesecake; - } -#endif - -#if !0 - auto dysel = dynamic_select(db).dynamic_columns(p.name).from(p).dynamic_where(); - - if (some_condition) - dysel.selected_columns.add(p.feature); - - if (some_other_condition) - dysel.where.add(p.id > 17); - - for (const auto& row : db(dysel)) - { - std::string name = row.name; - std::string feature = row.at("feature"); - } -#endif - - return 0; -} diff --git a/examples/update.cpp b/examples/update.cpp deleted file mode 100644 index d5562c25..00000000 --- a/examples/update.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2014-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. - */ - -#include "Sample.h" -#include "MockDb.h" -#include - -int update(int, char* []) -{ - MockDb db{}; - - const auto p = test::TabPerson{}; - - db(update(p).set(p.feature = 7).where(p.id == 23)); - return 0; -}