DBIx::SearchBuilder - Encapsulate SQL queries and rows in simple perl objects use DBIx::SearchBuilder; use DBIx::SearchBuilder::Handle; my $handle = DBIx::SearchBuilder::Handle->new(); $handle->Connect( Driver => 'SQLite', Database => "my_test_db" ); my $sb = DBIx::SearchBuilder->new( Handle => $handle, Table => "my_table" ); $sb->Limit( FIELD => "column_1", VALUE => "matchstring" ); while ( my $record = $sb->Next ) { print $record->my_column_name(); } This module provides an object-oriented mechanism for retrieving and updating data in a DBI-accesible database.

CleanSlate
This completely erases all the data in the SearchBuilder object. It's useful if a subclass is doing funky stuff to keep track of a search

_Handle  [DBH]
Get or set this object's DBIx::SearchBuilder::Handle object.

AddRecord RECORD
Adds a record object to this collection

_ApplyLimits STATEMENTREF
This routine takes a reference to a scalar containing an SQL statement. It massages the statement to limit the returned rows to $self->RowsPerPage starting with $self->FirstRow

_DistinctQuery STATEMENTREF
This routine takes a reference to a scalar containing an SQL statement. It massages the statement to ensure a distinct result set is returned.

_BuildJoins
Build up all of the joins we need to perform this query

_isJoined
Returns true if this Searchbuilder requires joins between tables

_isLimited
If we've limited down this search, return true. Otherwise, return false.

BuildSelectQuery
Builds a query string for a "SELECT rows from Tables" statement for this SearchBuilder object

BuildSelectCountQuery
Builds a SELECT statement to find the number of rows this SearchBuilder object would find.

Next
Returns the next row from the set as an object of the type defined by sub NewItem. When the complete set has been iterated through, returns undef and resets the search such that the following call to Next will start over with the first item retrieved from the database.

GotoFirstItem
Starts the recordset counter over from the first item. The next time you call Next, you'll get the first item returned by the database, as if you'd just started iterating through the result set.

GotoItem
Takes an integer, n. Sets the record counter to n. the next time you call Next, you'll get the nth item.

First
Returns the first item

Last
Returns the last item

ItemsArrayRef
Return a refernece to an array containing all objects found by this search.

NewItem
NewItem must be subclassed. It is used by DBIx::SearchBuilder to create record objects for each row returned from the database.

RedoSearch
Takes no arguments. Tells DBIx::SearchBuilder that the next time it's asked for a record, it should requery the database

UnLimit
UnLimit clears all restrictions and causes this object to return all rows in the primary table.

Limit
Limit takes a hash of parameters with the following keys: Can be set to something different than this table if a join is wanted (that means we can't do recursive joins as for now). Unless ALIAS is set, the join criterias will be taken from EXT_LINKFIELD and INT_LINKFIELD and added to the criterias. If ALIAS is set, new criterias about the foreign table will be added. Column to be checked against. Should always be set and will always be quoted. OPERATOR is the SQL operator to use for this phrase. Possible choices include: In the case of LIKE, the string is surrounded in % signs. Yes. this is a bug. STARTSWITH is like LIKE, except it only appends a % at the end of the string ENDSWITH is like LIKE, except it prepends a % to the beginning of the string Can be AND or OR (or anything else valid to aggregate two clauses in SQL) on some databases, such as postgres, setting CASESENSITIVE to 1 will make this search case sensitive

ShowRestrictions
Returns the current object's proposed WHERE clause. Deprecated.

ImportRestrictions
Replaces the current object's WHERE clause with the string passed as its argument. Deprecated

Orderby PARAMHASH
Orders the returned results by ALIAS.FIELD ORDER. (by default 'main.id ASC') Takes a paramhash of ALIAS, FIELD and ORDER. ALIAS defaults to main FIELD defaults to the primary key of the main table. Also accepts "FUNCTION(FIELD)" format ORDER defaults to ASC(ending). DESC(ending) is also a valid value for OrderBy

OrderByCols ARRAY
OrderByCols takes an array of paramhashes of the form passed to OrderBy. The result set is ordered by the items in the array.

_OrderClause
returns the ORDER BY clause for the search.

GroupBy
Alias for the GroupByCols method.

GroupByCols ARRAY_OF_HASHES
Each hash contains the keys ALIAS and FIELD. ALIAS defaults to 'main' if ignored.

_GroupClause
Private function to return the "GROUP BY" clause for this query.

NewAlias
Takes the name of a table. Returns the string of a new Alias for that table, which can be used to Join tables or to Limit what gets found by a search.

Join
Join instructs DBIx::SearchBuilder to join two tables. The standard form takes a param hash with keys ALIAS1, FIELD1, ALIAS2 and FIELD2. ALIAS1 and ALIAS2 are column aliases obtained from $self->NewAlias or a $self->Limit. FIELD1 and FIELD2 are the fields in ALIAS1 and ALIAS2 that should be linked, respectively. For this type of join, this method has no return value. Supplying the parameter TYPE => 'left' causes Join to preform a left join. in this case, it takes ALIAS1, FIELD1, TABLE2 and FIELD2. Because of the way that left joins work, this method needs a TABLE for the second field rather than merely an alias. For this type of join, it will return the alias generated by the join.

RowsPerPage
Limits the number of rows returned by the database. Optionally, takes an integer which restricts the # of rows returned in a result Returns the number of rows the database should display.

FirstRow
Get or set the first row of the result set the database should return. Takes an optional single integer argrument. Returns the currently set integer first row that the database should return.

_ItemsCounter
Returns the current position in the record set.

Count
Returns the number of records in the set.

CountAll
Returns the total number of potential records in the set, ignoring any LimitClause.

IsLast
Returns true if the current row is the last record in the set.

Column { FIELD => undef }
Specify that we want to load the column FIELD. Other parameters are TABLE ALIAS AND FUNCTION. Autrijus and Ruslan owe docs.

Columns LIST
Specify that we want to load only the columns in LIST

Fields TABLE
Return a list of fields in TABLE, lowercased. TODO: Why are they lowercased?

HasField  { TABLE => undef, FIELD => undef }
Returns true if TABLE has field FIELD. Return false otherwise

Table [TABLE]
If called with an arguemnt, sets this collection's table. Always returns this collection's table. Copyright (c) 2001-2004 Jesse Vincent, jesse@fsck.com. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. DBIx::SearchBuilder::Handle, DBIx::SearchBuilder::Record.