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

Use clang-tidy to wrap single-line blocks into {}

This commit is contained in:
rbock 2017-09-10 15:05:34 +02:00
parent f4612061d7
commit 6a9715b59d
24 changed files with 90 additions and 0 deletions

View File

@ -98,7 +98,9 @@ namespace sqlpp
serialize_operand(t._expr, context); serialize_operand(t._expr, context);
} }
else else
{
serialize(t._expr, context); serialize(t._expr, context);
}
context << ")"; context << ")";
return context; return context;

View File

@ -48,9 +48,13 @@ namespace sqlpp
{ {
target._bind_text_result(index, &text, &len); target._bind_text_result(index, &text, &len);
if (text) if (text)
{
this->_value.assign(text, len); this->_value.assign(text, len);
}
else else
{
this->_value.assign(""); this->_value.assign("");
}
this->_is_null = (text == nullptr); this->_is_null = (text == nullptr);
} }
@ -59,9 +63,13 @@ namespace sqlpp
{ {
target._post_bind_text_result(index, &text, &len); target._post_bind_text_result(index, &text, &len);
if (text) if (text)
{
this->_value.assign(text, len); this->_value.assign(text, len);
}
else else
{
this->_value.assign(""); this->_value.assign("");
}
this->_is_null = (text == nullptr); this->_is_null = (text == nullptr);
} }
}; };

View File

@ -87,9 +87,13 @@ namespace sqlpp
for (const auto column : t._dynamic_columns) for (const auto column : t._dynamic_columns)
{ {
if (first) if (first)
{
first = false; first = false;
}
else else
{
context << ','; context << ',';
}
serialize(column, context); serialize(column, context);
} }
return context; return context;

View File

@ -108,9 +108,13 @@ namespace sqlpp
for (const auto& entry : t._container) for (const auto& entry : t._container)
{ {
if (first) if (first)
{
first = false; first = false;
}
else else
{
context << ','; context << ',';
}
serialize_operand(value(entry), context); serialize_operand(value(entry), context);
} }

View File

@ -260,11 +260,15 @@ namespace sqlpp
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
{
return context; return context;
}
context << " GROUP BY "; context << " GROUP BY ";
interpret_tuple(t._expressions, ',', context); interpret_tuple(t._expressions, ',', context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
{
context << ','; context << ',';
}
interpret_list(t._dynamic_expressions, ',', context); interpret_list(t._dynamic_expressions, ',', context);
return context; return context;
} }

View File

@ -302,7 +302,9 @@ namespace sqlpp
context << " HAVING "; context << " HAVING ";
serialize(t._expression, context); serialize(t._expression, context);
if (not t._dynamic_expressions.empty()) if (not t._dynamic_expressions.empty())
{
context << " AND "; context << " AND ";
}
interpret_list(t._dynamic_expressions, " AND ", context); interpret_list(t._dynamic_expressions, " AND ", context);
return context; return context;
} }

View File

@ -83,9 +83,13 @@ namespace sqlpp
serialize(t._operand, context); serialize(t._operand, context);
context << " IN("; context << " IN(";
if (sizeof...(Args) == 1) if (sizeof...(Args) == 1)
{
serialize(std::get<0>(t._args), context); serialize(std::get<0>(t._args), context);
}
else else
{
interpret_tuple(t._args, ',', context); interpret_tuple(t._args, ',', context);
}
context << ')'; context << ')';
return context; return context;
} }

View File

@ -109,9 +109,13 @@ namespace sqlpp
context << "NULL"; context << "NULL";
} }
else if (t._is_default) else if (t._is_default)
{
context << "DEFAULT"; context << "DEFAULT";
}
else else
{
serialize_operand(t._value, context); serialize_operand(t._value, context);
}
return context; return context;
} }
}; };

View File

@ -587,9 +587,13 @@ namespace sqlpp
for (const auto& row : t._insert_values) for (const auto& row : t._insert_values)
{ {
if (not first) if (not first)
{
context << ','; context << ',';
}
else else
{
first = false; first = false;
}
context << '('; context << '(';
interpret_tuple(row, ",", context); interpret_tuple(row, ",", context);
context << ')'; context << ')';
@ -616,12 +620,16 @@ namespace sqlpp
context << " ("; context << " (";
interpret_tuple(t._columns, ",", context); interpret_tuple(t._columns, ",", context);
if (sizeof...(Assignments) and not t._dynamic_columns.empty()) if (sizeof...(Assignments) and not t._dynamic_columns.empty())
{
context << ','; context << ',';
}
interpret_list(t._dynamic_columns, ',', context); interpret_list(t._dynamic_columns, ',', context);
context << ") VALUES("; context << ") VALUES(";
interpret_tuple(t._values, ",", context); interpret_tuple(t._values, ",", context);
if (sizeof...(Assignments) and not t._dynamic_values.empty()) if (sizeof...(Assignments) and not t._dynamic_values.empty())
{
context << ','; context << ',';
}
interpret_list(t._dynamic_values, ',', context); interpret_list(t._dynamic_values, ',', context);
context << ")"; context << ")";
} }

View File

@ -39,12 +39,18 @@ namespace sqlpp
const Element& element, const Separator& separator, Context& context, const UseBraces& /*unused*/, size_t index) const Element& element, const Separator& separator, Context& context, const UseBraces& /*unused*/, size_t index)
{ {
if (index) if (index)
{
context << separator; context << separator;
}
if (UseBraces::value) if (UseBraces::value)
{
serialize_operand(element, context); serialize_operand(element, context);
}
else else
{
serialize(element, context); serialize(element, context);
} }
}
template <typename Tuple, typename Separator, typename Context, typename UseBraces, size_t... Is> template <typename Tuple, typename Separator, typename Context, typename UseBraces, size_t... Is>
auto interpret_tuple_impl(const Tuple& t, auto interpret_tuple_impl(const Tuple& t,

View File

@ -130,7 +130,9 @@ namespace sqlpp
context << ')'; context << ')';
} }
else else
{
t.serialize(context); t.serialize(context);
}
return context; return context;
} }

View File

@ -140,7 +140,9 @@ namespace sqlpp
context << ')'; context << ')';
} }
else else
{
t.serialize(context); t.serialize(context);
}
return context; return context;
} }

View File

@ -83,9 +83,13 @@ namespace sqlpp
serialize_operand(t._operand, context); serialize_operand(t._operand, context);
context << " NOT IN("; context << " NOT IN(";
if (sizeof...(Args) == 1) if (sizeof...(Args) == 1)
{
serialize(std::get<0>(t._args), context); serialize(std::get<0>(t._args), context);
}
else else
{
interpret_tuple(t._args, ',', context); interpret_tuple(t._args, ',', context);
}
context << ')'; context << ')';
return context; return context;
} }

View File

@ -258,11 +258,15 @@ namespace sqlpp
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {
if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty()) if (sizeof...(Expressions) == 0 and t._dynamic_expressions.empty())
{
return context; return context;
}
context << " ORDER BY "; context << " ORDER BY ";
interpret_tuple(t._expressions, ',', context); interpret_tuple(t._expressions, ',', context);
if (sizeof...(Expressions) and not t._dynamic_expressions.empty()) if (sizeof...(Expressions) and not t._dynamic_expressions.empty())
{
context << ','; context << ',';
}
interpret_list(t._dynamic_expressions, ',', context); interpret_list(t._dynamic_expressions, ',', context);
return context; return context;
} }

View File

@ -87,14 +87,18 @@ namespace sqlpp
bool is_null() const bool is_null() const
{ {
if (not _is_valid) if (not _is_valid)
{
throw exception("accessing is_null in non-existing row"); throw exception("accessing is_null in non-existing row");
}
return _is_null; return _is_null;
} }
bool _is_trivial() const bool _is_trivial() const
{ {
if (not _is_valid) if (not _is_valid)
{
throw exception("accessing is_null in non-existing row"); throw exception("accessing is_null in non-existing row");
}
return value() == _cpp_storage_type{}; return value() == _cpp_storage_type{};
} }
@ -102,7 +106,9 @@ namespace sqlpp
_cpp_value_type value() const _cpp_value_type value() const
{ {
if (not _is_valid) if (not _is_valid)
{
throw exception("accessing value in non-existing row"); throw exception("accessing value in non-existing row");
}
if (_is_null) if (_is_null)
{ {

View File

@ -436,7 +436,9 @@ namespace sqlpp
{ {
interpret_tuple(t._columns, ',', context); interpret_tuple(t._columns, ',', context);
if (sizeof...(Columns) and not t._dynamic_columns.empty()) if (sizeof...(Columns) and not t._dynamic_columns.empty())
{
context << ','; context << ',';
}
serialize(t._dynamic_columns, context); serialize(t._dynamic_columns, context);
return context; return context;
} }

View File

@ -249,10 +249,14 @@ namespace sqlpp
{ {
interpret_tuple(t._flags, ' ', context); interpret_tuple(t._flags, ' ', context);
if (sizeof...(Flags)) if (sizeof...(Flags))
{
context << ' '; context << ' ';
}
interpret_list(t._dynamic_flags, ',', context); interpret_list(t._dynamic_flags, ',', context);
if (not t._dynamic_flags.empty()) if (not t._dynamic_flags.empty())
{
context << ' '; context << ' ';
}
return context; return context;
} }
}; };

View File

@ -48,7 +48,9 @@ namespace sqlpp
context << ')'; context << ')';
} }
else else
{
serializer_t<Context, T>::_(t, context); serializer_t<Context, T>::_(t, context);
}
return context; return context;
} }

View File

@ -50,14 +50,18 @@ namespace sqlpp
for (const auto c : arg) for (const auto c : arg)
{ {
if (c == '\'') if (c == '\'')
{
retVal.push_back(c); retVal.push_back(c);
}
retVal.push_back(c); retVal.push_back(c);
} }
return retVal; return retVal;
} }
else else
{
return arg; return arg;
} }
}
std::ostream& _os; std::ostream& _os;
}; };

View File

@ -108,10 +108,14 @@ namespace sqlpp
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {
if (requires_braces_t<Table>::value) if (requires_braces_t<Table>::value)
{
context << "("; context << "(";
}
serialize(t._table, context); serialize(t._table, context);
if (requires_braces_t<Table>::value) if (requires_braces_t<Table>::value)
{
context << ")"; context << ")";
}
context << " AS " << name_of<T>::char_ptr(); context << " AS " << name_of<T>::char_ptr();
return context; return context;
} }

View File

@ -296,7 +296,9 @@ namespace sqlpp
context << " SET "; context << " SET ";
interpret_tuple(t._assignments, ",", context); interpret_tuple(t._assignments, ",", context);
if (sizeof...(Assignments) and not t._dynamic_assignments.empty()) if (sizeof...(Assignments) and not t._dynamic_assignments.empty())
{
context << ','; context << ',';
}
interpret_list(t._dynamic_assignments, ',', context); interpret_list(t._dynamic_assignments, ',', context);
return context; return context;
} }

View File

@ -248,11 +248,15 @@ namespace sqlpp
static Context& _(const T& t, Context& context) static Context& _(const T& t, Context& context)
{ {
if (sizeof...(Tables) == 0 and t._dynamic_tables.empty()) if (sizeof...(Tables) == 0 and t._dynamic_tables.empty())
{
return context; return context;
}
context << " USING "; context << " USING ";
interpret_tuple(t._tables, ',', context); interpret_tuple(t._tables, ',', context);
if (sizeof...(Tables) and not t._dynamic_tables.empty()) if (sizeof...(Tables) and not t._dynamic_tables.empty())
{
context << ','; context << ',';
}
interpret_list(t._dynamic_tables, ',', context); interpret_list(t._dynamic_tables, ',', context);
return context; return context;
} }

View File

@ -370,7 +370,9 @@ namespace sqlpp
context << " WHERE "; context << " WHERE ";
serialize(t._expression, context); serialize(t._expression, context);
if (not t._dynamic_expressions.empty()) if (not t._dynamic_expressions.empty())
{
context << " AND "; context << " AND ";
}
interpret_list(t._dynamic_expressions, " AND ", context); interpret_list(t._dynamic_expressions, " AND ", context);
return context; return context;
} }

View File

@ -201,7 +201,9 @@ namespace sqlpp
// FIXME: If there is a recursive CTE, add a "RECURSIVE" here // FIXME: If there is a recursive CTE, add a "RECURSIVE" here
context << " WITH "; context << " WITH ";
if (T::_is_recursive::value) if (T::_is_recursive::value)
{
context << "RECURSIVE "; context << "RECURSIVE ";
}
interpret_tuple(t._expressions, ',', context); interpret_tuple(t._expressions, ',', context);
context << ' '; context << ' ';
return context; return context;