diff --git a/drogon_ctl/create_model.cc b/drogon_ctl/create_model.cc index f38c0561..0b07b2c1 100644 --- a/drogon_ctl/create_model.cc +++ b/drogon_ctl/create_model.cc @@ -66,6 +66,17 @@ static std::string escapeConnString(const std::string &str) return escaped; } +std::string drogon_ctl::escapeIdentifier(const std::string &identifier, + const std::string &rdbms) +{ + if (rdbms != "postgresql") + { + return identifier; + } + + return "\\\"" + identifier + "\\\""; +} + static std::map> getConvertMethods( const Json::Value &convertColumns) { @@ -166,7 +177,7 @@ void create_model::createModelClassFromPG( auto className = nameTransform(tableName, true); HttpViewData data; data["className"] = className; - data["tableName"] = toLower(tableName); + data["tableName"] = tableName; data["hasPrimaryKey"] = (int)0; data["primaryKeyName"] = ""; data["dbName"] = dbname_; diff --git a/drogon_ctl/create_model.h b/drogon_ctl/create_model.h index 577ad5e3..79bec0af 100644 --- a/drogon_ctl/create_model.h +++ b/drogon_ctl/create_model.h @@ -78,6 +78,9 @@ inline std::string nameTransform(const std::string &origName, bool isType) return ret; } +std::string escapeIdentifier(const std::string &identifier, + const std::string &rdbms); + class PivotTable { public: diff --git a/drogon_ctl/templates/model_cc.csp b/drogon_ctl/templates/model_cc.csp index 4f2fa504..d2a29a67 100644 --- a/drogon_ctl/templates/model_cc.csp +++ b/drogon_ctl/templates/model_cc.csp @@ -76,7 +76,7 @@ else <%c++for(auto col:cols){ %> -const std::string [[className]]::Cols::_{%col.colName_%} = "{%col.colName_%}"; +const std::string [[className]]::Cols::_{%col.colName_%} = "{%escapeIdentifier(col.colName_, rdbms)%}"; <%c++ }%> <%c++if(@@.get("hasPrimaryKey")<=1){%> @@ -102,7 +102,7 @@ if(!schema.empty()) { $$<[[tableName]]"; +%>{%escapeIdentifier(@@.get("tableName"), rdbms)%}"; const std::vector [[className]]::metaData_={ <%c++for(size_t i=0;i