Perl TemplateDBI

Reviews
Shared by: mimama
Stats
views:
20
rating:
not rated
reviews:
0
posted:
11/16/2008
language:
pages:
0
Perl Template::DBI Hartmut PILCH http://a2e.de/adv/pak/perl-Template-DBI October 27, 2008 This package is required by perl-A2E Contents 1 Situation 2 Issues during building 2.1 Build Requirement Template Toolkit . . . . . . . . . . . . . . . . . . . . 2.2 UTF8 Patch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Issues during Use 3.1 Reuse existing database connection? . . . . . . . . . . . . . . . . . . . . 3.2 Complex SQL Select Commands . . . . . . . . . . . . . . . . . . . . . . . 4 Resources 5 Chronology 1 1 1 2 2 2 3 3 3 1 Situation We have packaged the module as compressed tar, source rpm and object rpm package, based on perl-Template-DBI.spec, for the a2e opensuse public repository. 2 Issues during building 2.1 Build Requirement Template Toolkit Can’t locate Template.pm in @INC (@INC contains: ./lib ../lib /usr/lib/perl5/5.8.8/i5 although Template.pm is definitely found in this path at 1 -r--r--r-- 1 root root 24510 2007-04-27 /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-t This was overcome by adding BuildRequires: perl-Template-Toolkit Of course it is also a runtime requirement. 2.2 UTF8 Patch Perl still handles Unicode encoding in a very unsatisfactory manner: every package must be made explicitely aware that we are not intending to support US English only. We do this by putting a few ugly lines of code into DBI.pm use Encode qw(_utf8_on); _utf8_on $data->{$_} for keys %$data; and creating a patch from this according to the rule specified in our Makefile. Hopefully these quick & dirty changes can help us patiently wait for a Perl 6.0 that wholeheartedly supports Unicode (so that any package will be Unicode-aware by default or as soon as a certain switch/pragma is used by the application). Before resorting to this patch solution, we tried to set all the Unicode switches on in the applications, also on the Perl commandline with #!/usr/bin/perl -CSDA but to no no avail. 3 Issues during Use 3.1 Reuse existing database connection? The manual says If you already have a database handle then you can instruct the plugin to reuse it by passing it as the ‘dbh’ parameter. [* DBI.connect( dbh = my_dbh_ref ) *] but doesn’t conretise my dbh ref. What could be an example of my dbh ref? ? Upon testing this, I really found that by rewriting mlht so that it passes the database handle into a template variable mlht dbh, 2 $m->{tmplvars}->{mlht_dbh} = $m->{db}; [...] $m->{template}->process($m->fh(’i’), $m->{tmplvars}, undef, binmode => ’:utf8’) or die $m->{template}->error(); I can then reuse that handle as follows: [* USE DBI(dbh = mlht_dbh) *] This makes a big difference. Now I do not have to transport any passwords in visible places. Neither as cleartext in a file nor a values of template variables that any knowledgable user could print out. The only value that I carry in a template variable is the ready database connection handle mlht dbh, which Template/Perl renders as follows: DBI::db=HASH(0x8a11d48) 3.2 Complex SQL Select Commands Something like select taktg || ’@’ || supktg as tasup, taktgrem, sum(tabetrag) as tasum from sskmta natural join tadok natural join taktg where tadatum >= ’2007-01-01’ and tadatum <= ’2007-12-31’ group by taktg, supktg, taktgrem’ will work. No issue here. Take care to name each field with ‘as’ and to use the quotes correctly. 4 Resources 5 Chronology • dat: 2008-05-02; prs: phm: Directory created 3

Related docs
A Guide to PERL
Views: 82  |  Downloads: 21
Perl Tutorial
Views: 149  |  Downloads: 40
Introduction to PERL
Views: 108  |  Downloads: 22
Introduction to Perl
Views: 76  |  Downloads: 18
Introduction to Perl
Views: 44  |  Downloads: 12
Perl
Views: 5  |  Downloads: 3
Tutorial of Perl
Views: 129  |  Downloads: 36
Perl Tutorial
Views: 59  |  Downloads: 5
Introduction to Perl
Views: 463  |  Downloads: 48
An Introduction to Perl
Views: 0  |  Downloads: 0
SeLnIkraJ - Perl
Views: 101  |  Downloads: 16
Introduction to PERL
Views: 23  |  Downloads: 7
Perl for Bioinformatics
Views: 13  |  Downloads: 1
premium docs
Other docs by mimama