Skip to content

Commit c09ba03

Browse files
json for SelectSimple
1 parent 99dde83 commit c09ba03

File tree

4 files changed

+16
-26
lines changed

4 files changed

+16
-26
lines changed

tests/integration/basic_example_it/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ add_ydb_test(NAME basic-example_it
99
library-getopt
1010
YDB-CPP-SDK::Table
1111
GTest::gtest_main
12+
public-lib-json_value
1213
LABELS
1314
integration
1415
)

tests/integration/basic_example_it/basic_example.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -440,10 +440,11 @@ std::string SelectSimple(TTableClient client, const std::string& path) {
440440
}));
441441
TResultSetParser parser(*resultSet);
442442
if (parser.TryNextRow()) {
443-
return std::format("> SelectSimple:\nSeries, Id: {}, Title: {}, Release date: {}\n"
443+
std::cout << std::format("> SelectSimple:\nSeries, Id: {}, Title: {}, Release date: {}\n"
444444
, ToString(parser.ColumnParser("series_id").GetOptionalUint64())
445445
, ToString(parser.ColumnParser("title").GetOptionalUtf8())
446446
, ToString(parser.ColumnParser("release_date").GetOptionalString()));
447+
return FormatResultSetJson(resultSet.value(), EBinaryStringEncoding::Unicode);
447448
}
448449
return "";
449450
}
@@ -577,9 +578,8 @@ std::string ScanQuerySelect(TTableClient client, const std::string& path) {
577578

578579
///////////////////////////////////////////////////////////////////////////////
579580

580-
std::unique_ptr<Response> Run(const TDriver& driver, const std::string& path) {
581+
bool Run(const TDriver& driver, const std::string& path) {
581582
TTableClient client(driver);
582-
auto response = std::make_unique<Response>();
583583
try {
584584
CreateTables(client, path);
585585

@@ -589,28 +589,27 @@ std::unique_ptr<Response> Run(const TDriver& driver, const std::string& path) {
589589
return FillTableDataTransaction(session, path);
590590
}));
591591

592-
response->result += SelectSimple(client, path);
592+
std::string expectedResultSelectSimple = "{\"series_id\":1,\"title\":\"IT Crowd\",\"release_date\":\"2006-02-03\"}";
593+
std::string resultSelectSimple = SelectSimple(client, path);
593594
UpsertSimple(client, path);
594595

595-
response->result += SelectWithParams(client, path);
596+
SelectWithParams(client, path);
596597

597-
response->result += PreparedSelect(client, path, 2, 3, 7);
598-
response->result += PreparedSelect(client, path, 2, 3, 8);
598+
PreparedSelect(client, path, 2, 3, 7);
599+
PreparedSelect(client, path, 2, 3, 8);
599600

600-
response->result += MultiStep(client, path);
601+
MultiStep(client, path);
601602

602603
ExplicitTcl(client, path);
603604

604-
response->result += PreparedSelect(client, path, 2, 6, 1);
605+
PreparedSelect(client, path, 2, 6, 1);
605606

606-
response->result += ScanQuerySelect(client, path);
607+
ScanQuerySelect(client, path);
607608
}
608609
catch (const TYdbErrorException& e) {
609-
response->success = false;
610610
std::cerr << "Execution failed due to fatal error:" << std::endl;
611611
PrintStatus(e.Status);
612-
return response;
612+
return false;
613613
}
614-
response->success = true;
615-
return response;
614+
return true;
616615
}

tests/integration/basic_example_it/basic_example.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
#include <ydb-cpp-sdk/client/driver/driver.h>
44
#include <ydb-cpp-sdk/client/table/table.h>
55

6-
struct Response {
7-
bool success;
8-
std::string result;
9-
};
10-
116
NYdb::TParams GetTablesDataParams();
127

13-
std::unique_ptr<Response> Run(const NYdb::TDriver& driver, const std::string& path);
8+
bool Run(const NYdb::TDriver& driver, const std::string& path);

tests/integration/basic_example_it/main.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,11 @@ TEST(Integration, BasicExample) {
3939
}
4040

4141
TDriver driver(driverConfig);
42-
std::unique_ptr<Response> response = ::Run(driver, path);
4342

44-
if (!response->success) {
45-
std::cerr << std::format("The driver could not be started (path = {})", path) << std::endl;
43+
if (!::Run(driver, path)) {
4644
FAIL();
4745
driver.Stop(true);
4846
}
4947

50-
std::string correct_output = "> Describe table: series\nColumn, name: series_id, type: Uint64?\nColumn, name: title, type: Utf8?\nColumn, name: series_info, type: Utf8?\nColumn, name: release_date, type: Uint64?\n> SelectSimple:\nSeries, Id: 1, Title: IT Crowd, Release date: 2006-02-03\n> SelectWithParams:\nSeason, Title: Season 3, Series title: Silicon Valley\n> PreparedSelect:\nEpisode 7, Title: To Build a Better Beta, Air date: Sun Jun 05, 2016\n> PreparedSelect:\nEpisode 8, Title: Bachman's Earnings Over-Ride, Air date: Sun Jun 12, 2016\n> MultiStep:\nEpisode 1, Season: 5, Title: Grow Fast or Die Slow, Air date: Sun Mar 25, 2018\nEpisode 2, Season: 5, Title: Reorientation, Air date: Sun Apr 01, 2018\nEpisode 3, Season: 5, Title: Chief Operating Officer, Air date: Sun Apr 08, 2018\n> PreparedSelect:\nEpisode 1, Title: TBD, Air date: Thu Jan 01, 1970\n> ScanQuerySelect:\nSeason, SeriesId: 1, SeasonId: 1, Title: Season 1, Air date: 2006-02-03\nSeason, SeriesId: 1, SeasonId: 2, Title: Season 2, Air date: 2007-08-24\nSeason, SeriesId: 1, SeasonId: 3, Title: Season 3, Air date: 2008-11-21\nSeason, SeriesId: 1, SeasonId: 4, Title: Season 4, Air date: 2010-06-25\n";
51-
ASSERT_EQ(response->result, correct_output);
52-
5348
driver.Stop(true);
5449
}

0 commit comments

Comments
 (0)