Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57484 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17162 invoked from network); 23 Jan 2012 22:44:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jan 2012 22:44:06 -0000 Authentication-Results: pb1.pair.com header.from=damz@damz.org; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=damz@damz.org; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain damz.org designates 74.125.82.170 as permitted sender) X-PHP-List-Original-Sender: damz@damz.org X-Host-Fingerprint: 74.125.82.170 mail-we0-f170.google.com Received: from [74.125.82.170] ([74.125.82.170:60391] helo=mail-we0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4F/0F-36418-5B2ED1F4 for ; Mon, 23 Jan 2012 17:44:06 -0500 Received: by werm1 with SMTP id m1so1298899wer.29 for ; Mon, 23 Jan 2012 14:44:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=damz.org; s=google; h=mime-version:x-originating-ip:in-reply-to:references:date :message-id:subject:from:to:cc:x-gm-message-state:content-type :content-transfer-encoding; bh=sUSxz+C8e5ThvzUFMCd9LwfJD3h9X91TqK6+29jFpfQ=; b=hN8/scDDMOPtoGCR19OBsJlJgljpEQUWwu8uNe/lcJPhIEabPwAB9oB8R0TXWQMEzr /3ILqRpgFxzpcZ2nuv3ClqqEE3Jbor5iZxzWkkA+ptRJ20RmI2IcPF9HdrpBzacSMuvq z1zFzTq2yGxfPn3MDkVju6vaNey9GQMBDtROE= MIME-Version: 1.0 Received: by 10.216.133.142 with SMTP id q14mr4242021wei.57.1327358642875; Mon, 23 Jan 2012 14:44:02 -0800 (PST) Received: by 10.216.234.105 with HTTP; Mon, 23 Jan 2012 14:44:02 -0800 (PST) X-Originating-IP: [82.231.176.147] In-Reply-To: References: Date: Mon, 23 Jan 2012 23:44:02 +0100 Message-ID: To: b dewar Cc: internals@lists.php.net X-Gm-Message-State: ALoCoQlJ3ebejc5W99bXpwPmWZveCBhxll8Eu2M+87AFljZzZ7/8g79h4wKl73AdD5PgCJlwL5M9 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] SQLite3 class missing createCollation() From: damz@damz.org (Damien Tournoud) Also see https://bugs.php.net/bug.php?id=3D55226 Same idea, but for the PDO_sqlite implementation. Damien On Mon, Jan 23, 2012 at 11:28 PM, b dewar wrote: > Hi > > I initially sent this to php-db, but I guess it really belongs on interna= ls. > > The C API for SQLite3 has an sqlite3_create_collation() feature that's > missing from PHP's SQLite3 class API. > > I'm working on a patch that adds the SQLite3::createCollation(string > collation_name, mixed callback) method.=A0 This allows registering a PHP > function as a comparator for the database to use while collating data. > =A0The callback passed to createCollation() should act like strcmp(), > i.e. it should accept two strings and return an integer indicating > their relative sort order. > > e.g. > > > $filenames =3D array( > =A0 'ab1.png', > =A0 'ab2.png', > =A0 'ab10.png', > =A0 'ab11.png', > =A0 'ac.png', > =A0 'aa.png', > =A0 'ab3.png'); > > $db =3D new SQLite3(':memory:'); > > $db->createCollation('NATURAL_SORT', 'strnatcmp'); > > $db->exec("CREATE TABLE filenames (fname varchar(32));"); > > $stmt =3D $db->prepare("INSERT INTO filenames VALUES (?);"); > foreach($filenames as $fname){ > =A0 $stmt->bindParam(1, $fname); > =A0 $stmt->execute(); > } > $result =3D $db->query("SELECT fname FROM filenames ORDER BY fname > COLLATE NATURAL_SORT;"); > while($row =3D $result->fetchArray()){ > =A0 echo $row['fname'], "\n"; > } > > $db->close(); > > ?> > > Output: > > aa.png > ab1.png > ab2.png > ab3.png > ab10.png > ab11.png > ac.png > > > > I've built 5.3.9 with my patch on Ubuntu on x86_64, and it works as > expected. I've never submitted a patch for PHP before, so I could use > some advice/hand-holding on the process. > > Thanks, > Brad > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >