Fix an error with missing composite key to sqlite3 ORM generator (#673)

This commit is contained in:
丁盟 2021-01-05 22:14:31 +08:00 committed by GitHub
parent f26450f04b
commit 64e916ccb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -548,7 +548,7 @@ void create_model::createModelClassFromSqlite3(
for (auto &row : result)
{
bool notnull = row["notnull"].as<bool>();
bool primary = row["pk"].as<bool>();
bool primary = row["pk"].as<int>();
auto type = row["type"].as<std::string>();
std::transform(type.begin(), type.end(), type.begin(), tolower);
ColumnInfo info;
@ -627,13 +627,14 @@ void create_model::createModelClassFromSqlite3(
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_);
pkTypes.push_back(col.colType_);
pkValNames.push_back(nameTransform(col.colName_, false));
}
}
data["hasPrimaryKey"] = (int)pkNames.size();
@ -646,6 +647,7 @@ void create_model::createModelClassFromSqlite3(
{
data["primaryKeyName"] = pkNames;
data["primaryKeyType"] = pkTypes;
data["primaryKeyValNames"] = pkValNames;
}
data["columns"] = cols;
std::ofstream headerFile(path + "/" + className + ".h", std::ofstream::out);