Using Perl Server Pages and mySQL
by Andy Yuen and Hung-Wai Yuen


Listing One
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Nested Custom Tag Demo</TITLE>
</HEAD>

<BODY>
<H3>PSP Nested Custom Tag Demo</H3><P>
<UL>

<test:loop repts=10>
<LI>
<test:if>
  <test:condition><%= (rand > .5) %></test:condition>
  <test:then>Head</test:then>
  <test:else>Tail</test:else>
</test:if>
</test:loop>

</UL>

</BODY>
</HTML>


Listing Two
 ...
# extract SID from cookie
my $sid = $request->cookie($self->{'cookiename'});
if ($sid) {
    # cookie present: record the fact that we are using cookie
    $url_flag = 2;
}
else {
    # cookie not present
    if (($sid = $request->param("SID"))) {
        # sid found in query string: record that we are using URL rewriting
        $url_flag = 1;
    }
    else {
        # no sid found, redirect url using both cookie and url rewriting
        $self->_sendSid();
        exit(0);
    }
}
 ...
# check if session has timed out
 ...

Listing Three
DROP DATABASE IF EXISTS pecs;
CREATE DATABASE pecs;
USE pecs;
DROP TABLE IF EXISTS appl_global_mapping;
CREATE TABLE  appl_global_mapping(
  appname   varchar(32) NOT NULL PRIMARY KEY,
  path     varchar(128) NOT NULL,
  login_page    varchar(32) NOT NULL,
  error_page    varchar(32) NOT NULL,
  home_page varchar(32) NOT NULL,
  mdate     date NOT NULL,
  comment   text
);
DROP TABLE IF EXISTS appl_page_mapping;
CREATE TABLE  appl_page_mapping(
  appname   varchar(32) NOT NULL,
  cmd       varchar(32) NOT NULL,
  model     varchar(32) NOT NULL,
  success_view  varchar(32) NOT NULL,
  failure_view  varchar(32) NOT NULL,
  authen_level  int unsigned NOT NULL,
  comment   text,
  PRIMARY KEY (appname, cmd)
);
DROP TABLE IF EXISTS user;
CREATE TABLE user  (
  username  varchar(16) NOT NULL PRIMARY KEY,
  passwd    varchar(16) NOT NULL,
  email     varchar(64) NOT NULL
);
DROP TABLE IF EXISTS security;
CREATE TABLE security  (
  username  varchar(16) NOT NULL,
  appname   varchar(32) NOT NULL,
  sec_level int unsigned NOT NULL,
  PRIMARY KEY (username, appname)
  );
DROP TABLE IF EXISTS session;
CREATE TABLE session  (
  sid       varchar(36) NOT NULL PRIMARY KEY,
  mtime     timestamp NOT NULL,
  ctime     timestamp NOT NULL,
  state     text
);
GRANT select, insert, update, delete
ON pecs.*
TO pecs@localhost identified by 'xfiles';

Listing Four
<%!
use PECS::Request;
use PECS::Session;
use PECS::Page;

my $page = new PECS::Page;
$request->attribute('page', $page);
%>
<PECS:UseSession timeout="15" cookieName="ConsoleApp" 
         dsn="DBI:mysql:pecs" user="pecs" password="xfiles">
    <PECS:Application name="ConsoleApp" /> 
</PECS:UseSession> 






1

