Received: from cr322781-a.ym1.on.wave.home.com (cr322781-a.ym1.on.wave.home.com [24.112.37.89]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f2UIGXK11844 for ; Fri, 30 Mar 2001 13:16:33 -0500 (EST) (envelope-from svanegmond@bang.dhs.org) Received: from svanegmond by cr322781-a.ym1.on.wave.home.com with local (Exim 3.20 #1 (Debian)) id 14ipQ1-000241-00; Thu, 29 Mar 2001 22:17:45 -0500 Date: Thu, 29 Mar 2001 22:17:44 -0500 To: Andrew Hammond Cc: PostgreSQL-PHP list Subject: Re: A valuable addition to PHP... Message-ID: <20010329221744.A6990@bang.dhs.org> References: <3ABFADEE.6000802@greatbridge.com> <20010329171654.A12635@waugh.econ.queensu.ca> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.15i In-Reply-To: <20010329171654.A12635@waugh.econ.queensu.ca>; from drew@waugh.econ.queensu.ca on Thu, Mar 29, 2001 at 05:16:54PM -0500 From: Stephen van Egmond X-Archive-Number: 200103/66 X-Sequence-Number: 251 On Thu, Mar 29, 2001 at 05:16:54PM -0500, Andrew Hammond wrote: > independant way of accessing metadata. Writing SQL queries that derive > metadata by futzing around with the pg_* tables works but is totally > non-portable. What I would really like to see is a database interface > layer that encapsulates all that nasty mess. Metadata and other > introspective stuff is a glaring ommission from SQL. I have written something that does this in two directions: listing out the indices, tables, columns, etc. For a simpleminded db abstraction layer for work. I can provide code shortly. IMHO the database "abstraction toolkits" are all missing the point. In my scripts, I want my variables. Now. It failed? Not the concern of the script. So far I've laid out 5 functions: # returns the value of that column or NULL if it's NULL $scalar = db_value("SELECT column FROM table WHERE unique_id=5"): # returns an array of values of these columns $list = db_list("SELECT column FROM table"); # returns a hash[column] = value $row = db_row("SELECT * FROM table WHERE unique_id=5"); # returns a array of hashes $rows = db_row("SELECT * FROM table"); # for sending updates, etc. $result = db_send("UPDATE/INSERT/DELETE whatever"); All the guts of connections, interation, freeing results, etc. are hidden. I've even implemented failover behind the scenes. Error handling is ambiguous with respect to NULL values, so that gets a -1 until something exception-like appears in the language. (And I'm not in a hurry for that.) This has turned out to be really effective. One thing which would also be amazing (also borrowed from some simple-DBI thing) is to automatically map primary keys into hashes. So when fetching a bunch of rows that have a primary key: $rows = db_row("SELECT pkey, value FORM table", 'user_id'); # $rows['somepkey'] is then a reference to the value of that key Get it?