update copyright to 2014
[xtuple] / enyo-client / database / source / xt / trigger_functions / sharetype_did_change.sql
1 create or replace function xt.sharetype_did_change() returns trigger as $$\r
2 /* Copyright (c) 1999-2014 by OpenMFG LLC, d/b/a xTuple.\r
3    See www.xm.ple.com/CPAL for the full text of the software license. */\r
4 \r
5  var sql,\r
6    rows,\r
7    ary = [];\r
8 \r
9  rows = plv8.execute("select * from xt.sharetype");\r
10 \r
11  if (rows.length) {\r
12    rows.forEach(function (row) {\r
13      sql = "select " +\r
14        row.sharetype_col_obj_uuid + " as obj_uuid," +\r
15        row.sharetype_col_username + " as username " +\r
16        "from " + row.sharetype_nsname + "." + row.sharetype_tblname + " ";\r
17      ary.push(sql);\r
18    });\r
19 \r
20    sql = "select xt.create_view('xt.share_users','" + ary.join(" union all ") + "', true)";\r
21    plv8.execute(sql);\r
22 \r
23  }\r
24 \r
25  return NEW;\r
26 \r
27 $$ language plv8;\r