Skip Menu |
 

This queue is for tickets about the DBD-SQLite CPAN distribution.

Report information
The Basics
Id: 47178
Status: resolved
Priority: 0/
Queue: DBD-SQLite

People
Owner: Nobody in particular
Requestors: gfuji [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: Sample programs in the cookbock is not good examples
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Charset: utf8
X-RT-Original-Encoding: utf-8
Content-Type: multipart/mixed; boundary="----------=_1245481038-13950-1032"
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
Content-Length: 677
Download (untitled) / with headers
text/plain 677b
Hello ADAMK and others, DBD::SQLite::Cookbook does not seem to be good examples. SQLite aggrigates are designed to be object-oriented, but these examples use no benefits of OOP. Take the highly-scalable version of variance() for example. It uses some global variabes ($mu, $count, $S), so it can be called only once in a SQL statement. Why do you use object properties, instead of global variables? The attached file "Variance.pm" is a new example, which implements simple variance (Variance::Simple) and highly-scalable variance (Variance::Fast). I think it is a little better. "variance.pl" is a demo file for "Variance.pm". Regards, -- Goro Fuji (gfx) GFUJI at CPAN.org
Subject: Variance.pm
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----------=_1245480969-13950-1030"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: application/octet-stream; name="Variance.pm"
Content-Disposition: inline; filename="Variance.pm"
Content-Transfer-Encoding: base64
Content-Length: 927
Download Variance.pm
text/x-perl 927b
package Variance::Simple; use strict; use warnings; sub new { my($class) = @_; return bless { sum => 0, data => [], } => $class; } sub step { my($self, $value) = @_; $self->{sum} += $value; push @{$self->{data}}, $value; return; } sub finalize { my($self) = @_; my $n = scalar @{$self->{data}}; my $mu = $self->{sum} / $n; my $s = 0; foreach my $datum(@{$self->{data}}){ $s += ($datum - $mu) ** 2; } return $s / ($n-1); } package Variance::Fast; sub new { my($class) = @_; return bless { n => 0, sum => 0, mu => 0, s => 0, } => $class; } sub step { my($self, $value) = @_; $self->{n}++; my $delta = $value - $self->{mu}; $self->{mu} += $delta / $self->{n}; $self->{S} += $delta * ($value - $self->{mu}); return; } sub finalize { my($self) = @_; return $self->{S} / ($self->{n}-1); } 1;
Subject: variance.pl
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="----------=_1245481038-13950-1031"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Charset: utf8
Content-Length: 0
Content-Type: text/plain
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: iso-8859-1
Content-Length: 0
Content-Type: application/octet-stream; name="variance.pl"
Content-Disposition: inline; filename="variance.pl"
Content-Transfer-Encoding: base64
Content-Length: 716
Download variance.pl
text/x-perl 716b
#!perl -w use strict; use DBI; use Data::Dumper; use FindBin qw($Bin); use lib $Bin; use Variance; my $dbh = DBI->connect('dbi:SQLite:dbname=:memory:', undef, undef, { PrintError => 0, RaiseError => 1}); $dbh->do(<<'SQL'); CREATE TABLE foo( value INTEGER NOT NULL ); SQL { my $sth = $dbh->prepare('INSERT INTO foo VALUES(?)'); foreach my $value(10, 12, 11, 10, 8, 9, 10, 11, 9){ $sth->execute($value); } $sth->finish(); } foreach my $vclass (qw(Variance::Simple Variance::Fast)){ $dbh->sqlite_create_aggregate(variance => 1, $vclass); my $sth = $dbh->prepare('SELECT variance(value) FROM foo'); $sth->execute(); print Data::Dumper->new([$sth->fetchrow_hashref()], [$vclass])->Indent(1)->Dump; }
MIME-Version: 1.0
X-Spam-Status: No, hits=0.0 required=8.0 tests=DK_SIGNED,HTML_MESSAGE,SPF_PASS
In-Reply-To: <rt-3.6.HEAD-13950-1245481042-1469.47178-4-0 [...] rt.cpan.org>
References: <RT-Ticket-47178 [...] rt.cpan.org> <rt-3.6.HEAD-13950-1245481042-1469.47178-4-0 [...] rt.cpan.org>
X-Virus-Checked: Checked by ClamAV on 16.mx.develooper.com
Message-ID: <b8cb49a40906202328q7fd1eaf5r14a8489a4318ff62 [...] mail.gmail.com>
Content-Type: multipart/alternative; boundary=0016e646477e276e01046cd5dcde
Received: from la.mx.develooper.com (x1.develooper.com [207.171.7.70]) by diesel.bestpractical.com (Postfix) with SMTP id 0435019B81D7 for <bug-DBD-SQLite [...] rt.cpan.org>; Sun, 21 Jun 2009 02:28:12 -0400 (EDT)
Received: (qmail 14764 invoked by uid 103); 21 Jun 2009 06:28:12 -0000
Received: from x16.dev (10.0.100.26) by x1.dev with QMQP; 21 Jun 2009 06:28:12 -0000
Received: from mail-qy0-f171.google.com (HELO mail-qy0-f171.google.com) (209.85.221.171) by 16.mx.develooper.com (qpsmtpd/0.80) with ESMTP; Sat, 20 Jun 2009 23:28:07 -0700
Received: by qyk1 with SMTP id 1so387428qyk.33 for <bug-DBD-SQLite [...] rt.cpan.org>; Sat, 20 Jun 2009 23:28:04 -0700 (PDT)
Received: by 10.220.95.194 with SMTP id e2mr3440984vcn.65.1245565684247; Sat, 20 Jun 2009 23:28:04 -0700 (PDT)
Delivered-To: cpan-bug+DBD-SQLite [...] diesel.bestpractical.com
Subject: Re: [rt.cpan.org #47178] Sample programs in the cookbock is not good examples
Domainkey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=nSe/pHNqsuBOu9eX921KfMcFN/K9RvvJ3yfPNJnPppXxZgKP6nHCkFesQ/XYrTtgD7 2WYx2B4GKkjXk14fBAZ9DU5vYM1jmphKiRtJFBWGPN/tIwTolbov435sOfxUrl0cyL/w tjU8GLZaxiaZ3Y2kowukpfyO7vtAhU04zaqik=
Return-Path: <adamkennedybackup [...] gmail.com>
Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=zhL0EL/6cq8n9/eqxPAgtYie32FtD1iBAx/tJ2GuI4A=; b=LkyB0yecq7S8SCQHeXkUWk5NAc2cWAhWBMZYWpe5nAawV4W8cyOffxFY9OfyuvrY7D t/tnTmqLwaEN16gFGFW0O2xCh9ByMK6025EOdw/6zUaGBuiUBKyezGuT5GlBHKuKjTaJ e/7ZKCpcEeOaC6jSHDtFz/IGj45YY9uz3Jkj8=
X-Spam-Check-BY: 16.mx.develooper.com
X-Original-To: bug-DBD-SQLite [...] rt.cpan.org
Date: Sun, 21 Jun 2009 16:28:04 +1000
X-Spam-Level: *
To: bug-DBD-SQLite [...] rt.cpan.org
From: Adam Kennedy <adamkennedybackup [...] gmail.com>
RT-Message-ID: <rt-3.6.HEAD-13950-1245565706-1866.47178-0-0 [...] rt.cpan.org>
Content-Length: 0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 7bit
X-RT-Original-Encoding: utf-8
Content-Length: 1351
Download (untitled) / with headers
text/plain 1.3k
If you are interested in helping to rewrite the cookbook entries, I can get you commit rights to the repository, so that you can edit, improve and add to it directly. Would you prefer this? Adam K 2009/6/20 Goro Fuji via RT <bug-DBD-SQLite@rt.cpan.org> Show quoted text
> Sat Jun 20 02:57:22 2009: Request 47178 was acted upon. > Transaction: Ticket created by GFUJI > Queue: DBD-SQLite > Subject: Sample programs in the cookbock is not good examples > Broken in: (no value) > Severity: Normal > Owner: Nobody > Requestors: gfuji@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=47178 > > > > Hello ADAMK and others, > > DBD::SQLite::Cookbook does not seem to be good examples. SQLite > aggrigates are designed to be object-oriented, but these examples use no > benefits of OOP. > > Take the highly-scalable version of variance() for example. It uses some > global variabes ($mu, $count, $S), so it can be called only once in a > SQL statement. Why do you use object properties, instead of global > variables? > > The attached file "Variance.pm" is a new example, which implements > simple variance (Variance::Simple) and highly-scalable variance > (Variance::Fast). I think it is a little better. "variance.pl" is a demo > file for "Variance.pm". > > Regards, > -- > Goro Fuji (gfx) GFUJI at CPAN.org >
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
X-RT-Original-Encoding: utf-8
Content-Length: 1897
MIME-Version: 1.0
X-Mailer: MIME-tools 5.504 (Entity 5.504)
Content-Disposition: inline
X-RT-Interface: Web
Content-Type: text/plain; charset="utf-8"
Message-ID: <rt-4.0.18-28335-1423802258-940.47178-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
X-RT-Encrypt: 0
X-RT-Sign: 0
Content-Length: 865
Download (untitled) / with headers
text/plain 865b
On Sat Jun 20 15:57:22 2009, GFUJI wrote: Show quoted text
> Hello ADAMK and others, > > DBD::SQLite::Cookbook does not seem to be good examples. SQLite > aggrigates are designed to be object-oriented, but these examples use no > benefits of OOP. > > Take the highly-scalable version of variance() for example. It uses some > global variabes ($mu, $count, $S), so it can be called only once in a > SQL statement. Why do you use object properties, instead of global > variables? > > The attached file "Variance.pm" is a new example, which implements > simple variance (Variance::Simple) and highly-scalable variance > (Variance::Fast). I think it is a little better. "variance.pl" is a demo > file for "Variance.pm". > > Regards,
Closing as https://github.com/DBD-SQLite/DBD-SQLite/commit/d30f3ab45934a55493de71703da39fecc3ab0438 had fixed the major part of this ticket. Thanks.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.