Improvements in generated SQL for CREATE FUNCTION
This commit is contained in:
parent
f692569d27
commit
1854a4bdaa
2 changed files with 40 additions and 14 deletions
|
|
@ -2,7 +2,9 @@
|
||||||
#include "std_utils.h"
|
#include "std_utils.h"
|
||||||
#include "SqlFormattingUtils.h"
|
#include "SqlFormattingUtils.h"
|
||||||
#include "PgDatabaseCatalog.h"
|
#include "PgDatabaseCatalog.h"
|
||||||
|
#include "PgLanguageContainer.h"
|
||||||
#include "PgTypeContainer.h"
|
#include "PgTypeContainer.h"
|
||||||
|
#include <QStringBuilder>
|
||||||
#include <boost/assert.hpp>
|
#include <boost/assert.hpp>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
@ -218,31 +220,42 @@ QString PgProc::createSql() const
|
||||||
// {
|
// {
|
||||||
// if (GetConnection()->BackendMinimumVersion(7, 5))
|
// if (GetConnection()->BackendMinimumVersion(7, 5))
|
||||||
// sql += qtDbStringDollar(GetSource());
|
// sql += qtDbStringDollar(GetSource());
|
||||||
sql += dollarQuoteString(src);
|
|
||||||
// else
|
// else
|
||||||
// sql += qtDbString(GetSource());
|
// 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 += wxT("\n LANGUAGE ") + GetLanguage() + wxT(" ");
|
||||||
|
sql += "\n LANGUAGE " % language % " ";
|
||||||
// if (GetConnection()->BackendMinimumVersion(8, 4) && GetIsWindow())
|
// if (GetConnection()->BackendMinimumVersion(8, 4) && GetIsWindow())
|
||||||
// sql += wxT("WINDOW ");
|
// sql += wxT("WINDOW ");
|
||||||
|
if (iswindow)
|
||||||
|
sql += "WINDOW ";
|
||||||
// sql += GetVolatility();
|
// 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())
|
// if (GetSecureDefiner())
|
||||||
// sql += wxT(" SECURITY DEFINER");
|
// sql += wxT(" SECURITY DEFINER");
|
||||||
|
|
||||||
// // PostgreSQL 8.3+ cost/row estimations
|
sql += QString("\n COST %1").arg(cost);
|
||||||
// if (GetConnection()->BackendMinimumVersion(8, 3))
|
if (retset)
|
||||||
// {
|
sql += QString("n ROWS %1").arg(rows);
|
||||||
// sql += wxT("\n COST ") + NumToStr(GetCost());
|
sql += ";";
|
||||||
|
|
||||||
// if (GetReturnAsSet())
|
|
||||||
// sql += wxT("\n ROWS ") + NumToStr(GetRows());
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (!sql.Strip(wxString::both).EndsWith(wxT(";")))
|
// if (!sql.Strip(wxString::both).EndsWith(wxT(";")))
|
||||||
// sql += wxT(";");
|
// sql += wxT(";");
|
||||||
|
|
||||||
|
|
@ -276,3 +289,14 @@ QString PgProc::createSql() const
|
||||||
|
|
||||||
return createSqlCache;
|
return createSqlCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QString PgProc::volatility() const
|
||||||
|
{
|
||||||
|
switch (provolatile) {
|
||||||
|
case 'i': return "IMMUTABLE";
|
||||||
|
case 's': return "STABLE";
|
||||||
|
case 'v': return "VOLATILE";
|
||||||
|
}
|
||||||
|
return "<unknown>";
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,8 @@ public:
|
||||||
QString argListWithNames(bool multiline = false) const;
|
QString argListWithNames(bool multiline = false) const;
|
||||||
QString argSigList(const bool forScript = false) const;
|
QString argSigList(const bool forScript = false) const;
|
||||||
|
|
||||||
|
QString volatility() const;
|
||||||
|
|
||||||
// bool isTrigger() const
|
// bool isTrigger() const
|
||||||
// {
|
// {
|
||||||
// return typname == wxT("\"trigger\"") || typname == wxT("trigger") || typname == wxT("event_trigger") || typname == wxT("\"event_trigger\""))
|
// return typname == wxT("\"trigger\"") || typname == wxT("trigger") || typname == wxT("event_trigger") || typname == wxT("\"event_trigger\""))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue