Fix some bugs when creating models via drogon_ctl (#660)
This commit is contained in:
parent
61bb2cf130
commit
1cb8b17709
|
@ -140,9 +140,7 @@ void create_model::createModelClassFromPG(
|
|||
info.colType_ = "int32_t";
|
||||
info.colLength_ = 4;
|
||||
}
|
||||
else if (type == "bigint" ||
|
||||
type == "numeric") /// TODO:Use int64 to represent
|
||||
/// numeric type?
|
||||
else if (type == "bigint")
|
||||
{
|
||||
info.colType_ = "int64_t";
|
||||
info.colLength_ = 8;
|
||||
|
@ -181,6 +179,10 @@ void create_model::createModelClassFromPG(
|
|||
{
|
||||
info.colType_ = "std::vector<char>";
|
||||
}
|
||||
else if (type.find("numeric") != std::string::npos)
|
||||
{
|
||||
info.colType_ = "std::string";
|
||||
}
|
||||
else
|
||||
{
|
||||
info.colType_ = "std::string";
|
||||
|
@ -446,7 +448,8 @@ void create_model::createModelClassFromMysql(
|
|||
{
|
||||
info.colType_ = "std::string";
|
||||
}
|
||||
if (type.find("unsigned") != std::string::npos)
|
||||
if (type.find("unsigned") != std::string::npos &&
|
||||
info.colType_ != "std::string")
|
||||
{
|
||||
info.colType_ = "u" + info.colType_;
|
||||
}
|
||||
|
@ -466,12 +469,13 @@ void create_model::createModelClassFromMysql(
|
|||
std::cerr << e.base().what() << std::endl;
|
||||
exit(1);
|
||||
};
|
||||
std::vector<std::string> pkNames, pkTypes;
|
||||
std::vector<std::string> pkNames, pkTypes, pkValNames;
|
||||
for (auto const &col : cols)
|
||||
{
|
||||
if (col.isPrimaryKey_)
|
||||
{
|
||||
pkNames.push_back(col.colName_);
|
||||
pkValNames.push_back(nameTransform(col.colName_, false));
|
||||
pkTypes.push_back(col.colType_);
|
||||
}
|
||||
}
|
||||
|
@ -485,6 +489,7 @@ void create_model::createModelClassFromMysql(
|
|||
{
|
||||
data["primaryKeyName"] = pkNames;
|
||||
data["primaryKeyType"] = pkTypes;
|
||||
data["primaryKeyValNames"] = pkValNames;
|
||||
}
|
||||
data["columns"] = cols;
|
||||
std::ofstream headerFile(path + "/" + className + ".h", std::ofstream::out);
|
||||
|
|
|
@ -138,17 +138,20 @@ const std::string &[[className]]::getColumnName(size_t index) noexcept(false)
|
|||
$$<<" auto p = strptime(timeStr.c_str(),\"%Y-%m-%d %H:%M:%S\",&stm);\n";
|
||||
$$<<" time_t t = mktime(&stm);\n";
|
||||
$$<<" size_t decimalNum = 0;\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" if(p)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
// $$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(::trantor::Date(946656000000000).after(daysNum*86400));\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
continue;
|
||||
}
|
||||
|
@ -209,17 +212,20 @@ const std::string &[[className]]::getColumnName(size_t index) noexcept(false)
|
|||
$$<<" auto p = strptime(timeStr.c_str(),\"%Y-%m-%d %H:%M:%S\",&stm);\n";
|
||||
$$<<" time_t t = mktime(&stm);\n";
|
||||
$$<<" size_t decimalNum = 0;\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" if(p)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
// $$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(::trantor::Date(946656000000000).after(daysNum*86400));\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
continue;
|
||||
}
|
||||
|
@ -294,17 +300,20 @@ const std::string &[[className]]::getColumnName(size_t index) noexcept(false)
|
|||
$$<<" auto p = strptime(timeStr.c_str(),\"%Y-%m-%d %H:%M:%S\",&stm);\n";
|
||||
$$<<" time_t t = mktime(&stm);\n";
|
||||
$$<<" size_t decimalNum = 0;\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" if(p)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
// $$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(::trantor::Date(946656000000000).after(daysNum*86400));\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
continue;
|
||||
|
@ -418,17 +427,20 @@ const std::string &[[className]]::getColumnName(size_t index) noexcept(false)
|
|||
$$<<" auto p = strptime(timeStr.c_str(),\"%Y-%m-%d %H:%M:%S\",&stm);\n";
|
||||
$$<<" time_t t = mktime(&stm);\n";
|
||||
$$<<" size_t decimalNum = 0;\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" if(p)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
// $$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(::trantor::Date(946656000000000).after(daysNum*86400));\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
continue;
|
||||
|
@ -551,17 +563,20 @@ void [[className]]::updateByMasqueradedJson(const Json::Value &pJson,
|
|||
$$<<" auto p = strptime(timeStr.c_str(),\"%Y-%m-%d %H:%M:%S\",&stm);\n";
|
||||
$$<<" time_t t = mktime(&stm);\n";
|
||||
$$<<" size_t decimalNum = 0;\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" if(p)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
// $$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(::trantor::Date(946656000000000).after(daysNum*86400));\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
continue;
|
||||
|
@ -678,17 +693,20 @@ void [[className]]::updateByJson(const Json::Value &pJson) noexcept(false)
|
|||
$$<<" auto p = strptime(timeStr.c_str(),\"%Y-%m-%d %H:%M:%S\",&stm);\n";
|
||||
$$<<" time_t t = mktime(&stm);\n";
|
||||
$$<<" size_t decimalNum = 0;\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" if(p)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" if(*p=='.')\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" std::string decimals(p+1,&timeStr[timeStr.length()]);\n";
|
||||
$$<<" while(decimals.length()<6)\n";
|
||||
$$<<" {\n";
|
||||
$$<<" decimals += \"0\";\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
$$<<" decimalNum = (size_t)atol(decimals.c_str());\n";
|
||||
$$<<" }\n";
|
||||
// $$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(::trantor::Date(946656000000000).after(daysNum*86400));\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" "<<col.colValName_<<"_=std::make_shared<::trantor::Date>(t*1000000+decimalNum);\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
$$<<" }\n";
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue