™.. DBD::SQLite::Cookbook - Online Linux Manual PageSection : 3
Updated : 2009-11-23
Source : perl v5.10.1
Note : User Contributed Perl Documentation

NAMEDBD::SQLite::Cookbook − The DBD::SQLite Cookbook

DESCRIPTIONThis is the DBD::SQLite cookbook. It is intended to provide a place to keep a variety of functions and formals for use in callback APIs in DBD::SQLite.

VarianceThis is a simple aggregate function which returns a variance. It is adapted from an example implementation in pysqlite. ​ package variance; ​ ​ sub new { bless [], shift; } ​ ​ sub step { ​ my ( $self, $value ) = @_; ​ ​ push @$self, $value; ​ } ​ ​ sub finalize { ​ my $self = $_[0]; ​ ​ my $n = @$self; ​ ​ # Variance is NULL unless there is more than one row ​ return undef unless $n || $n == 1; ​ ​ my $mu = 0; ​ foreach my $v ( @$self ) { ​ $mu += $v; ​ } ​ $mu /= $n; ​ ​ my $sigma = 0; ​ foreach my $v ( @$self ) { ​ $sigma += ($x − $mu)**2; ​ } ​ $sigma = $sigma / ($n − 1); ​ ​ return $sigma; ​ } ​ ​ # NOTE: If you use an older DBI (< 1.608), ​ # use $dbh−>func(..., "create_aggregate") instead. ​ $dbh−>sqlite_create_aggregate( "variance", 1, 'variance' ); The function can then be used as: ​ SELECT group_name, variance(score) ​ FROM results ​ GROUP BY group_name;

Variance (Memory Efficient)A more efficient variance function, optimized for memory usage at the expense of precision: ​ package variance2; ​ ​ my $sum = 0; ​ my $count = 0; ​ my %hash; ​ ​ sub new { bless [], shift; } ​ ​ sub step { ​ my ( $self, $value ) = @_; ​ ​ # by truncating and hashing, we can comsume many more data points ​ $value = int($value); # change depending on need for precision ​ # use sprintf for arbitrary fp precision ​ if (defined $hash{$value}) { ​ $hash{$value}++; ​ } else { ​ $hash{$value} = 1; ​ } ​ $sum += $value; ​ $count++; ​ } ​ ​ sub finalize { ​ my $self = $_[0]; ​ ​ # Variance is NULL unless there is more than one row ​ return undef unless $count > 1; ​ ​ # calculate avg ​ my $mu = $sum / $count; ​ ​ my $sigma = 0; ​ foreach my $h (keys %hash) { ​ $sigma += (($h − $mu)**2) * $hash{$h}; ​ } ​ $sigma = $sigma / ($count − 1); ​ ​ return $sigma; ​ } The function can then be used as: ​ SELECT group_name, variance2(score) ​ FROM results ​ GROUP BY group_name;

Variance (Highly Scalable)A third variable implementation, designed for arbitrarily large data sets: ​ package variance; ​ ​ my $mu = 0; ​ my $count = 0; ​ my $S = 0 ​ ​ sub new { bless [], shift; } ​ ​ sub step { ​ my ( $self, $value ) = @_; ​ $count++; ​ $delta = $value − $mu; ​ $mu = $mu + $delta/$count ​ $S = $S + $delta*($value − $mu); ​ } ​ ​ sub finalize { ​ my $self = $_[0]; ​ return $S / ($count − 1); ​ } The function can then be used as: ​ SELECT group_name, variance3(score) ​ FROM results ​ GROUP BY group_name;

SUPPORTBugs should be reported via the CPAN bug tracker at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=DBD−SQLite>

TO DO* Add more and varied cookbook recipes, until we have enough to turn them into a seperate CPAN distribution. * Create a series of tests scripts that validate the cookbook recipies.

AUTHORAdam Kennedy <adamk@cpan.org>

COPYRIGHTCopyright 2009 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the ​LICENSE file included with this module.
0
Johanes Gumabo
Data Size   :   12,317 byte
man-DBD::SQLite::Cookbook.3pmBuild   :   2024-12-29, 07:25   :  
Visitor Screen   :   x
Visitor Counter ( page / site )   :   6 / 255,606
Visitor ID   :     :  
Visitor IP   :   18.189.194.225   :  
Visitor Provider   :   AMAZON-02   :  
Provider Position ( lat x lon )   :   39.962500 x -83.006100   :   x
Provider Accuracy Radius ( km )   :   1000   :  
Provider City   :   Columbus   :  
Provider Province   :   Ohio ,   :   ,
Provider Country   :   United States   :  
Provider Continent   :   North America   :  
Visitor Recorder   :   Version   :  
Visitor Recorder   :   Library   :  
Online Linux Manual Page   :   Version   :   Online Linux Manual Page - Fedora.40 - march=x86-64 - mtune=generic - 24.12.29
Online Linux Manual Page   :   Library   :   lib_c - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Online Linux Manual Page   :   Library   :   lib_m - 24.10.03 - march=x86-64 - mtune=generic - Fedora.40
Data Base   :   Version   :   Online Linux Manual Page Database - 24.04.13 - march=x86-64 - mtune=generic - fedora-38
Data Base   :   Library   :   lib_c - 23.02.07 - march=x86-64 - mtune=generic - fedora.36

Very long time ago, I have the best tutor, Wenzel Svojanovsky . If someone knows the email address of Wenzel Svojanovsky , please send an email to johanes_gumabo@yahoo.co.id .
If error, please print screen and send to johanes_gumabo@yahoo.co.id
Under development. Support me via PayPal.

ERROR : Need New Coding :         (parse_manual_page_|252|DBD::SQLite::Cookbook.3pm|36/37|el══─{─══.|.el══─{─══. ds -- \|\(em\| )         (htmlprn|149|DBD::SQLite::Cookbook.3pm|36/37|.el══─{─══. ds --  —  |.el══─{─══. ds -- \|\(em\| )         (parse_manual_page_|252|DBD::SQLite::Cookbook.3pm|41|br══─}─══|'br══─}─══ )         (htmlprn|149|DBD::SQLite::Cookbook.3pm|41|'br══─}─══ |'br══─}─══ )         (rof_nr_x|149|DBD::SQLite::Cookbook.3pm|51/52|\nF|.ie \nF ══─{─══. de IX )         (rof_unit_scale_px|41|DBD::SQLite::Cookbook.3pm|51/52|F|.ie \nF ══─{─══. de IX )         (rof_if|19|DBD::SQLite::Cookbook.3pm|51/52|\nF|.ie \nF ══─{─══. de IX )         (htmlprn|149|DBD::SQLite::Cookbook.3pm|51/52|.ie \nF ══─{─══. de IX|.ie \nF ══─{─══. de IX )         (rof_escape_sequence|91|DBD::SQLite::Cookbook.3pm|53|\$1\t\\n%\t"\\$2" |. tm Index:\\$1\t\\n%\t"\\$2" )         (parse_manual_page_|252|DBD::SQLite::Cookbook.3pm|57|══─}─══|.══─}─══ )         (htmlprn|149|DBD::SQLite::Cookbook.3pm|57|.══─}─══ |.══─}─══ )