From 1854a4bdaaa0c1cc272f4353f2d1354149fa1158 Mon Sep 17 00:00:00 2001 From: eelke Date: Sat, 22 Dec 2018 13:52:19 +0100 Subject: [PATCH] Improvements in generated SQL for CREATE FUNCTION --- pglablib/catalog/PgProc.cpp | 52 +++++++++++++++++++++++++++---------- pglablib/catalog/PgProc.h | 2 ++ 2 files changed, 40 insertions(+), 14 deletions(-) diff --git a/pglablib/catalog/PgProc.cpp b/pglablib/catalog/PgProc.cpp index 5ef4278..bf779d1 100644 --- a/pglablib/catalog/PgProc.cpp +++ b/pglablib/catalog/PgProc.cpp @@ -2,7 +2,9 @@ #include "std_utils.h" #include "SqlFormattingUtils.h" #include "PgDatabaseCatalog.h" +#include "PgLanguageContainer.h" #include "PgTypeContainer.h" +#include #include namespace { @@ -218,31 +220,42 @@ QString PgProc::createSql() const // { // if (GetConnection()->BackendMinimumVersion(7, 5)) // sql += qtDbStringDollar(GetSource()); - sql += dollarQuoteString(src); // else // sql += qtDbString(GetSource()); // } + QString language; + { + auto l = catalog().languages()->getByKey(lang); + if (l) + language = l->objectName(); + } + if (language == "c") { + sql += escapeLiteral(bin) % ", " % escapeLiteral(src); + } + else { + sql += dollarQuoteString(src); + } // sql += wxT("\n LANGUAGE ") + GetLanguage() + wxT(" "); + sql += "\n LANGUAGE " % language % " "; // if (GetConnection()->BackendMinimumVersion(8, 4) && GetIsWindow()) // sql += wxT("WINDOW "); + if (iswindow) + sql += "WINDOW "; // sql += GetVolatility(); + sql += volatility(); + + if (leakproof) + sql += " LEAKPROOF"; + if (isstrict) + sql += " STRICT"; -// if (GetConnection()->BackendMinimumVersion(9, 2) && GetIsLeakProof()) -// sql += wxT(" LEAKPROOF"); -// if (GetIsStrict()) -// sql += wxT(" STRICT"); // if (GetSecureDefiner()) // sql += wxT(" SECURITY DEFINER"); -// // PostgreSQL 8.3+ cost/row estimations -// if (GetConnection()->BackendMinimumVersion(8, 3)) -// { -// sql += wxT("\n COST ") + NumToStr(GetCost()); - -// if (GetReturnAsSet()) -// sql += wxT("\n ROWS ") + NumToStr(GetRows()); -// } - + sql += QString("\n COST %1").arg(cost); + if (retset) + sql += QString("n ROWS %1").arg(rows); + sql += ";"; // if (!sql.Strip(wxString::both).EndsWith(wxT(";"))) // sql += wxT(";"); @@ -276,3 +289,14 @@ QString PgProc::createSql() const return createSqlCache; } + + +QString PgProc::volatility() const +{ + switch (provolatile) { + case 'i': return "IMMUTABLE"; + case 's': return "STABLE"; + case 'v': return "VOLATILE"; + } + return ""; +} diff --git a/pglablib/catalog/PgProc.h b/pglablib/catalog/PgProc.h index 3ad9158..6de4438 100644 --- a/pglablib/catalog/PgProc.h +++ b/pglablib/catalog/PgProc.h @@ -75,6 +75,8 @@ public: QString argListWithNames(bool multiline = false) const; QString argSigList(const bool forScript = false) const; + QString volatility() const; + // bool isTrigger() const // { // return typname == wxT("\"trigger\"") || typname == wxT("trigger") || typname == wxT("event_trigger") || typname == wxT("\"event_trigger\""))