[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SF.net SVN: ledger-smb:[2905] addons/1.3
- Subject: SF.net SVN: ledger-smb:[2905] addons/1.3
- From: ..hidden..
- Date: Mon, 22 Feb 2010 20:24:19 +0000
Revision: 2905
http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=2905&view=rev
Author: einhverfr
Date: 2010-02-22 20:24:18 +0000 (Mon, 22 Feb 2010)
Log Message:
-----------
Late commit on memorized reports: Includes everything except hooks into legacy code.
Added Paths:
-----------
addons/1.3/saved_reports/
addons/1.3/saved_reports/tags/
addons/1.3/saved_reports/trunk/
addons/1.3/saved_reports/trunk/LedgerSMB/
addons/1.3/saved_reports/trunk/LedgerSMB/DBObject/
addons/1.3/saved_reports/trunk/scripts/
addons/1.3/saved_reports/trunk/sql/
addons/1.3/saved_reports/trunk/sql/modules/
addons/1.3/saved_reports/trunk/sql/modules/SavedReports/
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/sql/modules/test/
addons/1.3/saved_reports/trunk/t/
addons/1.3/saved_reports/trunk/t/43-dbtest-saved_reports.t
Added: addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Functions.sql
===================================================================
--- addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Functions.sql (rev 0)
+++ addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Functions.sql 2010-02-22 20:24:18 UTC (rev 2905)
@@ -0,0 +1,69 @@
+CREATE 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;
+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);
+
+IF FOUND THEN
+ t_id := in_id;
+ DELETE FROM saved_report_attr where id = in_id;
+ELSE
+ INSERT INTO saved_report(user_id, description, module, action)
+ SELECT id, in_description, in_module, in_action
+ FROM users WHERE username = SESSION_USER;
+ t_id := currval('saved_report_id_seq')::int;
+end if;
+
+FOR a_count IN
+ array_lower(in_attrs,1)
+ .. array_upper(in_attrs,1)
+LOOP
+
+ insert into saved_report_attrs(report_id, attribute, value)
+ values (t_id, in_attrs[a_count][1], in_attrs[a_count][2]);
+
+END LOOP;
+
+END;
+$$ language plpgsql security definer;
+
+CREATE 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;
+$$ language sql;
+
+CREATE 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)
+ WHERE user_id = (select id from users where username = SESSION_USER)
+ ORDER BY description;
+$$ language sql;
+
+CREATE FUNCTION report__delete(in_id int)
+returns bool as
+$$
+BEGIN
+DELETE FROM saved_report
+ WHERE user_id = (select id from users where username = SESSION_USER)
+ AND id = in_id;
+
+RETURN FOUND;
+END;
+$$ language plpgsql security definer;
Added: addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Tables.sql
===================================================================
--- addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Tables.sql (rev 0)
+++ addons/1.3/saved_reports/trunk/sql/modules/SavedReports/Tables.sql 2010-02-22 20:24:18 UTC (rev 2905)
@@ -0,0 +1,24 @@
+CREATE TABLE saved_report (
+ user_id int references users(id) on delete cascade,
+ description text,
+ id serial not null unique,
+ module text not null,
+ action text not null,
+ primary key (user_id, description)
+);
+
+CREATE TABLE saved_report_attr (
+ report_id references saved_report(id) ON DELETE CASCADE,
+ attribute text,
+ value text not null,
+ primary key (report_id, attribute)
+);
+
+CREATE TYPE saved_report_result AS (
+ user_id int,
+ description text,
+ report_id int,
+ module text,
+ action text,
+ args text[];
+);
Added: addons/1.3/saved_reports/trunk/t/43-dbtest-saved_reports.t
===================================================================
--- addons/1.3/saved_reports/trunk/t/43-dbtest-saved_reports.t (rev 0)
+++ addons/1.3/saved_reports/trunk/t/43-dbtest-saved_reports.t 2010-02-22 20:24:18 UTC (rev 2905)
@@ -0,0 +1,29 @@
+use Test::More;
+use strict;
+
+if (!defined $ENV{LSMB_TEST_DB}){
+ plan skip_all => 'Skipping all. Told not to test db.';
+}
+else {
+ plan tests => 3;
+ if (defined $ENV{LSMB_NEW_DB}){
+ $ENV{PGDATABASE} = $ENV{LSMB_NEW_DB};
+ }
+ if (!defined $ENV{PGDATABASE}){
+ die "We were told to run tests, but no database specified!";
+ }
+}
+
+my @testscripts = qw(Util);
+
+chdir 'sql/modules/test/';
+
+for my $testscript (@testscripts){
+ open (TEST, '-|', "psql -f $testscript.sql");
+ my @testlines = grep /\|\s+(t|f)\s?$/, <TEST>;
+ cmp_ok(scalar @testlines, '>', 0, "$testscript.sql returned test results");
+ for my $test (@testlines){
+ my @parts = split /\|/, $test;
+ like($parts[1], qr/t\s?$/, $parts[0]);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.