Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42517 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81245 invoked from network); 6 Jan 2009 21:54:23 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Jan 2009 21:54:23 -0000 Authentication-Results: pb1.pair.com smtp.mail=patchnow@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=patchnow@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.78.26 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: patchnow@gmail.com X-Host-Fingerprint: 74.125.78.26 ey-out-2122.google.com Received: from [74.125.78.26] ([74.125.78.26:26309] helo=ey-out-2122.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 60/C3-07052-E03D3694 for ; Tue, 06 Jan 2009 16:54:23 -0500 Received: by ey-out-2122.google.com with SMTP id 25so1257279eya.59 for ; Tue, 06 Jan 2009 13:54:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=8RSGJK6euF2eOIblwW5FktRFTr15odgnPE+45TW8ilk=; b=epujDm224ueWtijnxAEHni6NNkGQTZ46KhDYrNvwBEW3GwU43S2oqljVMajjF6JOmz 5oTHm7FKwQeWlSYAN3Im0KCjydiaVtbxqMNwhmQVUEl32EdHesjo124rXHb3DZdRmxEL dC4fkXT6E+OT5/TV68wJu1oIl1gdNfyj1w7lQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=FiV1hI0wrDtMQYRd+Q2f+USs8cUJY8XvxeZX4Wymw5WioNly3TkfMDfAlZ3b7CpRl0 3i7fhQ6LcL+5Wftzw3vQyQAn5abFuOjrPF58/WEmV522H5QDiNBE/GOqqbeC39yK+k88 FWlnXX5rRK2TmimayKsa2kRl3EmoSqGDB121A= Received: by 10.210.51.18 with SMTP id y18mr26379441eby.103.1231278858897; Tue, 06 Jan 2009 13:54:18 -0800 (PST) Received: from ?192.168.0.80? (xdsl-78-34-146-154.netcologne.de [78.34.146.154]) by mx.google.com with ESMTPS id 28sm4322497eye.30.2009.01.06.13.54.16 (version=SSLv3 cipher=RC4-MD5); Tue, 06 Jan 2009 13:54:17 -0800 (PST) Message-ID: <4963D30D.6020700@gmail.com> Date: Tue, 06 Jan 2009 22:54:21 +0100 User-Agent: Thunderbird 2.0.0.19 (Windows/20081209) MIME-Version: 1.0 To: internals@lists.php.net References: <495FCE1A.2000904@gmail.com> <65868A42-9F4A-43B1-8D51-C426E24B7B0F@pooteeweet.org> In-Reply-To: <65868A42-9F4A-43B1-8D51-C426E24B7B0F@pooteeweet.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] PDO: table name of field in SQLite #42589 and a new fetch style FETCH_ASSOC_TREE From: patchnow@gmail.com (Oskar Eisemuth) Hello Lukas Kahwe Smith wrote: >> Using the column key to build a hierarchical tree structure by using >> the dot as delimiter for the keys. > PDO::FETCH_ASSOC_TREE > > Personally I am not such a fan of the bit-wise parameter approach. > Then again it provides a lot of flexibility. That being said finding a > good API for this particular feature is non trivial (maybe we can > borrow from LINQ?). Of course having PHP do this work internally is > more efficient than doing it in userland and I think its an often seen > enough use case. So I guess file a feature request, ideally with a > solid proposal for an API for this. LINQ/DBLINQ translates to SQL and has an understanding how to access the SQL server. PDO doesn't try to understand much of SQL and passes SQL to the database and so doesn't know much of the structure. I guess a LINQ extension system for PHP could use PDO as backend but my intention wasn't to add ORM functionality with tree fetching. Currently I would describe the tree proposal as a way to route the columns to the right "end-point" by using SQL aliasing specially when complex queries are done. As with FETCH_2D the mapping comes from the database driver/sql. Only being N dimensional and as well cover the other fetch modes. The other way would be to do the mapping by column index in user land with something like getColumnMeta lite in a stable api. Without breaking the current api this could be done with something like getColumnMeta(int $column, [int $meta_type]) PDO::META_NAME PDO::META_TABLE ... getColumnMeta($column, PDO::META_NAME) would return the column name as string. In userland this information can be used to create a "path" for each column, (split at dots, prefixing by table name) then apply the path for every fetch. With Objects and ArrayAccess this should be quite transparent, only mixing Objects and arrays will be tricky as ArrayAccess::offsetGet can't be forced to return references (#32983), so an array in an object would break, however plain arrays won't be a problem. A general and fast way to traverse the object path would be nice, then the whole thing would end up being something like this: --- $stmt->execute(); /* Create a map array with getColumnName and/or getColumnMeta to the tree locations */ $map = my_createmap($stmt); /* Example Map: $map = array( array('prop1'), array('prop2', 'a'), array('prop2', 'b') ); */ while($row = $stmt->fetch(PDO::FETCH_NUM)) { /* Create an Object instance or new array */ $objorarray = new MyObject(); /* Apply the data */ applymap($objorarray, $map, $row); $result[] = $objorarray } ------ Or the functionality is provided as PDO internal: $stmt->execute(); $stmt->setFetchMode( PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE, 'MyObject', array()) $map = my_createmap($stmt); /* new function to register the map */ $stmt->setFetchMap($map); while($obj = $stmt->fetch(PDO::FETCH_CLASS | PDO::FETCH_PROPS_LATE | PDO::FETCH_USEMAP)) { $result[] = $obj } ---- How should the path be stored, it could be a string with dots "a.b.c" or an array like array('a','b','c')? Should the map functionality exposed to userland, only build-in or maybe both? If applymap would be some kind of generic functionality, the impact on PDO would be limited to getColumnMeta and the PDO change could be done later. The script may decide to cache the map for later use too. Anyway applymap($objorarray, $map, $data) should really have a better name.... Best regards, Oskar Eisemuth