DBA
[ class tree: DBA ] [ index: DBA ] [ all elements ]

Class: DBA_Table

Source Location: /DBA_Relational-0.2.0/Table.php

Class Overview

PEAR
   |
   --DBA_Table

DBA Table This class provides a table storage object.


Author(s):

Version:

  • 0.20

Methods


Inherited Variables

Inherited Methods


Class Details

[line 98]
DBA Table This class provides a table storage object.

It uses a DBA storage object as returned by DBA::create(). This class is used extensively in DBA_Relational as part of a complete, relational database system.

Enough functionality exists within this class to create and delete tables, insert, retrieve, remove and validate data based on a table schema, and perform basic database operations such as selects, projects and sorts.



[ Top ]


Method Detail

DBA_Table (Constructor)   [line 160]

DBA_Table DBA_Table( [string $driver = 'file'])

Constructor

Parameters:

string   $driver   —  dba driver to use for storage

[ Top ]

close   [line 235]

object PEAR_Error close( )

Closes a table
  • Return: on failure
  • Access: public

[ Top ]

cmpRows   [line 1372]

bool cmpRows( array $a, array $b)

Compares two rows
  • Return: true if they are the same, false if they are not
  • Access: public

Parameters:

array   $a   —  row a
array   $b   —  row b

[ Top ]

create   [line 264]

object PEAR_Error create( string $tableName, array $schema, $driver, [ $format = 'php'])

Creates a new table. Note, this is a static function, and operates independently of a table object. It no longer closes an open table.
  • Return: on failure

Parameters:

string   $tableName   —  name of the table to create
array   $schema   —  field schema for the table
   $driver   — 
   $format   — 

[ Top ]

exists   [line 386]

boolean exists( string $key)

Check if a row with a primary key exists
  • Return: true if the row exists
  • Access: public

Parameters:

string   $key   — 

[ Top ]

fetch   [line 901]

mixed fetch( string $key)

Fetches an existing row from a table
  • Return: PEAR_Error on failure, the row array on success
  • Access: public

Parameters:

string   $key   —  row id to fetch

[ Top ]

fieldExists   [line 435]

boolean fieldExists( $fieldName)

Returns whether a field exists in the current table's schema
  • Return: true if the field exists, false otherwise

Parameters:

   $fieldName   — 

[ Top ]

finalize   [line 956]

mixed finalize( [array $rows = null])

Converts the results from any of the row operations to a 'finalized'

display-ready form. That means that timestamps, sets and enums are converted into strings. This obviously has some consequences if you plan on chaining the results into another row operation, so don't call this unless it is the final operation.

  • Return: PEAR_Error on failure, the row array on success
  • Access: public

Parameters:

array   $rows   —  rows to finalize, if none are specified, returns the whole table

[ Top ]

firstRow   [line 1022]

mixed firstRow( )

Returns the first row in the table. The built-in cursor for the

internal _dba object is used, so no other operations should be performed other than nextRow() if iterating through the rows is the desired operation

  • Return: PEAR_Error on failure, the row array on success or false if there are no elements in the table i.e (firstRow() === false) = table is empty
  • Access: public

[ Top ]

getFieldNames   [line 1076]

array getFieldNames( )

Returns an array of the defined field names in the table
  • Return: the field names in an array
  • Access: public

[ Top ]

getKeys   [line 1059]

mixed getKeys( )

Returns all keys in the table Similar to PostgrSQL's row ID's
  • Return: array
  • Access: public

[ Top ]

getRows   [line 985]

mixed getRows( [array $rowKeys = null])

Returns the specified rows. A multiple-value version of getRow
  • Return: PEAR_Error on failure, the row array on success
  • Access: public

Parameters:

array   $rowKeys   —  keys of rows to get, if none are specified, returns the whole table

[ Top ]

getSchema   [line 355]

mixed getSchema( )

Returns the stored schema for the table
  • Return: an array of the form 'fieldname'=>array(fieldmeta) on success, PEAR_Error on failure
  • Access: public

[ Top ]

insert   [line 778]

mixed insert( array $data)

Inserts a new row in a table
  • Return: PEAR_Error on failure, the row index on success
  • Access: public

Parameters:

array   $data   —  assoc array or ordered list of data to insert

[ Top ]

isOpen   [line 399]

true isOpen( )

Returns the current open status for the database
  • Return: if the table exists, false otherwise

[ Top ]

isReadable   [line 411]

boolean isReadable( )

Returns the current read status for the database
  • Return: true if the table is readable, false otherwise

[ Top ]

isWritable   [line 423]

boolean isWritable( )

Returns the current write status for the database
  • Return: true if the table is writable, false otherwise

[ Top ]

lockEx   [line 447]

object PEAR_Error lockEx( )

Aquire an exclusive lock on the table
  • Return: on failure

[ Top ]

lockSh   [line 459]

object PEAR_Error lockSh( $table_name)

Aquire a shared lock on the table
  • Return: on failure

Parameters:

   $table_name   — 

[ Top ]

nextRow   [line 1041]

mixed nextRow( )

Returns the next row in the table after a firstRow or nextRow.
  • Return: PEAR_Error on failure, the row array on success or false if there are no more elements in the table
  • Access: public

[ Top ]

open   [line 197]

object PEAR_Error open( string $tableName, [char $mode = 'r'])

Opens a table
  • Return: on failure
  • Access: public

Parameters:

string   $tableName   —  name of the table to open
char   $mode   —  mode to open the table; one of r,w,c,n

[ Top ]

project   [line 1335]

mixed project( array $fields, array $rows)

Projects rows by field. This means that a subset of the possible fields i are in the resulting rows. The SQL analog is 'select fields from table'
  • Return: PEAR_Error on failure, the row array on success
  • Access: public

Parameters:

array   $fields   —  fields to project
array   $rows   —  rows to project

[ Top ]

raiseError   [line 182]

void raiseError( $message)


Parameters:

   $message   — 

[ Top ]

remove   [line 864]

object PEAR_Error remove( string $rawQuery, [array $rows = null])

Removes existing rows from table that match $rawQuery
  • Return: on failure
  • Access: public

Parameters:

string   $rawQuery   —  query expression for performing the remove
array   $rows   —  rows to select on

[ Top ]

removeKey   [line 887]

object PEAR_Error removeKey( string $key)

Removes an existing row from a table, referenced by the row key
  • Return: on failure
  • Access: public

Parameters:

string   $key   —  row id to remove

[ Top ]

replace   [line 808]

object PEAR_Error replace( string $rawQuery, $data, [array $rows = null])

Replaces rows that match $rawQuery with $data
  • Return: on failure
  • Access: public

Parameters:

string   $rawQuery   —  query expression for performing the replace
array   $rows   —  rows to select on
   $data   — 

[ Top ]

replaceKey   [line 839]

mixed replaceKey( string $key, array $data)

Replaces an existing row in a table, inserts if the row does not exist
  • Return: PEAR_Error on failure, the row index on success
  • Access: public

Parameters:

string   $key   —  row id to replace
array   $data   —  assoc array or ordered list of data to insert

[ Top ]

select   [line 1181]

mixed &select( string $rawQuery, [array $rows = null])

Performs a select on a table. This means that a subset of rows in a

table are filtered and returned based on the query. Accepts any valid expression of the form '(field == field) || (field > 3)', etc. Using the expression '*' returns the entire table SQL analog: 'select * from rows where rawQuery'

  • Return: PEAR_Error on failure, the row array on success
  • Access: public

Parameters:

string   $rawQuery   —  query expression for performing the select
array   $rows   —  rows to select on

[ Top ]

sort   [line 1254]

mixed sort( mixed $fields, string $order, array $rows)

Sorts rows by field in either ascending or descending order SQL analog: 'select * from rows, order by fields'
  • Return: PEAR_Error on failure, the row array on success
  • Access: public

Parameters:

mixed   $fields   —  a string with the field name to sort by or an array of fields to sort by in order of preference
string   $order   —  'a' for ascending, 'd' for descending
array   $rows   —  rows to sort

[ Top ]

tableExists   [line 372]

boolean tableExists( string $tableName)

Check whether table exists
  • Return: true if the table exists, false otherwise
  • Access: public

Parameters:

string   $tableName   — 

[ Top ]

unique   [line 1392]

mixed unique( array $rows)

Returns the unique rows from a set of rows
  • Return: PEAR_Error on failure, the row array on success
  • Access: public

Parameters:

array   $rows   —  rows to process

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:59:55 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.