Skip to content

Commit 2d764a8

Browse files
silvakidrsomla1
authored andcommitted
MYCPP-273: Allow nuppptr initialization of Value class + disambiguate Value ctors.
1 parent 2fdd928 commit 2d764a8

File tree

2 files changed

+70
-2
lines changed

2 files changed

+70
-2
lines changed

devapi/tests/types-t.cc

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ TEST_F(Types, numeric)
184184
EXPECT_NO_THROW(v4 = val);
185185
EXPECT_TRUE(v4);
186186
}
187+
188+
{
189+
Value val(nullptr);
190+
191+
EXPECT_TRUE(val.isNull());
192+
193+
val = mysqlx::nullvalue;
194+
195+
EXPECT_TRUE(val.isNull());
196+
197+
val = 0;
198+
199+
EXPECT_FALSE(val.isNull());
200+
}
187201
}
188202

189203

@@ -296,12 +310,52 @@ TEST_F(Types, basic)
296310
cout << "value: " << row[0] << endl;
297311
EXPECT_FALSE(row[0]);
298312

313+
cout << "Testing null value" << endl;
314+
315+
types.update().set("c0", nullvalue).set("c1", nullptr).execute();
316+
res = types.select("c0","c1").execute();
317+
row = res.fetchOne();
318+
319+
EXPECT_TRUE(row);
320+
EXPECT_TRUE(row[0].isNull());
321+
EXPECT_TRUE(row[1].isNull());
322+
299323
cout << "Done!" << endl;
300324
}
301325

302326

303327
TEST_F(Types, integer)
304328
{
329+
// Note: this part of the test does not require a running server
330+
331+
{
332+
Value v1(-7);
333+
EXPECT_EQ(Value::INT64, v1.getType());
334+
EXPECT_EQ(-7, (int64_t)v1);
335+
336+
Value v2(-7L);
337+
EXPECT_EQ(Value::INT64, v1.getType());
338+
EXPECT_EQ(-7, (int64_t)v1);
339+
340+
Value v3(-7LL);
341+
EXPECT_EQ(Value::INT64, v1.getType());
342+
EXPECT_EQ(-7, (int64_t)v1);
343+
}
344+
345+
{
346+
Value v1(7U);
347+
EXPECT_EQ(Value::UINT64, v1.getType());
348+
EXPECT_EQ(7, (uint64_t)v1);
349+
350+
Value v2(7UL);
351+
EXPECT_EQ(Value::UINT64, v1.getType());
352+
EXPECT_EQ(7, (uint64_t)v1);
353+
354+
Value v3(7ULL);
355+
EXPECT_EQ(Value::UINT64, v1.getType());
356+
EXPECT_EQ(7, (uint64_t)v1);
357+
}
358+
305359
SKIP_IF_NO_XPLUGIN;
306360

307361
cout << "Preparing test.int_types..." << endl;
@@ -729,6 +783,7 @@ TEST_F(Types, geometry)
729783
}
730784
}
731785

786+
732787
TEST_F(Types, int64_conversion)
733788
{
734789
SKIP_IF_NO_XPLUGIN;

include/devapi/document.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ class PUBLIC_API Value : public internal::Printable
272272
///@{
273273

274274
Value(); ///< Constructs Null value.
275+
Value(std::nullptr_t); ///< Constructs Null value.
275276
Value(const string&);
276277
Value(string&&);
277278
Value(const char *str) : Value(string(str)) {}
@@ -282,9 +283,17 @@ class PUBLIC_API Value : public internal::Printable
282283
Value(float);
283284
Value(double);
284285
Value(bool);
286+
Value(const DbDoc& doc);
287+
288+
/*
289+
Note: These overloads are needed to disambiguate constructor
290+
resolution.
291+
*/
292+
285293
Value(int x) : Value((int64_t)x) {}
286294
Value(unsigned x) : Value((uint64_t)x) {}
287-
Value(const DbDoc& doc);
295+
Value(long x) : Value((int64_t)x) {}
296+
Value(unsigned long x) : Value((uint64_t)x) {}
288297

289298
Value(const std::initializer_list<Value> &list)
290299
: m_type(ARRAY)
@@ -449,6 +458,8 @@ class PUBLIC_API Value : public internal::Printable
449458
friend Access;
450459
};
451460

461+
static const Value nullvalue;
462+
452463

453464
namespace internal {
454465

@@ -538,6 +549,9 @@ const Value& DbDoc::operator[](const wchar_t *name) const
538549
inline Value::Value() : m_type(VNULL)
539550
{}
540551

552+
inline Value::Value(std::nullptr_t) : m_type(VNULL)
553+
{}
554+
541555
inline Value::Value(int64_t val) : m_type(INT64)
542556
{
543557
m_val._int64_v = val;
@@ -548,7 +562,6 @@ inline Value::Value(uint64_t val) : m_type(UINT64)
548562
m_val._uint64_v = val;
549563
}
550564

551-
552565
inline Value::operator int() const
553566
{
554567
int64_t val = (int64_t)*this;

0 commit comments

Comments
 (0)