[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb:[2908] addons/1.3/saved_reports/trunk



Revision: 2908
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2908&view=rev
Author:   einhverfr
Date:     2010-02-24 18:04:20 +0000 (Wed, 24 Feb 2010)

Log Message:
-----------
Test cases pass, audited to ensure it works with DBD::Pg 1.x

Modified Paths:
--------------
    addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Functions.sql
    addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Tables.sql
    addons/1.3/saved_reports/trunk/t/43-dbtest-saved_reports.t

Added Paths:
-----------
    addons/1.3/saved_reports/trunk/t/01-load-saved_reports.t

Modified: addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Functions.sql
===================================================================
--- addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Functions.sql	2010-02-24 18:03:26 UTC (rev 2907)
+++ addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Functions.sql	2010-02-24 18:04:20 UTC (rev 2908)
@@ -1,16 +1,17 @@
-CREATE FUNCTION report__save
+CREATE OR REPLACE FUNCTION report__save
 (in_id int, in_description text, in_module text, in_action text, 
 in_attrs text[])
 returns saved_report_result as
 $$
 declare t_id int;
+        retval saved_report_result;
 BEGIN
 UPDATE saved_report 
    set description = in_description,
        module = in_module,
        action = in_action
 WHERE  id = in_id  
-       AND users_id = (select id from users where username = SESSION_USER);
+       AND user_id = (select id from users where username = SESSION_USER);
 
 IF FOUND THEN
        t_id := in_id;
@@ -22,6 +23,11 @@
        t_id := currval('saved_report_id_seq')::int;
 end if;
 
+if  array_lower(in_attrs,1) is null then
+    retval := report__get(t_id);
+    return retval;
+end if;
+
 FOR a_count IN
         array_lower(in_attrs,1)
         .. array_upper(in_attrs,1)
@@ -32,31 +38,35 @@
 
 END LOOP;
 
+retval := report__get(t_id);
+return retval;
 END;
 $$ language plpgsql security definer;
 
-CREATE FUNCTION report__get(in_id int)
+CREATE OR REPLACE FUNCTION report__get(in_id int)
 returns saved_report_result AS
 $$
    SELECT r.id, r.user_id, r.description, r.module, r.action, 
           compound_array(ARRAY[a.attribute, a.value])
      FROM saved_report r
-LEFT JOIN saved_report_attribute a ON (r.id = a.report_id)
-    WHERE r.id = in_id;
+LEFT JOIN saved_report_attr a ON (r.id = a.report_id)
+    WHERE r.id = $1
+ group by r.id, r.user_id, r.description, r.module, r.action;
 $$ language sql;
 
-CREATE FUNCTION report__list_mine()
+CREATE OR REPLACE FUNCTION report__list_mine()
 RETURNS SETOF saved_report_result AS
 $$
    SELECT r.id, r.user_id, r.description, r.module, r.action, 
           compound_array(ARRAY[a.attribute, a.value])
      FROM saved_report r
-LEFT JOIN saved_report_attribute a ON (r.id = a.report_id)
+LEFT JOIN saved_report_attr a ON (r.id = a.report_id)
     WHERE user_id = (select id from users where username = SESSION_USER)
+ group by r.id, r.user_id, r.description, r.module, r.action
  ORDER BY description;
 $$ language sql;
 
-CREATE FUNCTION report__delete(in_id int)
+CREATE OR REPLACE FUNCTION report__delete(in_id int)
 returns bool as
 $$
 BEGIN

Modified: addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Tables.sql
===================================================================
--- addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Tables.sql	2010-02-24 18:03:26 UTC (rev 2907)
+++ addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Tables.sql	2010-02-24 18:04:20 UTC (rev 2908)
@@ -8,17 +8,17 @@
 );
 
 CREATE TABLE saved_report_attr (
-     report_id references saved_report(id) ON DELETE CASCADE,
+     report_id int references saved_report(id) ON DELETE CASCADE,
      attribute text,
      value text not null,
      primary key (report_id, attribute)
 );
 
 CREATE TYPE saved_report_result AS (
+   id int,
    user_id int,
    description text,
-   report_id int,
    module text,
    action text,
-   args text[];
+   args text[]
 );

Added: addons/1.3/saved_reports/trunk/t/01-load-saved_reports.t
===================================================================
--- addons/1.3/saved_reports/trunk/t/01-load-saved_reports.t	                        (rev 0)
+++ addons/1.3/saved_reports/trunk/t/01-load-saved_reports.t	2010-02-24 18:04:20 UTC (rev 2908)
@@ -0,0 +1,5 @@
+use strict;
+use warnings;
+use Test::More tests => 1;
+
+use_ok('LedgerSMB::DBObject::Saved_Report');

Modified: addons/1.3/saved_reports/trunk/t/43-dbtest-saved_reports.t
===================================================================
--- addons/1.3/saved_reports/trunk/t/43-dbtest-saved_reports.t	2010-02-24 18:03:26 UTC (rev 2907)
+++ addons/1.3/saved_reports/trunk/t/43-dbtest-saved_reports.t	2010-02-24 18:04:20 UTC (rev 2908)
@@ -14,7 +14,7 @@
         }
 }
 
-my @testscripts = qw(Util);
+my @testscripts = qw(Saved_Report);
 
 chdir 'sql/modules/test/';
 


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.