diff --git a/include/sqlpp11/data_types/text/result_field.h b/include/sqlpp11/data_types/text/result_field.h index 0c0f0d0b..11639a04 100644 --- a/include/sqlpp11/data_types/text/result_field.h +++ b/include/sqlpp11/data_types/text/result_field.h @@ -40,23 +40,28 @@ namespace sqlpp struct result_field_t> : public result_field_base> { + const char* text{nullptr}; // Non-owning + size_t len{}; + template 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 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); } }; diff --git a/include/sqlpp11/ppgen.h b/include/sqlpp11/ppgen.h index 4e60d66b..0fd267a6 100644 --- a/include/sqlpp11/ppgen.h +++ b/include/sqlpp11/ppgen.h @@ -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,111 +80,141 @@ /***************************************************************************/ // 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_COMMA_IF(BOOST_PP_LESS(BOOST_PP_ADD(idx, 1), size)) +#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_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)); \ - using _name_t = sqlpp::make_char_sequence; \ - \ - template \ - struct _member_t \ - { \ - T SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \ - \ - T& operator()() \ - { \ - return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \ - } \ - const T& operator()() const \ - { \ - return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \ - } \ - }; /* struct _member_t */ \ - }; /* struct _alias_t */ \ - \ - using _traits = sqlpp::make_traits; \ - \ +#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)); \ + using _name_t = sqlpp::make_char_sequence; \ + \ + template \ + struct _member_t \ + { \ + T SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \ + \ + T& operator()() \ + { \ + return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \ + } \ + const T& operator()() const \ + { \ + return SQLPP_DECLARE_COLUMN_GET_COLUMN_NAME(elem); \ + } \ + }; /* struct _member_t */ \ + }; /* struct _alias_t */ \ + \ + 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))) +#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)) \ + ) /***************************************************************************/ // main -#define SQLPP_DECLARE_TABLE_IMPL(table, cols) \ - namespace SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \ - { \ - namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) \ - { \ - 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 \ - { \ - 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)); \ - using _name_t = sqlpp::make_char_sequence; \ - \ - template \ - struct _member_t \ - { \ - T SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \ - \ - T& operator()() \ - { \ - return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \ - } \ - const T& operator()() const \ - { \ - return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \ - } \ - \ - }; /* struct _member_t */ \ - \ - }; /* struct _alias_t */ \ - \ - }; /* struct SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) */ \ +#define SQLPP_DECLARE_TABLE_IMPL(table, cols) \ + namespace SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table) \ + { \ + namespace BOOST_PP_CAT(SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table), _) \ + { \ + 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 \ + ) \ + > \ + { \ + 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)); \ + using _name_t = sqlpp::make_char_sequence; \ + \ + template \ + struct _member_t \ + { \ + T SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \ + \ + T& operator()() \ + { \ + return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \ + } \ + const T& operator()() const \ + { \ + return SQLPP_DECLARE_TABLE_GET_TABLE_NAME(table); \ + } \ + \ + }; /* 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)) +#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) \ + ) /***************************************************************************/ diff --git a/include/sqlpp11/ppgen/colops/auto_increment.h b/include/sqlpp11/ppgen/colops/auto_increment.h index f465b4f7..fc370b39 100644 --- a/include/sqlpp11/ppgen/colops/auto_increment.h +++ b/include/sqlpp11/ppgen/colops/auto_increment.h @@ -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,12 +24,14 @@ * 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 #define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_AUTO_INCREMENT \ - PROC_SQLPP_AUTO_INCREMENT + PROC_SQLPP_AUTO_INCREMENT #define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_AUTO_INCREMENT(...) \ - ::sqlpp::tag::must_not_insert, ::sqlpp::tag::must_not_update + ::sqlpp::tag::must_not_insert, ::sqlpp::tag::must_not_update #endif // _sqlpp__ppgen__colops__auto_increment_h diff --git a/include/sqlpp11/ppgen/colops/blob.h b/include/sqlpp11/ppgen/colops/blob.h index 233740a1..5e5332d9 100644 --- a/include/sqlpp11/ppgen/colops/blob.h +++ b/include/sqlpp11/ppgen/colops/blob.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/bool.h b/include/sqlpp11/ppgen/colops/bool.h index 11acd226..d1ec8662 100644 --- a/include/sqlpp11/ppgen/colops/bool.h +++ b/include/sqlpp11/ppgen/colops/bool.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/comment.h b/include/sqlpp11/ppgen/colops/comment.h index a819920c..e5ab8d82 100644 --- a/include/sqlpp11/ppgen/colops/comment.h +++ b/include/sqlpp11/ppgen/colops/comment.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/datetime.h b/include/sqlpp11/ppgen/colops/datetime.h index aec6bb04..ecc134bf 100644 --- a/include/sqlpp11/ppgen/colops/datetime.h +++ b/include/sqlpp11/ppgen/colops/datetime.h @@ -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,12 +24,14 @@ * 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 #define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_datetime \ - PROC_datetime + PROC_datetime #define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_datetime(...) \ - [datetime is not implemented] + [datetime is not implemented] #endif // _sqlpp__ppgen__colops__datetime_h diff --git a/include/sqlpp11/ppgen/colops/default.h b/include/sqlpp11/ppgen/colops/default.h index ed8121ba..f58c095f 100644 --- a/include/sqlpp11/ppgen/colops/default.h +++ b/include/sqlpp11/ppgen/colops/default.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/floating_point.h b/include/sqlpp11/ppgen/colops/floating_point.h index 2221d444..bd8881f3 100644 --- a/include/sqlpp11/ppgen/colops/floating_point.h +++ b/include/sqlpp11/ppgen/colops/floating_point.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/foreign_key.h b/include/sqlpp11/ppgen/colops/foreign_key.h index f5372572..8b43938b 100644 --- a/include/sqlpp11/ppgen/colops/foreign_key.h +++ b/include/sqlpp11/ppgen/colops/foreign_key.h @@ -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] diff --git a/include/sqlpp11/ppgen/colops/index.h b/include/sqlpp11/ppgen/colops/index.h index 3da56940..bbea4bec 100644 --- a/include/sqlpp11/ppgen/colops/index.h +++ b/include/sqlpp11/ppgen/colops/index.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/integer.h b/include/sqlpp11/ppgen/colops/integer.h index 017735c6..ccf2c60e 100644 --- a/include/sqlpp11/ppgen/colops/integer.h +++ b/include/sqlpp11/ppgen/colops/integer.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/not_null.h b/include/sqlpp11/ppgen/colops/not_null.h index 449ef7e1..cae2767e 100644 --- a/include/sqlpp11/ppgen/colops/not_null.h +++ b/include/sqlpp11/ppgen/colops/not_null.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/null.h b/include/sqlpp11/ppgen/colops/null.h index 4856d4bd..c45807f0 100644 --- a/include/sqlpp11/ppgen/colops/null.h +++ b/include/sqlpp11/ppgen/colops/null.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/primary_key.h b/include/sqlpp11/ppgen/colops/primary_key.h index 2258bac6..dd8583a1 100644 --- a/include/sqlpp11/ppgen/colops/primary_key.h +++ b/include/sqlpp11/ppgen/colops/primary_key.h @@ -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,11 +24,13 @@ * 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 #define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_SQLPP_PRIMARY_KEY \ - PROC_SQLPP_PRIMARY_KEY + PROC_SQLPP_PRIMARY_KEY #define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_SQLPP_PRIMARY_KEY(...) \ ::sqlpp::tag::must_not_update diff --git a/include/sqlpp11/ppgen/colops/text.h b/include/sqlpp11/ppgen/colops/text.h index f91788bf..44203c4c 100644 --- a/include/sqlpp11/ppgen/colops/text.h +++ b/include/sqlpp11/ppgen/colops/text.h @@ -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 diff --git a/include/sqlpp11/ppgen/colops/timestamp.h b/include/sqlpp11/ppgen/colops/timestamp.h index 130e005b..6c0899ae 100644 --- a/include/sqlpp11/ppgen/colops/timestamp.h +++ b/include/sqlpp11/ppgen/colops/timestamp.h @@ -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,12 +24,14 @@ * 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 #define SQLPP_DECLARE_COLUMN_GET_TRAITS_LAZY_timestamp \ - PROC_timestamp + PROC_timestamp #define SQLPP_DECLARE_COLUMN_GEN_TRAITS_PROC_timestamp(...) \ - [timestamp is not implemented] + [timestamp is not implemented] #endif // _sqlpp__ppgen__colops__timestamp_h diff --git a/include/sqlpp11/ppgen/colops/unique_index.h b/include/sqlpp11/ppgen/colops/unique_index.h index eb7037a3..b003c13b 100644 --- a/include/sqlpp11/ppgen/colops/unique_index.h +++ b/include/sqlpp11/ppgen/colops/unique_index.h @@ -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] diff --git a/include/sqlpp11/ppgen/colops/varchar.h b/include/sqlpp11/ppgen/colops/varchar.h index e4b0f55f..2f952ee4 100644 --- a/include/sqlpp11/ppgen/colops/varchar.h +++ b/include/sqlpp11/ppgen/colops/varchar.h @@ -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 diff --git a/include/sqlpp11/ppgen/tblops/character_set.h b/include/sqlpp11/ppgen/tblops/character_set.h index 38825bdf..2db1ba64 100644 --- a/include/sqlpp11/ppgen/tblops/character_set.h +++ b/include/sqlpp11/ppgen/tblops/character_set.h @@ -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 diff --git a/include/sqlpp11/ppgen/tblops/comment.h b/include/sqlpp11/ppgen/tblops/comment.h index 499611a9..5b85563b 100644 --- a/include/sqlpp11/ppgen/tblops/comment.h +++ b/include/sqlpp11/ppgen/tblops/comment.h @@ -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 diff --git a/include/sqlpp11/ppgen/tblops/default.h b/include/sqlpp11/ppgen/tblops/default.h index 51cd6063..0de848af 100644 --- a/include/sqlpp11/ppgen/tblops/default.h +++ b/include/sqlpp11/ppgen/tblops/default.h @@ -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 diff --git a/include/sqlpp11/ppgen/tblops/engine.h b/include/sqlpp11/ppgen/tblops/engine.h index 01d44da9..d2345f93 100644 --- a/include/sqlpp11/ppgen/tblops/engine.h +++ b/include/sqlpp11/ppgen/tblops/engine.h @@ -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 diff --git a/include/sqlpp11/ppgen/tools/tuple_pop_front.h b/include/sqlpp11/ppgen/tools/tuple_pop_front.h index c958fb89..0cf5f3d1 100644 --- a/include/sqlpp11/ppgen/tools/tuple_pop_front.h +++ b/include/sqlpp11/ppgen/tools/tuple_pop_front.h @@ -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 diff --git a/include/sqlpp11/ppgen/tools/wrap_seq.h b/include/sqlpp11/ppgen/tools/wrap_seq.h index 9f9451f9..49a8a71b 100644 --- a/include/sqlpp11/ppgen/tools/wrap_seq.h +++ b/include/sqlpp11/ppgen/tools/wrap_seq.h @@ -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,15 @@ * 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 #define SQLPP_WRAP_SEQUENCE_X(...) \ - ((__VA_ARGS__)) SQLPP_WRAP_SEQUENCE_Y + ((__VA_ARGS__)) SQLPP_WRAP_SEQUENCE_Y #define SQLPP_WRAP_SEQUENCE_Y(...) \ - ((__VA_ARGS__)) SQLPP_WRAP_SEQUENCE_X + ((__VA_ARGS__)) SQLPP_WRAP_SEQUENCE_X #define SQLPP_WRAP_SEQUENCE_X0 #define SQLPP_WRAP_SEQUENCE_Y0 diff --git a/include/sqlpp11/result.h b/include/sqlpp11/result.h index 527a6e08..b93cd84c 100644 --- a/include/sqlpp11/result.h +++ b/include/sqlpp11/result.h @@ -27,9 +27,17 @@ #ifndef SQLPP_RESULT_H #define SQLPP_RESULT_H -// FIXME: include for move? +#include +#include + namespace sqlpp { + template + struct iterator_category + { + using type = std::input_iterator_tag; + }; + template class result_t { @@ -60,16 +68,22 @@ namespace sqlpp class iterator { public: + using iterator_category = typename iterator_category::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; diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 208d3369..603080bf 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -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: diff --git a/tests/Select.cpp b/tests/Select.cpp index 268488f2..74edacfc 100644 --- a/tests/Select.cpp +++ b/tests/Select.cpp @@ -26,6 +26,7 @@ #include "MockDb.h" #include "Sample.h" #include "is_regular.h" +#include #include #include #include @@ -52,6 +53,14 @@ struct to_cerr } }; +template +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); + } + for (const auto& row : db(select(all_of(t)).from(t).unconditionally())) { int64_t a = row.alpha; diff --git a/tests/sample.sql b/tests/sample.sql index e6ff21bd..f46f7dd7 100644 --- a/tests/sample.sql +++ b/tests/sample.sql @@ -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,