Skip to content

Commit 25d21eb

Browse files
committed
Codegen. DbClient. Introduce PARAMS_DTO macro.
1 parent 460bfc4 commit 25d21eb

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

src/oatpp-postgresql/mapping/Serializer.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ void Serializer::serInt8(OutputData& outData, v_int64 value) {
130130
// Serializer functions
131131

132132
void Serializer::serializeString(OutputData& outData, const oatpp::Void& polymorph) {
133-
base::StrBuffer* buff = static_cast<base::StrBuffer*>(polymorph.get());
134-
outData.data = buff->c_str();
135-
outData.dataSize = buff->getSize();
136-
outData.dataFormat = 1;
133+
if(polymorph) {
134+
base::StrBuffer *buff = static_cast<base::StrBuffer *>(polymorph.get());
135+
outData.data = buff->c_str();
136+
outData.dataSize = buff->getSize();
137+
outData.dataFormat = 1;
138+
} else {
139+
serNull(outData);
140+
}
137141
}
138142

139143
void Serializer::serializeInt8(OutputData& outData, const oatpp::Void& polymorph) {

src/oatpp-postgresql/ql_template/Parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ data::share::StringTemplate::Variable Parser::parseIdentifier(parser::Caret& car
3535
auto label = caret.putLabel();
3636
while(caret.canContinue()) {
3737
v_char8 a = *caret.getCurrData();
38-
bool isAllowedChar = (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z') || (a >= '0' && a <= '9') || (a == '_');
38+
bool isAllowedChar = (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z') || (a >= '0' && a <= '9') || (a == '_') || (a == '.');
3939
if(!isAllowedChar) {
4040
result.posEnd = caret.getPosition() - 1;
4141
result.name = label.toString();

test/oatpp-postgresql/tests.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Ints : public oatpp::DTO {
3737

3838
#include OATPP_CODEGEN_END(DTO)
3939

40+
#include OATPP_CODEGEN_BEGIN(DTO)
4041
#include OATPP_CODEGEN_BEGIN(DbClient)
4142

4243
class MyClient : public oatpp::orm::DbClient {
@@ -62,10 +63,27 @@ class MyClient : public oatpp::orm::DbClient {
6263
QUERY(insertStrs,
6364
"INSERT INTO test_strs "
6465
"(f_str1, f_str2, f_str3) VALUES "
65-
"(:f_str1, :f_str2, :f_str3);",
66-
PARAM(oatpp::String, f_str1),
67-
PARAM(oatpp::String, f_str2),
68-
PARAM(oatpp::String, f_str3))
66+
"(:f_str1.param, :f_str2.param, :f_str3.param);",
67+
PARAM(oatpp::String, f_str1, "f_str1.param"),
68+
PARAM(oatpp::String, f_str2, "f_str2.param"),
69+
PARAM(oatpp::String, f_str3, "f_str3.param"))
70+
71+
72+
class InsertStrsDto : public oatpp::DTO {
73+
74+
DTO_INIT(InsertStrsDto, DTO)
75+
76+
DTO_FIELD(oatpp::String, f_str1);
77+
DTO_FIELD(oatpp::String, f_str2);
78+
DTO_FIELD(oatpp::String, f_str3);
79+
80+
};
81+
82+
QUERY(insertStrsWithDtoParams,
83+
"INSERT INTO test_strs "
84+
"(f_str1, f_str2, f_str3) VALUES "
85+
"(:dto.f_str1, :dto.f_str2, :dto.f_str3);",
86+
PARAMS_DTO(oatpp::Object<InsertStrsDto>, rowDto, "dto"))
6987

7088
QUERY(selectStrs, "SELECT * FROM test_strs")
7189

@@ -91,6 +109,7 @@ class MyClient : public oatpp::orm::DbClient {
91109
};
92110

93111
#include OATPP_CODEGEN_END(DbClient)
112+
#include OATPP_CODEGEN_END(DTO)
94113

95114
class Test : public oatpp::test::UnitTest {
96115
public:
@@ -119,10 +138,18 @@ class Test : public oatpp::test::UnitTest {
119138
//client.insertFloats(0.32, 0.64, connection);
120139
//client.insertFloats(-0.32, -0.64, connection);
121140

122-
// client.insertStrs("Hello", "World", "Oat++");
141+
// client.insertStrs("Hello", "Dot", "Param");
123142
// client.insertStrs("Hello", "World", "oatpp");
124143
// client.insertStrs("Yeah", "Ops", "!!!");
125144

145+
{
146+
auto row = MyClient::InsertStrsDto::createShared();
147+
row->f_str1 = "A";
148+
row->f_str2 = "B";
149+
row->f_str3 = "C";
150+
client.insertStrsWithDtoParams(row);
151+
}
152+
126153
{
127154

128155
auto res = client.selectStrs();

0 commit comments

Comments
 (0)