Sitellite Application Framework
Class Tree         Index         All Elements

Class: DatabaseTable

Source Location: Program_Root/Database/Table.php

Class Overview


DatabaseTable is an extension of the Database class, which provides high-level functions, such as fetchAll(), that aim to lessen the need to type common queries out each time you use them.


Author(s)

Version

  • 1.4, 2002-01-14, $Id: Table.php,v 1.3 2005/07/06 15:30:56 lux Exp $

Copyright

  • Copyright (C) 2001-2003, Simian Systems Inc.

Variables

Methods


Child Classes

MySQL_DatabaseTable
MySQL_DatabaseTable provides all of the MySQL-specific functionality for the saf.Database.Table package.
PgSQL_DatabaseTable
PgSQL_DatabaseTable provides all of the PgSQL-specific functionality for the saf.Database.Table package.

Inherited Variables

Inherited Methods


Class Details

[line 71]
DatabaseTable is an extension of the Database class, which provides high-level functions, such as fetchAll(), that aim to lessen the need to type common queries out each time you use them.

Note: This class does not worry about database abstraction, since that will be handled by subclassing the I18n class and calling its get() method on each query automatically in the Database class.

New in 1.2:

  • Added the following properties: $info, $columns, $pkey, $alt, $datefield, $statusfield, $queryfield, $orderfield, $treefield, $accessfield, $add_form_template, $add_form_message, $edit_form_template, and $edit_form_message.
  • Added the following methods: getInfo(), getPkey(), _makeWidget(), and changeType().
  • This class is now not accessed directly, but through the saf.Database driver system. This is done transparently however, since table objects are always created using the saf.Database table() method.
New in 1.4:
  • Added the addFacet() method.

1 <?php
2
3 $dt = new DatabaseTable ($db, 'tablename', 'pkeycolumn');
4
5 if ($res = $dt->fetchAll ()) {
6 // do something with $res
7 } else {
8 echo $dt->error;
9 }
10
11 ? >




Tags:

access:  public
version:  1.4, 2002-01-14, $Id: Table.php,v 1.3 2005/07/06 15:30:56 lux Exp $
license:  http://www.sitellite.org/index/license
copyright:  Copyright (C) 2001-2003, Simian Systems Inc.
author:  John Luxford <mailto:lux@simian.ca>


[ Top ]


Class Variables

$accessfield =  ''

[line 210]

Contains the column to search for access level values in the Sitellite CMS database manager.



Tags:

access:  public

Type:   mixed


[ Top ]

$add_form_message =  ''

[line 228]

Contains the message to use for displaying the Add Record form in the Sitellite CMS.



Tags:

access:  public

Type:   mixed


[ Top ]

$add_form_template =  ''

[line 219]

Contains the template to use for displaying the Add Record form in the Sitellite CMS.



Tags:

access:  public

Type:   mixed


[ Top ]

$alt =  ''

[line 155]

An alternate name to display for this table, which makes it nicer to read for people. By default the $alt is the $name with underscores converted to spaces and the first letter (of the first word only) capitalized.



Tags:

access:  public

Type:   mixed


[ Top ]

$columns = array ()

[line 135]

An array of MailForm widgets created based on the $info data.



Tags:

access:  public

Type:   mixed


[ Top ]

$datefield =  ''

[line 164]

Contains the column to search for date values in the Sitellite CMS database manager.



Tags:

access:  public

Type:   mixed


[ Top ]

$db =

[line 78]

Contains a reference to the database connection resource.



Tags:

access:  public

Type:   mixed


[ Top ]

$edit_form_message =  ''

[line 246]

Contains the message to use for displaying the Edit Record form in the Sitellite CMS.



Tags:

access:  public

Type:   mixed


[ Top ]

$edit_form_template =  ''

[line 237]

Contains the template to use for displaying the Edit Record form in the Sitellite CMS.



Tags:

access:  public

Type:   mixed


[ Top ]

$errno =

[line 102]

Contains the error number if there is one, or false otherwise.



Tags:

access:  public

Type:   mixed


[ Top ]

$error =

[line 94]

Contains the error message if there is one, or false otherwise.



Tags:

access:  public

Type:   mixed


[ Top ]

$facets = array ()

[line 258]


Type:   mixed


[ Top ]

$info =  false

[line 127]

The unparsed info from the database about this table and its columns.



Tags:

access:  public

Type:   mixed


[ Top ]

$name =

[line 86]

The name of the table.



Tags:

access:  public

Type:   mixed


[ Top ]

$orderfield =  ''

[line 191]

Contains the column to order search results by in the Sitellite CMS database manager.



Tags:

access:  public

Type:   mixed


[ Top ]

$pkey =  false

[line 144]

The name of the primary key field. This property is also duplicated in the $primary_key property, which is a reference to this one.



Tags:

access:  public

Type:   mixed


[ Top ]

$queryfield =  ''

[line 182]

Contains the column to search for any string values in the Sitellite CMS database manager.



Tags:

access:  public

Type:   mixed


[ Top ]

$rows =

[line 110]

The number of rows returned by the previous query.



Tags:

access:  public

Type:   mixed


[ Top ]

$sql =

[line 118]

The sql from the previous query, if an error occurred.



Tags:

access:  public

Type:   mixed


[ Top ]

$statusfield =  ''

[line 173]

Contains the column to search for status values in the Sitellite CMS database manager.



Tags:

access:  public

Type:   mixed


[ Top ]

$treefield =  ''

[line 201]

Contains the column that makes a self-reference (a reference to the primary key of its own table), which can be used in the Sitellite CMS database manager to show a tree representation of this table.



Tags:

access:  public

Type:   mixed


[ Top ]

$typemap = array ()

[line 256]

Contains a key/value list of database types (regular expressions are used here to save repeating ourselves) and their corresponding MailForm widget types. Used internally by the drivers.



Tags:

access:  public

Type:   mixed


[ Top ]



Class Methods


constructor DatabaseTable [line 269]

DatabaseTable DatabaseTable( Database &$db, string $name, string $pkey)

Constructor method.



Tags:

access:  public


Parameters:

string   $name  
string   $pkey  
Database   &$db   object reference $db

[ Top ]

method addFacet [line 662]

object reference &addFacet( string $column, string $title, [string $extra = ''])

Creates a "facet" about this widget based on one of its columns. See saf.Database.Facet for more info about those.



Tags:

access:  public


Parameters:

string   $column  
string   $title  
string   $extra  

[ Top ]

method changeType [line 608]

boolean changeType( string $name, string $type, [associative $extra = array ()])

PLEASE NOTE: This method is deprecated in favour of the built-in changeType() method in the base MF_Widget class.

Takes a widget name, a new type, and any extra properties that should be set immediately, and translates one MailForm widget (from the $columns list) into another type. This is the new way to change types of columns in the columns.php configuration file in the Sitellite CMS.




Tags:

access:  public


Parameters:

string   $name  
string   $type  
associative   $extra   array $extra

[ Top ]

method delete [line 486]

boolean delete( string $keyval)

Creates an DELETE query from the key value or values provided.



Tags:

access:  public


Parameters:

string   $keyval   or associative array $keyval

[ Top ]

method fetch [line 299]

mixed fetch( mixed $keyval, [array $columns = ''], [string $order = ''], [string $ascdesc = ''])

Creates a SELECT query based on the key given to it.

$keyval may be a value to query against the primary key column or an associative array of values to be placed in the WHERE clause of the SELECT query. $columns is an optional array of columns to return. $ascdesc can be either 'asc' or 'desc'. Returns an object if the query returns a single result (ie. for queries against the primary key column), or an array of objects, or false.




Tags:

access:  public


Parameters:

mixed   $keyval  
array   $columns  
string   $order  
string   $ascdesc  

[ Top ]

method fetchAll [line 357]

array fetchAll( [array $columns = ''], [string $order = ''], [string $ascdesc = ''])

Creates a SELECT query without a WHERE clause, returning all columns from the table. $columns is an optional array of columns to return. $ascdesc can be either 'asc' or 'desc'. Returns an array of objects, or false on failure.



Tags:

access:  public


Parameters:

array   $columns  
string   $order  
string   $ascdesc  

[ Top ]

method getInfo [line 533]

boolean getInfo( )

Gets all the info it can from the database about this table and

its columns, stores it in the $info property, and parses it into an associative array ($columns) of MailForm widgets. This method is left entirely to the drivers to implement, as its workings will always be database-specific.




Tags:

access:  public


Overridden in child classes as:

MySQL_DatabaseTable::getInfo()
Gets all the info it can from the database about this table and its columns, stores it in the $info property, and parses it into an associative array ($columns) of MailForm widgets.
PgSQL_DatabaseTable::getInfo()
Gets all the info it can from the database about this table and its columns, stores it in the $info property, and parses it into an associative array ($columns) of MailForm widgets.

[ Top ]

method getPkey [line 518]

string getPkey( )

Gets the name of the primary key field for this table using the results of getInfo() (see below). Used by the constructor method to set the $pkey property if a primary key column was not specified.

Returns false on failure. This method is left entirely to the drivers to implement, as its workings will always be database-specific.




Tags:

access:  public


Overridden in child classes as:

MySQL_DatabaseTable::getPkey()
Gets the name of the primary key field for this table using the results of getInfo() (see below). Used by the constructor method to set the $pkey property if a primary key column was not specified.
PgSQL_DatabaseTable::getPkey()
Gets the name of the primary key field for this table using the results of getInfo() (see below). Used by the constructor method to set the $pkey property if a primary key column was not specified.

[ Top ]

method getRefInfo [line 552]

boolean getRefInfo( string $name, string $table)

Uses the global $tables array (Sitellite CMS specific) to get

the primary key, referencing column, display column, and a true or false self-reference value, when given a Ref column name and its corresponding table. This method is left to the drivers to implement, since some of it may be database-specific, namely the logic that the display column should be a concatenation of the first two columns that are not of the types Hidden, File, or Password.




Tags:

access:  public


Overridden in child classes as:

MySQL_DatabaseTable::getRefInfo()
Uses the global $tables array (Sitellite CMS specific) to get the primary key, referencing column, display column, and a true or false self-reference value, when given a Ref column name and its corresponding table.
PgSQL_DatabaseTable::getRefInfo()
Uses the global $tables array (Sitellite CMS specific) to get the primary key, referencing column, display column, and a true or false self-reference value, when given a Ref column name and its corresponding table.

Parameters:

string   $name  
string   $table  

[ Top ]

method insert [line 398]

mixed insert( associative $columns)

Creates an INSERT query from the columns provided. Returns the lastid() of the query, or the $columns[$this->pkey] value if there is no sequential key in this table, or false on failure.



Tags:

access:  public


Parameters:

associative   $columns   array $columns

[ Top ]

method update [line 446]

boolean update( mixed $keyval, associative $columns)

Creates an UPDATE query from the $keyval and $columns provided.

Returns true if successful, false on failure.




Tags:

access:  public


Parameters:

mixed   $keyval  
associative   $columns   array $columns

[ Top ]


Copyright © 2007, SIMIAN systems Inc.
All rights reserved. Privacy policy
Documentation generated on Tue, 13 Feb 2007 17:19:45 -0600 by Sitellite AppDoc and phpDocumentor 1.2.2