Fix a bug of creating models for mysql (#237)

This commit is contained in:
An Tao 2019-09-10 15:58:42 +08:00 committed by GitHub
parent aaaba8aa97
commit 1e83a5cc4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

View File

@ -209,7 +209,7 @@ const std::string &[[className]]::getColumnName(size_t index) noexcept(false)
}
$$<<"\n";
}
if(@@.get<std::string>("rdbms")=="postgresql")
if(@@.get<std::string>("rdbms")=="postgresql"||@@.get<int>("hasPrimaryKey")!=1)
{
$$<<"void "<<className<<"::updateId(const uint64_t id)\n";
$$<<"{\n";
@ -217,13 +217,21 @@ const std::string &[[className]]::getColumnName(size_t index) noexcept(false)
}
else if(@@.get<std::string>("rdbms")=="mysql"||@@.get<std::string>("rdbms")=="sqlite3")
{
auto primaryKeyTypeString=@@.get<std::string>("primaryKeyType");
$$<<"void "<<className<<"::updateId(const uint64_t id)\n";
$$<<"{\n";
for(auto col:cols)
{
if(col._isAutoVal)
{
$$<<" _"<<col._colValName<<" = std::make_shared<uint64_t>(id);\n";
if(primaryKeyTypeString!="uint64_t")
{
$$<<" _"<<col._colValName<<" = std::make_shared<"<<primaryKeyTypeString<<">(static_cast<"<<primaryKeyTypeString<<">(id));\n";
}
else
{
$$<<" _"<<col._colValName<<" = std::make_shared<uint64_t>(id);\n";
}
break;
}
}