NAME

DBIx::HTMLView::Selection - A kriteria used to select posts

SYNOPSIS

$sel=DBIx::HTMLView::Selection->new($table, $search_string);
print $sel->sql_select

DESCRIPTION

This class is used to parse search query strings and generate SQL select queries out of them. You usually don't use this class itself, but simply pass the strings to methods like list in DBIx::HTMLView::Table, which then uses this class to parse them.

The format of the search strings looks very much like the SQL select querys, but with some modifications. All fields are supposed to belong to the table $tab passed to the constructor and fields in related posts are accessed using the string <relation_name>-><field_name> (eg group->name). It's even possible (not yet implemeted though) to access fields through several relations (eg rel1->rel2->field).

Here is a more precise definition of the language useed:

<expr>       = <bool_value> (("AND" | "OR") <bool_value>)?
<bool_value> = <fld_spec> <opperator> <value> | "(" <expr> ")"
<fld_spec>   = <fld_name> ("->" <fld_name>)*
<fld_name>   = <word>
<value>      = <literal>|<fld_spec>
<literal>    = \d+ | "'" <string> "'" 
<string>     = [^']*
<word>       = [a-zA-Z0-9_.]+
<operator>   = "<" | ">" | "=" | "<=" | ">=" | "<>" | "LIKE" | ...

METHODS

$sel=DBIx::HTMLView::Selection->new($table, $str, $flds, $opps);

Creats a new selection for posts in the table $table (a DBIx::HTMLView::Table object) selecting posts matching the search string $str (in the format described above).

$flds is for optimisations. If it is definied it is supposed to be a reference to an array with the names of the extra fields to select from the database server. All fields used in the $str query will ofcourse also be selected. If this parameter is not defined, all fields of the table will be selected.

$opps is an array ref listing all the opperations your SQL server supports and you wish to be able to use in your search query. Deault is: ['<', '>', '=', '<=', '>=', '<>', 'LIKE', 'RLIKE', 'CLIKE', 'SLIKE'].

$sel->sql_select

Returns a SQL select query mathing the posts described in the search query passed to the constructor.

$sel->sql_count

Returns a SQL select query counting the posts described in the search query passed to the constructor.

$sel->tab

Returns the table we're selecting posts from (a DBIx::HTMLView::Table object).

$sel->add_to_where($str)

Add $str to the end of the string that will be the where clause of the slect query.

$sel->add_fld($field_name)

Adds the field named $field_name to the list of fields selected.

$sel->add_tab($table_name)

Adds the table named $table_name to the list of tabels selected from.

$sel->opps

Returns an array of comparation opperation recognised as specified by the $opps parameter to the constructor.

$sel->token

Returns the current token.

$sel->token($kind)

Returns true if the current token is of the kind $kind.

$sel->token($kind,$val)

Set $val as the curent token, and $kind as the kind of that token.

$sel->next_token

Get's the next token from the string, determins it's type and makes it the current token using $self->token.

$sel->expr =head2 $sel->bool_value =head2 $sel->fld_spec =head2 $sel->value

All those reads and parsers a specifik sub expretions as defined in the description.