From 9cdfa8dc91eeda6af715329bff7a880506e616d7 Mon Sep 17 00:00:00 2001 From: Gil Moskowitz Date: Tue, 16 Sep 2014 12:19:25 -0400 Subject: [PATCH] use the proper column name in pg_stat_activity for the postgres version --- .../public/functions/logout.sql | 11 +++++-- lib/orm/source/xt/javascript/data.sql | 31 +++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/foundation-database/public/functions/logout.sql b/foundation-database/public/functions/logout.sql index 1626bf200..e571e6618 100644 --- a/foundation-database/public/functions/logout.sql +++ b/foundation-database/public/functions/logout.sql @@ -3,9 +3,16 @@ CREATE OR REPLACE FUNCTION logout() RETURNS integer AS $$ -- Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple. -- See www.xtuple.com/CPAL for the full text of the software license. BEGIN - PERFORM pg_advisory_unlock(datid::integer, procpid) + IF (compareversion('9.2.0') <= 0) + THEN + PERFORM pg_try_advisory_unlock(datid::integer, pid) FROM pg_stat_activity - WHERE(procpid = pg_backend_pid()); + WHERE(pid = pg_backend_pid()); + ELSE + PERFORM pg_advisory_unlock(datid::integer, procpid) + FROM pg_stat_activity + WHERE(procpid = pg_backend_pid()); + END IF; RETURN 0; END; diff --git a/lib/orm/source/xt/javascript/data.sql b/lib/orm/source/xt/javascript/data.sql index 0cacd1851..a93b75adb 100644 --- a/lib/orm/source/xt/javascript/data.sql +++ b/lib/orm/source/xt/javascript/data.sql @@ -1727,6 +1727,31 @@ select xt.install_js('XT','Data','xtuple', $$ return ret; }, + /** + * Get the current database server version. + * If the optional precision argument is passed, return the first prec + * fields of the full version number. + * + * @example + * var x = getPgVersion(1), // '9' + * xy = getPgVersion(2), // '9.1' + * xyz = getPgVersion(3), // '9.1.3' + * all = getPgVersion(); // '9.1.3' + * + * @param {Number} proc - optional precision + * @returns {String} X[.Y[.Z]] + */ + getPgVersion: function (prec) { + var q = plv8.execute("select setting from pg_settings " + + "where name='server_version';"), + ret; + ret = q[0].setting; + if (typeof prec === 'number') { + ret = ret.split(".").slice(0,prec).join("."); + } + return ret; + }, + /** * Get the oid for a given table name. * @@ -2399,12 +2424,14 @@ select xt.install_js('XT','Data','xtuple', $$ lockExp, oid, pcheck, + pgver = 0 + XT.Data.getPgVersion(2), pid = options.pid || null, - pidSql = "select usename, procpid " + + pidcol = (pgver < 9.2) ? "procpid" : "pid", + pidSql = "select usename, {pidcol} " + "from pg_stat_activity " + "where datname=current_database() " + " and usename=$1 " + - " and procpid=$2;", + " and procpid=$2;".replace("{pidcol}", pidcol), query, selectSql = "select * " + "from xt.lock " + -- 2.39.2