Skip to content

Commit 2ca7faf

Browse files
committed
Bug#30838230: DATETIME types doens't have trailing 0x00. Copy all buffer.
1 parent b3ea26e commit 2ca7faf

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

common/result.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,14 @@ convert(cdk::bytes data, Format_descr<cdk::TYPE_DOCUMENT>&)
155155
}
156156

157157

158+
Value
159+
mysqlx::impl::common::
160+
convert(cdk::foundation::bytes data, Format_descr<cdk::TYPE_DATETIME> &)
161+
{
162+
return{ data.begin(), data.size()};
163+
}
164+
165+
158166

159167
/*
160168
Result implementation

common/result.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ Value convert(cdk::bytes, Format_descr<cdk::TYPE_STRING>&);
693693
Value convert(cdk::bytes, Format_descr<cdk::TYPE_INTEGER>&);
694694
Value convert(cdk::bytes, Format_descr<cdk::TYPE_FLOAT>&);
695695
Value convert(cdk::bytes, Format_descr<cdk::TYPE_DOCUMENT>&);
696+
Value convert(cdk::bytes, Format_descr<cdk::TYPE_DATETIME>&);
696697

697698
/*
698699
Generic template used when no type-specific specialization is defined.

devapi/tests/types-t.cc

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,8 @@ TEST_F(Types, datetime)
777777
" c0 DATE,"
778778
" c1 TIME,"
779779
" c2 DATETIME,"
780-
" c3 TIMESTAMP"
780+
" c3 TIMESTAMP,"
781+
" c4 DATETIME"
781782
")"
782783
);
783784

@@ -789,6 +790,7 @@ TEST_F(Types, datetime)
789790
data[1] = "10:40:23.456";
790791
data[2] = "2014-05-11 10:40";
791792
data[3] = "2014-05-11 11:35:00.000";
793+
data[4] = Value();
792794

793795
types.insert().values(data).execute();
794796

@@ -812,6 +814,10 @@ TEST_F(Types, datetime)
812814
cout << "column #3 type: " << c3.getType() << endl;
813815
EXPECT_EQ(Type::TIMESTAMP, c3.getType());
814816

817+
const Column &c4 = res.getColumn(4);
818+
cout << "column #4 type: " << c4.getType() << endl;
819+
EXPECT_EQ(Type::DATETIME, c4.getType());
820+
815821

816822
Row row = res.fetchOne();
817823

@@ -822,7 +828,25 @@ TEST_F(Types, datetime)
822828
for (unsigned j = 0; j < res.getColumnCount(); ++j)
823829
{
824830
cout << "- col#" << j << ": " << row[j] << endl;
831+
if(j==4)
832+
{
833+
EXPECT_TRUE(row[j].isNull());
834+
break;
835+
}
825836
EXPECT_EQ(Value::RAW, row[j].getType());
837+
switch(res.getColumn(j).getType())
838+
{
839+
case Type::DATE:
840+
case Type::TIME:
841+
EXPECT_EQ(4, row[j].getRawBytes().size());
842+
break;
843+
case Type::DATETIME:
844+
case Type::TIMESTAMP:
845+
EXPECT_EQ(6, row[j].getRawBytes().size());
846+
break;
847+
default:
848+
FAIL() << "Unexpected type! Update UT";
849+
}
826850
}
827851
}
828852

0 commit comments

Comments
 (0)