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

SF.net SVN: ledger-smb:[6851] trunk/sql/modules/Files.sql



Revision: 6851
          http://sourceforge.net/p/ledger-smb/code/6851
Author:   einhverfr
Date:     2014-02-12 08:01:45 +0000 (Wed, 12 Feb 2014)
Log Message:
-----------
Internal/incoming file attachment stored procs added

Modified Paths:
--------------
    trunk/sql/modules/Files.sql

Modified: trunk/sql/modules/Files.sql
===================================================================
--- trunk/sql/modules/Files.sql	2014-02-12 07:33:53 UTC (rev 6850)
+++ trunk/sql/modules/Files.sql	2014-02-12 08:01:45 UTC (rev 6851)
@@ -208,6 +208,52 @@
 END;
 $$ LANGUAGE PLPGSQL;
 
+CREATE OR REPLACE FUNCTION file__save_incoming
+(in_content bytea, in_mime_type_id int, in_file_name text,
+in_description text)
+RETURNS file_base LANGUAGE SQL AS
+$$
+INSERT INTO file_incoming(content, mime_type_id, file_name, description, 
+                          ref_key, file_class, uploaded_by)
+SELECT $1, $2, $3, $4, 0, 7, entity_id
+  FROM users where username = SESSION_USER
+ RETURNING *;
+$$;
+
+COMMENT ON FUNCTION file__save_incoming
+(in_content bytea, in_mime_type_id int, in_file_name text,
+in_description text) IS 
+$$If the file_name is not unique, a unique constraint violation will be thrown.
+$$;
+
+CREATE OR REPLACE FUNCTION file__save_internal
+(in_content bytea, in_mime_type_id int, in_file_name text,
+in_description text)
+RETURNS file_base LANGUAGE SQL AS
+$$
+WITH up AS (
+    UPDATE file_internal 
+       SET content = $1, uploaded_at = now(),
+           uploaded_by = (select entity_id from users 
+                           where username = session_user)
+     WHERE file_name = $3
+ RETURNING true as found_it
+)   
+INSERT INTO file_internal (content, mime_type_id, file_name, description,
+                          ref_key, file_class, uploaded_by)
+SELECT $1, $2, $3, $4, 0, 6, entity_id
+  FROM users 
+ where username = SESSION_USER 
+       AND NOT EXISTS (select 1 from up)
+RETURNING *;
+$$;
+
+COMMENT ON FUNCTION file__save_internal
+(in_content bytea, in_mime_type_id int, in_file_name text,
+in_description text) IS 
+$$If the file_name is not unique, this will overwrite the previous stored file.
+$$;
+
 COMMENT ON FUNCTION file__attach_to_order
 (in_content bytea, in_mime_type_id int, in_file_name text,
 in_description text, in_id int, in_ref_key int, in_file_class int) IS

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


------------------------------------------------------------------------------
Android apps run on BlackBerry 10
Introducing the new BlackBerry 10.2.1 Runtime for Android apps.
Now with support for Jelly Bean, Bluetooth, Mapview and more.
Get your Android app in front of a whole new audience.  Start now.
http://pubads.g.doubleclick.net/gampad/clk?id=124407151&iu=/4140/ostg.clktrk
_______________________________________________
Ledger-smb-commits mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-commits