NAME
CGI::Bus::tm - database Transaction page Manager to view and edit data
SYNOPSIS
use CGI::Bus;
$s =CGI::Bus->new();
$s->tm->...see 'Transaction Sequence' below
DESCRIPTION
This module is database Transaction page Manager to view and edit data.
There are a common TRANSACTION SEQUENCE and simplest programming interface using cmd(-command) conditions and direct database calls along with cnd and qparam calls. Some common transaction commands for more usable programming interface are also implemented.
Some slots are only predefined for children and not used within this module. Some slots may be extended in subclasses.
See CGI::Bus::tmsql as an example of details and for more advanced SQL database applications development features.
See CGI::Bus::Base for inherited slots and methods.
TRANSACTION SEQUENCE
Transaction sequence is a series of hooks dependent on current command cmd and current generic (or general or global) command cmdg. cmd(-command) calls are used as conditions. In simplest programming interface this conditions should be programmed. In more usable programming interface (SQL generator) this conditions are hidden inside eval or cmd(-cmd) call evaluating cmdCCC methods, but may be hooked with -cmdCCC slots.
A transaction sequence looks like something as:
my $s =CGI::Bus->new();
my $t =$s->tmsql;
my $d =$s->dbi; #
eval { # inside $t->eval(?connect, sub{
if ($t->cmd(-chk)) { # check before insert, update, delete # $t->cmdchk
}
if ($t->cmd(-ins)) { # insert record
$d->execute('insert ...', @{$t->qparam([names])});
}
if ($t->cmd(-upd)) { # update record where cnd
$t->cnd(-upd, field=>flags,...);
$d->execute('update ...' .$t->cnd, @{$p->qparam([names])});
}
if ($t->cmd(-del)) { # delete record where cnd
$t->cnd(-del, field=>flags,...);
$d->execute('delete ...' .$t->cnd);
}
if ($t->cmd(-sel)) { # select record fields to edit
$t->cnd(-sel, field=>flags,...);
$p->qparam($d->selectrow_hashref('...' .$t->cnd));
}
if ($t->cmd(-crt)) { # create new record values # $t->cmdcrt
}
if ($t->cmd(-qry)) { # list query condition # $t->cmdqry
}
if ($t->cmd(-htm)) { # html page begin # $t->cmdhtm
print $t->htmlhid;
print $t->htmlbar;
}
if ($t->cmd(-frm)) { # html record form # $t->cmdfrm
# print html form
}
if ($t->cmd(-lst)) { # list records
$t->cnd(-lst, field=>flags,...);
$d->select...
}
if ($t->cmd(-end)) { # commit, inside $t->eval call
$d->commit
}
};
$t->print($t->htmlres);# result msg, inside $t->eval call
}
Transaction Sequence and Calls
- -chk
-
Check or compute fields values before insert, update, delete operation -
cmdchkcall - -ins
-
Insert record into database
- -upd
-
Update record in the database. Previous values parameters names have
-pxpvprefix. - -del
-
Delete record in the database. Previous values parameters names have
-pxpvprefix. - -sel
-
Select record fields into CGI params to view or edit. Previous values parameters will be reseted.
- -crt
-
Create new record fields values into CGI params. Initiate to present new record form.
cmdcrtcall. - -qry
-
List query condition values initiate as CGI params -
cmdqrycall - -htm
-
HTML page begin output - print operations action bar and hidden HTML -
cmdhtmcall - -frm
-
Output HTML record form for query condition, view or edit -
cmdfrmcall - -lst
-
List records to user according to filter, view chosen, query condition given
- -end
-
Commit database transaction, the last command, implemented inside
evalcall along withhtmlresand rollback.
SLOTS
- -acd
-
Access control description hash ref. RESERVED
-
Banner to place above the toolbar. May be sub{}(self) or HTML. See also <-logo>
- -cmd
-
Current transaction command cached by
cmd - -cmdc
-
Current transaction command cached inside
cndcalls - -cmdCCC
-
Transacion command 'CCC' hook subroutine reference. Default operation is
cmdCCCcall. Commands are described inTRANSACTION SEQUENCEabove. - -cmde
-
Current transaction command edit state flag cached by
cmdcalls - -cmdg
-
Generic (general, global) transaction command cached by
cmd, available viacmdg. This is any-cmdcommand exept form exchanges --frm,-ins,-updcommands. - -cnd
-
Transaction condition string generated by
cnd - -fields
-
Form fields hash ref, converted from
-formbyset - -filter
-
Filter 'WHERE' clause for all SQL commands - string or sub{}.
-fltsel,-fltlst,-fltedttakes precedence. RESERVED - -fltedt
-
Filter 'WHERE' clause SQL 'UPDATE' and 'DELETE' commands - string or sub{}. RESERVED
- -fltlst
-
Filter 'WHERE' clause SQL 'SELECT' command to list records - string or sub{}. RESERVED
- -fltsel
-
Filter 'WHERE' clause SQL 'SELECT' commands to view record - string or sub{}. RESERVED
- -form
-
Form data description array ref, extendable in subclasses. See CGI::Bus::tmsql for descriptions of field attributes used here:
-fld,-lbl,-cmt,-flg('k'ey and 'm'andatory),-col-crt,-frm,-sav,-ins,-upd,-del - -formtgf
-
Form Target Frame. Target frame to open form for create new or edit existed record. Undefined value means the same browser window as for list of records, '_BLANK' opens new browser window
- -fsd
-
File store description hash ref, RESERVED
- -ftext
-
Full-text search expression template for use in query condition for
-lists, '$_' is placeholder. RESERVED - -genXXX
-
Generated database commands and clauses, RESERVED
- -htmlts
- -htmlte
-
Starting and ending data (form or view) table HTML. Commonly used by default are '<table>' and '/<table>'.
- -keyfld
-
Single key field name, RESERVED
- -lboxrnm
-
Listbox rows number margin, RESERVED
- -lists
-
Views data description hash ref, extendable in subclasses. See CGI::Bus::tmsql for descriptions of view attributes used here:
-lbl,-cmt,-fields,-key,-orderby - -listrnm
-
View rows number default margin. Margin of the number of the rows returned by
-lstoperation - -logo
-
Logotype to place at the left of the toolbar. May be image URL or HTML. See also
-banner,-tbarl - -opflg
-
Operations allowed letters: '<' leftmost left navigation action bar from
htmlbar; 'a'll: 'c'reate/'i'nsert, 'e'dit/'u'pdate, 'd'elete, 's'elect (?), 'v'iew record, 'l'ist, 'q'uery records; !'c'reate/'i'nsert, !'e'dit/'u'pdate, !'d'elete record, !'s'elect record button, !'v'iew record mode, !'q'uery condition - -pxcb
-
-pxcb => '_tcb_' - Transaction command or button name prefix
- -pxqc
-
-pxqc => '_tsw_' - Special widget name prefix
- -pxpv
-
-pxpv => '_tpv_' - Previous value parameter name prefix for
-updand-deloperation - -pxqc
-
-pxqc => '_tqc_' - Query condition parameter name prefix for save by
-lstoperation - -refresh
-
Refresh frequency for all lists (views) of recods, used to generate <meta http-equiv="refresh" CONTENT=XX>
- -rowlst
- -rowsel
- -rowedt
- -rowsav
- -rowins
- -rowupd
- -rowdel
-
Subs{} to allow or filter row operation given. Are used at a lower level, then
-cmdCCCsubs{}. May be used for access control.-rowlstis to be evaluated for each row incmdlstto filter rows to display.-rowedtcontrols record edit appearance.-rowupdand-rowdel(and-rowsavin this cases) are to evaluate when previous values of fields are fetched to-pxpvparameters. Partially RESERVED. - -rowsav1
- -rowsav2
- -rowsav1a
- -rowsav2a
-
Like
-rowsav, but immediatelly before or 'a'fter database (SQL) command generation and execution. Actual field values to be used for or 'a'fter database command are available as CGI params.-rowsav1is used for edited record only (new value fieldnames not prefixed).-rowsav2is used for each database command (new value fieldnames may be prefixed). - -rowsel1a
- -rowsel2a
-
Like
-rowsel, but immediatelly 'a'fter database (SQL SELECT) command generation and execution. Field values are available as CGI params, both previous (-pxpv) and pending.-rowsel1ais used while editing record only (when previous field values selected).-rowsel2ais used for each record selection (previous or current field values selected). - -tbarl
-
Left toolbar HTML or HTML strings array ref for
-htmoperation - -tbarr
-
Right toolbar HTML or HTML strings array ref for
-htmoperation - -vsd
-
Version store description hash ref, RESERVED
- -width
-
Width of data (form or view) table, in ' ' chars
METHODS
Common methods: qparampv, qparamsw, qparampx, htmlself, cmd, cmdg, htmlbar, htmlhid, htmlres, htmlself, eval, evaluate
Programming interface: evaluate, eval, cmd, cnd
Transaction commands implementations: cmdchk, cmdcrt, cmdqry, cmdhtm, cmdfrm, cmdhlp
- cmd -> current command
- cmd (-command) -> is command matched?
- cmd (-cmd) -> execution of all commands required
-
Current transaction command
- cmdchk () -> check before insert, update, delete
-
Check fields (CGI params) values before insert or update with
-chksubs{}. Calculate fields values with-frm,-sav,-ins,-upd,-delsubs{} before insert, update, delete - cmdcrt () -> params with default values
-
Create CGI params with
-crtdefault values for new record - cmdfe () -> form editing?
-
Check if there is form editing operation.
- cmdfrm () -> HTML form fields printed
-
Print HTML form fields for new, view or edit record
- cmdg -> current generic command
- cmdg (-command,...) -> is one of commands matched?
-
Current generic (general, global) transaction command is any
-cmdcommand exept form exchanges like-frm,-ins,-upd. - cmdhlp () -> Help screen HTML printed
-
Print Help page HTML, constructed with
-formand-listsdescriptions - cmdhtm () -> top form HTML printed
-
Print HTML at the top of the list of records or form of record. By other words, print
htmlbarandhtmlhid. - cmdqry () -> params with default values
-
Create CGI params with
-qrydefault values for query parameters form - cnd -> current transaction command condition string
- cnd (?-cmd, param => format,...) -> condition string
- cnd (?-cmd, ?'+', ?'-and|or', ?'+and|or', ?'prefix.', param, ?'fieldname=', format,...) -> condition string
-
Makes dbi transaction command condition string or returns current condition string. '-+and|or' prepends or appends 'and' or 'or' to condition string generated if it is not empty. Field values may contain condition expression used for
-lsttransaction. Field values are given from CGIparams. Field formats may be empty, quote ("'", '"'), sub, string template with '?' placeholder for value. - eval (?dbi connect parameters, ?sub{}) -> DBI transaction
-
Connect to the database, execute given sub{} in DBI transaction, print
htmlres, commit or rollback on errors. Default procedure iscmd('-cmd'). See alsoevaluate - evaluate () -> operation requested by browser
-
Full CGI::Bus::tm execution. Like
eval, but with starting HTTP, starting and ending HTML page. Uses '-htpgstart' and '-htpfstart' from parent CGI::Bus - htmlbar (?opt) -> action bar HTML
-
Generate action bar HTML string dependent on options or
-opflg, current transaction,-tbarl,-tbarr. -
Generate hidden HTML string. Hidden HTML contains saved parameters values like previous values of fields.
- htmlres () -> transaction result HTML
-
Generate transaction result HTML string - empty or success or error message.
- htmlself (command, param=>val,...) -> self command hyperlink HTML
- htmlself (command, param=>val,..., {attributes})
- htmlself ({attributes}, command, param=>val,...)
-
Generate self script command hyperlink HTML. See
cmdandTRANSACTION SEQUENCEfor commands. Attributes for 'A' HTML tag may be given as an array or hash ref. - pxnme ( prefix => name ) -> prefixed name
- pxsw ( name ) -> special widget name
- pxpv ( name ) -> previous value name
- pxqc ( name ) -> query condition name
-
Prefix field or param name given to construct special name. Prefixes are
-pxcb,-pxsw,-pxpv,-pxqc. - qlst () -> queried list name
-
List (view) name queried or default
- qparampv (name,...) -> previous value of param
-
qparamcall with-pxpvprefixed param names. - qparampx (prefix) -> [field names]
- qparampx (prefix,...) -> qparam prefixed
-
Get params names with prefix given or
qparamcall with prefixed param names. Empty prefix means non-prefixed names. - qparamsw (name,...) -> special widget value
-
qparamcall with-pxswprefixed param names.
VERSION
23/08/2007
New -banner.
16-17/11/2004
New !'c'reate/'i'nsert, !'d'elete, !'e'dit/'u'pdate, !'q'uery -opflg options. New cmdfe method. Changed htmlbar considering -vsd option.
03/11/2004
New experimantal _tsw_LSO / qloval / qlourl / qlowgh / qlowgl / qloparse interface to implement options embedded into views.
18-19/10/2004
- Changed:
-
evaluateexecutes now some CGI::Bus::upws '_run' commands as full-text 'SEARCH' or user 'SETUP'.qlstmay determine default view via '_' sign not only at the end of the view name, but at the end of the view label too.
26/06/2003
- Changed:
-
htmlbarbutton set behaviour: 'Login' button moved after 'Back' and will be always shown for guests; 'Login' button small picture resized; 'List' button in the record form replaced with 'Query' button and excluded when record editing; 'Edit' button will not be shown for guests.
28/04/2003
- Fixed:
-
cmdfrm'l'ist, 's'elect, '"'quoted only fields (-flg=~/^["'ls]*$/) are not considered in form layout now
17/04/2003
25/11/2002
13/09/2002
05/06/2002
02/06/2002
16/05/2002
07/05/2002
- Changed:
-
- textarea fields displays linebreaks when viewed - 'Select' and 'Edit' command buttons appearance - '!s'elect record button '-opflg' value
05/04/2002 - 06/05/2002
- New:
-
- imagebuttons toolbar using -iurl slot; uncomment at the beginning of the source to disable; see issue in the source code
19/01/2002 - 23/03/2002
- New:
-
Implemented and Documented.
- ToDo:
-
- review & test & debug - Questions:
-
- how to move 'qparampv' and 'qparamsw' methods up to the application object?
AUTHOR
Andrew V Makarow <makarow at mail.com>
24 POD Errors
The following errors were encountered while parsing the POD:
- Around line 629:
You forgot a '=back' before '=head2'
- Around line 649:
'=item' outside of any '=over'
- Around line 658:
You forgot a '=back' before '=head2'
- Around line 660:
'=item' outside of any '=over'
- Around line 670:
You forgot a '=back' before '=head2'
- Around line 672:
'=item' outside of any '=over'
- Around line 678:
You forgot a '=back' before '=head2'
- Around line 680:
'=item' outside of any '=over'
- Around line 685:
You forgot a '=back' before '=head2'
- Around line 687:
'=item' outside of any '=over'
- Around line 692:
You forgot a '=back' before '=head2'
- Around line 694:
'=item' outside of any '=over'
- Around line 704:
You forgot a '=back' before '=head2'
- Around line 706:
'=item' outside of any '=over'
- Around line 712:
You forgot a '=back' before '=head2'
- Around line 714:
'=item' outside of any '=over'
- Around line 719:
You forgot a '=back' before '=head2'
- Around line 721:
'=item' outside of any '=over'
- Around line 726:
You forgot a '=back' before '=head2'
- Around line 728:
'=item' outside of any '=over'
- Around line 735:
You forgot a '=back' before '=head2'
- Around line 737:
'=item' outside of any '=over'
- Around line 745:
You forgot a '=back' before '=head2'
- Around line 747:
'=item' outside of any '=over'