The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Apache::Wyrd::SQLForm - General Form Wyrd for editing data in SQL

SYNOPSIS

    <BASENAME::SQLForm index="user_id" table="users">
      <BASENAME::Form::Template name="password">
        <BASENAME::Form::Preload>
          <BASENAME::Defaults>
            select 'root' as user_id;
          </BASENAME::Defaults>
          <BASENAME::Query>
            select user_id from users where name='Groucho'
          </BASENAME::Query>
        </BASENAME::Form::Preload>
        <b>Enter Password:</b><br>
        <BASENAME::Input name="password" type="password" />
        <BASENAME::Input name="user_id" type="hidden" />
      </BASENAME::Form::Template>
      <BASENAME::Form::Template name="result">
        <H1>Status: $:_status</H1>
        <HR>
        <P>$:_message</P>
      </BASENAME::Form::Template>
    </BASENAME::SQLForm>

DESCRIPTION

The SQLForm is a subclass of Apache::Wyrd::Form. It is meant to simplify the creation of forms that are used to edit data within a database connected to via the Apache::Wyrd::DBL.

The SQLForm makes the assumption that there is a primary table on which the edit is operating and that other tables will, if necessary, have elements inserted, changed or deleted from them as they relate to the primary table.

This module is meant to be subclassed, so a large number of its methods are only defined in order to be overridden. Any changes to secondary tables, for example, need to be handled by subclassing _prep_secondary, _submit_secondary, and _perform_secondary_deletes, all of which do nothing by default.

HTML ATTRIBUTES

index

The index column of the primary table, i.e. the name of the primary key column.

table

The name of the primary table.

PERL METHODS

(format: (returns) name (arguments after self))

(scalar) cancelled (void)

Determine if the action has been cancelled. Defaults to assuming the form is cancelled if the action parameter is set to cancel.

(scalar) index (void)

Returns the name of the primary key column, or index.

(scalar) table (void)

Returns the name of the primary table.

(scalar) default_ok (void)

Returns the word used to describe the status of OK. Default is literal "OK".

(scalar) default_ok (void)

Returns the word used to describe the status of not OK. Default is literal "Error".

(scalar) default_log (void)

Initializes the log of SQL transactions which took place during the submission. The idea is that each SQL query or command will produce results, and these results will be fed back to the user as a log. Defaults to undef.

(scalar) default_insert_error (scalar)

Format the error that occurs when there has been a database error during an insert command. The error itself is the argument.

(scalar) default_update_error (scalar)

Format the error that occurs when there has been a database error during an update command. The error itself is the argument.

(scalar) default_insert_ok (void)

Format the log entry that occurs when there has been a successful insert command.

(scalar) default_update_ok (void)

Format the log entry that occurs when there has been a successful update command.

(scalar) primary_delete_error (void)

Format the log entry that occurs when the edited record cannot be deleted. The error is the argument.

(scalar) deleted (void)

Checks to see if the action CGI parameter is set to "really_delete", and if so, deletes the record from the primary table and calls the _perform_secondary_deletes method to remove associated records in secondary tables. Returns a 1 if the deletion occurred, undef otherwise.

(void) _prep_submission (void)

Hook method for preparing the data submission. Performed prior to submitting, but after a check for deletions. Does nothing by default.

(void) _prep_secondary (void)

Hook method for preparing the secondary data. Called prior to _submit_secondary. Does nothing by default.

(void) _submit_secondary (void)

Hook method for performing alterations on tables other than the primary one. Does nothing by default.

(void) _perform_secondary_deletes (void)

Hook method for removing records associated with the primary record. Does nothing by default.

(scalar) _logger_hook (hashref, scalar)

Generic logger for the hook methods (below). Is the method called by the default hooks. Takes a hook hashref and an action scalar.

(scalar) _deleted_hook (hashref)

Backend hook. Allows a secondary device to be notified that a deletion, addition, or update has occurred. Takes the argument of a hashref in the same format as Apache::Wyrd::Services::SAK::_exists_in_table. By default only logs the event in the _info log via the _logger_hook above.

(scalar) _added_hook (hashref)

Like the _deleted_hook above.

(scalar) _updated_hook (hashref)

Like the _deleted_hook above.

_sets, _join_sets, _split_sets

Hook methods for dealing with data which may arrive from CGI as an array, but is submitted in the form of a comma-joined set of values. These are usually data in a SET or ENUM column within an SQL database table.

(array) _sets (void)

List all columns to be treated as sets. The CGI param of this name will be manipulated to convert to and from arrays in order to translate between SQL and CGI.

(void) _split_sets (void)

depending how sets data types are treated in your DBA, use this method for splitting the set value into an arrayref of the values of the set. The default is to split the sets by comma.

(void) _join_sets (void)

the opposite of _split_sets. How to turn an arrayref of values into a value acceptable by your DBA. By default, joins the values with a comma.

(void) _set_feedback (void)

Allow globals to be set for the feedback page. Called as a last step after all the data has been submitted.

BUGS/CAVEATS/RESERVED METHODS

Reserves the _submit_data method above and beyond the methods already reserved by Apache::Wyrd::Form. Also overrides the Form methods _prep_preloads and _check_form.

AUTHOR

Barry King <wyrd@nospam.wyrdwright.com>

SEE ALSO

Apache::Wyrd

General-purpose HTML-embeddable perl object

LICENSE

Copyright 2002-2007 Wyrdwright, Inc. and licensed under the GNU GPL.

See LICENSE under the documentation for Apache::Wyrd.