Skip to content

Commit 1c4f1f6

Browse files
committed
Allow TRIM to be used with sub selects
1 parent 3fba3e7 commit 1c4f1f6

File tree

5 files changed

+49
-3
lines changed

5 files changed

+49
-3
lines changed

include/sqlpp11/trim.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ namespace sqlpp
8383
Context& serialize(const trim_t<Flag, Expr>& t, Context& context)
8484
{
8585
context << "TRIM(";
86-
serialize(t._expr, context);
86+
serialize_operand(t._expr, context);
8787
context << ")";
8888
return context;
8989
}

tests/core/serialize/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ set(test_files
4040
Over.cpp
4141
Sum.cpp
4242
TableAlias.cpp
43+
Trim.cpp
4344
Upper.cpp
4445
Where.cpp
4546
ParameterizedVerbatim.cpp

tests/core/serialize/Lower.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2023, Roland Bock
2+
* Copyright (c) 2023, Roland Bock
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without modification,

tests/core/serialize/Trim.cpp

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright (c) 2023, Roland Bock
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without modification,
6+
* are permitted provided that the following conditions are met:
7+
*
8+
* * Redistributions of source code must retain the above copyright notice,
9+
* this list of conditions and the following disclaimer.
10+
* * Redistributions in binary form must reproduce the above copyright notice,
11+
* this list of conditions and the following disclaimer in the documentation
12+
* and/or other materials provided with the distribution.
13+
*
14+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16+
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17+
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
22+
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
23+
* OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#include "Sample.h"
27+
#include "compare.h"
28+
#include <sqlpp11/sqlpp11.h>
29+
30+
int Trim(int, char* [])
31+
{
32+
const auto bar = test::TabBar{};
33+
34+
// Single column.
35+
compare(__LINE__, trim(bar.beta), "TRIM(tab_bar.beta)");
36+
37+
// Expression.
38+
// Note that the inner parens aren't necessary.
39+
compare(__LINE__, trim(bar.beta + "suffix"), "TRIM((tab_bar.beta||'suffix'))");
40+
41+
// With sub select.
42+
compare(__LINE__, trim(select(sqlpp::value("something").as(sqlpp::alias::a))), "TRIM((SELECT 'something' AS a))");
43+
44+
return 0;
45+
}

tests/core/serialize/Upper.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023-2023, Roland Bock
2+
* Copyright (c) 2023, Roland Bock
33
* All rights reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without modification,

0 commit comments

Comments
 (0)