Skip to content

Commit 39a7662

Browse files
committed
bug#26715673 (METHODS REPLACEONE() AND ADDORREPLACEONE() HAVE WRONG RETURN TYPE)
1 parent 9c2d2a9 commit 39a7662

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

devapi/tests/crud-t.cc

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,6 +2292,12 @@ TEST_F(Crud, single_document)
22922292
{
22932293
SKIP_IF_NO_XPLUGIN;
22942294

2295+
/*
2296+
Note: requires x-protocol support for 'upsert' flag and WL#10682
2297+
(Mysqlx.CRUD.Update on top level document). The later is not implemented
2298+
in 5.7 plugin.
2299+
*/
2300+
22952301
SKIP_IF_SERVER_VERSION_LESS(8, 0, 3);
22962302

22972303
cout << "Creating session..." << endl;
@@ -2318,22 +2324,26 @@ TEST_F(Crud, single_document)
23182324
EXPECT_TRUE(coll.getOne("id1").isNull());
23192325

23202326
// Replace existing document
2321-
EXPECT_TRUE(coll.replaceOne("id3", expr("{\"name\": \"qux\" }")));
2327+
EXPECT_EQ(1, coll.replaceOne("id3", expr("{\"name\": \"qux\" }"))
2328+
.getAffectedItemsCount());
23222329
EXPECT_EQ(string("qux"), coll.getOne("id3")["name"].get<string>());
23232330

23242331
// Ignore _id field on document and replace existing docment
23252332
// Document passed as string
2326-
EXPECT_TRUE(coll.replaceOne("id3", "{\"_id\": \"id4\", \"name\": \"baz\" }"));
2333+
EXPECT_EQ(1, coll.replaceOne("id3", "{\"_id\": \"id4\", \"name\": \"baz\" }")
2334+
.getAffectedItemsCount());
23272335
EXPECT_EQ(string("baz"), coll.getOne("id3")["name"].get<string>());
23282336
EXPECT_EQ(string("id3"), coll.getOne("id3")["_id"].get<string>());
23292337

23302338
// should not affect none
2331-
EXPECT_FALSE(coll.replaceOne("id4", expr("{\"_id\":\"id4\", \"name\": \"baz\" }")));
2339+
EXPECT_EQ(0,
2340+
coll.replaceOne("id4", expr("{\"_id\":\"id4\", \"name\": \"baz\" }"))
2341+
.getAffectedItemsCount());
23322342

23332343
// Using DbDoc
23342344
DbDoc doc("{\"_id\":\"id4\", \"name\": \"quux\" }");
23352345

2336-
EXPECT_TRUE(coll.replaceOne("id3", doc));
2346+
EXPECT_EQ(1, coll.replaceOne("id3", doc).getAffectedItemsCount());
23372347
EXPECT_EQ(string("quux"), coll.getOne("id3")["name"].get<string>());
23382348
}
23392349

@@ -2356,11 +2366,13 @@ TEST_F(Crud, add_or_replace)
23562366
.add("{\"_id\":\"id3\", \"name\":\"baz\" }")
23572367
.execute();
23582368

2359-
EXPECT_TRUE(coll.addOrReplace("id4", "{\"name\":\"zaz\"}"));
2369+
EXPECT_EQ(1, coll.addOrReplaceOne("id4", "{\"name\":\"zaz\"}")
2370+
.getAffectedItemsCount());
23602371
// Check that the document was added
23612372
EXPECT_EQ(string("zaz"), coll.getOne("id4")["name"].get<string>());
23622373

2363-
EXPECT_FALSE(coll.addOrReplace("id4", "{\"name\":\"zzz\"}"));
2374+
EXPECT_EQ(0, coll.addOrReplaceOne("id4", "{\"name\":\"zzz\"}")
2375+
.getAffectedItemsCount());
23642376
// Check that the document was replaced
23652377
EXPECT_EQ(string("zzz"), coll.getOne("id4")["name"].get<string>());
23662378

include/mysql_devapi.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -454,14 +454,14 @@ class PUBLIC_API Collection
454454
because the statement gets executed upon calling of this function.
455455
*/
456456

457-
bool replaceOne(string id, internal::ExprValue &&document)
457+
Result replaceOne(string id, internal::ExprValue &&document)
458458
{
459-
return
460-
internal::CollectionReplace(*this, id, std::move(document)).execute().getAffectedItemsCount() == 1;
459+
return
460+
internal::CollectionReplace(*this, id, std::move(document)).execute();
461461
}
462462

463463
/**
464-
Adds a new document identified by id if it does not exist and
464+
Adds a new document identified by id if it does not exist and
465465
returns true. Otherwise replaces the existing document
466466
with that id and returns false.
467467
Parameter document can be either DbDoc object,
@@ -471,9 +471,11 @@ class PUBLIC_API Collection
471471
because the statement is executed upon calling of this function.
472472
*/
473473

474-
bool addOrReplace(string id, internal::ExprValue &&document)
474+
Result addOrReplaceOne(string id, internal::ExprValue &&document)
475475
{
476-
return internal::CollectionReplace(*this, id, std::move(document), true).execute().getAffectedItemsCount() == 1;
476+
return
477+
internal::CollectionReplace(*this, id, std::move(document), true)
478+
.execute();
477479
}
478480

479481
};

0 commit comments

Comments
 (0)