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

Merge branch 'release/0.35'

Conflicts:
	README.md
This commit is contained in:
rbock 2015-12-29 11:03:17 +01:00
commit 6dcdc419c1
300 changed files with 19927 additions and 13729 deletions

27
.appveyor.yml Normal file
View File

@ -0,0 +1,27 @@
os: Visual Studio 2015
platform:
- x64
configuration:
- Debug
- Release
matrix:
fast_finish: true
build_script:
- CD
- cd ..
- CD
- git clone https://github.com/HowardHinnant/date
- cd sqlpp11
- CD
- echo %configuration%
- mkdir build
- cd build
- cmake --version
- cmake .. -DCMAKE_CXX_FLAGS="/EHsc /wd4503"
- cmake --build . --config %configuration%
- ctest . --build-config %configuration%

View File

@ -14,7 +14,7 @@ BreakBeforeBinaryOperators: false
BreakBeforeTernaryOperators: true BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false BreakConstructorInitializersBeforeComma: false
BinPackParameters: false BinPackParameters: false
ColumnLimit: 160 ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: true ConstructorInitializerAllOnOneLineOrOnePerLine: true
DerivePointerAlignment: false DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false ExperimentalAutoDetectBinPacking: false

View File

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

View File

@ -22,26 +22,50 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
cmake_minimum_required(VERSION 2.6) cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(sqlpp11 VERSION 0.1 LANGUAGES CXX)
# Cygwin does not define WIN32 and warn if not use with this flag
set(CMAKE_LEGACY_CYGWIN_WIN32 0) # Remove when CMake >= 2.8.4 is required
project (sqlpp11)
enable_testing() enable_testing()
message(STATUS "Using ${CMAKE_CXX_COMPILER} (compiler id: ${CMAKE_CXX_COMPILER_ID})") add_library(sqlpp11 INTERFACE)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++ -Wall ${CMAKE_CXX_FLAGS}") set(DATE_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../date" CACHE FILEPATH "Path to Howard Hinnant's date library")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "-std=c++11 -Wall ${CMAKE_CXX_FLAGS}") if(NOT EXISTS ${DATE_INCLUDE_DIR}/date.h)
endif () message(SEND_ERROR "Can't find date.h in ${DATE_INCLUDE_DIR}")
set(CMAKE_CXX_FLAGS "-Wconversion -Wpedantic -Wshadow ${CMAKE_CXX_FLAGS}") endif()
target_include_directories(sqlpp11 INTERFACE
$<BUILD_INTERFACE:${DATE_INCLUDE_DIR}>
$<BUILD_INTERFACE:${sqlpp11_SOURCE_DIR}/include>
)
if (NOT MSVC)
target_compile_features(sqlpp11 INTERFACE
cxx_alias_templates
cxx_auto_type
cxx_constexpr
cxx_decltype
cxx_defaulted_functions
cxx_defaulted_move_initializers
cxx_deleted_functions
cxx_explicit_conversions
cxx_lambdas
cxx_noexcept
cxx_nullptr
cxx_range_for
cxx_right_angle_brackets
cxx_rvalue_references
cxx_static_assert
cxx_trailing_return_types
cxx_uniform_initialization
cxx_template_template_parameters
cxx_variadic_templates
)
endif ()
set(include_dir "${PROJECT_SOURCE_DIR}/include")
file(GLOB_RECURSE sqlpp_headers "${include_dir}/*.h")
include_directories("${include_dir}")
add_subdirectory(tests) add_subdirectory(tests)
add_subdirectory(test_static_asserts)
add_subdirectory(test_constraints) add_subdirectory(test_constraints)
add_subdirectory(examples) add_subdirectory(examples)

13
CREDITS
View File

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

View File

@ -1,18 +1,26 @@
sqlpp11 sqlpp11
======= =======
Branch / Compiler | clang-3.4, gcc-4.9, Xcode-7 | MSVC 2015 | 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)
A type safe embedded domain specific language for SQL queries and results in C++ A type safe embedded domain specific language for SQL queries and results in C++
Extensive documentation is found in the wiki, https://github.com/rbock/sqlpp11/wiki Documentation is found in the wiki, https://github.com/rbock/sqlpp11/wiki
Talks/workshops Past talks about sqlpp11 and some coding concepts used within the library:
* MeetingC++ (Berlin, Germany): http://meetingcpp.com/index.php/mcpp2014.html
* 2014-12-05: http://meetingcpp.com/index.php/tv14/items/4.html
* CppCon (Bellevue, Washington, USA): http://cppcon.org
* 2014-09-08: http://sched.co/1qhngYK (Workshop Part 1)
* 2014-09-11: http://sched.co/1r4lue3 (Talk)
* 2014-09-12: http://sched.co/Wi8aWM (Workshop Part 2)
* [CppCast:](http://cppcast.com)
* 2015-05-07: http://cppcast.com/2015/05/roland-bock/
* [CppCon:](http://cppcon.org)
* 2015-09-24: [Pruning Error Messages From Your C++ Template Code](https://www.youtube.com/watch?v=2ISqFW9fRws), with examples from sqlpp11
* 2014-09-11: [sqlpp11, An SQL Library Worthy Of Modern C++](https://www.youtube.com/watch?v=cJPAjhBm-HQ)
* [Meeting C++:](http://meetingcpp.com)
* 2014-12-05: [sqlpp11, An EDSL For Type-Safe SQL In C++11](https://www.youtube.com/watch?v=9Hjfg9IfzhU)
* [MUC++:](http://www.meetup.com/MUCplusplus/)
* 2014-02-27: [Selected C++11 Template Toffees From sqlpp11, Part1](https://www.youtube.com/watch?v=hXnGFYNbmXg), [Part2](https://www.youtube.com/watch?v=WPCV6dvxZ_U), [Part 3](https://www.youtube.com/watch?v=eB7hd_KjTig), [Part 4](https://www.youtube.com/watch?v=NBfqzcN0_EQ)
You can contact me You can contact me
* by posting issues at https://github.com/rbock/sqlpp11/issues * by posting issues at https://github.com/rbock/sqlpp11/issues
@ -104,11 +112,12 @@ Requirements:
__Compiler:__ __Compiler:__
sqlpp11 makes heavy use of C++11 and requires a recent compiler and STL. The following compilers are known to compile the test programs: sqlpp11 makes heavy use of C++11 and requires a recent compiler and STL. The following compilers are known to compile the test programs:
* clang-3.2 on Ubuntu-12.4 * clang-3.4+ on Ubuntu-12.4
* clang-3.4 on Ubuntu-12.4 * g++-4.8+ on Ubuntu-12.4
* g++-4.8 on Ubuntu-12.4 * g++-4.8+ on cygwin 64bit
* g++-4.8 on cygwin 64bit * g++-4.9+ on Debian Unstable
* g++-4.9 on Debian Unstable * Xcode-7 on OS X
* MSVC 2015 Update 1 on Windows Server 2012
__Database Connector:__ __Database Connector:__
sqlpp11 requires a certain api in order to connect with the database, see database/api.h. sqlpp11 requires a certain api in order to connect with the database, see database/api.h.
@ -117,6 +126,9 @@ sqlpp11 requires a certain api in order to connect with the database, see databa
* Sqlite3: https://github.com/rbock/sqlpp11-connector-sqlite3 * Sqlite3: https://github.com/rbock/sqlpp11-connector-sqlite3
* PostgreSQL: https://github.com/matthijs/sqlpp11-connector-postgresql * PostgreSQL: https://github.com/matthijs/sqlpp11-connector-postgresql
__Date Library:__
sqlpp11 requires [Howard Hinnant's date library](https://github.com/HowardHinnant/date) for `date` and `date_time` data types.
To demonstrate that sqlpp11 can work with other backends as well, here is an experimental backend for structs in standard containers: To demonstrate that sqlpp11 can work with other backends as well, here is an experimental backend for structs in standard containers:
* STL Container: https://github.com/rbock/sqlpp11-connector-stl * STL Container: https://github.com/rbock/sqlpp11-connector-stl

View File

@ -24,7 +24,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SQLPP_DATABASE_BIND_RESULT_H #ifndef SQLPP_DATABASE_BIND_RESULT_H
#define SQLPP_DATABASE_BIND_RESULT_H #define SQLPP_DATABASE_BIND_RESULT_H
@ -32,62 +31,61 @@
namespace sqlpp namespace sqlpp
{ {
namespace database namespace database
{ {
/* /*
* bind_result_t binds values of a sqlpp11 result row * bind_result_t binds values of a sqlpp11 result row
* to the results of a statement * to the results of a statement
*/ */
class bind_result_t class bind_result_t
{ {
public: public:
bind_result_t(); // default constructor for a result that will not yield a valid row bind_result_t(); // default constructor for a result that will not yield a valid row
bind_result_t(...); bind_result_t(...);
bind_result_t(const bind_result_t&) = delete; bind_result_t(const bind_result_t&) = delete;
bind_result_t(bind_result_t&& rhs); bind_result_t(bind_result_t&& rhs);
bind_result_t& operator=(const bind_result_t&) = delete; bind_result_t& operator=(const bind_result_t&) = delete;
bind_result_t& operator=(bind_result_t&&); bind_result_t& operator=(bind_result_t&&);
~bind_result_t(); ~bind_result_t();
bool operator==(const bind_result_t& rhs) const; bool operator==(const bind_result_t& rhs) const;
template<typename ResultRow> template <typename ResultRow>
void next(ResultRow& result_row); void next(ResultRow& result_row);
// something similar to this: // something similar to this:
/* /*
{ {
if (!_handle) if (!_handle)
{ {
result_row.invalidate(); result_row.invalidate();
return; return;
} }
if (next_impl()) if (next_impl())
{ {
if (not result_row) if (not result_row)
{ {
result_row.validate(); result_row.validate();
} }
result_row._bind(*this); // bind result row values to results result_row._bind(*this); // bind result row values to results
} }
else else
{ {
if (result_row) if (result_row)
result_row.invalidate(); result_row.invalidate();
} }
}; };
*/ */
// These are called by the result row to bind individual result values // These are called by the result row to bind individual result values
// More will be added over time // More will be added over time
void _bind_boolean_result(size_t index, signed char* value, bool* is_null); void _bind_boolean_result(size_t index, signed char* value, bool* is_null);
void _bind_floating_point_result(size_t index, double* value, bool* is_null); void _bind_floating_point_result(size_t index, double* value, bool* is_null);
void _bind_integral_result(size_t index, int64_t* value, bool* is_null); void _bind_integral_result(size_t index, int64_t* value, bool* is_null);
void _bind_text_result(size_t index, const char** text, size_t* len); void _bind_text_result(size_t index, const char** text, size_t* len);
... ...
}; };
}
}
} }
#endif #endif

View File

@ -24,122 +24,125 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SQLPP_DATABASE_CONNECTION_H #ifndef SQLPP_DATABASE_CONNECTION_H
#define SQLPP_DATABASE_CONNECTION_H #define SQLPP_DATABASE_CONNECTION_H
#include <string> #include <string>
#include <sqlpp11/connection.h> #include <sqlpp11/connection.h>
#include <sqlpp11/database/char_result.h> // You may use char result or bind result or both #include <sqlpp11/database/char_result.h> // You may use char result or bind result or both
#include <sqlpp11/database/bind_result.h> // to represent results of select and prepared select #include <sqlpp11/database/bind_result.h> // to represent results of select and prepared select
namespace sqlpp namespace sqlpp
{ {
namespace database namespace database
{ {
// The context is not a requirement, but if the database requires // The context is not a requirement, but if the database requires
// any deviations from the SQL standard, you should use your own // any deviations from the SQL standard, you should use your own
// context in order to specialize the behaviour, see also interpreter.h // context in order to specialize the behaviour, see also interpreter.h
struct context_t struct context_t
{ {
template<typename T> template <typename T>
std::ostream& operator<<(T t); std::ostream& operator<<(T t);
std::string escape(std::string arg); std::string escape(std::string arg);
}; };
class connection: public sqlpp::connection // this inheritance helps with ADL for dynamic_select, for instance class connection : public sqlpp::connection // this inheritance helps with ADL for dynamic_select, for instance
{ {
public: public:
using _traits = ::sqlpp::make_traits<::sqlpp::no_value_t, using _traits = ::sqlpp::make_traits<
::sqlpp::tag::enforce_null_result_treatment // If that is what you really want, leave it out otherwise ::sqlpp::no_value_t,
>; ::sqlpp::tag::enforce_null_result_treatment // If that is what you really want, leave it out otherwise
>;
using _prepared_statement_t = << handle to a prepared statement of the database >>; using _prepared_statement_t = << handle to a prepared statement of the database >> ;
using _serializer_context_t = << This context is used to serialize a statement >> using _serializer_context_t = << This context is used to serialize a statement >> using _interpreter_context_t =
using _interpreter_context_t = << This context is used interpret a statement >>; << This context is used interpret a statement >>
// serializer and interpreter are typically the same for string based connectors ;
// the types are required for dynamic statement components, see sqlpp11/interpretable.h // serializer and interpreter are typically the same for string based connectors
// the types are required for dynamic statement components, see sqlpp11/interpretable.h
connection(...); connection(...);
~connection(); ~connection();
connection(const connection&) = delete; connection(const connection&) = delete;
connection(connection&&) = delete; connection(connection&&) = delete;
connection& operator=(const connection&) = delete; connection& operator=(const connection&) = delete;
connection& operator=(connection&&) = delete; connection& operator=(connection&&) = delete;
//! "direct" select //! "direct" select
template<typename Select> template <typename Select>
<<bind_result_t>> select(const Select& s); << bind_result_t >>
select(const Select& s);
//! prepared select //! prepared select
template<typename Select> template <typename Select>
_prepared_statement_t prepare_select(Select& s); _prepared_statement_t prepare_select(Select& s);
template<typename PreparedSelect> template <typename PreparedSelect>
<<bind_result_t>> run_prepared_select(const PreparedSelect& s); // call s._bind_params() << bind_result_t >>
run_prepared_select(const PreparedSelect& s); // call s._bind_params()
//! "direct insert //! "direct insert
template<typename Insert> template <typename Insert>
size_t insert(const Insert& i); size_t insert(const Insert& i);
//! prepared insert //! prepared insert
template<typename Insert> template <typename Insert>
_prepared_statement_t prepare_insert(Insert& i); _prepared_statement_t prepare_insert(Insert& i);
template<typename PreparedInsert> template <typename PreparedInsert>
size_t run_prepared_insert(const PreparedInsert& i); // call i._bind_params() size_t run_prepared_insert(const PreparedInsert& i); // call i._bind_params()
//! "direct" update //! "direct" update
template<typename Update> template <typename Update>
size_t update(const Update& u); size_t update(const Update& u);
//! "prepared" update //! "prepared" update
template<typename Update> template <typename Update>
_prepared_statement_t prepare_update(Update& u); _prepared_statement_t prepare_update(Update& u);
template<typename PreparedUpdate> template <typename PreparedUpdate>
size_t run_prepared_update(const PreparedUpdate& u); // call u._bind_params() size_t run_prepared_update(const PreparedUpdate& u); // call u._bind_params()
//! "direct" remove //! "direct" remove
template<typename Remove> template <typename Remove>
size_t remove(const Remove& r) size_t remove(const Remove& r)
//! prepared remove //! prepared remove
template<typename Remove> template <typename Remove>
_prepared_statement_t prepare_remove(Remove& r); _prepared_statement_t prepare_remove(Remove& r);
template<typename PreparedRemove> template <typename PreparedRemove>
size_t run_prepared_remove(const PreparedRemove& r); // call r._bind_params() size_t run_prepared_remove(const PreparedRemove& r); // call r._bind_params()
//! call run on the argument //! call run on the argument
template<typename T> template <typename T>
auto operator() (const T& t) -> decltype(t._run(*this)) auto operator()(const T& t) -> decltype(t._run(*this))
{ {
return t._run(*this); return t._run(*this);
} }
//! call prepare on the argument //! call prepare on the argument
template<typename T> template <typename T>
auto prepare(const T& t) -> decltype(t._prepare(*this)) auto prepare(const T& t) -> decltype(t._prepare(*this))
{ {
return t._prepare(*this); return t._prepare(*this);
} }
//! start transaction //! start transaction
void start_transaction(); void start_transaction();
//! commit transaction (or throw transaction if the transaction has been finished already) //! commit transaction (or throw transaction if the transaction has been finished already)
void commit_transaction(); void commit_transaction();
//! rollback transaction with or without reporting the rollback (or throw if the transaction has been finished already) //! rollback transaction with or without reporting the rollback (or throw if the transaction has been finished
void rollback_transaction(bool report); // already)
void rollback_transaction(bool report);
//! report a rollback failure (will be called by transactions in case of a rollback failure in the destructor) //! report a rollback failure (will be called by transactions in case of a rollback failure in the destructor)
void report_rollback_failure(const std::string message) noexcept; void report_rollback_failure(const std::string message) noexcept;
}; };
}
}
} }
#include <sqlpp11/database/interpreter.h> #include <sqlpp11/database/interpreter.h>

View File

@ -41,22 +41,21 @@
*/ */
namespace sqlpp namespace sqlpp
{ {
namespace vendor namespace vendor
{ {
template<typename ValueType, typename NameType> template <typename ValueType, typename NameType>
struct interpreter_t<database::context_t, parameter_t<ValueType, NameType>> struct interpreter_t<database::context_t, parameter_t<ValueType, NameType>>
{ {
using T = parameter_t<ValueType, NameType>; using T = parameter_t<ValueType, NameType>;
static database::context_t& _(const T& t, database::context_t& context) static database::context_t& _(const T& t, database::context_t& context)
{ {
context << "?" << context.count(); context << "?" << context.count();
context.pop_count(); context.pop_count();
return context; return context;
} }
}; };
}
}
} }
#endif #endif

View File

@ -24,7 +24,6 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SQLPP_DATABASE_PREPARED_STATEMENT_H #ifndef SQLPP_DATABASE_PREPARED_STATEMENT_H
#define SQLPP_DATABASE_PREPARED_STATEMENT_H #define SQLPP_DATABASE_PREPARED_STATEMENT_H
@ -33,28 +32,28 @@
namespace sqlpp namespace sqlpp
{ {
namespace database namespace database
{ {
class prepared_statement_t class prepared_statement_t
{ {
public: public:
prepared_statement_t() = delete; prepared_statement_t() = delete;
prepared_statement_t(...); prepared_statement_t(...);
prepared_statement_t(const prepared_statement_t&) = delete; prepared_statement_t(const prepared_statement_t&) = delete;
prepared_statement_t(prepared_statement_t&& rhs); prepared_statement_t(prepared_statement_t&& rhs);
prepared_statement_t& operator=(const prepared_statement_t&) = delete; prepared_statement_t& operator=(const prepared_statement_t&) = delete;
prepared_statement_t& operator=(prepared_statement_t&&); prepared_statement_t& operator=(prepared_statement_t&&);
~prepared_statement_t(); ~prepared_statement_t();
bool operator==(const prepared_statement_t& rhs) const; bool operator==(const prepared_statement_t& rhs) const;
// These are called by the sqlpp11::prepared_*_t to bind the individual parameters // These are called by the sqlpp11::prepared_*_t to bind the individual parameters
// More will be added over time // More will be added over time
void _bind_boolean_parameter(size_t index, const signed char* value, bool is_null); void _bind_boolean_parameter(size_t index, const signed char* value, bool is_null);
void _bind_floating_point_parameter(size_t index, const double* value, bool is_null); void _bind_floating_point_parameter(size_t index, const double* value, bool is_null);
void _bind_integral_parameter(size_t index, const int64_t* value, bool is_null); void _bind_integral_parameter(size_t index, const int64_t* value, bool is_null);
void _bind_text_parameter(size_t index, const std::string* value, bool is_null); void _bind_text_parameter(size_t index, const std::string* value, bool is_null);
}; };
} }
} }
#endif #endif

31
coveralls Executable file
View File

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

View File

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

View File

@ -2,9 +2,10 @@
#define TEST_SAMPLE_H #define TEST_SAMPLE_H
#include <sqlpp11/table.h> #include <sqlpp11/table.h>
#include <sqlpp11/column_types.h> #include <sqlpp11/data_types.h>
#include <sqlpp11/char_sequence.h> #include <sqlpp11/char_sequence.h>
// clang-format off
namespace test namespace test
{ {
namespace TabPerson_ namespace TabPerson_

View File

@ -30,7 +30,7 @@
#include <sqlpp11/table_base.h> #include <sqlpp11/table_base.h>
#include <sqlpp11/column_types.h> #include <sqlpp11/column_types.h>
// clang-format off
namespace TabFoo_ namespace TabFoo_
{ {
struct Omega struct Omega

View File

@ -27,41 +27,40 @@
#include "MockDb.h" #include "MockDb.h"
#include <sqlpp11/sqlpp11.h> #include <sqlpp11/sqlpp11.h>
int main() int insert(int, char* [])
{ {
MockDb db; MockDb db{};
test::TabPerson p; const auto p = test::TabPerson{};
test::TabFeature f; const auto f = test::TabFeature{};
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(f).set(f.nahme = "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(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(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.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.id = 42, f.name = "loves c++", f.fatal = false));
//db(insert_into(f).set(f.name = "loves c++")); // db(insert_into(f).set(f.name = "loves c++"));
db(insert_into(f).default_values());
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 i = insert_into(p).columns(p.name, p.feature); auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature)));
i.values.add(p.name = "Roland", p.feature = 1); pi.params.name = "likes java";
i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value); pi.params.feature = true;
db(i);
db(pi);
auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature))); return 0;
pi.params.name = "likes java";
pi.params.feature = true;
db(pi);
} }

View File

@ -24,7 +24,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#if 0 // syntax example #if 0 // syntax example
SQLPP_DECLARE_TABLE( SQLPP_DECLARE_TABLE(
(table, \ (table, \
SQLPP_DROP_IF_EXISTS \ SQLPP_DROP_IF_EXISTS \
@ -45,56 +45,57 @@ SQLPP_DECLARE_TABLE(
#include "MockDb.h" #include "MockDb.h"
// clang-format off
SQLPP_DECLARE_TABLE( SQLPP_DECLARE_TABLE(
(tab_person) (tab_person)
, ,
(id , int , SQLPP_AUTO_INCREMENT) (id , int , SQLPP_PRIMARY_KEY)
(name , varchar(255), SQLPP_NOT_NULL ) (name , varchar(255), SQLPP_NOT_NULL )
(feature, int , SQLPP_NOT_NULL ) (feature, int , SQLPP_NOT_NULL )
) )
SQLPP_DECLARE_TABLE( SQLPP_DECLARE_TABLE(
(tab_feature) (tab_feature)
, ,
(id , int , SQLPP_AUTO_INCREMENT) (id , int , SQLPP_PRIMARY_KEY)
(name , varchar(255), SQLPP_NULL ) (name , varchar(255), SQLPP_NULL )
(fatal, bool , SQLPP_NOT_NULL ) (fatal, bool , SQLPP_NOT_NULL )
) )
// clang-format on
int main() int ppgen(int, char* [])
{ {
MockDb db; MockDb db{};
tab_person::tab_person p; const auto p = tab_person::tab_person{};
tab_feature::tab_feature f; 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.name = "loves c++", f.fatal = false));
//db(insert_into(f).set(f.nahme = "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(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(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.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.id = 42, f.name = "loves c++", f.fatal = false));
//db(insert_into(f).set(f.name = "loves c++")); // db(insert_into(f).set(f.name = "loves c++"));
db(insert_into(f).default_values());
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 i = insert_into(p).columns(p.name, p.feature); auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature)));
i.values.add(p.name = "Roland", p.feature = 1); pi.params.name = "likes java";
i.values.add(p.name = "Zaphod", p.feature = sqlpp::default_value); pi.params.feature = true;
db(i);
db(pi);
auto pi = db.prepare(insert_into(p).set(p.name = parameter(f.name), p.feature = parameter(p.feature))); return 0;
pi.params.name = "likes java";
pi.params.feature = true;
db(pi);
} }

View File

@ -27,14 +27,13 @@
#include "MockDb.h" #include "MockDb.h"
#include <sqlpp11/sqlpp11.h> #include <sqlpp11/sqlpp11.h>
int main() int remove(int, char* [])
{ {
MockDb db; MockDb db{};
test::TabPerson p; const auto p = test::TabPerson{};
test::TabFeature q; const auto q = test::TabFeature{};
db(remove_from(p) db(remove_from(p).using_(p, q).where(p.feature == q.id and q.fatal == true));
.using_(p, q) return 0;
.where(p.feature == q.id and q.fatal == true));
} }

View File

@ -29,31 +29,28 @@
int main() int main()
{ {
MockDb db; MockDb db{};
test::TabPerson p; const auto p = test::TabPerson{};
test::TabFeature f; const auto f = test::TabFeature{};
db(insert_into(f).set(f.name = "Loves C++", p.fatal = false)); db(insert_into(f).set(f.name = "Loves C++", p.fatal = false));
db(insert_into(f).set(p.name = "Roland", p.feature = 1)); db(insert_into(f).set(p.name = "Roland", p.feature = 1));
auto s = select(all_of(p)) auto s = select(all_of(p))
.from(p, q) .from(p, q)
.where(p.name == any(select(q.name) .where(p.name == any(select(q.name).from(q).where(true)))
.from(q) .group_by(q.name)
.where(true))) .having(p.name.like("%Bee%"))
.group_by(q.name) .order_by(p.name.asc())
.having(p.name.like("%Bee%")) .limit(3)
.order_by(p.name.asc()) .offset(7);
.limit(3).offset(7);
auto x = s.as(sqlpp::alias::x); auto x = s.as(sqlpp::alias::x);
for (const auto& row : db(select(p.id, x.name) for (const auto& row : db(select(p.id, x.name).from(p.join(x).on(p.feature == x.feature)).where(true)))
.from(p.join(x).on(p.feature == x.feature)) {
.where(true))) int id = row.id;
{ std::string name = row.name;
int id = row.id; }
std::string name = row.name;
}
} }

View File

@ -36,25 +36,26 @@
SQLPP_ALIAS_PROVIDER(cheesecake) SQLPP_ALIAS_PROVIDER(cheesecake)
int main() int select(int, char* [])
{ {
static constexpr bool some_condition = true; static constexpr bool some_condition = true;
static constexpr bool some_other_condition = false; static constexpr bool some_other_condition = false;
MockDb db; MockDb db{};
test::TabPerson p; const auto p = test::TabPerson{};
test::TabFeature f; #if 0
const auto f = test::TabFeature{};
#endif
for (const auto& row : db(select(all_of(p)).from(p).where(p.id > 7))) for (const auto& row : db(select(all_of(p)).from(p).where(p.id > 7)))
{ {
int64_t id = row.id; int64_t id = row.id;
std::string name = row.name; std::string name = row.name;
int64_t feature = row.feature; int64_t feature = row.feature;
} }
#if 0
#if 0
for (const auto& row : db(select(p.name).from(p).where(p.name.like("Herb%")))) for (const auto& row : db(select(p.name).from(p).where(p.name.like("Herb%"))))
{ {
int64_t id = row.id; int64_t id = row.id;
@ -63,8 +64,6 @@ int main()
} }
#endif #endif
#if 0 #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))) for (const auto& row : db(select(p.name, f.name.as(cheesecake)).from(p,f).where(p.id > 7 and p.feature == 3)))
{ {
@ -75,8 +74,6 @@ int main()
} }
#endif #endif
#if 0 #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))) 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)))
{ {
@ -88,12 +85,6 @@ int main()
} }
#endif #endif
#if 0 #if 0
auto s = select(p.id, p.name, f.id.as(cheesecake)) auto s = select(p.id, p.name, f.id.as(cheesecake))
.from(p, f) .from(p, f)
@ -117,40 +108,21 @@ int main()
} }
#endif #endif
#if !0 #if !0
auto dysel = dynamic_select(db).dynamic_columns(p.name).from(p).dynamic_where(); auto dysel = dynamic_select(db).dynamic_columns(p.name).from(p).dynamic_where();
if (some_condition) if (some_condition)
dysel.selected_columns.add(p.feature); dysel.selected_columns.add(p.feature);
if (some_other_condition) if (some_other_condition)
dysel.where.add(p.id > 17); dysel.where.add(p.id > 17);
for (const auto& row : db(dysel)) for (const auto& row : db(dysel))
{ {
std::string name = row.name; std::string name = row.name;
std::string feature = row.at("feature"); std::string feature = row.at("feature");
} }
#endif #endif
return 0;
} }

View File

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

View File

@ -0,0 +1,36 @@
/*
* 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_AGGREGATE_FUNCTIONS_H
#define SQLPP_AGGREGATE_FUNCTIONS_H
#include <sqlpp11/aggregate_functions/count.h>
#include <sqlpp11/aggregate_functions/min.h>
#include <sqlpp11/aggregate_functions/max.h>
#include <sqlpp11/aggregate_functions/avg.h>
#include <sqlpp11/aggregate_functions/sum.h>
#endif

View File

@ -0,0 +1,128 @@
/*
* 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_AVG_H
#define SQLPP_AVG_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/char_sequence.h>
namespace sqlpp
{
struct avg_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "avg_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T avg;
T& operator()()
{
return avg;
}
const T& operator()() const
{
return avg;
}
};
};
};
template <typename Flag, typename Expr>
struct avg_t : public expression_operators<avg_t<Flag, Expr>, floating_point>,
public alias_operators<avg_t<Flag, Expr>>
{
using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value,
"avg() used with flag other than 'distinct'");
static_assert(is_numeric_t<Expr>::value, "avg() requires a value expression as argument");
using _auto_alias_t = avg_alias_t;
avg_t(Expr expr) : _expr(expr)
{
}
avg_t(const avg_t&) = default;
avg_t(avg_t&&) = default;
avg_t& operator=(const avg_t&) = default;
avg_t& operator=(avg_t&&) = default;
~avg_t() = default;
Expr _expr;
};
template <typename Context, typename Flag, typename Expr>
struct serializer_t<Context, avg_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = avg_t<Flag, Expr>;
static Context& _(const T& t, Context& context)
{
context << "AVG(";
if (std::is_same<distinct_t, Flag>::value)
{
serialize(Flag(), context);
context << ' ';
serialize_operand(t._expr, context);
}
else
{
serialize(t._expr, context);
}
context << ")";
return context;
}
};
template <typename T>
auto avg(T t) -> avg_t<noop, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"avg() cannot be used on an aggregate function");
static_assert(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return {t};
}
template <typename T>
auto avg(const distinct_t&, T t) -> avg_t<distinct_t, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"avg() cannot be used on an aggregate function");
static_assert(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return {t};
}
}
#endif

View File

@ -0,0 +1,129 @@
/*
* 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_COUNT_H
#define SQLPP_COUNT_H
#include <sqlpp11/char_sequence.h>
#include <sqlpp11/select_flags.h>
#include <sqlpp11/data_types/integral/data_type.h>
namespace sqlpp
{
struct count_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "count_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T count;
T& operator()()
{
return count;
}
const T& operator()() const
{
return count;
}
};
};
};
template <typename Flag, typename Expr>
struct count_t : public expression_operators<count_t<Flag, Expr>, integral>,
public alias_operators<count_t<Flag, Expr>>
{
using _traits = make_traits<integral, tag::is_expression /*, tag::is_selectable*/>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _can_be_null = std::false_type;
using _is_aggregate_expression = std::true_type;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value,
"count() used with flag other than 'distinct'");
using _auto_alias_t = count_alias_t;
count_t(const Expr expr) : _expr(expr)
{
}
count_t(const count_t&) = default;
count_t(count_t&&) = default;
count_t& operator=(const count_t&) = default;
count_t& operator=(count_t&&) = default;
~count_t() = default;
Expr _expr;
};
template <typename Context, typename Flag, typename Expr>
struct serializer_t<Context, count_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = count_t<Flag, Expr>;
static Context& _(const T& t, Context& context)
{
context << "COUNT(";
if (std::is_same<distinct_t, Flag>::value)
{
serialize(Flag(), context);
context << ' ';
serialize_operand(t._expr, context);
}
else
{
serialize(t._expr, context);
}
context << ")";
return context;
}
};
template <typename T>
auto count(T t) -> count_t<noop, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"count() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return {t};
}
template <typename T>
auto count(const distinct_t&, T t) -> count_t<distinct_t, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"count() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return {t};
}
}
#endif

View File

@ -0,0 +1,105 @@
/*
* 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_MAX_H
#define SQLPP_MAX_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/char_sequence.h>
namespace sqlpp
{
struct max_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "max_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T max;
T& operator()()
{
return max;
}
const T& operator()() const
{
return max;
}
};
};
};
template <typename Expr>
struct max_t : public expression_operators<max_t<Expr>, value_type_of<Expr>>, public alias_operators<max_t<Expr>>
{
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;
using _auto_alias_t = max_alias_t;
max_t(Expr expr) : _expr(expr)
{
}
max_t(const max_t&) = default;
max_t(max_t&&) = default;
max_t& operator=(const max_t&) = default;
max_t& operator=(max_t&&) = default;
~max_t() = default;
Expr _expr;
};
template <typename Context, typename Expr>
struct serializer_t<Context, max_t<Expr>>
{
using _serialize_check = serialize_check_of<Context, Expr>;
using T = max_t<Expr>;
static Context& _(const T& t, Context& context)
{
context << "MAX(";
serialize(t._expr, context);
context << ")";
return context;
}
};
template <typename T>
auto max(T t) -> max_t<wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"max() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "max() requires an expression as argument");
return {t};
}
}
#endif

View File

@ -0,0 +1,105 @@
/*
* 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_MIN_H
#define SQLPP_MIN_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/char_sequence.h>
namespace sqlpp
{
struct min_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "min_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T min;
T& operator()()
{
return min;
}
const T& operator()() const
{
return min;
}
};
};
};
template <typename Expr>
struct min_t : public expression_operators<min_t<Expr>, value_type_of<Expr>>, public alias_operators<min_t<Expr>>
{
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;
using _auto_alias_t = min_alias_t;
min_t(Expr expr) : _expr(expr)
{
}
min_t(const min_t&) = default;
min_t(min_t&&) = default;
min_t& operator=(const min_t&) = default;
min_t& operator=(min_t&&) = default;
~min_t() = default;
Expr _expr;
};
template <typename Context, typename Expr>
struct serializer_t<Context, min_t<Expr>>
{
using _serialize_check = serialize_check_of<Context, Expr>;
using T = min_t<Expr>;
static Context& _(const T& t, Context& context)
{
context << "MIN(";
serialize(t._expr, context);
context << ")";
return context;
}
};
template <typename T>
auto min(T t) -> min_t<wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"min() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "min() requires an expression as argument");
return {t};
}
}
#endif

View File

@ -0,0 +1,127 @@
/*
* 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_SUM_H
#define SQLPP_SUM_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/char_sequence.h>
namespace sqlpp
{
struct sum_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "sum_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T sum;
T& operator()()
{
return sum;
}
const T& operator()() const
{
return sum;
}
};
};
};
template <typename Flag, typename Expr>
struct sum_t : public expression_operators<sum_t<Flag, Expr>, value_type_of<Expr>>,
public alias_operators<sum_t<Flag, Expr>>
{
using _traits = make_traits<value_type_of<Expr>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _can_be_null = std::true_type;
using _is_aggregate_expression = std::true_type;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value,
"sum() used with flag other than 'distinct'");
static_assert(is_numeric_t<Expr>::value, "sum() requires a numeric expression as argument");
using _auto_alias_t = sum_alias_t;
sum_t(Expr expr) : _expr(expr)
{
}
sum_t(const sum_t&) = default;
sum_t(sum_t&&) = default;
sum_t& operator=(const sum_t&) = default;
sum_t& operator=(sum_t&&) = default;
~sum_t() = default;
Expr _expr;
};
template <typename Context, typename Flag, typename Expr>
struct serializer_t<Context, sum_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = sum_t<Flag, Expr>;
static Context& _(const T& t, Context& context)
{
context << "SUM(";
if (std::is_same<distinct_t, Flag>::value)
{
serialize(Flag(), context);
context << ' ';
serialize_operand(t._expr, context);
}
else
serialize(t._expr, context);
context << ")";
return context;
}
};
template <typename T>
auto sum(T t) -> sum_t<noop, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"sum() cannot be used on an aggregate function");
static_assert(is_numeric_t<wrap_operand_t<T>>::value, "sum() requires a numeric expression as argument");
return {t};
}
template <typename T>
auto sum(const distinct_t&, T t) -> sum_t<distinct_t, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value,
"sum() cannot be used on an aggregate function");
static_assert(is_numeric_t<wrap_operand_t<T>>::value, "sum() requires a numeric expression as argument");
return {t};
}
}
#endif

View File

@ -32,35 +32,44 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Expression, typename AliasProvider> template <typename Expression, typename AliasProvider>
struct expression_alias_t struct expression_alias_t
{ {
using _traits = make_traits<value_type_of<Expression>, tag::is_selectable, tag::is_alias>; using _traits = make_traits<value_type_of<Expression>, tag::is_selectable, tag::is_alias>;
using _nodes = detail::type_vector<Expression>; using _nodes = detail::type_vector<Expression>;
static_assert(is_expression_t<Expression>::value, "invalid argument for an expression alias"); static_assert(is_expression_t<Expression>::value, "invalid argument for an expression alias");
static_assert(not is_alias_t<Expression>::value, "cannot create an alias of an alias"); static_assert(not is_alias_t<Expression>::value, "cannot create an alias of an alias");
using _alias_t = typename AliasProvider::_alias_t; using _alias_t = typename AliasProvider::_alias_t;
Expression _expression; expression_alias_t(Expression expression) : _expression(expression)
}; {
}
template<typename Context, typename Expression, typename AliasProvider> expression_alias_t(const expression_alias_t&) = default;
struct serializer_t<Context, expression_alias_t<Expression, AliasProvider>> expression_alias_t(expression_alias_t&&) = default;
{ expression_alias_t& operator=(const expression_alias_t&) = default;
using _serialize_check = serialize_check_of<Context, Expression>; expression_alias_t& operator=(expression_alias_t&&) = default;
using T = expression_alias_t<Expression, AliasProvider>; ~expression_alias_t() = default;
static Context& _(const T& t, Context& context) Expression _expression;
{ };
serialize_operand(t._expression, context);
context << " AS ";
context << name_of<T>::char_ptr();
return context;
}
};
template <typename Context, typename Expression, typename AliasProvider>
struct serializer_t<Context, expression_alias_t<Expression, AliasProvider>>
{
using _serialize_check = serialize_check_of<Context, Expression>;
using T = expression_alias_t<Expression, AliasProvider>;
static Context& _(const T& t, Context& context)
{
serialize_operand(t._expression, context);
context << " AS ";
context << name_of<T>::char_ptr();
return context;
}
};
} }
#endif #endif

View File

@ -0,0 +1,44 @@
/*
* 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_ALIAS_OPERATORS_H
#define SQLPP_ALIAS_OPERATORS_H
#include <sqlpp11/alias.h>
namespace sqlpp
{
template <typename Expr>
struct alias_operators
{
template <typename alias_provider>
expression_alias_t<Expr, alias_provider> as(const alias_provider&) const
{
return {*static_cast<const Expr*>(this)};
}
};
}
#endif

View File

@ -30,69 +30,76 @@
#include <type_traits> #include <type_traits>
#include <sqlpp11/char_sequence.h> #include <sqlpp11/char_sequence.h>
#define SQLPP_ALIAS_PROVIDER(name) \ #define SQLPP_ALIAS_PROVIDER(name) \
struct name##_t\ struct name##_t \
{\ { \
struct _alias_t\ struct _alias_t \
{\ { \
static constexpr const char _literal[] = #name;\ static constexpr const char _literal[] = #name; \
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;\ using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>; \
template<typename T>\ template <typename T> \
struct _member_t\ struct _member_t \
{\ { \
T name;\ T name; \
T& operator()() { return name; }\ T& operator()() \
const T& operator()() const { return name; }\ { \
};\ return name; \
};\ } \
};\ const T& operator()() const \
constexpr name##_t name = {}; { \
return name; \
} \
}; \
}; \
}; \
constexpr name##_t name = {};
namespace sqlpp namespace sqlpp
{ {
template<typename T, typename Enable = void> template <typename T, typename Enable = void>
struct is_alias_provider_t struct is_alias_provider_t
{ {
static constexpr bool value = false; static constexpr bool value = false;
}; };
template<typename T> template <typename T>
struct is_alias_provider_t<T, typename std::enable_if<std::is_class<typename T::_alias_t::template _member_t<int>>::value, void>::type> struct is_alias_provider_t<
{ T,
static constexpr bool value = true; typename std::enable_if<std::is_class<typename T::_alias_t::template _member_t<int>>::value, void>::type>
}; {
static constexpr bool value = true;
};
namespace alias namespace alias
{ {
SQLPP_ALIAS_PROVIDER(a) SQLPP_ALIAS_PROVIDER(a)
SQLPP_ALIAS_PROVIDER(b) SQLPP_ALIAS_PROVIDER(b)
SQLPP_ALIAS_PROVIDER(c) SQLPP_ALIAS_PROVIDER(c)
SQLPP_ALIAS_PROVIDER(d) SQLPP_ALIAS_PROVIDER(d)
SQLPP_ALIAS_PROVIDER(e) SQLPP_ALIAS_PROVIDER(e)
SQLPP_ALIAS_PROVIDER(f) SQLPP_ALIAS_PROVIDER(f)
SQLPP_ALIAS_PROVIDER(g) SQLPP_ALIAS_PROVIDER(g)
SQLPP_ALIAS_PROVIDER(h) SQLPP_ALIAS_PROVIDER(h)
SQLPP_ALIAS_PROVIDER(i) SQLPP_ALIAS_PROVIDER(i)
SQLPP_ALIAS_PROVIDER(j) SQLPP_ALIAS_PROVIDER(j)
SQLPP_ALIAS_PROVIDER(k) SQLPP_ALIAS_PROVIDER(k)
SQLPP_ALIAS_PROVIDER(l) SQLPP_ALIAS_PROVIDER(l)
SQLPP_ALIAS_PROVIDER(m) SQLPP_ALIAS_PROVIDER(m)
SQLPP_ALIAS_PROVIDER(n) SQLPP_ALIAS_PROVIDER(n)
SQLPP_ALIAS_PROVIDER(o) SQLPP_ALIAS_PROVIDER(o)
SQLPP_ALIAS_PROVIDER(p) SQLPP_ALIAS_PROVIDER(p)
SQLPP_ALIAS_PROVIDER(q) SQLPP_ALIAS_PROVIDER(q)
SQLPP_ALIAS_PROVIDER(s) SQLPP_ALIAS_PROVIDER(s)
SQLPP_ALIAS_PROVIDER(t) SQLPP_ALIAS_PROVIDER(t)
SQLPP_ALIAS_PROVIDER(u) SQLPP_ALIAS_PROVIDER(u)
SQLPP_ALIAS_PROVIDER(v) SQLPP_ALIAS_PROVIDER(v)
SQLPP_ALIAS_PROVIDER(w) SQLPP_ALIAS_PROVIDER(w)
SQLPP_ALIAS_PROVIDER(x) SQLPP_ALIAS_PROVIDER(x)
SQLPP_ALIAS_PROVIDER(y) SQLPP_ALIAS_PROVIDER(y)
SQLPP_ALIAS_PROVIDER(z) SQLPP_ALIAS_PROVIDER(z)
SQLPP_ALIAS_PROVIDER(left) SQLPP_ALIAS_PROVIDER(left)
SQLPP_ALIAS_PROVIDER(right) SQLPP_ALIAS_PROVIDER(right)
} }
} }
#endif #endif

View File

@ -30,51 +30,41 @@
#include <sqlpp11/interpret.h> #include <sqlpp11/interpret.h>
#include <sqlpp11/alias.h> #include <sqlpp11/alias.h>
#include <sqlpp11/multi_column.h> #include <sqlpp11/multi_column.h>
#include <sqlpp11/portable_static_assert.h>
namespace sqlpp namespace sqlpp
{ {
template<typename Table> template <typename Table>
struct all_of_t struct all_of_t
{ {
using _column_tuple_t = typename Table::_column_tuple_t; using _column_tuple_t = typename Table::_column_tuple_t;
template<typename AliasProvider> template <typename AliasProvider>
detail::copy_tuple_args_t<multi_column_alias_t, AliasProvider, _column_tuple_t> as(const AliasProvider& alias) detail::copy_tuple_args_t<multi_column_alias_t, AliasProvider, _column_tuple_t> as(const AliasProvider& alias)
{ {
return multi_column(_column_tuple_t{}).as(alias); return multi_column(_column_tuple_t{}).as(alias);
} }
}; };
template<typename Table> template <typename Table>
auto all_of(Table t) -> all_of_t<Table> auto all_of(Table) -> all_of_t<Table>
{ {
return {}; return {};
} }
struct assert_no_stand_alone_all_of_t SQLPP_PORTABLE_STATIC_ASSERT(assert_no_stand_alone_all_of_t, "all_of(table) seems to be used outside of select");
{
using type = std::false_type;
template<typename T = void> template <typename Context, typename Table>
static void _() struct serializer_t<Context, all_of_t<Table>>
{ {
static_assert(wrong_t<T>::value, "all_of(table) seems to be used outside of select"); using _serialize_check = assert_no_stand_alone_all_of_t;
} using T = all_of_t<Table>;
};
template<typename Context, typename Table>
struct serializer_t<Context, all_of_t<Table>>
{
using _serialize_check = assert_no_stand_alone_all_of_t;
using T = all_of_t<Table>;
static Context& _(const T& t, const Context&)
{
_serialize_check::_();
}
};
static Context& _(const T&, const Context&)
{
_serialize_check::_();
}
};
} }
#endif #endif

View File

@ -27,68 +27,55 @@
#ifndef SQLPP_ANY_H #ifndef SQLPP_ANY_H
#define SQLPP_ANY_H #define SQLPP_ANY_H
#include <sqlpp11/boolean.h> #include <sqlpp11/data_types/boolean.h>
#include <sqlpp11/char_sequence.h> #include <sqlpp11/char_sequence.h>
#include <sqlpp11/detail/type_set.h> #include <sqlpp11/detail/type_set.h>
namespace sqlpp namespace sqlpp
{ {
template<typename Select> template <typename Select>
struct any_t struct any_t
{ {
using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>; using _traits = make_traits<value_type_of<Select>, tag::is_multi_expression>;
using _nodes = detail::type_vector<Select>; using _nodes = detail::type_vector<Select>;
struct _alias_t any_t(Select select) : _select(select)
{ {
static constexpr const char _literal[] = "any_"; }
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T any;
T& operator()() { return any; }
const T& operator()() const { return any; }
};
};
any_t(Select select): any_t(const any_t&) = default;
_select(select) any_t(any_t&&) = default;
{} any_t& operator=(const any_t&) = default;
any_t& operator=(any_t&&) = default;
~any_t() = default;
any_t(const any_t&) = default; Select _select;
any_t(any_t&&) = default; };
any_t& operator=(const any_t&) = default;
any_t& operator=(any_t&&) = default;
~any_t() = default;
Select _select; template <typename Context, typename Select>
}; struct serializer_t<Context, any_t<Select>>
{
using _serialize_check = serialize_check_of<Context, Select>;
using T = any_t<Select>;
template<typename Context, typename Select> static Context& _(const T& t, Context& context)
struct serializer_t<Context, any_t<Select>> {
{ context << "ANY(";
using _serialize_check = serialize_check_of<Context, Select>; serialize(t._select, context);
using T = any_t<Select>; context << ")";
return context;
static Context& _(const T& t, Context& context) }
{ };
context << "ANY(";
serialize(t._select, context);
context << ")";
return context;
}
};
template<typename T>
auto any(T t) -> any_t<wrap_operand_t<T>>
{
static_assert(is_select_t<wrap_operand_t<T>>::value, "any() requires a select expression as argument");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "any() requires a single column select expression as argument");
// FIXME: can we accept non-values like NULL here?
return { t };
}
template <typename T>
auto any(T t) -> any_t<wrap_operand_t<T>>
{
static_assert(is_select_t<wrap_operand_t<T>>::value, "any() requires a select expression as argument");
static_assert(is_expression_t<wrap_operand_t<T>>::value,
"any() requires a single column select expression as argument");
// FIXME: can we accept non-values like NULL here?
return {t};
}
} }
#endif #endif

View File

@ -37,46 +37,46 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Lhs, typename Rhs> template <typename Lhs, typename Rhs>
struct assignment_t struct assignment_t
{ {
using _traits = make_traits<no_value_t, tag::is_assignment>; using _traits = make_traits<no_value_t, tag::is_assignment>;
using _lhs_t = Lhs; using _lhs_t = Lhs;
using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>; using _rhs_t = rhs_wrap_t<allow_tvin_t<Rhs>, trivial_value_is_null_t<_lhs_t>::value>;
using _nodes = detail::type_vector<_lhs_t, _rhs_t>; using _nodes = detail::type_vector<_lhs_t, _rhs_t>;
static_assert(can_be_null_t<_lhs_t>::value ? true : not (std::is_same<_rhs_t, null_t>::value or is_tvin_t<_rhs_t>::value), "column must not be null"); static_assert(can_be_null_t<_lhs_t>::value ? true
: not(std::is_same<_rhs_t, null_t>::value or is_tvin_t<_rhs_t>::value),
"column must not be null");
assignment_t(_lhs_t lhs, _rhs_t rhs): assignment_t(_lhs_t lhs, _rhs_t rhs) : _lhs(lhs), _rhs(rhs)
_lhs(lhs), {
_rhs(rhs) }
{}
assignment_t(const assignment_t&) = default; assignment_t(const assignment_t&) = default;
assignment_t(assignment_t&&) = default; assignment_t(assignment_t&&) = default;
assignment_t& operator=(const assignment_t&) = default; assignment_t& operator=(const assignment_t&) = default;
assignment_t& operator=(assignment_t&&) = default; assignment_t& operator=(assignment_t&&) = default;
~assignment_t() = default; ~assignment_t() = default;
_lhs_t _lhs; _lhs_t _lhs;
_rhs_t _rhs; _rhs_t _rhs;
}; };
template<typename Context, typename Lhs, typename Rhs> template <typename Context, typename Lhs, typename Rhs>
struct serializer_t<Context, assignment_t<Lhs, Rhs>> struct serializer_t<Context, assignment_t<Lhs, Rhs>>
{ {
using T = assignment_t<Lhs, Rhs>; using T = assignment_t<Lhs, Rhs>;
using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>; using _serialize_check = serialize_check_of<Context, typename T::_lhs_t, typename T::_rhs_t>;
static Context& _(const T& t, Context& context)
{
serialize(simple_column(t._lhs), context);
context << "=";
serialize_operand(t._rhs, context);
return context;
}
};
static Context& _(const T& t, Context& context)
{
serialize(simple_column(t._lhs), context);
context << "=";
serialize_operand(t._rhs, context);
return context;
}
};
} }
#endif #endif

View File

@ -0,0 +1,65 @@
/*
* 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_AUTO_ALIAS_H
#define SQLPP_AUTO_ALIAS_H
#include <sqlpp11/alias.h>
namespace sqlpp
{
template <typename T, typename Enable = void>
struct has_auto_alias_t
{
static constexpr bool value = false;
};
template <typename T>
struct has_auto_alias_t<T, typename std::enable_if<not wrong_t<typename T::_auto_alias_t>::value>::type>
{
static constexpr bool value = true;
};
namespace detail
{
template <typename T, typename Enable = void>
struct auto_alias_impl
{
using type = T;
};
template <typename T>
struct auto_alias_impl<T, typename std::enable_if<has_auto_alias_t<T>::value>::type>
{
using type = expression_alias_t<T, typename T::_auto_alias_t>;
};
}
template <typename T>
using auto_alias_t = typename detail::auto_alias_impl<T>::type;
}
#endif

View File

@ -1,114 +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_AVG_H
#define SQLPP_AVG_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/char_sequence.h>
namespace sqlpp
{
template<typename Flag, typename Expr>
struct avg_t:
public expression_operators<avg_t<Flag, Expr>, floating_point>,
public alias_operators<avg_t<Flag, Expr>>
{
using _traits = make_traits<floating_point, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "avg() used with flag other than 'distinct'");
static_assert(is_numeric_t<Expr>::value, "avg() requires a value expression as argument");
struct _alias_t
{
static constexpr const char _literal[] = "avg_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T avg;
T& operator()() { return avg; }
const T& operator()() const { return avg; }
};
};
avg_t(Expr expr):
_expr(expr)
{}
avg_t(const avg_t&) = default;
avg_t(avg_t&&) = default;
avg_t& operator=(const avg_t&) = default;
avg_t& operator=(avg_t&&) = default;
~avg_t() = default;
Expr _expr;
};
template<typename Context, typename Flag, typename Expr>
struct serializer_t<Context, avg_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = avg_t<Flag, Expr>;
static Context& _(const T& t, Context& context)
{
context << "AVG(";
if (std::is_same<distinct_t, Flag>::value)
{
serialize(Flag(), context);
context << ' ';
serialize_operand(t._expr, context);
}
else
{
serialize(t._expr, context);
}
context << ")";
return context;
}
};
template<typename T>
auto avg(T t) -> avg_t<noop, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "avg() cannot be used on an aggregate function");
static_assert(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return { t };
}
template<typename T>
auto avg(const distinct_t&, T t) -> avg_t<distinct_t, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "avg() cannot be used on an aggregate function");
static_assert(is_numeric_t<wrap_operand_t<T>>::value, "avg() requires a value expression as argument");
return { t };
}
}
#endif

View File

@ -0,0 +1,58 @@
/*
* 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_BAD_EXPRESSION_H
#define SQLPP_BAD_EXPRESSION_H
#include <sqlpp11/portable_static_assert.h>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
SQLPP_PORTABLE_STATIC_ASSERT(assert_valid_operands, "Invalid operand(s)");
template <typename ValueType>
struct bad_expression
{
template <typename... T>
bad_expression(T&&...)
{
}
using _traits = make_traits<ValueType, tag::is_expression>;
using _nodes = detail::type_vector<>;
};
template <typename Context, typename ValueType>
struct serializer_t<Context, bad_expression<ValueType>>
{
using _serialize_check = assert_valid_operands;
using T = bad_expression<ValueType>;
static Context& _(const T&, Context&);
};
}
#endif

View File

@ -29,13 +29,13 @@
namespace sqlpp namespace sqlpp
{ {
struct bad_statement struct bad_statement
{ {
template<typename... T> template <typename... T>
bad_statement(T&&...) {} bad_statement(T&&...)
}; {
}
};
} }
#endif #endif

View File

@ -28,129 +28,306 @@
#define SQLPP_DETAIL_BASIC_EXPRESSION_OPERATORS_H #define SQLPP_DETAIL_BASIC_EXPRESSION_OPERATORS_H
#include <sqlpp11/value_type_fwd.h> #include <sqlpp11/value_type_fwd.h>
#include <sqlpp11/bad_statement.h>
#include <sqlpp11/portable_static_assert.h>
#include <sqlpp11/consistent.h>
#include <sqlpp11/alias.h> #include <sqlpp11/alias.h>
#include <sqlpp11/sort_order.h> #include <sqlpp11/sort_order.h>
#include <sqlpp11/expression_fwd.h> #include <sqlpp11/expression_fwd.h>
#include <sqlpp11/in_fwd.h> #include <sqlpp11/in_fwd.h>
#include <sqlpp11/is_null_fwd.h> #include <sqlpp11/is_null_fwd.h>
#include <sqlpp11/wrap_operand_fwd.h> #include <sqlpp11/wrap_operand.h>
#include <sqlpp11/logic.h> #include <sqlpp11/logic.h>
namespace sqlpp namespace sqlpp
{ {
// basic operators SQLPP_PORTABLE_STATIC_ASSERT(assert_valid_rhs_comparison_operand_t, "invalid rhs operand in comparison");
template<typename Expr, typename ValueType>
struct basic_expression_operators
{
template<typename T>
struct _is_valid_comparison_operand
{
static constexpr bool value =
(is_expression_t<T>::value // expressions are OK
or is_multi_expression_t<T>::value) // multi-expressions like ANY are OK for comparisons, too
and ValueType::template _is_valid_operand<T>::value // the correct value type is required, of course
;
};
template<typename T> template <typename LhsValueType, typename RhsType>
equal_to_t<Expr, wrap_operand_t<T>> operator==(T t) const using check_rhs_comparison_operand_t =
{ static_check_t<(is_expression_t<sqlpp::wrap_operand_t<RhsType>>::value // expressions are OK
using rhs = wrap_operand_t<T>; or
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); is_multi_expression_t<sqlpp::wrap_operand_t<RhsType>>::value) // multi-expressions like ANY are
// OK for comparisons, too
and
LhsValueType::template _is_valid_operand<
sqlpp::wrap_operand_t<RhsType>>::value, // the correct value type is required, of course
assert_valid_rhs_comparison_operand_t>;
return { *static_cast<const Expr*>(this), {rhs{t}} }; SQLPP_PORTABLE_STATIC_ASSERT(assert_valid_in_arguments_t, "at least one operand of in() is not valid");
}
template<typename T> template <typename LhsValueType, typename... InTypes>
not_equal_to_t<Expr, wrap_operand_t<T>> operator!=(T t) const using check_rhs_in_arguments_t =
{ static_check_t<logic::all_t<check_rhs_comparison_operand_t<LhsValueType, InTypes>::value...>::value,
using rhs = wrap_operand_t<T>; assert_valid_in_arguments_t>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison");
return { *static_cast<const Expr*>(this), {rhs{t}} }; namespace detail
} {
template <bool Enable, template <typename Lhs> class Expr, typename Lhs>
struct new_unary_expression_impl
{
using type = bad_statement;
};
template<typename T> template <template <typename Lhs> class Expr, typename Lhs>
less_than_t<Expr, wrap_operand_t<T>> operator<(T t) const struct new_unary_expression_impl<true, Expr, Lhs>
{ {
using rhs = wrap_operand_t<T>; using type = Expr<Lhs>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); };
}
template <typename Check, template <typename Lhs> class Expr, typename Lhs>
using new_unary_expression_t = typename detail::new_unary_expression_impl<Check::value, Expr, Lhs>::type;
return { *static_cast<const Expr*>(this), rhs{t} }; namespace detail
} {
template <bool Enable, template <typename Lhs, typename Rhs> class Expr, typename Lhs, typename Rhs>
struct new_binary_expression_impl
{
using type = bad_statement;
};
template<typename T> template <template <typename Lhs, typename Rhs> class Expr, typename Lhs, typename Rhs>
less_equal_t<Expr, wrap_operand_t<T>> operator<=(T t) const struct new_binary_expression_impl<true, Expr, Lhs, Rhs>
{ {
using rhs = wrap_operand_t<T>; using type = Expr<Lhs, Rhs>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); };
}
template <typename Check, template <typename Lhs, typename Rhs> class Expr, typename Lhs, typename Rhs>
using new_binary_expression_t = typename detail::new_binary_expression_impl<Check::value, Expr, Lhs, Rhs>::type;
return { *static_cast<const Expr*>(this), rhs{t} }; namespace detail
} {
template <bool Enable, template <typename Lhs, typename... Rhs> class Expr, typename Lhs, typename... Rhs>
struct new_nary_expression_impl
{
using type = bad_statement;
};
template<typename T> template <template <typename Lhs, typename... Rhs> class Expr, typename Lhs, typename... Rhs>
greater_than_t<Expr, wrap_operand_t<T>> operator>(T t) const struct new_nary_expression_impl<true, Expr, Lhs, Rhs...>
{ {
using rhs = wrap_operand_t<T>; using type = Expr<Lhs, Rhs...>;
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); };
}
template <typename Check, template <typename Lhs, typename... Rhs> class Expr, typename Lhs, typename... Rhs>
using new_nary_expression_t = typename detail::new_nary_expression_impl<Check::value, Expr, Lhs, Rhs...>::type;
return { *static_cast<const Expr*>(this), rhs{t} }; // basic operators
} template <typename Expr, typename ValueType>
struct basic_expression_operators
{
template <template <typename Lhs, typename Rhs> class NewExpr, typename T>
using _new_binary_expression_t =
new_binary_expression_t<check_rhs_comparison_operand_t<ValueType, wrap_operand_t<T>>,
NewExpr,
Expr,
wrap_operand_t<T>>;
template<typename T> // workaround for msvs bug
greater_equal_t<Expr, wrap_operand_t<T>> operator>=(T t) const // template <template <typename Lhs, typename... Rhs> class NewExpr, typename... T>
{ // using _new_nary_expression_t =
using rhs = wrap_operand_t<T>; // new_nary_expression_t<logic::all_t<check_rhs_comparison_operand_t<ValueType,
static_assert(_is_valid_comparison_operand<rhs>::value, "invalid rhs operand in comparison"); // wrap_operand_t<T>>::value...>,
// NewExpr,
// Expr,
// wrap_operand_t<T>...>;
template <template <typename Lhs, typename... Rhs> class NewExpr, typename... T>
struct _new_nary_expression
{
using type =
new_nary_expression_t<logic::all_t<check_rhs_comparison_operand_t<ValueType, wrap_operand_t<T>>::value...>,
NewExpr,
Expr,
wrap_operand_t<T>...>;
};
return { *static_cast<const Expr*>(this), rhs{t} }; template <typename T>
} _new_binary_expression_t<equal_to_t, T> operator==(T t) const
{
using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<ValueType, rhs>::_();
is_null_t<Expr> is_null() const return {*static_cast<const Expr*>(this), {rhs{t}}};
{ }
return { *static_cast<const Expr*>(this) };
}
is_not_null_t<Expr> is_not_null() const template <typename T>
{ _new_binary_expression_t<not_equal_to_t, T> operator!=(T t) const
return { *static_cast<const Expr*>(this) }; {
} using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<ValueType, rhs>::_();
sort_order_t<Expr, sort_type::asc> asc() const return {*static_cast<const Expr*>(this), {rhs{t}}};
{ }
return { *static_cast<const Expr*>(this) };
}
sort_order_t<Expr, sort_type::desc> desc() const template <typename T>
{ _new_binary_expression_t<less_than_t, T> operator<(T t) const
return { *static_cast<const Expr*>(this) }; {
} using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<ValueType, rhs>::_();
// Hint: use value_list wrapper for containers... return {*static_cast<const Expr*>(this), rhs{t}};
template<typename... T> }
in_t<Expr, wrap_operand_t<T>...> in(T... t) const
{
static_assert(logic::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid");
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... };
}
template<typename... T> template <typename T>
not_in_t<Expr, wrap_operand_t<T>...> not_in(T... t) const _new_binary_expression_t<less_equal_t, T> operator<=(T t) const
{ {
static_assert(logic::all_t<_is_valid_comparison_operand<wrap_operand_t<T>>::value...>::value, "at least one operand of in() is not valid"); using rhs = wrap_operand_t<T>;
return { *static_cast<const Expr*>(this), wrap_operand_t<T>{t}... }; check_rhs_comparison_operand_t<ValueType, rhs>::_();
}
};
template<typename Expr> return {*static_cast<const Expr*>(this), rhs{t}};
struct alias_operators }
{
template<typename alias_provider>
expression_alias_t<Expr, alias_provider> as(const alias_provider&) const
{
return { *static_cast<const Expr*>(this) };
}
};
template <typename T>
_new_binary_expression_t<greater_than_t, T> operator>(T t) const
{
using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<ValueType, rhs>::_();
return {*static_cast<const Expr*>(this), rhs{t}};
}
template <typename T>
_new_binary_expression_t<greater_equal_t, T> operator>=(T t) const
{
using rhs = wrap_operand_t<T>;
check_rhs_comparison_operand_t<ValueType, rhs>::_();
return {*static_cast<const Expr*>(this), rhs{t}};
}
is_null_t<Expr> is_null() const
{
return {*static_cast<const Expr*>(this)};
}
is_not_null_t<Expr> is_not_null() const
{
return {*static_cast<const Expr*>(this)};
}
sort_order_t<Expr, sort_type::asc> asc() const
{
return {*static_cast<const Expr*>(this)};
}
sort_order_t<Expr, sort_type::desc> desc() const
{
return {*static_cast<const Expr*>(this)};
}
// Hint: use value_list wrapper for containers...
// workaround for msvs bug
// template <typename... T>
// _new_nary_expression_t<in_t, T...> in(T... t) const
// {
// check_rhs_in_arguments_t<ValueType, wrap_operand_t<T>...>::_();
// return {*static_cast<const Expr*>(this), wrap_operand_t<T>{t}...};
// }
template <typename... T>
typename _new_nary_expression<in_t, T...>::type in(T... t) const
{
check_rhs_in_arguments_t<ValueType, wrap_operand_t<T>...>::_();
return {*static_cast<const Expr*>(this), typename wrap_operand<T>::type{t}...};
}
// workaround for msvs bug
// template <typename... T>
// _new_nary_expression_t<not_in_t, T...> not_in(T... t) const
// {
// check_rhs_in_arguments_t<ValueType, wrap_operand_t<T>...>::_();
// return {*static_cast<const Expr*>(this), wrap_operand_t<T>{t}...};
// }
template <typename... T>
typename _new_nary_expression<not_in_t, T...>::type not_in(T... t) const
{
check_rhs_in_arguments_t<ValueType, wrap_operand_t<T>...>::_();
return {*static_cast<const Expr*>(this), typename wrap_operand<T>::type{t}...};
}
template <typename Defer = void>
auto operator not() const -> return_type_not_t<Expr, Defer>
{
return_type_not<Expr, Defer>::check::_();
return {*static_cast<const Expr*>(this)};
}
template <typename R>
auto operator and(const R& r) const -> return_type_and_t<Expr, R>
{
return_type_and<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator&(const R& r) const -> return_type_bitwise_and_t<Expr, R>
{
return_type_bitwise_and<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator|(const R& r) const -> return_type_bitwise_or_t<Expr, R>
{
return_type_bitwise_or<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator or(const R& r) const -> return_type_or_t<Expr, R>
{
return_type_or<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator+(const R& r) const -> return_type_plus_t<Expr, R>
{
return_type_plus<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator-(const R& r) const -> return_type_minus_t<Expr, R>
{
return_type_minus<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator*(const R& r) const -> return_type_multiplies_t<Expr, R>
{
return_type_multiplies<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator/(const R& r) const -> return_type_divides_t<Expr, R>
{
return_type_divides<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename R>
auto operator%(const R& r) const -> return_type_modulus_t<Expr, R>
{
return_type_modulus<Expr, R>::check::_();
return {*static_cast<const Expr*>(this), wrap_operand_t<R>{r}};
}
template <typename Defer = void>
auto operator+() const -> return_type_unary_plus_t<Expr, Defer>
{
return_type_unary_plus<Expr, Defer>::check::_();
return {*static_cast<const Expr*>(this)};
}
template <typename Defer = void>
auto operator-() const -> return_type_unary_minus_t<Expr, Defer>
{
return_type_unary_minus<Expr, Defer>::check::_();
return {*static_cast<const Expr*>(this)};
}
};
} }
#endif #endif

View File

@ -1,235 +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_BOOLEAN_H
#define SQLPP_BOOLEAN_H
#include <cstdlib>
#include <ostream>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/exception.h>
#include <sqlpp11/tvin.h>
#include <sqlpp11/result_field.h>
namespace sqlpp
{
// boolean value type
struct boolean
{
using _traits = make_traits<boolean, tag::is_value_type>;
using _tag = tag::is_boolean;
using _cpp_value_type = bool;
template<typename T>
using _is_valid_operand = is_boolean_t<T>;
};
// boolean parameter type
template<>
struct parameter_value_t<boolean>
{
using _value_type = boolean; // FIXME
using _cpp_value_type = typename _value_type::_cpp_value_type;
parameter_value_t():
_value(false),
_is_null(true)
{}
parameter_value_t(const _cpp_value_type& val):
_value(val),
_is_null(false)
{}
parameter_value_t& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_t& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = false;
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
parameter_value_t& operator=(const std::nullptr_t&)
{
_value = false;
_is_null = true;
return *this;
}
bool is_null() const
{
return _is_null;
}
_cpp_value_type value() const
{
return _value;
}
operator _cpp_value_type() const { return value(); }
template<typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_boolean_parameter(index, &_value, _is_null);
}
private:
signed char _value;
bool _is_null;
};
// boolean expression operators
template<typename Base>
struct expression_operators<Base, boolean>: public basic_expression_operators<Base, boolean>
{
template<typename T>
using _is_valid_operand = is_valid_operand<boolean, T>;
template<typename T>
logical_and_t<Base, wrap_operand_t<T>> operator and(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), rhs{t} };
}
template<typename T>
logical_or_t<Base, wrap_operand_t<T>> operator or(T t) const
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs operand");
return { *static_cast<const Base*>(this), rhs{t} };
}
logical_not_t<Base> operator not() const
{
return { *static_cast<const Base*>(this) };
}
};
// boolean column operators
template<typename Base>
struct column_operators<Base, boolean>
{
};
// boolean result field
template<typename Db, typename FieldSpec>
struct result_field_t<boolean, Db, FieldSpec>: public result_field_methods_t<result_field_t<boolean, Db, FieldSpec>>
{
static_assert(std::is_same<value_type_of<FieldSpec>, boolean>::value, "field type mismatch");
using _cpp_value_type = typename boolean::_cpp_value_type;
result_field_t():
_is_valid(false),
_is_null(true),
_value(false)
{}
void _validate()
{
_is_valid = true;
}
void _invalidate()
{
_is_valid = false;
_is_null = true;
_value = 0;
}
bool is_null() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return _is_null;
}
bool _is_trivial() const
{
if (not _is_valid)
throw exception("accessing is_null in non-existing row");
return value() == false;
}
_cpp_value_type value() const
{
if (not _is_valid)
throw exception("accessing value in non-existing row");
if (_is_null)
{
if (enforce_null_result_treatment_t<Db>::value and not null_is_trivial_value_t<FieldSpec>::value)
{
throw exception("accessing value of NULL field");
}
else
{
return false;
}
}
return _value;
}
template<typename Target>
void _bind(Target& target, size_t i)
{
target._bind_boolean_result(i, &_value, &_is_null);
}
private:
bool _is_valid;
bool _is_null;
signed char _value;
};
template<typename Db, typename FieldSpec>
inline std::ostream& operator<<(std::ostream& os, const result_field_t<boolean, Db, FieldSpec>& e)
{
return serialize(e, os);
}
}
#endif

View File

@ -32,54 +32,53 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Database> template <typename Database>
struct boolean_expression_t: public expression_operators<boolean_expression_t<Database>, boolean> struct boolean_expression_t : public expression_operators<boolean_expression_t<Database>, boolean>
{ {
using _traits = make_traits<boolean, tag::is_expression>; using _traits = make_traits<boolean, tag::is_expression>;
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
template<typename Expr> template <typename Expr>
boolean_expression_t(Expr expr): boolean_expression_t(Expr expr)
_expr(expr) : _expr(expr)
{ {
static_assert(is_expression_t<Expr>::value, "boolean_expression requires a boolean expression argument"); static_assert(is_expression_t<Expr>::value, "boolean_expression requires a boolean expression argument");
static_assert(is_boolean_t<Expr>::value, "boolean_expression requires a boolean expression argument"); static_assert(is_boolean_t<Expr>::value, "boolean_expression requires a boolean expression argument");
} }
boolean_expression_t(const boolean_expression_t&) = default; boolean_expression_t(const boolean_expression_t&) = default;
boolean_expression_t(boolean_expression_t&&) = default; boolean_expression_t(boolean_expression_t&&) = default;
boolean_expression_t& operator=(const boolean_expression_t&) = default; boolean_expression_t& operator=(const boolean_expression_t&) = default;
boolean_expression_t& operator=(boolean_expression_t&&) = default; boolean_expression_t& operator=(boolean_expression_t&&) = default;
~boolean_expression_t() = default; ~boolean_expression_t() = default;
interpretable_t<Database> _expr; interpretable_t<Database> _expr;
}; };
template<typename Database, typename T> template <typename Database, typename T>
boolean_expression_t<Database> boolean_expression(T t) boolean_expression_t<Database> boolean_expression(T t)
{ {
using Expr = wrap_operand_t<T>; using Expr = wrap_operand_t<T>;
return {Expr{t}}; return {Expr{t}};
} }
template<typename Database, typename T> template <typename Database, typename T>
boolean_expression_t<Database> boolean_expression(const Database&, T t) boolean_expression_t<Database> boolean_expression(const Database&, T t)
{ {
return boolean_expression<Database>(t); return boolean_expression<Database>(t);
} }
template<typename Context, typename Database> template <typename Context, typename Database>
struct serializer_t<Context, boolean_expression_t<Database>> struct serializer_t<Context, boolean_expression_t<Database>>
{ {
using _serialize_check = consistent_t; using _serialize_check = consistent_t;
using T = boolean_expression_t<Database>; using T = boolean_expression_t<Database>;
static Context& _(const T& t, Context& context)
{
return serialize(t._expr, context);
}
};
static Context& _(const T& t, Context& context)
{
return serialize(t._expr, context);
}
};
} }
#endif #endif

195
include/sqlpp11/case.h Normal file
View File

@ -0,0 +1,195 @@
/*
* Copyright (c) 2015-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_CASE_H
#define SQLPP_CASE_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/char_sequence.h>
#include <sqlpp11/data_types/boolean.h>
#include <sqlpp11/detail/type_set.h>
namespace sqlpp
{
SQLPP_PORTABLE_STATIC_ASSERT(assert_case_else_expression_t, "argument is not a value expression in else()");
SQLPP_PORTABLE_STATIC_ASSERT(assert_case_then_else_same_type_t,
"argument of then() and else() are not of the same type");
template <typename Then, typename Else>
using check_case_else_t = static_combined_check_t<
static_check_t<is_expression_t<wrap_operand_t<Else>>::value, assert_case_else_expression_t>,
static_check_t<logic::any_t<is_sql_null_t<Then>::value,
is_sql_null_t<wrap_operand_t<Else>>::value,
std::is_same<value_type_of<Then>, value_type_of<wrap_operand_t<Else>>>::value>::value,
assert_case_then_else_same_type_t>>;
SQLPP_PORTABLE_STATIC_ASSERT(assert_case_then_expression_t, "argument is not a value expression in then()");
template <typename Then>
using check_case_then_t =
static_check_t<logic::all_t<is_expression_t<wrap_operand_t<Then>>::value>::value, assert_case_then_expression_t>;
SQLPP_PORTABLE_STATIC_ASSERT(assert_case_when_boolean_expression_t,
"argument is not a boolean expression in case_when()");
template <typename When>
using check_case_when_t = static_check_t<
logic::all_t<is_boolean_t<wrap_operand_t<When>>::value, is_expression_t<wrap_operand_t<When>>::value>::value,
assert_case_when_boolean_expression_t>;
template <typename When, typename Then, typename Else>
struct case_t
: public expression_operators<
case_t<When, Then, Else>,
typename std::conditional<is_sql_null_t<Then>::value, value_type_of<Else>, value_type_of<Then>>::type>,
public alias_operators<case_t<When, Then, Else>>
{
using _traits = make_traits<value_type_of<Then>, tag::is_expression>;
using _nodes = detail::type_vector<When, Then, Else>;
case_t(When when, Then then, Else else_) : _when(when), _then(then), _else(else_)
{
}
case_t(const case_t&) = default;
case_t(case_t&&) = default;
case_t& operator=(const case_t&) = default;
case_t& operator=(case_t&&) = default;
~case_t() = default;
When _when;
Then _then;
Else _else;
};
template <typename When, typename Then>
class case_then_t
{
template <typename Else>
auto _else_impl(const std::true_type&, Else else_) -> case_t<When, Then, Else>
{
return {_when, _then, else_};
}
template <typename Else>
auto _else_impl(const std::false_type&, Else else_) -> void;
public:
case_then_t(When when, Then then) : _when(when), _then(then)
{
}
case_then_t(const case_then_t&) = default;
case_then_t(case_then_t&&) = default;
case_then_t& operator=(const case_then_t&) = default;
case_then_t& operator=(case_then_t&&) = default;
~case_then_t() = default;
template <typename Else>
auto else_(Else else_) -> decltype(this->_else_impl(check_case_else_t<Then, Else>{}, else_))
{
check_case_else_t<Then, Else>::_();
return _else_impl(check_case_else_t<Then, Else>{}, else_);
}
private:
When _when;
Then _then;
};
template <typename When>
class case_when_t
{
template <typename Then>
auto _then_impl(const std::true_type&, Then t) -> case_then_t<When, wrap_operand_t<Then>>
{
return {_when, t};
}
template <typename Then>
auto _then_impl(const std::false_type&, Then t) -> void;
public:
case_when_t(When when) : _when(when)
{
}
case_when_t(const case_when_t&) = default;
case_when_t(case_when_t&&) = default;
case_when_t& operator=(const case_when_t&) = default;
case_when_t& operator=(case_when_t&&) = default;
~case_when_t() = default;
template <typename Then>
auto then(Then t) -> decltype(this->_then_impl(check_case_then_t<Then>{}, t))
{
check_case_then_t<Then>::_();
return _then_impl(check_case_then_t<Then>{}, t);
}
private:
When _when;
};
template <typename Context, typename When, typename Then, typename Else>
struct serializer_t<Context, case_t<When, Then, Else>>
{
using _serialize_check = serialize_check_of<When, Then, Else>;
using T = case_t<When, Then, Else>;
static Context& _(const T& t, Context& context)
{
context << "(CASE WHEN ";
serialize(t._when, context);
context << " THEN ";
serialize(t._then, context);
context << " ELSE ";
serialize(t._else, context);
context << " END)";
return context;
}
};
namespace detail
{
template <typename When>
auto case_when_impl(const std::true_type&, When when) -> case_when_t<wrap_operand_t<When>>
{
return {when};
}
template <typename When>
auto case_when_impl(const std::false_type&, When when) -> void;
}
template <typename When>
auto case_when(When when) -> decltype(detail::case_when_impl(check_case_when_t<When>{}, when))
{
check_case_when_t<When>::_();
return detail::case_when_impl(typename check_case_when_t<When>::type{}, when);
}
}
#endif

View File

@ -31,26 +31,28 @@
namespace sqlpp namespace sqlpp
{ {
template<char... Cs> struct char_sequence template <char... Cs>
{ struct char_sequence
static const char* char_ptr() {
{ static const char* char_ptr()
static char s[] = {Cs...}; {
return s; static char s[] = {Cs...};
}; return s;
}; };
};
template<std::size_t N, const char (&s) [N], typename T> template <std::size_t N, const char(&s)[N], typename T>
struct make_char_sequence_impl; struct make_char_sequence_impl;
template<std::size_t N, const char (&s) [N], std::size_t... i> template <std::size_t N, const char(&s)[N], std::size_t... i>
struct make_char_sequence_impl<N, s, sqlpp::detail::index_sequence<i...>> struct make_char_sequence_impl<N, s, sqlpp::detail::index_sequence<i...>>
{ {
using type = char_sequence<s[i]...>; using type = char_sequence<s[i]...>;
}; };
template<std::size_t N, const char (&Input) [N]> template <std::size_t N, const char(&Input)[N]>
using make_char_sequence = typename make_char_sequence_impl<sizeof(Input), Input, sqlpp::detail::make_index_sequence<sizeof(Input)>>::type; using make_char_sequence =
typename make_char_sequence_impl<sizeof(Input), Input, sqlpp::detail::make_index_sequence<sizeof(Input)>>::type;
} }
#endif #endif

43
include/sqlpp11/chrono.h Normal file
View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2015-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_CHRONO_H
#define SQLPP_CHRONO_H
#include <chrono>
namespace sqlpp
{
namespace chrono
{
using days = std::chrono::duration<int, std::ratio_multiply<std::ratio<24>, std::chrono::hours::period>>;
using day_point = std::chrono::time_point<std::chrono::system_clock, days>;
using microsecond_point = std::chrono::time_point<std::chrono::system_clock, std::chrono::microseconds>;
}
}
#endif

View File

@ -41,84 +41,94 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Table, typename ColumnSpec> template <typename Table, typename ColumnSpec>
struct column_t: struct column_t : public expression_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>,
public expression_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>, public column_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>>
public column_operators<column_t<Table, ColumnSpec>, value_type_of<ColumnSpec>> {
{ struct _traits
struct _traits {
{ using _value_type = value_type_of<ColumnSpec>;
using _value_type = value_type_of<ColumnSpec>; using _tags = detail::make_joined_set_t<detail::type_set<tag::is_column, tag::is_expression, tag::is_selectable>,
using _tags = detail::make_joined_set_t<detail::type_set<tag::is_column, tag::is_expression, tag::is_selectable>, typename ColumnSpec::_traits::_tags>; typename ColumnSpec::_traits::_tags>;
}; };
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
using _required_tables = detail::type_set<Table>; using _required_tables = detail::type_set<Table>;
using _can_be_null = column_spec_can_be_null_t<ColumnSpec>; using _can_be_null = column_spec_can_be_null_t<ColumnSpec>;
using _spec_t = ColumnSpec; using _spec_t = ColumnSpec;
using _table = Table; using _table = Table;
using _alias_t = typename _spec_t::_alias_t; using _alias_t = typename _spec_t::_alias_t;
template<typename T> template <typename T>
using _is_valid_operand = is_valid_operand<value_type_of<ColumnSpec>, T>; using _is_valid_assignment_operand = is_valid_assignment_operand<value_type_of<ColumnSpec>, T>;
column_t() = default; column_t() = default;
column_t(const column_t&) = default; column_t(const column_t&) = default;
column_t(column_t&&) = default; column_t(column_t&&) = default;
column_t& operator=(const column_t&) = default; column_t& operator=(const column_t&) = default;
column_t& operator=(column_t&&) = default; column_t& operator=(column_t&&) = default;
~column_t() = default; ~column_t() = default;
template<typename T = _table> template <typename T = _table>
auto table() const -> _table auto table() const -> _table
{ {
static_assert(is_table_t<T>::value, "cannot call get_table for columns of a sub-selects or cte"); static_assert(is_table_t<T>::value, "cannot call get_table for columns of a sub-selects or cte");
return _table{}; return _table{};
} }
template<typename alias_provider> template <typename alias_provider>
expression_alias_t<column_t, alias_provider> as(const alias_provider&) const expression_alias_t<column_t, alias_provider> as(const alias_provider&) const
{ {
return { *this }; return {*this};
} }
template<typename T> template <typename T>
auto operator =(T t) const -> assignment_t<column_t, wrap_operand_t<T>> auto operator=(T t) const -> assignment_t<column_t, wrap_operand_t<T>>
{ {
using rhs = wrap_operand_t<T>; using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand"); static_assert(_is_valid_assignment_operand<rhs>::value, "invalid rhs assignment operand");
return { *this, {rhs{t}} }; return {*this, {rhs{t}}};
} }
auto operator =(null_t) const auto operator=(null_t) const -> assignment_t<column_t, null_t>
->assignment_t<column_t, null_t> {
{ static_assert(can_be_null_t<column_t>::value, "column cannot be null");
static_assert(can_be_null_t<column_t>::value, "column cannot be null"); return {*this, null_t{}};
return { *this, null_t{} }; }
}
auto operator =(default_value_t) const auto operator=(default_value_t) const -> assignment_t<column_t, default_value_t>
->assignment_t<column_t, default_value_t> {
{ return {*this, default_value_t{}};
return { *this, default_value_t{} }; }
} };
};
template<typename Context, typename... Args> // workaround for msvs bug https://connect.microsoft.com/VisualStudio/feedback/details/2173053
struct serializer_t<Context, column_t<Args...>> // template <typename Context, typename... Args>
{ // struct serializer_t<Context, column_t<Args...>>
using _serialize_check = consistent_t; // {
using T = column_t<Args...>; // using _serialize_check = consistent_t;
// using T = column_t<Args...>;
static Context& _(const T& t, Context& context) //
{ // static Context& _(const T&, Context& context)
context << name_of<typename T::_table>::char_ptr() << '.' << name_of<T>::char_ptr(); // {
return context; // context << name_of<typename T::_table>::char_ptr() << '.' << name_of<T>::char_ptr();
} // return context;
}; // }
// };
template <typename Context, typename Args1, typename Args2>
struct serializer_t<Context, column_t<Args1, Args2>>
{
using _serialize_check = consistent_t;
using T = column_t<Args1, Args2>;
static Context& _(const T&, Context& context)
{
context << name_of<typename T::_table>::char_ptr() << '.' << name_of<T>::char_ptr();
return context;
}
};
} }
#endif #endif

View File

@ -24,14 +24,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SQLPP_COLUMN_FWD_H #ifndef SQLPP_COLUMN_FWD_H
#define SQLPP_COLUMN_FWD_H #define SQLPP_COLUMN_FWD_H
namespace sqlpp namespace sqlpp
{ {
template<typename Table, typename ColumnSpec> template <typename Table, typename ColumnSpec>
struct column_t; struct column_t;
} }
#endif #endif

View File

@ -27,9 +27,6 @@
#ifndef SQLPP_COLUMN_TYPES_H #ifndef SQLPP_COLUMN_TYPES_H
#define SQLPP_COLUMN_TYPES_H #define SQLPP_COLUMN_TYPES_H
#include <sqlpp11/boolean.h> #include <sqlpp11/data_types.h>
#include <sqlpp11/integral.h>
#include <sqlpp11/floating_point.h>
#include <sqlpp11/text.h>
#endif #endif

View File

@ -1,89 +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_CONCAT_H
#define SQLPP_CONCAT_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/char_sequence.h>
#include <sqlpp11/interpret_tuple.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/logic.h>
namespace sqlpp
{
// FIXME: Remove First, inherit from text_t
template<typename First, typename... Args>
struct concat_t:
public expression_operators<concat_t<First, Args...>, value_type_of<First>>,
public alias_operators<concat_t<First, Args...>>
{
using _traits = make_traits<value_type_of<First>, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<First, Args...>;
static_assert(sizeof...(Args) > 0, "concat requires two arguments at least");
static_assert(logic::all_t<is_text_t<First>::value, is_text_t<Args>::value...>::value, "at least one non-text argument detected in concat()");
struct _alias_t
{
static constexpr const char _literal[] = "concat_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T concat;
};
};
concat_t(First first, Args... args):
_args(first, args...)
{}
concat_t(const concat_t&) = default;
concat_t(concat_t&&) = default;
concat_t& operator=(const concat_t&) = default;
concat_t& operator=(concat_t&&) = default;
~concat_t() = default;
std::tuple<First, Args...> _args;
};
template<typename Context, typename First, typename... Args>
struct serializer_t<Context, concat_t<First, Args...>>
{
using _serialize_check = serialize_check_of<Context, First, Args...>;
using T = concat_t<First, Args...>;
static Context& _(const T& t, Context& context)
{
context << "(";
interpret_tuple(t._args, "||", context);
context << ")";
return context;
}
};
}
#endif

View File

@ -29,8 +29,9 @@
namespace sqlpp namespace sqlpp
{ {
struct connection {}; struct connection
{
};
} }
#endif #endif

View File

@ -0,0 +1,40 @@
/*
* 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_CONSISTENT_H
#define SQLPP_CONSISTENT_H
#include <type_traits>
namespace sqlpp
{
struct consistent_t : std::true_type
{
static void _(){};
};
}
#endif

View File

@ -1,116 +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_COUNT_H
#define SQLPP_COUNT_H
#include <sqlpp11/char_sequence.h>
#include <sqlpp11/select_flags.h>
#include <sqlpp11/integral.h>
namespace sqlpp
{
template<typename Flag, typename Expr>
struct count_t:
public expression_operators<count_t<Flag, Expr>, integral>,
public alias_operators<count_t<Flag, Expr>>
{
using _traits = make_traits<integral, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Expr, aggregate_function>;
using _can_be_null = std::false_type;
static_assert(is_noop<Flag>::value or std::is_same<distinct_t, Flag>::value, "count() used with flag other than 'distinct'");
struct _alias_t
{
static constexpr const char _literal[] = "count_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template<typename T>
struct _member_t
{
T count;
T& operator()() { return count; }
const T& operator()() const { return count; }
};
};
count_t(const Expr expr):
_expr(expr)
{}
count_t(const count_t&) = default;
count_t(count_t&&) = default;
count_t& operator=(const count_t&) = default;
count_t& operator=(count_t&&) = default;
~count_t() = default;
Expr _expr;
};
template<typename Context, typename Flag, typename Expr>
struct serializer_t<Context, count_t<Flag, Expr>>
{
using _serialize_check = serialize_check_of<Context, Flag, Expr>;
using T = count_t<Flag, Expr>;
static Context& _(const T& t, Context& context)
{
context << "COUNT(";
if (std::is_same<distinct_t, Flag>::value)
{
serialize(Flag(), context);
context << ' ';
serialize_operand(t._expr, context);
}
else
{
serialize(t._expr, context);
}
context << ")";
return context;
}
};
template<typename T>
auto count(T t) -> count_t<noop, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "count() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return { t };
}
template<typename T>
auto count(const distinct_t&, T t) -> count_t<distinct_t, wrap_operand_t<T>>
{
static_assert(not contains_aggregate_function_t<wrap_operand_t<T>>::value, "count() cannot be used on an aggregate function");
static_assert(is_expression_t<wrap_operand_t<T>>::value, "count() requires an expression as argument");
return { t };
}
}
#endif

View File

@ -40,222 +40,240 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Flag, typename Lhs, typename Rhs> template <typename Flag, typename Lhs, typename Rhs>
struct cte_union_t struct cte_union_t
{ {
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
using _required_ctes = detail::make_joined_set_t<required_ctes_of<Lhs>, required_ctes_of<Rhs>>; using _required_ctes = detail::make_joined_set_t<required_ctes_of<Lhs>, required_ctes_of<Rhs>>;
using _parameters = detail::type_vector_cat_t<parameters_of<Lhs>, parameters_of<Rhs>>; using _parameters = detail::type_vector_cat_t<parameters_of<Lhs>, parameters_of<Rhs>>;
cte_union_t(Lhs lhs, Rhs rhs): cte_union_t(Lhs lhs, Rhs rhs) : _lhs(lhs), _rhs(rhs)
_lhs(lhs), {
_rhs(rhs) }
{}
cte_union_t(const cte_union_t&) = default; cte_union_t(const cte_union_t&) = default;
cte_union_t(cte_union_t&&) = default; cte_union_t(cte_union_t&&) = default;
cte_union_t& operator=(const cte_union_t&) = default; cte_union_t& operator=(const cte_union_t&) = default;
cte_union_t& operator=(cte_union_t&&) = default; cte_union_t& operator=(cte_union_t&&) = default;
~cte_union_t() = default; ~cte_union_t() = default;
Lhs _lhs; Lhs _lhs;
Rhs _rhs; Rhs _rhs;
}; };
// Interpreters // Interpreters
template<typename Context, typename Flag, typename Lhs, typename Rhs> template <typename Context, typename Flag, typename Lhs, typename Rhs>
struct serializer_t<Context, cte_union_t<Flag, Lhs, Rhs>> struct serializer_t<Context, cte_union_t<Flag, Lhs, Rhs>>
{ {
using _serialize_check = serialize_check_of<Context, Lhs, Rhs>; using _serialize_check = serialize_check_of<Context, Lhs, Rhs>;
using T = cte_union_t<Flag, Lhs, Rhs>; using T = cte_union_t<Flag, Lhs, Rhs>;
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {
serialize(t._lhs, context); serialize(t._lhs, context);
context << " UNION "; context << " UNION ";
serialize(Flag{}, context); serialize(Flag{}, context);
context << " "; context << " ";
serialize(t._rhs, context); serialize(t._rhs, context);
return context; return context;
} }
}; };
template<typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct cte_t; struct cte_t;
template<typename AliasProvider> template <typename AliasProvider>
struct cte_ref_t; struct cte_ref_t;
template<typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
auto from_table(cte_t<AliasProvider, Statement, FieldSpecs...> t) -> cte_ref_t<AliasProvider> auto from_table(cte_t<AliasProvider, Statement, FieldSpecs...>) -> cte_ref_t<AliasProvider>
{ {
return cte_ref_t<AliasProvider>{}; return cte_ref_t<AliasProvider>{};
} }
template<typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct from_table_impl<cte_t<AliasProvider, Statement, FieldSpecs...>> struct from_table_impl<cte_t<AliasProvider, Statement, FieldSpecs...>>
{ {
using type = cte_ref_t<AliasProvider>; using type = cte_ref_t<AliasProvider>;
}; };
template <typename FieldSpec>
struct cte_column_spec_t
{
using _alias_t = typename FieldSpec::_alias_t;
template<typename FieldSpec> using _traits = make_traits<value_type_of<FieldSpec>,
struct cte_column_spec_t tag::must_not_insert,
{ tag::must_not_update,
using _alias_t = typename FieldSpec::_alias_t; tag_if<tag::can_be_null, column_spec_can_be_null_t<FieldSpec>::value>>;
};
using _traits = make_traits<value_type_of<FieldSpec>, template <typename AliasProvider, typename Statement, typename ResultRow>
tag::must_not_insert, struct make_cte_impl
tag::must_not_update, {
tag_if<tag::can_be_null, column_spec_can_be_null_t<FieldSpec>::value> using type = void;
>; };
};
template<typename AliasProvider, typename Statement, typename ResultRow> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct make_cte_impl struct make_cte_impl<AliasProvider, Statement, result_row_t<void, FieldSpecs...>>
{ {
using type = void; using type = cte_t<AliasProvider, Statement, FieldSpecs...>;
}; };
template<typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement>
struct make_cte_impl<AliasProvider, Statement, result_row_t<void, FieldSpecs...>> using make_cte_t = typename make_cte_impl<AliasProvider, Statement, get_result_row_t<Statement>>::type;
{
using type = cte_t<AliasProvider, Statement, FieldSpecs...>;
};
template<typename AliasProvider, typename Statement> // workaround for msvc unknown internal error
using make_cte_t = typename make_cte_impl<AliasProvider, Statement, get_result_row_t<Statement>>::type; // template <typename AliasProvider, typename Statement, typename... FieldSpecs>
// struct cte_t
// : public member_t<cte_column_spec_t<FieldSpecs>, column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>>...
template <typename AliasProvider, typename FieldSpec>
struct cte_base
{
using type = member_t<cte_column_spec_t<FieldSpec>, column_t<AliasProvider, cte_column_spec_t<FieldSpec>>>;
};
template<typename AliasProvider, typename Statement, typename... FieldSpecs> template <typename AliasProvider, typename Statement, typename... FieldSpecs>
struct cte_t: public member_t<cte_column_spec_t<FieldSpecs>, column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>>... struct cte_t : public cte_base<AliasProvider, FieldSpecs>::type...
{ {
using _traits = make_traits<no_value_t, tag::is_cte, tag::is_table>; // FIXME: is table? really? using _traits = make_traits<no_value_t, tag::is_cte, tag::is_table>; // FIXME: is table? really?
using _nodes = detail::type_vector<>; using _nodes = detail::type_vector<>;
using _required_ctes = detail::make_joined_set_t<required_ctes_of<Statement>, detail::type_set<AliasProvider>>; using _required_ctes = detail::make_joined_set_t<required_ctes_of<Statement>, detail::type_set<AliasProvider>>;
using _parameters = parameters_of<Statement>; using _parameters = parameters_of<Statement>;
using _alias_t = typename AliasProvider::_alias_t; using _alias_t = typename AliasProvider::_alias_t;
constexpr static bool _is_recursive = detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value; constexpr static bool _is_recursive = detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value;
using _column_tuple_t = std::tuple<column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>...>; using _column_tuple_t = std::tuple<column_t<AliasProvider, cte_column_spec_t<FieldSpecs>>...>;
template<typename... T> // workaround for msvc bug https://connect.microsoft.com/VisualStudio/Feedback/Details/2086629
using _check = logic::all_t<is_statement_t<T>::value...>; // template <typename... T>
// using _check = logic::all_t<is_statement_t<T>::value...>;
template <typename... T>
struct _check : logic::all_t<is_statement_t<T>::value...>
{
};
using _result_row_t = result_row_t<void, FieldSpecs...>; using _result_row_t = result_row_t<void, FieldSpecs...>;
template<typename Rhs> template <typename Rhs>
auto union_distinct(Rhs rhs) const auto union_distinct(Rhs rhs) const ->
-> typename std::conditional<_check<Rhs>::value, cte_t<AliasProvider, cte_union_t<distinct_t, Statement, Rhs>, FieldSpecs...>, bad_statement>::type typename std::conditional<_check<Rhs>::value,
{ cte_t<AliasProvider, cte_union_t<distinct_t, Statement, Rhs>, FieldSpecs...>,
static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement"); bad_statement>::type
static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select"); {
static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement"); static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement");
static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select");
static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement");
static_assert(std::is_same<_result_row_t, get_result_row_t<Rhs>>::value, "both select statements in a union have to have the same result columns (type and name)"); static_assert(std::is_same<_result_row_t, get_result_row_t<Rhs>>::value,
"both select statements in a union have to have the same result columns (type and name)");
return _union_impl<void, distinct_t>(_check<Rhs>{}, rhs); return _union_impl<void, distinct_t>(_check<Rhs>{}, rhs);
} }
template<typename Rhs> template <typename Rhs>
auto union_all(Rhs rhs) const auto union_all(Rhs rhs) const ->
-> typename std::conditional<_check<Rhs>::value, cte_t<AliasProvider, cte_union_t<all_t, Statement, Rhs>, FieldSpecs...>, bad_statement>::type typename std::conditional<_check<Rhs>::value,
{ cte_t<AliasProvider, cte_union_t<all_t, Statement, Rhs>, FieldSpecs...>,
static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement"); bad_statement>::type
static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select"); {
static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement"); static_assert(is_statement_t<Rhs>::value, "argument of union call has to be a statement");
static_assert(has_policy_t<Rhs, is_select_t>::value, "argument of union call has to be a select");
static_assert(has_result_row_t<Rhs>::value, "argument of a union has to be a (complete) select statement");
static_assert(std::is_same<_result_row_t, get_result_row_t<Rhs>>::value, "both select statements in a union have to have the same result columns (type and name)"); static_assert(std::is_same<_result_row_t, get_result_row_t<Rhs>>::value,
"both select statements in a union have to have the same result columns (type and name)");
return _union_impl<all_t>(_check<Rhs>{}, rhs); return _union_impl<all_t>(_check<Rhs>{}, rhs);
} }
private: private:
template<typename Flag, typename Rhs> template <typename Flag, typename Rhs>
auto _union_impl(const std::false_type&, Rhs rhs) const auto _union_impl(const std::false_type&, Rhs rhs) const -> bad_statement;
-> bad_statement;
template<typename Flag, typename Rhs> template <typename Flag, typename Rhs>
auto _union_impl(const std::true_type&, Rhs rhs) const auto _union_impl(const std::true_type&, Rhs rhs) const
-> cte_t<AliasProvider, cte_union_t<Flag, Statement, Rhs>, FieldSpecs...> -> cte_t<AliasProvider, cte_union_t<Flag, Statement, Rhs>, FieldSpecs...>
{ {
return cte_union_t<Flag, Statement, Rhs>{_statement, rhs}; return cte_union_t<Flag, Statement, Rhs>{_statement, rhs};
} }
public: public:
cte_t(Statement statement) : _statement(statement)
{
}
cte_t(const cte_t&) = default;
cte_t(cte_t&&) = default;
cte_t& operator=(const cte_t&) = default;
cte_t& operator=(cte_t&&) = default;
~cte_t() = default;
cte_t(Statement statement): _statement(statement){} Statement _statement;
cte_t(const cte_t&) = default; };
cte_t(cte_t&&) = default;
cte_t& operator=(const cte_t&) = default;
cte_t& operator=(cte_t&&) = default;
~cte_t() = default;
Statement _statement; template <typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs>
}; struct serializer_t<Context, cte_t<AliasProvider, Statement, ColumnSpecs...>>
{
using _serialize_check = serialize_check_of<Context, Statement>;
using T = cte_t<AliasProvider, Statement, ColumnSpecs...>;
template<typename Context, typename AliasProvider, typename Statement, typename... ColumnSpecs> static Context& _(const T& t, Context& context)
struct serializer_t<Context, cte_t<AliasProvider, Statement, ColumnSpecs...>> {
{ context << name_of<T>::char_ptr() << " AS (";
using _serialize_check = serialize_check_of<Context, Statement>; serialize(t._statement, context);
using T = cte_t<AliasProvider, Statement, ColumnSpecs...>; context << ")";
return context;
}
};
static Context& _(const T& t, Context& context) // The cte_t is displayed as AliasProviderName except within the with:
{ // - the with needs the
context << name_of<T>::char_ptr() << " AS ("; // AliasProviderName AS (ColumnNames) (select/union)
serialize(t._statement, context); // The result row of the select should not have dynamic parts
context << ")"; template <typename AliasProvider>
return context; struct cte_ref_t
} {
}; using _traits = make_traits<no_value_t, tag::is_alias, tag::is_cte, tag::is_table>; // FIXME: is table? really?
using _nodes = detail::type_vector<>;
using _required_ctes = detail::make_type_set_t<AliasProvider>;
using _provided_tables = detail::type_set<AliasProvider>;
using _alias_t = typename AliasProvider::_alias_t;
// The cte_t is displayed as AliasProviderName except within the with: template <typename Statement>
// - the with needs the auto as(Statement statement) -> make_cte_t<AliasProvider, Statement>
// AliasProviderName AS (ColumnNames) (select/union) {
// The result row of the select should not have dynamic parts static_assert(required_tables_of<Statement>::size::value == 0,
template<typename AliasProvider> "common table expression must not use unknown tables");
struct cte_ref_t static_assert(not detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value,
{ "common table expression must not self-reference in the first part, use union_all/union_distinct "
using _traits = make_traits<no_value_t, tag::is_alias, tag::is_cte, tag::is_table>; // FIXME: is table? really? "for recursion");
using _nodes = detail::type_vector<>; static_assert(is_static_result_row_t<get_result_row_t<Statement>>::value,
using _required_ctes = detail::make_type_set_t<AliasProvider>; "ctes must not have dynamically added columns");
using _provided_tables = detail::type_set<AliasProvider>;
using _alias_t = typename AliasProvider::_alias_t; return {statement};
}
};
template<typename Statement> template <typename Context, typename AliasProvider>
auto as(Statement statement) struct serializer_t<Context, cte_ref_t<AliasProvider>>
-> make_cte_t<AliasProvider, Statement> {
{ using _serialize_check = consistent_t;
static_assert(required_tables_of<Statement>::size::value == 0, "common table expression must not use unknown tables"); using T = cte_ref_t<AliasProvider>;
static_assert(not detail::is_element_of<AliasProvider, required_ctes_of<Statement>>::value, "common table expression must not self-reference in the first part, use union_all/union_distinct for recursion");
static_assert(is_static_result_row_t<get_result_row_t<Statement>>::value, "ctes must not have dynamically added columns");
return { statement }; static Context& _(const T&, Context& context)
} {
}; context << name_of<T>::char_ptr();
return context;
template<typename Context, typename AliasProvider> }
struct serializer_t<Context, cte_ref_t<AliasProvider>> };
{
using _serialize_check = consistent_t;
using T = cte_ref_t<AliasProvider>;
static Context& _(const T& t, Context& context)
{
context << name_of<T>::char_ptr();
return context;
}
};
template<typename AliasProvider>
auto cte(const AliasProvider&)
-> cte_ref_t<AliasProvider>
{
return {};
}
template <typename AliasProvider>
auto cte(const AliasProvider&) -> cte_ref_t<AliasProvider>
{
return {};
}
} }
#endif #endif

View File

@ -34,111 +34,108 @@
namespace sqlpp namespace sqlpp
{ {
template<typename Database, typename... Parts> template <typename Database, typename... Parts>
struct custom_query_t; struct custom_query_t;
namespace detail namespace detail
{ {
template<typename Db, typename... Parts> template <typename Db, typename... Parts>
struct custom_parts_t struct custom_parts_t
{ {
using _custom_query_t = custom_query_t<Db, Parts...>; using _custom_query_t = custom_query_t<Db, Parts...>;
using _result_type_provider = detail::get_first_if<is_return_value_t, noop, Parts...>; using _result_type_provider = detail::get_first_if<is_return_value_t, noop, Parts...>;
using _result_methods_t = typename _result_type_provider::template _result_methods_t<_result_type_provider>; using _result_methods_t = typename _result_type_provider::template _result_methods_t<_result_type_provider>;
}; };
} }
template<typename Database, typename... Parts> template <typename Database, typename... Parts>
struct custom_query_t: struct custom_query_t : private detail::custom_parts_t<Database, Parts...>::_result_methods_t
private detail::custom_parts_t<Database, Parts...>::_result_methods_t {
{ using _methods_t = typename detail::custom_parts_t<Database, Parts...>::_result_methods_t;
using _methods_t = typename detail::custom_parts_t<Database, Parts...>::_result_methods_t; using _traits = make_traits<no_value_t, tag::is_statement>;
using _traits = make_traits<no_value_t, tag::is_statement>; using _nodes = detail::type_vector<Parts...>;
using _nodes = detail::type_vector<Parts...>;
using _parameter_check = typename std::conditional<detail::type_vector_size<parameters_of<custom_query_t>>::value == 0, using _parameter_check =
consistent_t, assert_no_parameters_t>::type; typename std::conditional<detail::type_vector_size<parameters_of<custom_query_t>>::value == 0,
using _run_check = detail::get_first_if<is_inconsistent_t, consistent_t, consistent_t,
_parameter_check>; assert_no_parameters_t>::type;
using _prepare_check = consistent_t; using _run_check = detail::get_first_if<is_inconsistent_t, consistent_t, _parameter_check>;
using _prepare_check = consistent_t;
custom_query_t(Parts... parts): custom_query_t(Parts... parts) : _parts(parts...)
_parts(parts...) {
{} }
custom_query_t(std::tuple<Parts...> parts): custom_query_t(std::tuple<Parts...> parts) : _parts(parts)
_parts(parts) {
{} }
custom_query_t(const custom_query_t&) = default; custom_query_t(const custom_query_t&) = default;
custom_query_t(custom_query_t&&) = default; custom_query_t(custom_query_t&&) = default;
custom_query_t& operator=(const custom_query_t&) = default; custom_query_t& operator=(const custom_query_t&) = default;
custom_query_t& operator=(custom_query_t&&) = default; custom_query_t& operator=(custom_query_t&&) = default;
~custom_query_t() = default; ~custom_query_t() = default;
template<typename Db> template <typename Db>
auto _run(Db& db) const -> decltype(std::declval<_methods_t>()._run(db, *this)) auto _run(Db& db) const -> decltype(std::declval<_methods_t>()._run(db, *this))
{ {
_run_check::_(); _run_check::_();
return _methods_t::_run(db, *this); return _methods_t::_run(db, *this);
} }
template<typename Db> template <typename Db>
auto _prepare(Db& db) const -> decltype(std::declval<_methods_t>()._prepare(db, *this)) auto _prepare(Db& db) const -> decltype(std::declval<_methods_t>()._prepare(db, *this))
{ {
_prepare_check::_(); _prepare_check::_();
return _methods_t::_prepare(db, *this); return _methods_t::_prepare(db, *this);
} }
static constexpr size_t _get_static_no_of_parameters() static constexpr size_t _get_static_no_of_parameters()
{ {
return std::tuple_size<parameters_of<custom_query_t>>::value; return std::tuple_size<parameters_of<custom_query_t>>::value;
} }
size_t _get_no_of_parameters() const size_t _get_no_of_parameters() const
{ {
return _get_static_no_of_parameters(); return _get_static_no_of_parameters();
} }
template<typename Part> template <typename Part>
auto with_result_type_of(Part part) auto with_result_type_of(Part part) -> custom_query_t<Database, Part, Parts...>
-> custom_query_t<Database, Part, Parts...> {
{ return {tuple_cat(std::make_tuple(part), _parts)};
return {tuple_cat(std::make_tuple(part), _parts)}; }
}
std::tuple<Parts...> _parts; std::tuple<Parts...> _parts;
}; };
template<typename Context, typename Database, typename... Parts> template <typename Context, typename Database, typename... Parts>
struct serializer_t<Context, custom_query_t<Database, Parts...>> struct serializer_t<Context, custom_query_t<Database, Parts...>>
{ {
using _serialize_check = serialize_check_of<Context, Parts...>; using _serialize_check = serialize_check_of<Context, Parts...>;
using T = custom_query_t<Database, Parts...>; using T = custom_query_t<Database, Parts...>;
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {
interpret_tuple_without_braces(t._parts, " ", context); interpret_tuple_without_braces(t._parts, " ", context);
return context; return context;
} }
}; };
template<typename... Parts> template <typename... Parts>
auto custom_query(Parts... parts) auto custom_query(Parts... parts) -> custom_query_t<void, wrap_operand_t<Parts>...>
-> custom_query_t<void, wrap_operand_t<Parts>...> {
{ static_assert(sizeof...(Parts) > 0, "custom query requires at least one argument");
static_assert(sizeof...(Parts) > 0, "custom query requires at least one argument"); return custom_query_t<void, wrap_operand_t<Parts>...>(parts...);
return custom_query_t<void, wrap_operand_t<Parts>...>(parts...); }
}
template<typename Database, typename... Parts> template <typename Database, typename... Parts>
auto dynamic_custom_query(const Database&, Parts... parts) auto dynamic_custom_query(const Database&, Parts... parts) -> custom_query_t<Database, wrap_operand_t<Parts>...>
-> custom_query_t<Database, wrap_operand_t<Parts>...> {
{ static_assert(sizeof...(Parts) > 0, "custom query requires at least one query argument");
static_assert(sizeof...(Parts) > 0, "custom query requires at least one query argument"); static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
static_assert(std::is_base_of<connection, Database>::value, "Invalid database parameter");
return custom_query_t<Database, wrap_operand_t<Parts>...>(parts...); return custom_query_t<Database, wrap_operand_t<Parts>...>(parts...);
} }
} }
#endif #endif

View File

@ -0,0 +1,38 @@
/*
* 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_DATA_TYPES_H
#define SQLPP_DATA_TYPES_H
#include <sqlpp11/data_types/boolean.h>
#include <sqlpp11/data_types/integral.h>
#include <sqlpp11/data_types/floating_point.h>
#include <sqlpp11/data_types/text.h>
#include <sqlpp11/data_types/day_point.h>
#include <sqlpp11/data_types/time_point.h>
#include <sqlpp11/data_types/no_value.h>
#endif

View File

@ -0,0 +1,38 @@
/*
* 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_BOOLEAN_H
#define SQLPP_BOOLEAN_H
#include <sqlpp11/data_types/boolean/data_type.h>
#include <sqlpp11/data_types/boolean/operand.h>
#include <sqlpp11/data_types/boolean/wrap_operand.h>
#include <sqlpp11/data_types/boolean/expression_operators.h>
#include <sqlpp11/data_types/boolean/column_operators.h>
#include <sqlpp11/data_types/boolean/parameter_value.h>
#include <sqlpp11/data_types/boolean/result_field.h>
#endif

View File

@ -0,0 +1,41 @@
/*
* 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_BOOLEAN_COLUMN_OPERATORS_H
#define SQLPP_BOOLEAN_COLUMN_OPERATORS_H
#include <sqlpp11/data_types/column_operators.h>
namespace sqlpp
{
struct boolean;
template <typename Column>
struct column_operators<Column, boolean>
{
};
}
#endif

View File

@ -0,0 +1,44 @@
/*
* 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_BOOLEAN_DATA_TYPE_H
#define SQLPP_BOOLEAN_DATA_TYPE_H
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
struct boolean
{
using _traits = make_traits<boolean, tag::is_value_type>;
using _cpp_value_type = bool;
template <typename T>
using _is_valid_operand = is_boolean_t<T>;
};
}
#endif

View File

@ -0,0 +1,64 @@
/*
* 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_BOOLEAN_EXPRESSION_OPERATORS_H
#define SQLPP_BOOLEAN_EXPRESSION_OPERATORS_H
#include <sqlpp11/expression_return_types.h>
#include <sqlpp11/operand_check.h>
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
namespace sqlpp
{
template <typename Expression>
struct expression_operators<Expression, boolean> : public basic_expression_operators<Expression, boolean>
{
};
template <typename L, typename R>
struct return_type_and<L, R, binary_operand_check_t<L, is_boolean_t, R, is_boolean_t>>
{
using check = consistent_t;
using type = logical_and_t<wrap_operand_t<L>, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_or<L, R, binary_operand_check_t<L, is_boolean_t, R, is_boolean_t>>
{
using check = consistent_t;
using type = logical_or_t<wrap_operand_t<L>, wrap_operand_t<R>>;
};
template <typename T, typename Defer>
struct return_type_not<T, Defer, unary_operand_check_t<T, is_boolean_t>>
{
using check = consistent_t;
using type = logical_not_t<wrap_operand_t<T>>;
};
}
#endif

View File

@ -0,0 +1,82 @@
/*
* 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_BOOLEAN_OPERAND_H
#define SQLPP_BOOLEAN_OPERAND_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp
{
struct boolean;
struct boolean_operand : public alias_operators<boolean_operand>
{
using _traits = make_traits<boolean, tag::is_expression, tag::is_wrapped_value>;
using _nodes = detail::type_vector<>;
using _is_aggregate_expression = std::true_type;
using _value_t = bool;
boolean_operand() : _t{}
{
}
boolean_operand(_value_t t) : _t(t)
{
}
boolean_operand(const boolean_operand&) = default;
boolean_operand(boolean_operand&&) = default;
boolean_operand& operator=(const boolean_operand&) = default;
boolean_operand& operator=(boolean_operand&&) = default;
~boolean_operand() = default;
bool _is_trivial() const
{
return _t == false;
}
_value_t _t;
};
template <typename Context>
struct serializer_t<Context, boolean_operand>
{
using _serialize_check = consistent_t;
using Operand = boolean_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
}
#endif

View File

@ -0,0 +1,52 @@
/*
* 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_BOOLEAN_PARAMETER_VALUE_H
#define SQLPP_BOOLEAN_PARAMETER_VALUE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/boolean/data_type.h>
#include <sqlpp11/tvin.h>
namespace sqlpp
{
template <>
struct parameter_value_t<boolean> : public parameter_value_base<boolean, signed char>
{
using base = parameter_value_base<boolean, signed char>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_boolean_parameter(index, &_value, _is_null);
}
};
}
#endif

View File

@ -0,0 +1,56 @@
/*
* 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_BOOLEAN_RESULT_FIELD_H
#define SQLPP_BOOLEAN_RESULT_FIELD_H
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/result_field.h>
#include <sqlpp11/result_field_base.h>
#include <sqlpp11/data_types/boolean/data_type.h>
#include <sqlpp11/field_spec.h>
namespace sqlpp
{
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
struct result_field_t<Db, field_spec_t<NameType, boolean, CanBeNull, NullIsTrivialValue>>
: public result_field_base<Db, field_spec_t<NameType, boolean, CanBeNull, NullIsTrivialValue>, signed char>
{
template <typename Target>
void _bind(Target& target, size_t index)
{
target._bind_boolean_result(index, &this->_value, &this->_is_null);
}
template <typename Target>
void _post_bind(Target& target, size_t index)
{
target._post_bind_boolean_result(index, &this->_value, &this->_is_null);
}
};
}
#endif

View File

@ -24,17 +24,20 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#ifndef SQLPP_DETAIL_WRAP_OPERAND_FWD_H #ifndef SQLPP_BOOLEAN_WRAP_OPERAND_H
#define SQLPP_DETAIL_WRAP_OPERAND_FWD_H #define SQLPP_BOOLEAN_WRAP_OPERAND_H
#include <sqlpp11/wrap_operand.h>
namespace sqlpp namespace sqlpp
{ {
template<typename T, typename Enable = void> struct boolean_operand;
struct wrap_operand;
template<typename T>
using wrap_operand_t = typename wrap_operand<T>::type;
template <>
struct wrap_operand<bool, void>
{
using type = boolean_operand;
};
} }
#endif #endif

View File

@ -0,0 +1,41 @@
/*
* 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_COLUMN_OPERATORS_H
#define SQLPP_COLUMN_OPERATORS_H
#include <sqlpp11/wrong.h>
namespace sqlpp
{
template <typename Column, typename ValueType>
struct column_operators
{
static_assert(wrong_t<column_operators>::value, "Missing column operators for ValueType");
};
}
#endif

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2015-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_DAY_POINT_H
#define SQLPP_DAY_POINT_H
#include <sqlpp11/data_types/day_point/data_type.h>
#include <sqlpp11/data_types/day_point/operand.h>
#include <sqlpp11/data_types/day_point/wrap_operand.h>
#include <sqlpp11/data_types/day_point/expression_operators.h>
#include <sqlpp11/data_types/day_point/column_operators.h>
#include <sqlpp11/data_types/day_point/parameter_value.h>
#include <sqlpp11/data_types/day_point/result_field.h>
#endif

View File

@ -0,0 +1,44 @@
/*
* Copyright (c) 2015-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_DAY_POINT_COLUMN_OPERATORS_H
#define SQLPP_DAY_POINT_COLUMN_OPERATORS_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/assignment.h>
#include <sqlpp11/data_types/day_point/data_type.h>
#include <sqlpp11/data_types/column_operators.h>
namespace sqlpp
{
template <typename Column>
struct column_operators<Column, day_point>
{
template <typename T>
using _is_valid_operand = is_valid_operand<day_point, T>;
};
}
#endif

View File

@ -0,0 +1,46 @@
/*
* Copyright (c) 2015-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_DAY_POINT_DATA_TYPE_H
#define SQLPP_DAY_POINT_DATA_TYPE_H
#include <sqlpp11/chrono.h>
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
struct day_point
{
using _traits = make_traits<day_point, tag::is_value_type>;
using _cpp_value_type = ::sqlpp::chrono::day_point;
template <typename T>
using _is_valid_operand = is_day_or_time_point_t<T>;
template <typename T>
using _is_valid_assignment_operand = is_day_point_t<T>;
};
}
#endif

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2015-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_DAY_POINT_EXPRESSION_OPERATORS_H
#define SQLPP_DAY_POINT_EXPRESSION_OPERATORS_H
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/day_point/data_type.h>
namespace sqlpp
{
template <typename Expression>
struct expression_operators<Expression, day_point> : public basic_expression_operators<Expression, day_point>
{
};
}
#endif

View File

@ -0,0 +1,84 @@
/*
* Copyright (c) 2015-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_DAY_POINT_OPERAND_H
#define SQLPP_DAY_POINT_OPERAND_H
#include <date.h>
#include <sqlpp11/chrono.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp
{
struct day_point;
struct day_point_operand : public alias_operators<day_point_operand>
{
using _traits = make_traits<day_point, tag::is_expression, tag::is_wrapped_value>;
using _nodes = detail::type_vector<>;
using _is_aggregate_expression = std::true_type;
using _value_t = ::sqlpp::chrono::day_point;
day_point_operand() : _t{}
{
}
day_point_operand(_value_t t) : _t(t)
{
}
day_point_operand(const day_point_operand&) = default;
day_point_operand(day_point_operand&&) = default;
day_point_operand& operator=(const day_point_operand&) = default;
day_point_operand& operator=(day_point_operand&&) = default;
~day_point_operand() = default;
bool _is_trivial() const
{
return _t == _value_t{};
}
_value_t _t;
};
template <typename Context>
struct serializer_t<Context, day_point_operand>
{
using _serialize_check = consistent_t;
using Operand = day_point_operand;
static Context& _(const Operand& t, Context& context)
{
const auto ymd = ::date::year_month_day{t._t};
context << "DATE '" << ymd << "'";
return context;
}
};
}
#endif

View File

@ -0,0 +1,53 @@
/*
* Copyright (c) 2015-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_DAY_POINT_PARAMETER_VALUE_H
#define SQLPP_DAY_POINT_PARAMETER_VALUE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/day_point/data_type.h>
#include <sqlpp11/data_types/day_point/wrap_operand.h>
#include <sqlpp11/data_types/day_point/operand.h>
#include <sqlpp11/tvin.h>
namespace sqlpp
{
template <>
struct parameter_value_t<day_point> : public parameter_value_base<day_point>
{
using base = parameter_value_base<day_point>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_date_parameter(index, &_value, _is_null);
}
};
}
#endif

View File

@ -0,0 +1,72 @@
/*
* Copyright (c) 2015-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_DAY_POINT_RESULT_FIELD_H
#define SQLPP_DAY_POINT_RESULT_FIELD_H
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/result_field.h>
#include <sqlpp11/result_field_base.h>
#include <sqlpp11/data_types/day_point/data_type.h>
#include <sqlpp11/field_spec.h>
#include <ostream>
namespace sqlpp
{
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
struct result_field_t<Db, field_spec_t<NameType, day_point, CanBeNull, NullIsTrivialValue>>
: public result_field_base<Db, field_spec_t<NameType, day_point, CanBeNull, NullIsTrivialValue>>
{
template <typename Target>
void _bind(Target& target, size_t index)
{
target._bind_date_result(index, &this->_value, &this->_is_null);
}
template <typename Target>
void _post_bind(Target& target, size_t index)
{
target._post_bind_date_result(index, &this->_value, &this->_is_null);
}
};
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
inline std::ostream& operator<<(
std::ostream& os, const result_field_t<Db, field_spec_t<NameType, day_point, CanBeNull, NullIsTrivialValue>>& e)
{
if (e.is_null() and not NullIsTrivialValue)
{
os << "NULL";
}
else
{
const auto ymd = ::date::year_month_day{e.value()};
os << ymd;
}
return os;
}
}
#endif

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2015-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_DAY_POINT_WRAP_OPERAND_H
#define SQLPP_DAY_POINT_WRAP_OPERAND_H
#include <utility>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/chrono.h>
#include <sqlpp11/wrap_operand.h>
namespace sqlpp
{
struct day_point_operand;
template <>
struct wrap_operand<std::chrono::time_point<std::chrono::system_clock, sqlpp::chrono::days>, void>
{
using type = day_point_operand;
};
}
#endif

View File

@ -0,0 +1,38 @@
/*
* 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_FLOATING_POINT_H
#define SQLPP_FLOATING_POINT_H
#include <sqlpp11/data_types/floating_point/data_type.h>
#include <sqlpp11/data_types/floating_point/operand.h>
#include <sqlpp11/data_types/floating_point/wrap_operand.h>
#include <sqlpp11/data_types/floating_point/expression_operators.h>
#include <sqlpp11/data_types/floating_point/column_operators.h>
#include <sqlpp11/data_types/floating_point/parameter_value.h>
#include <sqlpp11/data_types/floating_point/result_field.h>
#endif

View File

@ -0,0 +1,80 @@
/*
* 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_FLOATING_POINT_COLUMN_OPERATORS_H
#define SQLPP_FLOATING_POINT_COLUMN_OPERATORS_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/assignment.h>
#include <sqlpp11/data_types/floating_point/data_type.h>
#include <sqlpp11/data_types/column_operators.h>
namespace sqlpp
{
template <typename Column>
struct column_operators<Column, floating_point>
{
template <typename T>
using _is_valid_operand = is_valid_operand<floating_point, T>;
template <typename T>
auto operator+=(T t) const -> assignment_t<Column, plus_t<Column, floating_point, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
}
template <typename T>
auto operator-=(T t) const -> assignment_t<Column, minus_t<Column, floating_point, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
}
template <typename T>
auto operator/=(T t) const -> assignment_t<Column, divides_t<Column, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
}
template <typename T>
auto operator*=(T t) const -> assignment_t<Column, multiplies_t<Column, floating_point, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {*static_cast<const Column*>(this), rhs{t}}};
}
};
}
#endif

View File

@ -0,0 +1,43 @@
/*
* 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_FLOATING_POINT_DATA_TYPE_H
#define SQLPP_FLOATING_POINT_DATA_TYPE_H
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
struct floating_point
{
using _traits = make_traits<floating_point, tag::is_value_type>;
using _cpp_value_type = double;
template <typename T>
using _is_valid_operand = is_numeric_t<T>;
};
}
#endif

View File

@ -0,0 +1,86 @@
/*
* 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_FLOATING_POINT_EXPRESSION_OPERATORS_H
#define SQLPP_FLOATING_POINT_EXPRESSION_OPERATORS_H
#include <sqlpp11/expression_return_types.h>
#include <sqlpp11/operand_check.h>
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/floating_point/data_type.h>
namespace sqlpp
{
template <typename Expr>
struct expression_operators<Expr, floating_point> : public basic_expression_operators<Expr, floating_point>
{
};
template <typename L, typename R>
struct return_type_plus<L, R, binary_operand_check_t<L, is_floating_point_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = plus_t<wrap_operand_t<L>, floating_point, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_minus<L, R, binary_operand_check_t<L, is_floating_point_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = minus_t<wrap_operand_t<L>, floating_point, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_multiplies<L, R, binary_operand_check_t<L, is_floating_point_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = multiplies_t<wrap_operand_t<L>, floating_point, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_divides<L, R, binary_operand_check_t<L, is_floating_point_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = divides_t<wrap_operand_t<L>, wrap_operand_t<R>>;
};
template <typename T, typename Defer>
struct return_type_unary_plus<T, Defer, unary_operand_check_t<T, is_floating_point_t>>
{
using check = consistent_t;
using type = unary_plus_t<floating_point, wrap_operand_t<T>>;
};
template <typename T, typename Defer>
struct return_type_unary_minus<T, Defer, unary_operand_check_t<T, is_floating_point_t>>
{
using check = consistent_t;
using type = unary_minus_t<floating_point, wrap_operand_t<T>>;
};
}
#endif

View File

@ -0,0 +1,79 @@
/*
* 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_FLOATING_POINT_OPERAND_H
#define SQLPP_FLOATING_POINT_OPERAND_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp
{
struct floating_point_operand : public alias_operators<floating_point_operand>
{
using _traits = make_traits<floating_point, tag::is_expression, tag::is_wrapped_value>;
using _nodes = detail::type_vector<>;
using _is_aggregate_expression = std::true_type;
using _value_t = double;
floating_point_operand() : _t{}
{
}
floating_point_operand(_value_t t) : _t(t)
{
}
floating_point_operand(const floating_point_operand&) = default;
floating_point_operand(floating_point_operand&&) = default;
floating_point_operand& operator=(const floating_point_operand&) = default;
floating_point_operand& operator=(floating_point_operand&&) = default;
~floating_point_operand() = default;
bool _is_trivial() const
{
return _t == 0;
}
_value_t _t;
};
template <typename Context>
struct serializer_t<Context, floating_point_operand>
{
using _serialize_check = consistent_t;
using Operand = floating_point_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
}
#endif

View File

@ -0,0 +1,53 @@
/*
* 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_FLOATING_POINT_PARAMETER_VALUE_H
#define SQLPP_FLOATING_POINT_PARAMETER_VALUE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/floating_point/data_type.h>
#include <sqlpp11/data_types/floating_point/wrap_operand.h>
#include <sqlpp11/data_types/floating_point/operand.h>
#include <sqlpp11/tvin.h>
namespace sqlpp
{
template <>
struct parameter_value_t<floating_point> : public parameter_value_base<floating_point>
{
using base = parameter_value_base<floating_point>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_floating_point_parameter(index, &_value, _is_null);
}
};
}
#endif

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2013-2015, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_FLOATING_POINT_RESULT_FIELD_H
#define SQLPP_FLOATING_POINT_RESULT_FIELD_H
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/exception.h>
#include <sqlpp11/result_field.h>
#include <sqlpp11/result_field_base.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/floating_point/data_type.h>
#include <sqlpp11/field_spec.h>
namespace sqlpp
{
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
struct result_field_t<Db, field_spec_t<NameType, floating_point, CanBeNull, NullIsTrivialValue>>
: public result_field_base<Db, field_spec_t<NameType, floating_point, CanBeNull, NullIsTrivialValue>>
{
template <typename Target>
void _bind(Target& target, size_t index)
{
target._bind_floating_point_result(index, &this->_value, &this->_is_null);
}
template <typename Target>
void _post_bind(Target& target, size_t index)
{
target._post_bind_floating_point_result(index, &this->_value, &this->_is_null);
}
};
}
#endif

View File

@ -0,0 +1,43 @@
/*
* 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_FLOATING_POINT_WRAP_OPERAND_H
#define SQLPP_FLOATING_POINT_WRAP_OPERAND_H
#include <utility>
#include <sqlpp11/wrap_operand.h>
namespace sqlpp
{
struct floating_point_operand;
template <typename T>
struct wrap_operand<T, typename std::enable_if<std::is_floating_point<T>::value>::type>
{
using type = floating_point_operand;
};
}
#endif

View File

@ -0,0 +1,38 @@
/*
* 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_INTEGRAL_H
#define SQLPP_INTEGRAL_H
#include <sqlpp11/data_types/integral/data_type.h>
#include <sqlpp11/data_types/integral/operand.h>
#include <sqlpp11/data_types/integral/wrap_operand.h>
#include <sqlpp11/data_types/integral/expression_operators.h>
#include <sqlpp11/data_types/integral/column_operators.h>
#include <sqlpp11/data_types/integral/parameter_value.h>
#include <sqlpp11/data_types/integral/result_field.h>
#endif

View File

@ -0,0 +1,82 @@
/*
* 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_INTEGRAL_COLUMN_OPERATORS_H
#define SQLPP_INTEGRAL_COLUMN_OPERATORS_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/assignment.h>
#include <sqlpp11/value_type.h>
#include <sqlpp11/data_types/integral/data_type.h>
#include <sqlpp11/data_types/column_operators.h>
namespace sqlpp
{
template <typename Column>
struct column_operators<Column, integral>
{
template <typename T>
using _is_valid_operand = is_valid_operand<integral, T>;
template <typename T>
auto operator+=(T t) const -> assignment_t<Column, plus_t<Column, value_type_t<T>, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
}
template <typename T>
auto operator-=(T t) const -> assignment_t<Column, minus_t<Column, value_type_t<T>, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
}
template <typename T>
auto operator/=(T t) const -> assignment_t<Column, divides_t<Column, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
}
template <typename T>
auto operator*=(T t) const -> assignment_t<Column, multiplies_t<Column, value_type_t<T>, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this), {{*static_cast<const Column*>(this), rhs{t}}}};
}
};
}
#endif

View File

@ -0,0 +1,48 @@
/*
* 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_INTEGRAL_DATA_TYPE_H
#define SQLPP_INTEGRAL_DATA_TYPE_H
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
struct integral
{
using _traits = make_traits<integral, tag::is_value_type>;
using _cpp_value_type = int64_t;
template <typename T>
using _is_valid_operand = is_numeric_t<T>;
};
using tinyint = integral;
using smallint = integral;
using integer = integral;
using bigint = integral;
}
#endif

View File

@ -0,0 +1,108 @@
/*
* 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_INTEGRAL_EXPRESSION_OPERATORS_H
#define SQLPP_INTEGRAL_EXPRESSION_OPERATORS_H
#include <sqlpp11/expression_return_types.h>
#include <sqlpp11/operand_check.h>
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/value_type.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/integral/data_type.h>
namespace sqlpp
{
template <typename Expression>
struct expression_operators<Expression, integral> : public basic_expression_operators<Expression, integral>
{
};
template <typename L, typename R>
struct return_type_plus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = plus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_minus<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = minus_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_multiplies<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = multiplies_t<wrap_operand_t<L>, value_type_of<wrap_operand_t<R>>, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_divides<L, R, binary_operand_check_t<L, is_integral_t, R, is_numeric_t>>
{
using check = consistent_t;
using type = divides_t<wrap_operand_t<L>, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_modulus<L, R, binary_operand_check_t<L, is_integral_t, R, is_integral_t>>
{
using check = consistent_t;
using type = modulus_t<wrap_operand_t<L>, wrap_operand_t<R>>;
};
template <typename T, typename Defer>
struct return_type_unary_plus<T, Defer, unary_operand_check_t<T, is_integral_t>>
{
using check = consistent_t;
using type = unary_plus_t<integral, wrap_operand_t<T>>;
};
template <typename T, typename Defer>
struct return_type_unary_minus<T, Defer, unary_operand_check_t<T, is_integral_t>>
{
using check = consistent_t;
using type = unary_minus_t<integral, wrap_operand_t<T>>;
};
template <typename L, typename R>
struct return_type_bitwise_and<L, R, binary_operand_check_t<L, is_integral_t, R, is_integral_t>>
{
using check = consistent_t;
using type = bitwise_and_t<wrap_operand_t<L>, integral, wrap_operand_t<R>>;
};
template <typename L, typename R>
struct return_type_bitwise_or<L, R, binary_operand_check_t<L, is_integral_t, R, is_integral_t>>
{
using check = consistent_t;
using type = bitwise_or_t<wrap_operand_t<L>, integral, wrap_operand_t<R>>;
};
}
#endif

View File

@ -0,0 +1,82 @@
/*
* 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_INTEGRAL_OPERAND_H
#define SQLPP_INTEGRAL_OPERAND_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/alias_operators.h>
#include <sqlpp11/serializer.h>
namespace sqlpp
{
struct integral;
struct integral_operand : public alias_operators<integral_operand>
{
using _traits = make_traits<integral, tag::is_expression, tag::is_wrapped_value>;
using _nodes = detail::type_vector<>;
using _is_aggregate_expression = std::true_type;
using _value_t = int64_t;
integral_operand() : _t{}
{
}
integral_operand(_value_t t) : _t(t)
{
}
integral_operand(const integral_operand&) = default;
integral_operand(integral_operand&&) = default;
integral_operand& operator=(const integral_operand&) = default;
integral_operand& operator=(integral_operand&&) = default;
~integral_operand() = default;
bool _is_trivial() const
{
return _t == 0;
}
_value_t _t;
};
template <typename Context>
struct serializer_t<Context, integral_operand>
{
using _serialize_check = consistent_t;
using Operand = integral_operand;
static Context& _(const Operand& t, Context& context)
{
context << t._t;
return context;
}
};
}
#endif

View File

@ -0,0 +1,51 @@
/*
* 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_INTEGRAL_PARAMETER_VALUE_H
#define SQLPP_INTEGRAL_PARAMETER_VALUE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/data_types/parameter_value_base.h>
#include <sqlpp11/data_types/integral/data_type.h>
#include <sqlpp11/tvin.h>
namespace sqlpp
{
template <>
struct parameter_value_t<integral> : public parameter_value_base<integral>
{
using base = parameter_value_base<integral>;
using base::base;
using base::operator=;
template <typename Target>
void _bind(Target& target, size_t index) const
{
target._bind_integral_parameter(index, &_value, _is_null);
}
};
}
#endif

View File

@ -0,0 +1,55 @@
/*
* 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_INTEGRAL_RESULT_FIELD_H
#define SQLPP_INTEGRAL_RESULT_FIELD_H
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/result_field.h>
#include <sqlpp11/result_field_base.h>
#include <sqlpp11/data_types/integral/data_type.h>
#include <sqlpp11/field_spec.h>
namespace sqlpp
{
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
struct result_field_t<Db, field_spec_t<NameType, integral, CanBeNull, NullIsTrivialValue>>
: public result_field_base<Db, field_spec_t<NameType, integral, CanBeNull, NullIsTrivialValue>>
{
template <typename Target>
void _bind(Target& target, size_t index)
{
target._bind_integral_result(index, &this->_value, &this->_is_null);
}
template <typename Target>
void _post_bind(Target& target, size_t index)
{
target._post_bind_integral_result(index, &this->_value, &this->_is_null);
}
};
}
#endif

View File

@ -0,0 +1,43 @@
/*
* 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_INTEGRAL_WRAP_OPERAND_H
#define SQLPP_INTEGRAL_WRAP_OPERAND_H
#include <utility>
#include <sqlpp11/wrap_operand.h>
namespace sqlpp
{
struct integral_operand;
template <typename T>
struct wrap_operand<T, typename std::enable_if<std::is_integral<T>::value and not std::is_same<bool, T>::value>::type>
{
using type = integral_operand;
};
}
#endif

View File

@ -27,25 +27,12 @@
#ifndef SQLPP_NO_VALUE_H #ifndef SQLPP_NO_VALUE_H
#define SQLPP_NO_VALUE_H #define SQLPP_NO_VALUE_H
#include <type_traits> #include <sqlpp11/data_types/no_value/data_type.h>
#include <sqlpp11/value_type_fwd.h> #include <sqlpp11/data_types/no_value/operand.h>
#include <sqlpp11/data_types/no_value/wrap_operand.h>
#include <sqlpp11/data_types/no_value/expression_operators.h>
#include <sqlpp11/data_types/no_value/column_operators.h>
#include <sqlpp11/data_types/no_value/parameter_value.h>
#include <sqlpp11/data_types/no_value/result_field.h>
namespace sqlpp
{
struct no_value_t
{
using _tag = void;
};
template<typename Base>
struct expression_operators<Base, no_value_t>
{
};
template<typename Base>
struct column_operators<Base, no_value_t>
{
};
}
#endif #endif

View File

@ -0,0 +1,41 @@
/*
* 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_NO_VALUE_COLUMN_OPERATORS_H
#define SQLPP_NO_VALUE_COLUMN_OPERATORS_H
#include <sqlpp11/data_types/column_operators.h>
namespace sqlpp
{
struct no_value_t;
template <typename Base>
struct column_operators<Base, no_value_t>
{
};
}
#endif

View File

@ -0,0 +1,44 @@
/*
* 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_NO_VALUE_DATA_TYPE_H
#define SQLPP_NO_VALUE_DATA_TYPE_H
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
struct no_value_t
{
using _traits = make_traits<no_value_t>;
using _cpp_value_type = void;
template <typename T>
using _is_valid_operand = wrong_t<T>;
};
}
#endif

View File

@ -0,0 +1,42 @@
/*
* 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_NO_VALUE_EXPRESSION_OPERATORS_H
#define SQLPP_NO_VALUE_EXPRESSION_OPERATORS_H
#include <sqlpp11/expression_return_types.h>
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
namespace sqlpp
{
template <typename Expression>
struct expression_operators<Expression, no_value_t> : public basic_expression_operators<Expression, no_value_t>
{
};
}
#endif

View File

@ -0,0 +1,35 @@
/*
* 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_NO_VALUE_OPERAND_H
#define SQLPP_NO_VALUE_OPERAND_H
namespace sqlpp
{
// There is no no_value operand
}
#endif

View File

@ -0,0 +1,35 @@
/*
* 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_NO_VALUE_PARAMETER_VALUE_H
#define SQLPP_NO_VALUE_PARAMETER_VALUE_H
namespace sqlpp
{
// There is no no_value parameter
}
#endif

View File

@ -0,0 +1,72 @@
/*
* 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_NO_VALUE_RESULT_FIELD_H
#define SQLPP_NO_VALUE_RESULT_FIELD_H
#include <sqlpp11/result_field.h>
#include <sqlpp11/data_types/no_value/data_type.h>
#include <sqlpp11/field_spec.h>
namespace sqlpp
{
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
struct result_field_t<Db, field_spec_t<NameType, no_value_t, CanBeNull, NullIsTrivialValue>>
{
template <typename Target>
void _bind(Target&, size_t)
{
}
template <typename Target>
void _post_bind(Target&, size_t)
{
}
void _validate() const
{
}
void _invalidate() const
{
}
constexpr bool is_null() const
{
return true;
}
};
template <typename Db, typename NameType, bool CanBeNull, bool NullIsTrivialValue>
inline std::ostream& operator<<(
std::ostream& os, const result_field_t<Db, field_spec_t<NameType, no_value_t, CanBeNull, NullIsTrivialValue>>&)
{
os << "NULL";
return os;
}
}
#endif

View File

@ -0,0 +1,35 @@
/*
* 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_NO_VALUE_WRAP_OPERAND_H
#define SQLPP_NO_VALUE_WRAP_OPERAND_H
namespace sqlpp
{
// There is no no_value operand
}
#endif

View File

@ -0,0 +1,41 @@
/*
* 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_PARAMETER_VALUE_H
#define SQLPP_PARAMETER_VALUE_H
#include <sqlpp11/wrong.h>
namespace sqlpp
{
template <typename ValueType>
struct parameter_value_t
{
static_assert(wrong_t<parameter_value_t>::value, "Missing parameter value type for ValueType");
};
}
#endif

View File

@ -0,0 +1,98 @@
/*
* 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_PARAMETER_VALUE_BASE_H
#define SQLPP_PARAMETER_VALUE_BASE_H
#include <sqlpp11/data_types/parameter_value.h>
#include <sqlpp11/tvin.h>
namespace sqlpp
{
template <typename DataType, typename StorageType = typename DataType::_cpp_value_type>
struct parameter_value_base
{
using _value_type = DataType;
using _cpp_value_type = typename _value_type::_cpp_value_type;
using _cpp_storage_type = StorageType;
parameter_value_base() : _value{}, _is_null{true}
{
}
explicit parameter_value_base(const _cpp_value_type& val) : _value(val), _is_null(false)
{
}
parameter_value_base& operator=(const _cpp_value_type& val)
{
_value = val;
_is_null = false;
return *this;
}
parameter_value_base& operator=(const tvin_t<wrap_operand_t<_cpp_value_type>>& t)
{
if (t._is_trivial())
{
_value = {};
_is_null = true;
}
else
{
_value = t._value._t;
_is_null = false;
}
return *this;
}
void set_null()
{
_value = {};
_is_null = true;
}
bool is_null() const
{
return _is_null;
}
const _cpp_value_type& value() const
{
return _value;
}
operator _cpp_value_type() const
{
return _value;
}
protected:
_cpp_storage_type _value;
bool _is_null;
};
}
#endif

View File

@ -0,0 +1,42 @@
/*
* 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_TEXT_H
#define SQLPP_TEXT_H
#include <sqlpp11/data_types/text/data_type.h>
#include <sqlpp11/data_types/text/operand.h>
#include <sqlpp11/data_types/text/wrap_operand.h>
#include <sqlpp11/data_types/text/expression_operators.h>
#include <sqlpp11/data_types/text/column_operators.h>
#include <sqlpp11/data_types/text/parameter_value.h>
#include <sqlpp11/data_types/text/result_field.h>
// text specific functions
#include <sqlpp11/data_types/text/like.h>
#include <sqlpp11/data_types/text/concat.h>
#endif

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2013-2015, Roland Bock
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef SQLPP_TEXT_COLUMN_OPERATORS_H
#define SQLPP_TEXT_COLUMN_OPERATORS_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/assignment.h>
#include <sqlpp11/data_types/text/data_type.h>
#include <sqlpp11/data_types/column_operators.h>
namespace sqlpp
{
template <typename... Args>
struct concat_t;
template <typename Column>
struct column_operators<Column, text>
{
template <typename T>
using _is_valid_operand = is_valid_operand<text, T>;
template <typename T>
auto operator+=(T t) const -> assignment_t<Column, concat_t<Column, wrap_operand_t<T>>>
{
using rhs = wrap_operand_t<T>;
static_assert(_is_valid_operand<rhs>::value, "invalid rhs assignment operand");
return {*static_cast<const Column*>(this),
concat_t<Column, wrap_operand_t<T>>{*static_cast<const Column*>(this), rhs{t}}};
}
};
}
#endif

View File

@ -0,0 +1,103 @@
/*
* 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_CONCAT_H
#define SQLPP_CONCAT_H
#include <sqlpp11/type_traits.h>
#include <sqlpp11/char_sequence.h>
#include <sqlpp11/interpret_tuple.h>
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/alias_operators.h>
#include <sqlpp11/logic.h>
#include <sqlpp11/wrap_operand.h>
namespace sqlpp
{
struct text;
struct concat_alias_t
{
struct _alias_t
{
static constexpr const char _literal[] = "concat_";
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>;
template <typename T>
struct _member_t
{
T concat;
};
};
};
template <typename... Args>
struct concat_t : public expression_operators<concat_t<Args...>, text>, public alias_operators<concat_t<Args...>>
{
using _traits = make_traits<text, tag::is_expression, tag::is_selectable>;
using _nodes = detail::type_vector<Args...>;
using _auto_alias_t = concat_alias_t;
concat_t(Args... args) : _args(args...)
{
}
concat_t(const concat_t&) = default;
concat_t(concat_t&&) = default;
concat_t& operator=(const concat_t&) = default;
concat_t& operator=(concat_t&&) = default;
~concat_t() = default;
std::tuple<Args...> _args;
};
template <typename Context, typename... Args>
struct serializer_t<Context, concat_t<Args...>>
{
using _serialize_check = serialize_check_of<Context, Args...>;
using T = concat_t<Args...>;
static Context& _(const T& t, Context& context)
{
context << "(";
interpret_tuple(t._args, "||", context);
context << ")";
return context;
}
};
template <typename... Args>
auto concat(Args... args) -> concat_t<Args...>
{
static_assert(sizeof...(Args) >= 2, "concat requires two arguments at least");
static_assert(logic::all_t<is_text_t<wrap_operand_t<Args>>::value...>::value,
"at least one non-text argument detected in concat()");
return {args...};
}
}
#endif

View File

@ -0,0 +1,47 @@
/*
* 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_TEXT_DATA_TYPE_H
#define SQLPP_TEXT_DATA_TYPE_H
#include <sqlpp11/type_traits.h>
namespace sqlpp
{
struct text
{
using _traits = make_traits<text, tag::is_value_type>;
using _cpp_value_type = std::string;
template <typename T>
using _is_valid_operand = is_text_t<T>;
};
using blob = text;
using varchar = text;
using char_ = text;
}
#endif

View File

@ -0,0 +1,80 @@
/*
* 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_TEXT_EXPRESSION_OPERATORS_H
#define SQLPP_TEXT_EXPRESSION_OPERATORS_H
#include <sqlpp11/expression_operators.h>
#include <sqlpp11/basic_expression_operators.h>
#include <sqlpp11/type_traits.h>
#include <sqlpp11/data_types/text/data_type.h>
namespace sqlpp
{
template <typename... Args>
struct concat_t;
template <typename Operand, typename Pattern>
struct like_t;
template <typename T, typename Defer, typename Enable = void>
struct return_type_like
{
using check = assert_valid_operands;
using type = bad_expression<boolean>;
};
template <typename T, typename Defer>
using return_type_like_t = typename return_type_like<T, Defer>::type;
template <typename L, typename R>
struct return_type_like<L, R, binary_operand_check_t<L, is_text_t, R, is_text_t>>
{
using check = consistent_t;
using type = like_t<wrap_operand_t<L>, wrap_operand_t<R>>;
};
template <typename Expression>
struct expression_operators<Expression, text> : public basic_expression_operators<Expression, text>
{
template <typename T>
using _is_valid_operand = is_valid_operand<text, T>;
template <typename R>
auto like(const R& r) const -> return_type_like_t<Expression, R>
{
return_type_like<Expression, R>::check::_();
return {*static_cast<const Expression*>(this), wrap_operand_t<R>{r}};
}
};
template <typename L, typename R>
struct return_type_plus<L, R, binary_operand_check_t<L, is_text_t, R, is_text_t>>
{
using check = consistent_t;
using type = concat_t<wrap_operand_t<L>, wrap_operand_t<R>>;
};
}
#endif

Some files were not shown because too many files have changed in this diff Show More