@@ -95,9 +95,9 @@ static std::string DescribeTable(TTableClient client, const std::string& path, c
95
95
return result;
96
96
}));
97
97
98
- result += std::format (" > Describe table: {}" , name);
98
+ result += std::format (" > Describe table: {}\n " , name);
99
99
for (auto & column : desc->GetColumns ()) {
100
- result += std::format (" Column, name: {}, type: {}" , column.Name , FormatType (column.Type ));
100
+ result += std::format (" Column, name: {}, type: {}\n " , column.Name , FormatType (column.Type ));
101
101
}
102
102
return result;
103
103
}
@@ -434,20 +434,20 @@ static TStatus ExplicitTclTransaction(TSession session, const std::string& path,
434
434
435
435
// /////////////////////////////////////////////////////////////////////////////
436
436
437
- void SelectSimple (TTableClient client, const std::string& path) {
437
+ std::string SelectSimple (TTableClient client, const std::string& path) {
438
438
std::optional<TResultSet> resultSet;
439
439
ThrowOnError (client.RetryOperationSync ([path, &resultSet](TSession session) {
440
440
return SelectSimpleTransaction (session, path, resultSet);
441
441
}));
442
442
443
443
TResultSetParser parser (*resultSet);
444
444
if (parser.TryNextRow ()) {
445
- std::cout << " > SelectSimple:" << std::endl << " Series"
446
- << " , Id: " << ToString (parser.ColumnParser (" series_id" ).GetOptionalUint64 ())
447
- << " , Title: " << ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
448
- << " , Release date: " << ToString (parser.ColumnParser (" release_date" ).GetOptionalString ())
449
- << std::endl;
445
+ return std::format (" > SelectSimple:\n Series, Id: {}, Title: {}, Release date: {}\n "
446
+ , ToString (parser.ColumnParser (" series_id" ).GetOptionalUint64 ())
447
+ , ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
448
+ , ToString (parser.ColumnParser (" release_date" ).GetOptionalString ()));
450
449
}
450
+ return " " ;
451
451
}
452
452
453
453
void UpsertSimple (TTableClient client, const std::string& path) {
@@ -456,23 +456,25 @@ void UpsertSimple(TTableClient client, const std::string& path) {
456
456
}));
457
457
}
458
458
459
- void SelectWithParams (TTableClient client, const std::string& path) {
459
+ std::string SelectWithParams (TTableClient client, const std::string& path) {
460
460
std::optional<TResultSet> resultSet;
461
+ std::string result;
461
462
ThrowOnError (client.RetryOperationSync ([path, &resultSet](TSession session) {
462
463
return SelectWithParamsTransaction (session, path, 2 , 3 , resultSet);
463
464
}));
464
465
465
466
TResultSetParser parser (*resultSet);
466
467
if (parser.TryNextRow ()) {
467
- std::cout << " > SelectWithParams:" << std::endl << " Season"
468
- << " , Title: " << ToString (parser.ColumnParser (" season_title" ).GetOptionalUtf8 ())
469
- << " , Series title: " << ToString (parser.ColumnParser (" series_title" ).GetOptionalUtf8 ())
470
- << std::endl;
468
+ return std::format (" > SelectWithParams:\n Season, Title: {}, Series title: {}\n "
469
+ , ToString (parser.ColumnParser (" season_title" ).GetOptionalUtf8 ())
470
+ , ToString (parser.ColumnParser (" series_title" ).GetOptionalUtf8 ()));
471
471
}
472
+ return " " ;
472
473
}
473
474
474
- void PreparedSelect (TTableClient client, const std::string& path, ui32 seriesId, ui32 seasonId, ui32 episodeId) {
475
+ std::string PreparedSelect (TTableClient client, const std::string& path, ui32 seriesId, ui32 seasonId, ui32 episodeId) {
475
476
std::optional<TResultSet> resultSet;
477
+ std::string result;
476
478
ThrowOnError (client.RetryOperationSync ([path, seriesId, seasonId, episodeId, &resultSet](TSession session) {
477
479
return PreparedSelectTransaction (session, path, seriesId, seasonId, episodeId, resultSet);
478
480
}));
@@ -481,30 +483,32 @@ void PreparedSelect(TTableClient client, const std::string& path, ui32 seriesId,
481
483
if (parser.TryNextRow ()) {
482
484
auto airDate = TInstant::Days (*parser.ColumnParser (" air_date" ).GetOptionalUint64 ());
483
485
484
- std::cout << " > PreparedSelect:" << std::endl << " Episode " << ToString (parser. ColumnParser ( " episode_id " ). GetOptionalUint64 ())
485
- << " , Title: " << ToString (parser.ColumnParser (" title " ).GetOptionalUtf8 ())
486
- << " , Air date: " << airDate. FormatLocalTime ( " %a %b %d, %Y " )
487
- << std::endl ;
486
+ return std::format ( " > PreparedSelect:\n Episode {}, Title: {}, Air date: {} \n "
487
+ , ToString (parser.ColumnParser (" episode_id " ).GetOptionalUint64 ())
488
+ , ToString (parser. ColumnParser ( " title " ). GetOptionalUtf8 () )
489
+ , airDate. FormatLocalTime ( " %a %b %d, %Y " )) ;
488
490
}
491
+ return " " ;
489
492
}
490
493
491
- void MultiStep (TTableClient client, const std::string& path) {
494
+ std::string MultiStep (TTableClient client, const std::string& path) {
492
495
std::optional<TResultSet> resultSet;
496
+ std::string result;
493
497
ThrowOnError (client.RetryOperationSync ([path, &resultSet](TSession session) {
494
498
return MultiStepTransaction (session, path, 2 , 5 , resultSet);
495
499
}));
496
500
497
501
TResultSetParser parser (*resultSet);
498
- std::cout << " > MultiStep:" << std::endl ;
502
+ result = " > MultiStep:\n " ;
499
503
while (parser.TryNextRow ()) {
500
504
auto airDate = TInstant::Days (*parser.ColumnParser (" air_date" ).GetOptionalUint64 ());
501
-
502
- std::cout << " Episode " << ToString (parser.ColumnParser (" episode_id" ).GetOptionalUint64 ())
503
- << " , Season: " << ToString (parser.ColumnParser (" season_id" ).GetOptionalUint64 ())
504
- << " , Title: " << ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
505
- << " , Air date: " << airDate.FormatLocalTime (" %a %b %d, %Y" )
506
- << std::endl;
505
+ result += std::format (" Episode {}, Season: {}, Title: {}, Air date: {}\n "
506
+ , ToString (parser.ColumnParser (" episode_id" ).GetOptionalUint64 ())
507
+ , ToString (parser.ColumnParser (" season_id" ).GetOptionalUint64 ())
508
+ , ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
509
+ , airDate.FormatLocalTime (" %a %b %d, %Y" ));
507
510
}
511
+ return result;
508
512
}
509
513
510
514
void ExplicitTcl (TTableClient client, const std::string& path) {
@@ -513,7 +517,8 @@ void ExplicitTcl(TTableClient client, const std::string& path) {
513
517
}));
514
518
}
515
519
516
- void ScanQuerySelect (TTableClient client, const std::string& path) {
520
+ std::string ScanQuerySelect (TTableClient client, const std::string& path) {
521
+ std::string result;
517
522
auto query = std::format (R"(
518
523
--!syntax_v1
519
524
PRAGMA TablePathPrefix("{}");
@@ -534,17 +539,18 @@ void ScanQuerySelect(TTableClient client, const std::string& path) {
534
539
.Build ();
535
540
536
541
// Executes scan query
537
- auto result = client.StreamExecuteScanQuery (query, parameters).GetValueSync ();
542
+ auto resultScanQuery = client.StreamExecuteScanQuery (query, parameters).GetValueSync ();
538
543
539
- if (!result .IsSuccess ()) {
540
- std::cerr << " ScanQuery execution failure: " << result .GetIssues ().ToString () << std::endl;
541
- return ;
544
+ if (!resultScanQuery .IsSuccess ()) {
545
+ std::cerr << " ScanQuery execution failure: " << resultScanQuery .GetIssues ().ToString () << std::endl;
546
+ return " " ;
542
547
}
543
548
544
549
bool eos = false ;
545
- std::cout << " > ScanQuerySelect:" << std::endl;
550
+ result = " > ScanQuerySelect:\n " ;
551
+
546
552
while (!eos) {
547
- auto streamPart = result .ReadNext ().ExtractValueSync ();
553
+ auto streamPart = resultScanQuery .ReadNext ().ExtractValueSync ();
548
554
549
555
if (!streamPart.IsSuccess ()) {
550
556
eos = true ;
@@ -560,15 +566,15 @@ void ScanQuerySelect(TTableClient client, const std::string& path) {
560
566
561
567
TResultSetParser parser (rs);
562
568
while (parser.TryNextRow ()) {
563
- std::cout << " Season"
564
- << " , SeriesId: " << ToString (parser.ColumnParser (" series_id" ).GetOptionalUint64 ())
565
- << " , SeasonId: " << ToString (parser.ColumnParser (" season_id" ).GetOptionalUint64 ())
566
- << " , Title: " << ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
567
- << " , Air date: " << ToString (parser.ColumnParser (" first_aired" ).GetOptionalString ())
568
- << std::endl;
569
+ result += std::format (" Season, SeriesId: {}, SeasonId: {}, Title: {}, Air date: {}\n "
570
+ , ToString (parser.ColumnParser (" series_id" ).GetOptionalUint64 ())
571
+ , ToString (parser.ColumnParser (" season_id" ).GetOptionalUint64 ())
572
+ , ToString (parser.ColumnParser (" title" ).GetOptionalUtf8 ())
573
+ , ToString (parser.ColumnParser (" first_aired" ).GetOptionalString ()));
569
574
}
570
575
}
571
576
}
577
+ return result;
572
578
}
573
579
574
580
// /////////////////////////////////////////////////////////////////////////////
@@ -585,21 +591,21 @@ std::unique_ptr<Response> Run(const TDriver& driver, const std::string& path) {
585
591
return FillTableDataTransaction (session, path);
586
592
}));
587
593
588
- SelectSimple (client, path);
594
+ response-> result += SelectSimple (client, path);
589
595
UpsertSimple (client, path);
590
596
591
- SelectWithParams (client, path);
597
+ response-> result += SelectWithParams (client, path);
592
598
593
- PreparedSelect (client, path, 2 , 3 , 7 );
594
- PreparedSelect (client, path, 2 , 3 , 8 );
599
+ response-> result += PreparedSelect (client, path, 2 , 3 , 7 );
600
+ response-> result += PreparedSelect (client, path, 2 , 3 , 8 );
595
601
596
- MultiStep (client, path);
602
+ response-> result += MultiStep (client, path);
597
603
598
604
ExplicitTcl (client, path);
599
605
600
- PreparedSelect (client, path, 2 , 6 , 1 );
606
+ response-> result += PreparedSelect (client, path, 2 , 6 , 1 );
601
607
602
- ScanQuerySelect (client, path);
608
+ response-> result += ScanQuerySelect (client, path);
603
609
}
604
610
catch (const TYdbErrorException& e) {
605
611
response->success = false ;
0 commit comments