MySQL Forums
Forum List  »  Connector/C++

Re: Mysql connector c++ 8.0. How to work with datetime?
Posted by: egor s
Date: January 27, 2020 09:46AM

Hi Rafal,

Thanks for your reply.
I wrote two implementations using the CPP API and the Plain C API. And discovered a strange behavior.

Query:

"SELECT id, CAST(date_update as char) as date_update_string, date_update FROM table_name LIMIT 1"

Simple implementation for decoding raw bytes:


uint64_t DecodeOne(uint8_t *in, size_t * len)
{
uint64_t r = 0;

do {
uint64_t val = *in;
r = (r << 7) | (uint64_t)(val & 127);
in++;
(*len)--;
} while ((*len > 0) && (uint64_t(*in) & 128));

return r;
}
void DecodeBuffer(uint8_t * buffer, size_t size)
{
std::vector<uint8_t> reverseBuffer;
for (size_t i = 1; i <= size; i++) {
reverseBuffer.push_back(buffer[size - i]);
}

size_t tmpSize = size;
uint8_t * reverseData = reverseBuffer.data();
while (tmpSize > 0) {
std::cout << DecodeOne(&reverseData[size - tmpSize], &tmpSize) << " ";
}
std::cout << "\n";
}


Reading the "date_update_string" field in both implementations has the same result: "2010-09-17 11:38:26" - Its OK.


Reading "date_update" field using Plain C api:

mysqlx_get_bytes (row, idx, 0, data, size);
DecodeBuffer(data, size);

size == 7 and output is "26 38 11 17 9 2010"


Reading "date_update" field using CPP api:

std::pair<const unsigned char*, size_t> res = value.getRawBytes();
auto * data = res.first;
auto * size = res.second;
DecodeBuffer(data, size);

size == 6 and output is "38 11 17 9 2010"


Why does size differ and where are the seconds in the CPP example?

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.