Skip to content

Commit

Permalink
Fix compile (#244)
Browse files Browse the repository at this point in the history
* fix compile

* change proto tag

* fix fecherstore
  • Loading branch information
lgqss committed Jun 5, 2024
1 parent a66c2e9 commit 18b9a12
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
4 changes: 1 addition & 3 deletions include/common/type_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,7 @@ inline std::string to_mysql_type_full_string(pb::PrimitiveType type,
case pb::STRING:
return "varchar(1024)";
case pb::DATETIME:
if (float_precision_len == -1) {
return "datetime(6)";
} else if (float_precision_len > 0 && float_precision_len <= 6) {
if (float_precision_len > 0 && float_precision_len <= 6) {
return "datetime(" + std::to_string(float_precision_len) + ")";
}
return "datetime";
Expand Down
2 changes: 1 addition & 1 deletion src/common/datetime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::string datetime_to_str(uint64_t datetime, int precision_len) {
year, month, day, hour, minute, second, macrosec);
if (precision_len > 0 and precision_len <=6) {
buf[20 + precision_len] = '\0';
} else if (precision_len == 0) {
} else if (precision_len == 0 || macrosec == 0/*兼容以前*/) {
buf[19] = '\0';
} else {
buf[26] = '\0';
Expand Down
4 changes: 3 additions & 1 deletion src/exec/fetcher_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,9 @@ void OnRPCDone::select_addr() {
FetcherStore::choose_opt_instance(_info.region_id(), _info.peers(), _addr, addr_status, nullptr);
}
_request.set_select_without_leader(true);
} else if (_op_type == pb::OP_SELECT && _state->txn_id == 0 && _client_conn->query_ctx->peer_index != -1) {
} else if (_op_type == pb::OP_SELECT && _state->txn_id == 0
&& _client_conn != nullptr
&& _client_conn->query_ctx->peer_index != -1) {
int64_t peer_index = _client_conn->query_ctx->peer_index;
std::vector<std::string> sorted_peers; // leader first
sorted_peers.emplace_back(_info.leader());
Expand Down
12 changes: 6 additions & 6 deletions test/test_date_time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ TEST(test_datetime_str, case_all) {
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:")), "2017-12-03 19:00:00");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19")), "2017-12-03 19:00:00");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000")), "2017-12-03 19:28:44");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.1234567")), "2017-12-03 19:28:44.123456");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.123")), "2017-12-03 19:28:44.123000");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.1234567"), -1), "2017-12-03 19:28:44.123456");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.123"), -1), "2017-12-03 19:28:44.123000");

EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000123")), "2017-12-03 19:28:44.000123");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000123456")), "2017-12-03 19:28:44.000123");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000123"), -1), "2017-12-03 19:28:44.000123");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:28:44.000123456"), -1), "2017-12-03 19:28:44.000123");

EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 192:28:44")), "2017-12-03 19:00:00");
EXPECT_EQ(datetime_to_str(str_to_datetime("2017-12-03 19:284:44")), "2017-12-03 19:28:00");
Expand All @@ -100,8 +100,8 @@ TEST(test_datetime_str_other, case_all) {
EXPECT_EQ(datetime_to_str(str_to_datetime("89-12-03 19:28:44")), "1989-12-03 19:28:44");
EXPECT_EQ(datetime_to_str(str_to_datetime("891203")), "1989-12-03 00:00:00");
EXPECT_EQ(datetime_to_str(str_to_datetime("19891203")), "1989-12-03 00:00:00");
EXPECT_EQ(datetime_to_str(str_to_datetime("891203192844.111")), "1989-12-03 19:28:44.111000");
EXPECT_EQ(datetime_to_str(str_to_datetime("19891203192844.111")), "1989-12-03 19:28:44.111000");
EXPECT_EQ(datetime_to_str(str_to_datetime("891203192844.111"), -1), "1989-12-03 19:28:44.111000");
EXPECT_EQ(datetime_to_str(str_to_datetime("19891203192844.111"), -1), "1989-12-03 19:28:44.111000");
std::cout << "tm:" << str_to_datetime("20111303") << std::endl;
std::cout << "tm2:" << str_to_datetime("0000-00-00 00:00:00") << std::endl;
std::cout << "tm3:" << datetime_to_timestamp(0) << std::endl;
Expand Down

0 comments on commit 18b9a12

Please sign in to comment.