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

Merge branch 'release/0.46'

This commit is contained in:
rbock 2017-03-12 12:17:27 +01:00
commit 9100e51637
29 changed files with 349 additions and 173 deletions

View File

@ -40,23 +40,28 @@ namespace sqlpp
struct result_field_t<Db, field_spec_t<NameType, text, CanBeNull, NullIsTrivialValue>>
: public result_field_base<Db, field_spec_t<NameType, text, CanBeNull, NullIsTrivialValue>>
{
const char* text{nullptr}; // Non-owning
size_t len{};
template <typename Target>
void _bind(Target& target, size_t index)
{
const char* text{nullptr};
size_t len{};
target._bind_text_result(index, &text, &len);
this->_value = {text, len};
if (text)
this->_value.assign(text, len);
else
this->_value.assign("", 0);
this->_is_null = (text == nullptr);
}
template <typename Target>
void _post_bind(Target& target, size_t index)
{
const char* text{nullptr};
size_t len{};
target._post_bind_text_result(index, &text, &len);
this->_value = {text, len};
if (text)
this->_value.assign(text, len);
else
this->_value.assign("", 0);
this->_is_null = (text == nullptr);
}
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,6 +24,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen_h
#define _sqlpp__ppgen_h
@ -78,30 +80,39 @@
/***************************************************************************/
// tools
#define SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) BOOST_PP_TUPLE_ELEM(0, BOOST_PP_EXPAND table)
#define SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
BOOST_PP_TUPLE_ELEM(0, BOOST_PP_EXPAND table)
#define SQLPP_DECLARE_TABLE_GET_TABLE_PROPS(table) SQLPP_BOOST_PP_TUPLE_POP_FRONT(BOOST_PP_EXPAND table)
#define SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(col) \
BOOST_PP_TUPLE_ELEM(0, col)
#define SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(col) BOOST_PP_TUPLE_ELEM(0, col)
#define SQLPP_DECLARE_TABLE_ENUM_COLUMNS(unused, table, elem) , table::SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)
#define SQLPP_DECLARE_TABLE_ENUM_COLUMNS(unused, table, elem) \
,table::SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)
/***************************************************************************/
// columns
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX(unused, size, idx, elem) \
BOOST_PP_CAT(SQLPP_DECLARE_COLUMN_GEN_TRAITS_, BOOST_PP_CAT(SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_, elem))(elem) \
BOOST_PP_CAT( \
SQLPP_DECLARE_COLUMN_GEN_TRAITS_ \
,BOOST_PP_CAT(SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_, elem) \
)(elem) \
BOOST_PP_COMMA_IF(BOOST_PP_LESS(BOOST_PP_ADD(idx, 1), size))
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS(props) \
BOOST_PP_SEQ_FOR_EACH_I(SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX, BOOST_PP_TUPLE_SIZE(props), BOOST_PP_TUPLE_TO_SEQ(props))
BOOST_PP_SEQ_FOR_EACH_I( \
SQLPP_DECLARE_COLUMN_GEN_TRAITS_AUX \
,BOOST_PP_TUPLE_SIZE(props) \
,BOOST_PP_TUPLE_TO_SEQ(props) \
)
#define SQLPP_DECLARE_COLUMN(unused, data, elem) \
struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) \
{ \
struct _alias_t \
{ \
static constexpr const char _literal[] = BOOST_PP_STRINGIZE(SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)); \
static constexpr const char _literal[] = \
BOOST_PP_STRINGIZE(SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem)); \
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>; \
\
template <typename T> \
@ -120,19 +131,26 @@
}; /* struct _member_t */ \
}; /* struct _alias_t */ \
\
using _traits = sqlpp::make_traits<SQLPP_DECLARE_COLUMN_GEN_TRAITS(SQLPP_BOOST_PP_TUPLE_POP_FRONT(elem))>; \
\
using _traits = sqlpp::make_traits< \
SQLPP_DECLARE_COLUMN_GEN_TRAITS(SQLPP_BOOST_PP_TUPLE_POP_FRONT(elem)) \
>; \
}; /* struct SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem) */
/***************************************************************************/
// table props
#define SQLPP_DECLARE_TABLE_GEN_PROPS_AUX(unused1, unused2, elem) \
BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GEN_, BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_PROC_LAZY_, elem))(elem)
BOOST_PP_CAT( \
SQLPP_DECLARE_TABLE_GEN_ \
,BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_PROC_LAZY_, elem) \
)(elem)
#define SQLPP_DECLARE_TABLE_GEN_PROPS(table) \
BOOST_PP_SEQ_FOR_EACH(SQLPP_DECLARE_TABLE_GEN_PROPS_AUX, ~, \
BOOST_PP_TUPLE_TO_SEQ(SQLPP_BOOST_PP_TUPLE_POP_FRONT(table)))
BOOST_PP_SEQ_FOR_EACH( \
SQLPP_DECLARE_TABLE_GEN_PROPS_AUX \
,~ \
,BOOST_PP_TUPLE_TO_SEQ(SQLPP_BOOST_PP_TUPLE_POP_FRONT(table)) \
)
/***************************************************************************/
// main
@ -142,20 +160,33 @@
{ \
namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) \
{ \
BOOST_PP_SEQ_FOR_EACH(SQLPP_DECLARE_COLUMN, ~, cols) \
BOOST_PP_SEQ_FOR_EACH( \
SQLPP_DECLARE_COLUMN \
,~ \
,cols \
) \
} /* namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) */ \
\
struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
: sqlpp::table_t<SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) BOOST_PP_SEQ_FOR_EACH( \
SQLPP_DECLARE_TABLE_ENUM_COLUMNS, BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _), cols)> \
: sqlpp::table_t< \
SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \
BOOST_PP_SEQ_FOR_EACH( \
SQLPP_DECLARE_TABLE_ENUM_COLUMNS \
,BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) \
,cols \
) \
> \
{ \
BOOST_PP_IF(BOOST_PP_LESS(BOOST_PP_TUPLE_SIZE(table), 2), \
BOOST_PP_TUPLE_EAT(), \
SQLPP_DECLARE_TABLE_GEN_PROPS)(BOOST_PP_EXPAND table) \
BOOST_PP_IF( \
BOOST_PP_LESS(BOOST_PP_TUPLE_SIZE(table), 2) \
,BOOST_PP_TUPLE_EAT() \
,SQLPP_DECLARE_TABLE_GEN_PROPS \
)(BOOST_PP_EXPAND table) \
\
struct _alias_t \
{ \
static constexpr const char _literal[] = BOOST_PP_STRINGIZE(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table)); \
static constexpr const char _literal[] = \
BOOST_PP_STRINGIZE(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table)); \
using _name_t = sqlpp::make_char_sequence<sizeof(_literal), _literal>; \
\
template <typename T> \
@ -173,16 +204,17 @@
} \
\
}; /* struct _member_t */ \
\
}; /* struct _alias_t */ \
\
}; /* struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) */ \
}
/***************************************************************************/
#define SQLPP_DECLARE_TABLE(table, cols) \
SQLPP_DECLARE_TABLE_IMPL(BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X table, 0), BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X cols, 0))
SQLPP_DECLARE_TABLE_IMPL( \
BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X table, 0) \
,BOOST_PP_CAT(SQLPP_WRAP_SEQUENCE_X cols, 0) \
)
/***************************************************************************/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,6 +24,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__auto_increment_h
#define _sqlpp__ppgen__colops__auto_increment_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,19 +24,29 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__blob_h
#define _sqlpp__ppgen__colops__blob_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_tinyblob PROC_tinyblob
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_tinyblob(...) ::sqlpp::blob
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_tinyblob \
PROC_tinyblob
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_tinyblob(...) \
::sqlpp::blob
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_blob PROC_blob
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_blob(...) ::sqlpp::blob
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_blob \
PROC_blob
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_blob(...) \
::sqlpp::blob
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_mediumblob PROC_mediumblob
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_mediumblob(...) ::sqlpp::blob
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_mediumblob \
PROC_mediumblob
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_mediumblob(...) \
::sqlpp::blob
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_longblob PROC_longblob
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_longblob(...) ::sqlpp::blob
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_longblob \
PROC_longblob
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_longblob(...) \
::sqlpp::blob
#endif // _sqlpp__ppgen__colops__blob_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__bool_h
#define _sqlpp__ppgen__colops__bool_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_bool PROC_bool
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_bool(...) ::sqlpp::boolean
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_bool \
PROC_bool
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_bool(...) \
::sqlpp::boolean
#endif // _sqlpp__ppgen__colops__bool_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__comment_h
#define _sqlpp__ppgen__colops__comment_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_COMMENT PROC_SQLPP_COMMENT
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_COMMENT(str) [COMMENT is not implemented]
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_COMMENT \
PROC_SQLPP_COMMENT
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_COMMENT(str) \
[COMMENT is not implemented]
#endif // _sqlpp__ppgen__colops__comment_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,6 +24,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__datetime_h
#define _sqlpp__ppgen__colops__datetime_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__default_h
#define _sqlpp__ppgen__colops__default_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_DEFAULT PROC_SQLPP_DEFAULT
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_DEFAULT(...) [DEFAULT is not implemented]
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_DEFAULT \
PROC_SQLPP_DEFAULT
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_DEFAULT(...) \
[DEFAULT is not implemented]
#endif // _sqlpp__ppgen__colops__default_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,13 +24,19 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__floating_point_h
#define _sqlpp__ppgen__colops__floating_point_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_float PROC_float
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_float(...) ::sqlpp::floating_point
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_float \
PROC_float
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_float(...) \
::sqlpp::floating_point
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_double PROC_double
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_double(...) ::sqlpp::floating_point
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_double \
PROC_double
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_double(...) \
::sqlpp::floating_point
#endif // _sqlpp__ppgen__colops__floating_point_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__foreign_key_h
#define _sqlpp__ppgen__colops__foreign_key_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_FOREIGN_KEY PROC_SQLPP_FOREIGN_KEY
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_FOREIGN_KEY \
PROC_SQLPP_FOREIGN_KEY
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_FOREIGN_KEY(keyname, tblname, colname) \
[FOREIGN KEY is not implemented]

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__index_h
#define _sqlpp__ppgen__colops__index_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_INDEX PROC_SQLPP_INDEX
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_INDEX(indexname, tblname, /* cols */...) [INDEX is not implemented]
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_INDEX \
PROC_SQLPP_INDEX
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_INDEX(indexname, tblname, /* cols */...) \
[INDEX is not implemented]
#endif // _sqlpp__ppgen__colops__index_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,19 +24,29 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__integer_h
#define _sqlpp__ppgen__colops__integer_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_tinyint PROC_tinyint
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_tinyint(...) ::sqlpp::tinyint
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_tinyint \
PROC_tinyint
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_tinyint(...) \
::sqlpp::tinyint
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_smallint PROC_smallint
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_smallint(...) ::sqlpp::smallint
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_smallint \
PROC_smallint
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_smallint(...) \
::sqlpp::smallint
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_int PROC_int
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_int(...) ::sqlpp::integer
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_int \
PROC_int
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_int(...) \
::sqlpp::integer
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_bigint PROC_bigint
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_bigint(...) ::sqlpp::bigint
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_bigint \
PROC_bigint
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_bigint(...) \
::sqlpp::bigint
#endif // _sqlpp__ppgen__colops__integer_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__not_null_h
#define _sqlpp__ppgen__colops__not_null_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_NOT_NULL PROC_SQLPP_NOT_NULL
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_NOT_NULL(...) ::sqlpp::tag::require_insert
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_NOT_NULL \
PROC_SQLPP_NOT_NULL
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_NOT_NULL(...) \
::sqlpp::tag::require_insert
#endif // _sqlpp__ppgen__colops__not_null_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__null_h
#define _sqlpp__ppgen__colops__null_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_NULL PROC_SQLPP_NULL
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_NULL(...) ::sqlpp::tag::can_be_null
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_NULL \
PROC_SQLPP_NULL
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_NULL(...) \
::sqlpp::tag::can_be_null
#endif // _sqlpp__ppgen__colops__null_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,6 +24,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__primary_key_h
#define _sqlpp__ppgen__colops__primary_key_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__text_h
#define _sqlpp__ppgen__colops__text_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_text PROC_text
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_text(...) ::sqlpp::text
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_text \
PROC_text
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_text(...) \
::sqlpp::text
#endif // _sqlpp__ppgen__colops__text_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,6 +24,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__timestamp_h
#define _sqlpp__ppgen__colops__timestamp_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__unique_index_h
#define _sqlpp__ppgen__colops__unique_index_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_UNIQUE_INDEX PROC_SQLPP_UNIQUE_INDEX
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_UNIQUE_INDEX \
PROC_SQLPP_UNIQUE_INDEX
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_UNIQUE_INDEX(indexname, tblname, /* cols */...) \
[UNIQUE INDEX is not implemented]

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__colops__varchar_h
#define _sqlpp__ppgen__colops__varchar_h
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_varchar(str) PROC_varchar
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_varchar(str) ::sqlpp::varchar
#define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_varchar(str) \
PROC_varchar
#define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_varchar(str) \
::sqlpp::varchar
#endif // _sqlpp__ppgen__colops__varchar_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__tblops__character_set_h
#define _sqlpp__ppgen__tblops__character_set_h
#define SQLPP_DECLARE_TABLE_GET_PROC_LAZY_SQLPP_CHARACTER_SET PROC_SQLPP_CHARACTER_SET
#define SQLPP_DECLARE_TABLE_GEN_PROC_SQLPP_CHARACTER_SET(str) [CHARACTER_SET is not implemented]
#define SQLPP_DECLARE_TABLE_GET_PROC_LAZY_SQLPP_CHARACTER_SET \
PROC_SQLPP_CHARACTER_SET
#define SQLPP_DECLARE_TABLE_GEN_PROC_SQLPP_CHARACTER_SET(str) \
[CHARACTER_SET is not implemented]
#endif // _sqlpp__ppgen__tblops__character_set_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__tblops__comment_h
#define _sqlpp__ppgen__tblops__comment_h
#define SQLPP_DECLARE_TABLE_GET_TRAITS_LAZY_SQLPP_COMMENT PROC_SQLPP_COMMENT
#define SQLPP_DECLARE_TABLE_GEN_TRAITS_PROC_SQLPP_COMMENT(str) [COMMENT is not implemented]
#define SQLPP_DECLARE_TABLE_GET_TRAITS_LAZY_SQLPP_COMMENT \
PROC_SQLPP_COMMENT
#define SQLPP_DECLARE_TABLE_GEN_TRAITS_PROC_SQLPP_COMMENT(str) \
[COMMENT is not implemented]
#endif // _sqlpp__ppgen__tblops__comment_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__tblops__default_h
#define _sqlpp__ppgen__tblops__default_h
#define SQLPP_DECLARE_TABLE_GET_TRAITS_LAZY_SQLPP_DEFAULT PROC_SQLPP_DEFAULT
#define SQLPP_DECLARE_TABLE_GEN_TRAITS_PROC_SQLPP_DEFAULT(...) [DEFAULT is not implemented]
#define SQLPP_DECLARE_TABLE_GET_TRAITS_LAZY_SQLPP_DEFAULT \
PROC_SQLPP_DEFAULT
#define SQLPP_DECLARE_TABLE_GEN_TRAITS_PROC_SQLPP_DEFAULT(...) \
[DEFAULT is not implemented]
#endif // _sqlpp__ppgen__tblops__default_h

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,10 +24,14 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__tblops__engine_h
#define _sqlpp__ppgen__tblops__engine_h
#define SQLPP_DECLARE_TABLE_GET_PROC_LAZY_SQLPP_ENGINE PROC_SQLPP_ENGINE
#define SQLPP_DECLARE_TABLE_GEN_PROC_SQLPP_ENGINE(str) [ENGINE is not implemented]
#define SQLPP_DECLARE_TABLE_GET_PROC_LAZY_SQLPP_ENGINE \
PROC_SQLPP_ENGINE
#define SQLPP_DECLARE_TABLE_GEN_PROC_SQLPP_ENGINE(str) \
[ENGINE is not implemented]
#endif // _sqlpp__ppgen__tblops__engine_h

View File

@ -9,6 +9,8 @@
/* See http://www.boost.org for most recent version. */
// clang-format off
# ifndef SQLPP_BOOST_PREPROCESSOR_TUPLE_POP_FRONT_HPP
# define SQLPP_BOOST_PREPROCESSOR_TUPLE_POP_FRONT_HPP

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014-2015, niXman (i dot nixman dog gmail dot com)
* Copyright (c) 2014-2017, niXman (i dot nixman dog gmail dot com)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -24,6 +24,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// clang-format off
#ifndef _sqlpp__ppgen__tools__wrap_seq_h
#define _sqlpp__ppgen__tools__wrap_seq_h

View File

@ -27,9 +27,17 @@
#ifndef SQLPP_RESULT_H
#define SQLPP_RESULT_H
// FIXME: include for move?
#include <iterator>
#include <utility>
namespace sqlpp
{
template <typename>
struct iterator_category
{
using type = std::input_iterator_tag;
};
template <typename DbResult, typename ResultRow>
class result_t
{
@ -60,16 +68,22 @@ namespace sqlpp
class iterator
{
public:
using iterator_category = typename iterator_category<DbResult>::type;
using value_type = result_row_t;
using pointer = const result_row_t*;
using reference = const result_row_t&;
using difference_type = std::ptrdiff_t;
iterator(db_result_t& result, result_row_t& result_row) : _result(result), _result_row(result_row)
{
}
const result_row_t& operator*() const
reference operator*() const
{
return _result_row;
}
const result_row_t* operator->() const
pointer operator->() const
{
return &_result_row;
}
@ -84,9 +98,17 @@ namespace sqlpp
return not(operator==(rhs));
}
void operator++()
iterator& operator++()
{
_result.next(_result_row);
return *this;
}
iterator operator++(int)
{
auto previous_it = *this;
_result.next(_result_row);
return previous_it;
}
db_result_t& _result;

View File

@ -169,7 +169,12 @@ ddlName = Or([ddlTerm, ddlString])
ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")"
ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull")
ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue")
ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue")
ddlAutoValue = Or([
ddlWord("AUTO_INCREMENT"),
ddlWord("SMALLSERIAL"),
ddlWord("SERIAL"),
ddlWord("BIGSERIAL"),
]).setResultsName("hasAutoValue")
ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment")
ddlConstraint = Or([
ddlWord("CONSTRAINT"),
@ -180,7 +185,8 @@ ddlConstraint = Or([
ddlWord("UNIQUE"),
])
ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments])))
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
ddlIfNotExists = Optional(Group(ddlWord("IF") + ddlWord("NOT") + ddlWord("EXISTS")).setResultsName("ifNotExists"))
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlIfNotExists + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
#ddlString.setDebug(True) #uncomment to debug pyparsing
ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable)
@ -192,9 +198,12 @@ ddl.ignore(ddlComment)
types = {
'tinyint': 'tinyint',
'smallint': 'smallint',
'smallserial': 'smallint', # PostgreSQL
'integer': 'integer',
'int': 'integer',
'serial': 'integer', # PostgreSQL
'bigint': 'bigint',
'bigserial': 'bigint', # PostgreSQL
'char': 'char_',
'varchar': 'varchar',
'text': 'text',
@ -214,7 +223,7 @@ types = {
}
ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments])))
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlIfNotExists + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
ddlComment = oneOf(["--", "#"]) + restOfLine
if failOnParse:

View File

@ -26,6 +26,7 @@
#include "MockDb.h"
#include "Sample.h"
#include "is_regular.h"
#include <algorithm>
#include <iostream>
#include <sqlpp11/alias_provider.h>
#include <sqlpp11/connection.h>
@ -52,6 +53,14 @@ struct to_cerr
}
};
template <typename Row>
void print_row(Row const& row)
{
int64_t a = row.alpha;
const std::string b = row.beta;
std::cout << a << ", " << b << std::endl;
}
int Select(int, char* [])
{
MockDb db = {};
@ -69,6 +78,13 @@ int Select(int, char* [])
std::cout << row.a << std::endl;
}
{
// using stl algorithms
auto rows = db(select(all_of(t)).from(t).unconditionally());
// nicer in C++14
std::for_each(rows.begin(), rows.end(), &print_row<decltype(*rows.begin())>);
}
for (const auto& row : db(select(all_of(t)).from(t).unconditionally()))
{
int64_t a = row.alpha;

View File

@ -24,7 +24,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
CREATE TABLE tab_foo
CREATE TABLE IF NOT EXISTS tab_foo
(
delta varchar(255),
epsilon bigint,