Return-Path: Delivered-To: apmail-db-derby-user-archive@www.apache.org Received: (qmail 57260 invoked from network); 14 Feb 2010 14:04:53 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Feb 2010 14:04:53 -0000 Received: (qmail 57555 invoked by uid 500); 14 Feb 2010 14:04:53 -0000 Delivered-To: apmail-db-derby-user-archive@db.apache.org Received: (qmail 57488 invoked by uid 500); 14 Feb 2010 14:04:52 -0000 Mailing-List: contact derby-user-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Reply-To: "Derby Discussion" Delivered-To: mailing list derby-user@db.apache.org Received: (qmail 57480 invoked by uid 99); 14 Feb 2010 14:04:52 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Feb 2010 14:04:52 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of gcaddu-derby-user@m.gmane.org designates 80.91.229.12 as permitted sender) Received: from [80.91.229.12] (HELO lo.gmane.org) (80.91.229.12) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Feb 2010 14:04:43 +0000 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1Ngf5A-00039F-NB for derby-user@db.apache.org; Sun, 14 Feb 2010 15:04:20 +0100 Received: from p4FD3F9A0.dip.t-dialin.net ([79.211.249.160]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 14 Feb 2010 15:04:20 +0100 Received: from Thomas.K.Hill by p4FD3F9A0.dip.t-dialin.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 14 Feb 2010 15:04:20 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: derby-user@db.apache.org From: Thomas Subject: common use case for data base programming not possible in derby? Date: Sun, 14 Feb 2010 14:03:59 +0000 (UTC) Lines: 40 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 79.211.249.160 (Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)) Sender: news use case - use of database side programming to log data maintenance activities - tech columns CreatedBy/CreatedOn, LastUpdatedBy/LastUpdatedOn to store username, timestamp information on when row was inserted / last updated defined on every application table - no possibility for users/applications to tamper data stored in these columns - avoid implementation of extensive protection mechanisms (e.g. by allowing table data to be maintained only via stored procedures) approaches investigated 1) using default column values to populate CreatedBy/CreatedOn on insert, i.e. "CreatedBy" varchar(64) NOT NULL DEFAULT CURRENT_USER -> column values not secured -> works for insert statements only (can not be used for populating columns LastUpdatedBy/LastUpdatedOn in case of updates) 2) using a generated column spec with a value expression i.e. "CreatedBy" varchar(64) GENERATED ALWAYS AS CURRENT_USER; -> not possible as CURRENT_USER, CURRENT_TIMESTAMP as non-determinstic functions can not be used as value expressions 3) using INSERT triggers (with SQL statements or calling java procedures) i.e. CREATE TRIGGER xy AFTER INSERT FOR EACH ROW UPDATE "CreatedBy"... -> might work for insert statements, but triggering an update statement with the insert would prevent me from defining an after update trigger on the table which I would need to log update activity (and which would create an infinte loop) Can't think of a way that would work which is unfortunate as for example PostgreSQL would allow such an implementation easily as transition values can be referenced and updated with the system funtions associate with a trigger(i.e. all needed is a one line statement NEW.CreatedBy = CURRENT_USER within the trigger function). Any suggestions? Is there really no way this can be achieved in Derby? (other than maybe putting the tech cols on a separate table and joining the two base tables in a view so that at least in read operations it would look like the tech cols are held on the same table?) Thanks Thomas