Hello,

We found a problem with an sql statement not working on postgresql, causing
errors when trying to browse perl pages while not logged in to spacewalk.

To reproduce, try to navigate to one of these pages when not logged in on a
postgres based installation:

https://<hostname>/help/copyright.pxt
https://<hostname>/help/about.pxt

Attached please find a patch for the issue.

Regards,
Johannes

-- 
SUSE LINUX Products GmbH, HRB 16746 (AG Nürnberg)
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer
>From 76dfe76b7cb8a7882951849ed537a66154aa86cc Mon Sep 17 00:00:00 2001
From: Johannes Renner <jren...@suse.de>
Date: Wed, 15 Aug 2012 15:23:59 +0200
Subject: [PATCH] Fix insert pxt session for postgres when not logged in

---
 .../postgres/procs/create_pxt_session.sql          |    2 +-
 .../124-create_pxt_session.sql.oracle              |    1 +
 .../124-create_pxt_session.sql.postgresql          |   35 ++++++++++++++++++++
 3 files changed, 37 insertions(+), 1 deletions(-)
 create mode 100644 schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/124-create_pxt_session.sql.oracle
 create mode 100644 schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/124-create_pxt_session.sql.postgresql

diff --git a/schema/spacewalk/postgres/procs/create_pxt_session.sql b/schema/spacewalk/postgres/procs/create_pxt_session.sql
index 3b3417f..aafeb5f 100644
--- a/schema/spacewalk/postgres/procs/create_pxt_session.sql
+++ b/schema/spacewalk/postgres/procs/create_pxt_session.sql
@@ -29,7 +29,7 @@ begin
     perform pg_dblink_exec(
         'insert into PXTSessions (id, value, expires, web_user_id) values (' ||
         l_id || ', ' || coalesce(quote_literal(p_value), 'NULL') ||
-        ', ' || p_expires || ', ' || p_web_user_id || '); commit');
+        ', ' || p_expires || ', ' || coalesce(quote_literal(p_web_user_id), 'NULL') || '); commit');
 
 	return l_id;
 end;
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/124-create_pxt_session.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/124-create_pxt_session.sql.oracle
new file mode 100644
index 0000000..b7b00b1
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/124-create_pxt_session.sql.oracle
@@ -0,0 +1 @@
+-- This file is intentionally left empty.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/124-create_pxt_session.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/124-create_pxt_session.sql.postgresql
new file mode 100644
index 0000000..567be73
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/124-create_pxt_session.sql.postgresql
@@ -0,0 +1,35 @@
+-- oracle equivalent source sha1 b14267384bc104605623a41b755e68e0103b5aa8
+--
+-- Copyright (c) 2008--2012 Red Hat, Inc.
+--
+-- This software is licensed to you under the GNU General Public License,
+-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
+-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+-- along with this software; if not, see
+-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+--
+-- Red Hat trademarks are not licensed under GPLv2. No permission is
+-- granted to use or replicate Red Hat trademarks that are incorporated
+-- in this software or its documentation.
+--
+--
+--
+--
+
+create or replace function
+create_pxt_session(p_web_user_id in numeric, p_expires in numeric, p_value in varchar)
+returns numeric as $$
+declare
+	l_id numeric;
+begin
+    l_id := nextval( 'pxt_id_seq' );
+
+    perform pg_dblink_exec(
+        'insert into PXTSessions (id, value, expires, web_user_id) values (' ||
+        l_id || ', ' || coalesce(quote_literal(p_value), 'NULL') ||
+        ', ' || p_expires || ', ' || coalesce(quote_literal(p_web_user_id), 'NULL') || '); commit');
+
+	return l_id;
+end;
+$$ language plpgsql;
-- 
1.7.7

_______________________________________________
Spacewalk-devel mailing list
Spacewalk-devel@redhat.com
https://www.redhat.com/mailman/listinfo/spacewalk-devel

Reply via email to