mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Merge tag '0.44' into develop
Features: - Added dynamic sort order - Relaxed union requirements (if left hand side can be null, then the right hand side doesn't have to) - Fixed specs for several expressions with unsigned operands Misc: - More tests - Removed g++ warnings about unused parameters - Cleaned up travis-ci config (is shorter and uses much less resources now)
This commit is contained in:
commit
d06b386e03
@ -28,6 +28,8 @@ project(sqlpp11 VERSION 0.1 LANGUAGES CXX)
|
|||||||
|
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
|
option(ENABLE_TESTS "Build unit tests" On)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
|
||||||
find_package(HinnantDate REQUIRED)
|
find_package(HinnantDate REQUIRED)
|
||||||
|
|
||||||
@ -104,10 +106,11 @@ install(
|
|||||||
${ConfigPackageLocation}
|
${ConfigPackageLocation}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(ENABLE_TESTS)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
add_subdirectory(test_types)
|
add_subdirectory(test_types)
|
||||||
add_subdirectory(test_serializer)
|
add_subdirectory(test_serializer)
|
||||||
add_subdirectory(test_static_asserts)
|
add_subdirectory(test_static_asserts)
|
||||||
add_subdirectory(test_constraints)
|
add_subdirectory(test_constraints)
|
||||||
add_subdirectory(test_scripts)
|
add_subdirectory(test_scripts)
|
||||||
add_subdirectory(examples)
|
endif()
|
34
README.md
34
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:
|
// 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.
|
Of course there are joins and subqueries, more functions, order_by, group_by etc.
|
||||||
These will be documented soon.
|
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
|
* STL Container: https://github.com/rbock/sqlpp11-connector-stl
|
||||||
|
|
||||||
__Date Library:__
|
__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:
|
Basic usage:
|
||||||
-------------
|
-------------
|
||||||
__Linux install:__
|
|
||||||
git clone date library, needed connectors, cmake and make install them.
|
|
||||||
|
|
||||||
|
|
||||||
__Create DDL files__:
|
__Create DDL files__:
|
||||||
```
|
```
|
||||||
|
@ -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.")
|
Maybe you need to adjust the search paths or HinnantDate_ROOT_DIR.")
|
||||||
|
|
||||||
find_file(HinnantDate_INCLUDE_FILE
|
find_file(HinnantDate_INCLUDE_FILE
|
||||||
date.h
|
date.h date/date.h
|
||||||
HINTS ${HinnantDate_ROOT_DIR}
|
HINTS ${HinnantDate_ROOT_DIR}
|
||||||
)
|
)
|
||||||
mark_as_advanced(HinnantDate_INCLUDE_FILE)
|
mark_as_advanced(HinnantDate_INCLUDE_FILE)
|
||||||
|
@ -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
|
|
||||||
# )
|
|
||||||
|
|
@ -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.
|
|
@ -1,152 +0,0 @@
|
|||||||
#ifndef TEST_SAMPLE_H
|
|
||||||
#define TEST_SAMPLE_H
|
|
||||||
|
|
||||||
#include <sqlpp11/table.h>
|
|
||||||
#include <sqlpp11/data_types.h>
|
|
||||||
#include <sqlpp11/char_sequence.h>
|
|
||||||
|
|
||||||
// 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<sizeof(_literal), _literal>;
|
|
||||||
template<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
T id;
|
|
||||||
T& operator()() { return id; }
|
|
||||||
const T& operator()() const { return id; }
|
|
||||||
};
|
|
||||||
};
|
|
||||||
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update, sqlpp::tag::can_be_null>;
|
|
||||||
};
|
|
||||||
struct Name
|
|
||||||
{
|
|
||||||
struct _alias_t
|
|
||||||
{
|
|
||||||
static constexpr const char _literal[] = "name";
|
|
||||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
|
||||||
template<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
T name;
|
|
||||||
T& operator()() { return name; }
|
|
||||||
const T& operator()() const { return name; }
|
|
||||||
};
|
|
||||||
};
|
|
||||||
using _traits = sqlpp::make_traits<sqlpp::varchar, sqlpp::tag::require_insert>;
|
|
||||||
};
|
|
||||||
struct Feature
|
|
||||||
{
|
|
||||||
struct _alias_t
|
|
||||||
{
|
|
||||||
static constexpr const char _literal[] = "feature";
|
|
||||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
|
||||||
template<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
T feature;
|
|
||||||
T& operator()() { return feature; }
|
|
||||||
const T& operator()() const { return feature; }
|
|
||||||
};
|
|
||||||
};
|
|
||||||
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::require_insert>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct TabPerson: sqlpp::table_t<TabPerson,
|
|
||||||
TabPerson_::Id,
|
|
||||||
TabPerson_::Name,
|
|
||||||
TabPerson_::Feature>
|
|
||||||
{
|
|
||||||
struct _alias_t
|
|
||||||
{
|
|
||||||
static constexpr const char _literal[] = "tab_person";
|
|
||||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
|
||||||
template<typename T>
|
|
||||||
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<sizeof(_literal), _literal>;
|
|
||||||
template<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
T id;
|
|
||||||
T& operator()() { return id; }
|
|
||||||
const T& operator()() const { return id; }
|
|
||||||
};
|
|
||||||
};
|
|
||||||
using _traits = sqlpp::make_traits<sqlpp::integer, sqlpp::tag::must_not_insert, sqlpp::tag::must_not_update, sqlpp::tag::can_be_null>;
|
|
||||||
};
|
|
||||||
struct Name
|
|
||||||
{
|
|
||||||
struct _alias_t
|
|
||||||
{
|
|
||||||
static constexpr const char _literal[] = "name";
|
|
||||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
|
||||||
template<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
T name;
|
|
||||||
T& operator()() { return name; }
|
|
||||||
const T& operator()() const { return name; }
|
|
||||||
};
|
|
||||||
};
|
|
||||||
using _traits = sqlpp::make_traits<sqlpp::varchar, sqlpp::tag::can_be_null>;
|
|
||||||
};
|
|
||||||
struct Fatal
|
|
||||||
{
|
|
||||||
struct _alias_t
|
|
||||||
{
|
|
||||||
static constexpr const char _literal[] = "fatal";
|
|
||||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
|
||||||
template<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
T fatal;
|
|
||||||
T& operator()() { return fatal; }
|
|
||||||
const T& operator()() const { return fatal; }
|
|
||||||
};
|
|
||||||
};
|
|
||||||
using _traits = sqlpp::make_traits<sqlpp::boolean, sqlpp::tag::require_insert>;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
struct TabFeature: sqlpp::table_t<TabFeature,
|
|
||||||
TabFeature_::Id,
|
|
||||||
TabFeature_::Name,
|
|
||||||
TabFeature_::Fatal>
|
|
||||||
{
|
|
||||||
struct _alias_t
|
|
||||||
{
|
|
||||||
static constexpr const char _literal[] = "tab_feature";
|
|
||||||
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
|
|
||||||
template<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
T tabFeature;
|
|
||||||
T& operator()() { return tabFeature; }
|
|
||||||
const T& operator()() const { return tabFeature; }
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
#endif
|
|
@ -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 <sqlpp11/table_base.h>
|
|
||||||
#include <sqlpp11/column_types.h>
|
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
namespace TabFoo_
|
|
||||||
{
|
|
||||||
struct Omega
|
|
||||||
{
|
|
||||||
struct _name_t
|
|
||||||
{
|
|
||||||
static constexpr const char* _get_name() { return "omega"; }
|
|
||||||
};
|
|
||||||
template<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
template<typename... TT>
|
|
||||||
_name_t(TT&&... t): omega(std::forward<TT>(t)...) {}
|
|
||||||
|
|
||||||
template<typename TT>
|
|
||||||
_name_t& operator=(TT&& t) { omega = std::forward<TT>(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<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
T tabFoo;
|
|
||||||
};
|
|
||||||
template<typename Db>
|
|
||||||
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<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
template<typename... TT>
|
|
||||||
_name_t(TT&&... t): alpha(std::forward<TT>(t)...) {}
|
|
||||||
|
|
||||||
template<typename TT>
|
|
||||||
_name_t& operator=(TT&& t) { alpha = std::forward<TT>(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<typename T>
|
|
||||||
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<typename T>
|
|
||||||
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<typename T>
|
|
||||||
struct _member_t
|
|
||||||
{
|
|
||||||
T tabSample;
|
|
||||||
};
|
|
||||||
template<typename Db>
|
|
||||||
void serialize(std::ostream& os, Db& db) const
|
|
||||||
{
|
|
||||||
os << _name_t::_get_name();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -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 <sqlpp11/sqlpp11.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -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 <sqlpp11/sqlpp11.h>
|
|
||||||
#include <sqlpp11/ppgen.h>
|
|
||||||
|
|
||||||
#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;
|
|
||||||
}
|
|
@ -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 <sqlpp11/sqlpp11.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -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 <sqlpp11/sqlpp11.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -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
|
|
||||||
);
|
|
||||||
|
|
@ -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 <sqlpp11/sqlpp11.h>
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
@ -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 <sqlpp11/sqlpp11.h>
|
|
||||||
|
|
||||||
int update(int, char* [])
|
|
||||||
{
|
|
||||||
MockDb db{};
|
|
||||||
|
|
||||||
const auto p = test::TabPerson{};
|
|
||||||
|
|
||||||
db(update(p).set(p.feature = 7).where(p.id == 23));
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user