如何在MySQL Connector/C++8.0中使用DATETIME?
我使用的是mysql-connector-cpp-8.0.18 Mysql结果存储是类型为mysqlx::Value的变量 我应该如何使用DATETIME?我在上找到了答案 解决方案是解析原始数据。它使用 解码的简单示例:如何在MySQL Connector/C++8.0中使用DATETIME?,c++,mysql-8.0,C++,Mysql 8.0,我使用的是mysql-connector-cpp-8.0.18 Mysql结果存储是类型为mysqlx::Value的变量 我应该如何使用DATETIME?我在上找到了答案 解决方案是解析原始数据。它使用 解码的简单示例: uint64_t DecodeOne(uint8_t * in , size_t * len) { uint64_t r = 0; do { uint64_t val = * in ; r = (r << 7) | (uint64_t)(
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";
}
mysqlx_get_bytes(row, idx, 0, data, size);
DecodeBuffer(data, size);
std::pair <
const unsigned char * , size_t > res = value.getRawBytes();
DecodeBuffer(res.first, res.second);
但mysql-connector-CPP-8.0.18中的CPP API中存在漏洞
CPP结果不包含秒。因此,只使用c api是可能的
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";
}
mysqlx_get_bytes(row, idx, 0, data, size);
DecodeBuffer(data, size);
std::pair <
const unsigned char * , size_t > res = value.getRawBytes();
DecodeBuffer(res.first, res.second);