I am learning about Template::Toolkit and how to use the DBI plugin.

I am running Perl 5.10.1 on FreeBSD 8.0-STABLE and have these available:

   bsdpan-Template-DBI-2.64     Template::Plugin::DBI
   p5-Template-Toolkit-2.22_1   Extensive Toolkit for template processing
   p5-DBI-1.60.9                The perl5 Database Interface.
   p5-DBD-Oracle-1.19_3         DBI driver for Oracle RDBMS server

I used the following DDL to create my Oracle table.  I then INSERTed
three rows (see below):

freebsd% cat foo.create.sql
CREATE TABLE me.myuser (
  id                   INTEGER     CONSTRAINT con1 NOT NULL,
  name                 VARCHAR2(255),
  email                VARCHAR2(255),
  CONSTRAINT con3 PRIMARY KEY (id)
) ;

The following is my template file "foo.tmpl":

 =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

[% INCLUDE header.tmpl title = 'User Info' %]

[% USE DBI('dbi:Oracle:sid', 'me', 'pw') %]

[% rows = DBI.query('SELECT * FROM me.myuser') %]
<p> Number of users = [% rows.size %] </p>

<table border=0 width="100%">
  <tr>
    <th>User ID</th> 
    <th>Name</th>  
    <th>Email</th>
  </tr>
[% FOREACH user = DBI.query('SELECT * FROM me.myuser ORDER BY id') %]
  <tr>
    <td>[% user.id %]</td> 
    <td>[% user.name %]</td> 
    <td>[% user.email %]</td>
  </tr>
[% END %]
</table>

[% INCLUDE footer.tmpl %]

 =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

This is the output of "% tpage foo.tmpl":

<html>
  <head>
    <title>User Info</title>
  </head>
  <body>

<p> Number of users = 0 </p>

<table border=0 width="100%">
  <tr>
    <th>User ID</th> 
    <th>Name</th>  
    <th>Email</th>
  </tr>

  <tr>
    <td></td> 
    <td></td> 
    <td></td>
  </tr>

  <tr>
    <td></td> 
    <td></td> 
    <td></td>
  </tr>

  <tr>
    <td></td> 
    <td></td> 
    <td></td>
  </tr>
</table>

    <div class="copyright">
      &copy; Copyright 2010 by Web
    </div>
  </body>
</html>

 =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

I don't know how to track down what is wrong.  The same query in a
small Perl script using the same DSN and credentials results in this:

freebsd% ./foo.oracle.test.pl
1       curly   [email protected]
2       moe     [email protected]
3       larry   [email protected]

 =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

#!/usr/bin/perl

use strict;
use warnings;
use DBI;

# omit $user, $password, and $sid initallization for clarity

my $dbh = DBI->connect("dbi:Oracle:$sid", $user, $password)
                        or die "Can't connect to database: $DBI::errstr $!\n";

my $query = qq/select * from me.myuser/;

my $sth = $dbh->prepare ($query)
                        or die "Couldn't prepare statement: " . $dbh->errstr;

$sth->execute() or die "Couldn't execute statement: " . $sth->errstr;

while (my @row = $sth->fetchrow_array())
{
        print join ("\t", @row), "\n";
}

$sth->finish;

print "\n";

$dbh->disconnect;

exit (0);

 =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=

Can anyone recommend any pointers for ways to make this work?  Thanks.


Regards,

web...

--
William Bulley                     Email: [email protected]

72 characters width template ----------------------------------------->|

_______________________________________________
templates mailing list
[email protected]
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to