diff --git a/include/sqlpp11/aggregate_functions/sum.h b/include/sqlpp11/aggregate_functions/sum.h index 1f395be5..67428472 100644 --- a/include/sqlpp11/aggregate_functions/sum.h +++ b/include/sqlpp11/aggregate_functions/sum.h @@ -98,7 +98,9 @@ namespace sqlpp serialize_operand(t._expr, context); } else + { serialize(t._expr, context); + } context << ")"; return context; diff --git a/include/sqlpp11/data_types/text/result_field.h b/include/sqlpp11/data_types/text/result_field.h index d75e4941..b90dba42 100644 --- a/include/sqlpp11/data_types/text/result_field.h +++ b/include/sqlpp11/data_types/text/result_field.h @@ -48,9 +48,13 @@ namespace sqlpp { target._bind_text_result(index, &text, &len); if (text) + { this->_value.assign(text, len); + } else + { this->_value.assign(""); + } this->_is_null = (text == nullptr); } @@ -59,9 +63,13 @@ namespace sqlpp { target._post_bind_text_result(index, &text, &len); if (text) + { this->_value.assign(text, len); + } else + { this->_value.assign(""); + } this->_is_null = (text == nullptr); } }; diff --git a/include/sqlpp11/dynamic_select_column_list.h b/include/sqlpp11/dynamic_select_column_list.h index 10b7aa72..a7ec8727 100644 --- a/include/sqlpp11/dynamic_select_column_list.h +++ b/include/sqlpp11/dynamic_select_column_list.h @@ -87,9 +87,13 @@ namespace sqlpp for (const auto column : t._dynamic_columns) { if (first) + { first = false; + } else + { context << ','; + } serialize(column, context); } return context; diff --git a/include/sqlpp11/functions.h b/include/sqlpp11/functions.h index 095597f9..e867b656 100644 --- a/include/sqlpp11/functions.h +++ b/include/sqlpp11/functions.h @@ -108,9 +108,13 @@ namespace sqlpp for (const auto& entry : t._container) { if (first) + { first = false; + } else + { context << ','; + } serialize_operand(value(entry), context); } diff --git a/include/sqlpp11/group_by.h b/include/sqlpp11/group_by.h index 84fffb9e..3066e917 100644 --- a/include/sqlpp11/group_by.h +++ b/include/sqlpp11/group_by.h @@ -260,11 +260,15 @@ namespace sqlpp static Context& _(const T& t, Context& context) { if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) + { return context; + } context << " GROUP BY "; interpret_tuple(t._expressions, ',', context); if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) + { context << ','; + } interpret_list(t._dynamic_expressions, ',', context); return context; } diff --git a/include/sqlpp11/having.h b/include/sqlpp11/having.h index ad2f6478..ee451fb5 100644 --- a/include/sqlpp11/having.h +++ b/include/sqlpp11/having.h @@ -302,7 +302,9 @@ namespace sqlpp context << " HAVING "; serialize(t._expression, context); if (not t._dynamic_expressions.empty()) + { context << " AND "; + } interpret_list(t._dynamic_expressions, " AND ", context); return context; } diff --git a/include/sqlpp11/in.h b/include/sqlpp11/in.h index d3b6e72a..3f1c7fbb 100644 --- a/include/sqlpp11/in.h +++ b/include/sqlpp11/in.h @@ -83,9 +83,13 @@ namespace sqlpp serialize(t._operand, context); context << " IN("; if (sizeof...(Args) == 1) + { serialize(std::get<0>(t._args), context); + } else + { interpret_tuple(t._args, ',', context); + } context << ')'; return context; } diff --git a/include/sqlpp11/insert_value.h b/include/sqlpp11/insert_value.h index 451ed582..e78c9043 100644 --- a/include/sqlpp11/insert_value.h +++ b/include/sqlpp11/insert_value.h @@ -109,9 +109,13 @@ namespace sqlpp context << "NULL"; } else if (t._is_default) + { context << "DEFAULT"; + } else + { serialize_operand(t._value, context); + } return context; } }; diff --git a/include/sqlpp11/insert_value_list.h b/include/sqlpp11/insert_value_list.h index a50b6f96..1eb29bf2 100644 --- a/include/sqlpp11/insert_value_list.h +++ b/include/sqlpp11/insert_value_list.h @@ -587,9 +587,13 @@ namespace sqlpp for (const auto& row : t._insert_values) { if (not first) + { context << ','; + } else + { first = false; + } context << '('; interpret_tuple(row, ",", context); context << ')'; @@ -616,12 +620,16 @@ namespace sqlpp context << " ("; interpret_tuple(t._columns, ",", context); if (sizeof...(Assignments) and not t._dynamic_columns.empty()) + { context << ','; + } interpret_list(t._dynamic_columns, ',', context); context << ") VALUES("; interpret_tuple(t._values, ",", context); if (sizeof...(Assignments) and not t._dynamic_values.empty()) + { context << ','; + } interpret_list(t._dynamic_values, ',', context); context << ")"; } diff --git a/include/sqlpp11/interpret_tuple.h b/include/sqlpp11/interpret_tuple.h index ad350f22..f0de500f 100644 --- a/include/sqlpp11/interpret_tuple.h +++ b/include/sqlpp11/interpret_tuple.h @@ -39,11 +39,17 @@ namespace sqlpp const Element& element, const Separator& separator, Context& context, const UseBraces& /*unused*/, size_t index) { if (index) + { context << separator; + } if (UseBraces::value) + { serialize_operand(element, context); + } else + { serialize(element, context); + } } template diff --git a/include/sqlpp11/interpretable.h b/include/sqlpp11/interpretable.h index ff492afe..139d2809 100644 --- a/include/sqlpp11/interpretable.h +++ b/include/sqlpp11/interpretable.h @@ -130,7 +130,9 @@ namespace sqlpp context << ')'; } else + { t.serialize(context); + } return context; } diff --git a/include/sqlpp11/named_interpretable.h b/include/sqlpp11/named_interpretable.h index 019f8602..108dbaf4 100644 --- a/include/sqlpp11/named_interpretable.h +++ b/include/sqlpp11/named_interpretable.h @@ -140,7 +140,9 @@ namespace sqlpp context << ')'; } else + { t.serialize(context); + } return context; } diff --git a/include/sqlpp11/not_in.h b/include/sqlpp11/not_in.h index 5d4cab8c..08261a71 100644 --- a/include/sqlpp11/not_in.h +++ b/include/sqlpp11/not_in.h @@ -83,9 +83,13 @@ namespace sqlpp serialize_operand(t._operand, context); context << " NOT IN("; if (sizeof...(Args) == 1) + { serialize(std::get<0>(t._args), context); + } else + { interpret_tuple(t._args, ',', context); + } context << ')'; return context; } diff --git a/include/sqlpp11/order_by.h b/include/sqlpp11/order_by.h index a11fcf82..1ca1758d 100644 --- a/include/sqlpp11/order_by.h +++ b/include/sqlpp11/order_by.h @@ -258,11 +258,15 @@ namespace sqlpp static Context& _(const T& t, Context& context) { if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) + { return context; + } context << " ORDER BY "; interpret_tuple(t._expressions, ',', context); if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) + { context << ','; + } interpret_list(t._dynamic_expressions, ',', context); return context; } diff --git a/include/sqlpp11/result_field_base.h b/include/sqlpp11/result_field_base.h index caf74de3..10f517f0 100644 --- a/include/sqlpp11/result_field_base.h +++ b/include/sqlpp11/result_field_base.h @@ -87,14 +87,18 @@ namespace sqlpp 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() == _cpp_storage_type{}; } @@ -102,7 +106,9 @@ namespace sqlpp _cpp_value_type value() const { if (not _is_valid) + { throw exception("accessing value in non-existing row"); + } if (_is_null) { diff --git a/include/sqlpp11/select_column_list.h b/include/sqlpp11/select_column_list.h index 59048d2d..2f87a770 100644 --- a/include/sqlpp11/select_column_list.h +++ b/include/sqlpp11/select_column_list.h @@ -436,7 +436,9 @@ namespace sqlpp { interpret_tuple(t._columns, ',', context); if (sizeof...(Columns) and not t._dynamic_columns.empty()) + { context << ','; + } serialize(t._dynamic_columns, context); return context; } diff --git a/include/sqlpp11/select_flag_list.h b/include/sqlpp11/select_flag_list.h index afbea876..3a460685 100644 --- a/include/sqlpp11/select_flag_list.h +++ b/include/sqlpp11/select_flag_list.h @@ -249,10 +249,14 @@ namespace sqlpp { interpret_tuple(t._flags, ' ', context); if (sizeof...(Flags)) + { context << ' '; + } interpret_list(t._dynamic_flags, ',', context); if (not t._dynamic_flags.empty()) + { context << ' '; + } return context; } }; diff --git a/include/sqlpp11/serialize.h b/include/sqlpp11/serialize.h index cc367f63..0d12217a 100644 --- a/include/sqlpp11/serialize.h +++ b/include/sqlpp11/serialize.h @@ -48,7 +48,9 @@ namespace sqlpp context << ')'; } else + { serializer_t::_(t, context); + } return context; } diff --git a/include/sqlpp11/serializer_context.h b/include/sqlpp11/serializer_context.h index e4c02a99..84eb60d8 100644 --- a/include/sqlpp11/serializer_context.h +++ b/include/sqlpp11/serializer_context.h @@ -50,13 +50,17 @@ namespace sqlpp for (const auto c : arg) { if (c == '\'') + { retVal.push_back(c); + } retVal.push_back(c); } return retVal; } else + { return arg; + } } std::ostream& _os; diff --git a/include/sqlpp11/table_alias.h b/include/sqlpp11/table_alias.h index 20398b88..633fda79 100644 --- a/include/sqlpp11/table_alias.h +++ b/include/sqlpp11/table_alias.h @@ -108,10 +108,14 @@ namespace sqlpp static Context& _(const T& t, Context& context) { if (requires_braces_t::value) + { context << "("; + } serialize(t._table, context); if (requires_braces_t
::value) + { context << ")"; + } context << " AS " << name_of::char_ptr(); return context; } diff --git a/include/sqlpp11/update_list.h b/include/sqlpp11/update_list.h index 49552dad..b9b986f2 100644 --- a/include/sqlpp11/update_list.h +++ b/include/sqlpp11/update_list.h @@ -296,7 +296,9 @@ namespace sqlpp context << " SET "; interpret_tuple(t._assignments, ",", context); if (sizeof...(Assignments) and not t._dynamic_assignments.empty()) + { context << ','; + } interpret_list(t._dynamic_assignments, ',', context); return context; } diff --git a/include/sqlpp11/using.h b/include/sqlpp11/using.h index 75d565e1..8d368c5c 100644 --- a/include/sqlpp11/using.h +++ b/include/sqlpp11/using.h @@ -248,11 +248,15 @@ namespace sqlpp static Context& _(const T& t, Context& context) { if (sizeof...(Tables) == 0 and t._dynamic_tables.empty()) + { return context; + } context << " USING "; interpret_tuple(t._tables, ',', context); if (sizeof...(Tables) and not t._dynamic_tables.empty()) + { context << ','; + } interpret_list(t._dynamic_tables, ',', context); return context; } diff --git a/include/sqlpp11/where.h b/include/sqlpp11/where.h index 6dc5c60b..9acf0a4c 100644 --- a/include/sqlpp11/where.h +++ b/include/sqlpp11/where.h @@ -370,7 +370,9 @@ namespace sqlpp context << " WHERE "; serialize(t._expression, context); if (not t._dynamic_expressions.empty()) + { context << " AND "; + } interpret_list(t._dynamic_expressions, " AND ", context); return context; } diff --git a/include/sqlpp11/with.h b/include/sqlpp11/with.h index 3dfc8c65..7f03ea01 100644 --- a/include/sqlpp11/with.h +++ b/include/sqlpp11/with.h @@ -201,7 +201,9 @@ namespace sqlpp // FIXME: If there is a recursive CTE, add a "RECURSIVE" here context << " WITH "; if (T::_is_recursive::value) + { context << "RECURSIVE "; + } interpret_tuple(t._expressions, ',', context); context << ' '; return context;