Add support for escaped identifiers in Postgresql (#2167)
This commit is contained in:
parent
31fb18fb46
commit
c9f5754423
|
@ -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<std::string, std::vector<ConvertMethod>> 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_;
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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<int>("hasPrimaryKey")<=1){%>
|
||||
|
@ -102,7 +102,7 @@ if(!schema.empty())
|
|||
{
|
||||
$$<<schema<<".";
|
||||
}
|
||||
%>[[tableName]]";
|
||||
%>{%escapeIdentifier(@@.get<std::string>("tableName"), rdbms)%}";
|
||||
|
||||
const std::vector<typename [[className]]::MetaData> [[className]]::metaData_={
|
||||
<%c++for(size_t i=0;i<cols.size();i++){
|
||||
|
|
Loading…
Reference in New Issue