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

Class: DBA_Driver_File

Source Location: /DBA-1.1.1/DBA/Driver/File.php

Class Overview

PEAR
   |
   --DBA
      |
      --DBA_Driver_File

DBA_Driver_File provides a simple, file-based implementation of a


Author(s):

  • Brent Cook

Version:

  • 1.0

Methods


Inherited Variables

Inherited Methods

Class: DBA

DBA::DBA()
Default constructor
DBA::create()
Creates a new DBA object
DBA::db_drop()
Deletes a DBA database from the filesystem
DBA::db_exists()
Returns whether a database exists
DBA::errorMessage()
Return a textual error message for a DBA error code
DBA::getDriverList()
Returns an array of the currently supported drivers
DBA::isError()
Returns whether a result code from a DBA method is an error
DBA::raiseError()
This method is used to communicate an error and invoke error callbacks etc. Basically a wrapper for PEAR::raiseError without the message string.

Class Details

[line 79]
DBA_Driver_File provides a simple, file-based implementation of a

DBM-style database. It uses two files, and index and a data file to manage key/value pairs. These two files use the suffixes '.dat' and '.idx'. When a database is opened, only the index file is read. The index file contains pointers to locations within the data file, which are used to retrieve values.

The class uses a concept of blocks for data storage. When the first value is inserted, a new block is created by appending to the data file. If that value is deleted, it remains in the data file, but is marked as empty in the index file. A list of available blocks is kept, so when a new value is inserted, its size is compared to the list of available blocks. If one is of sufficient size, it is reused and marked as used in the index file. Blocks can be of any length.

In updating the index, lines are simply appended to the file after each operation. So, the index file might have the same block listed multiple time , just in different states. When the database is closed, it rewrites the index file, removing and duplicate entries for a single block. The index reader only uses the last entry for a block from the index file, so if close is not called for some reason, the index file is still in a valid state.

The optimize function merely removes duplicated index entries by rewriting the file, the same as close. The sync function calls fflush on the data and index files.

  • Author: Brent Cook
  • Version: 1.0
  • Access: public


[ Top ]


Method Detail

DBA_Driver_File (Constructor)   [line 125]

DBA_Driver_File DBA_Driver_File( [ $indexed = true])


Parameters:

   $indexed   — 

[ Top ]

close   [line 237]

object PEAR_Error close( )

Closes an open database.
  • Return: on failure
  • Access: public

[ Top ]

create   [line 637]

object PEAR_Error create( string $dbName)

Creates a new database file if one does not exist. If it already exists, updates the last-updated timestamp on the database
  • Return: on failure
  • Access: public

Overrides DBA::create() (Creates a new DBA object)

Parameters:

string   $dbName   —  the database to create

[ Top ]

db_drop   [line 667]

object PEAR_Error db_drop( string $dbName)

Removes a database from existence
  • Return: on failure
  • Access: public

Overrides DBA::db_drop() (Deletes a DBA database from the filesystem)

Parameters:

string   $dbName   —  the database name to drop

[ Top ]

db_exists   [line 653]

boolean db_exists( string $dbName)

Indicates whether a database with given name exists
  • Return: true if the database exists, false if it doesn't
  • Access: public

Overrides DBA::db_exists() (Returns whether a database exists)

Parameters:

string   $dbName   —  the database name to check for existence

[ Top ]

drop   [line 688]

object PEAR_Error drop( )

Removes the last open database from existence
  • Return: on failure
  • Access: public

[ Top ]

exists   [line 703]

boolean exists( string $key)

Check whether key exists
  • Return: true if the key exists, false if it doesn't
  • Access: public

Parameters:

string   $key   — 

[ Top ]

fetch   [line 377]

mixed &fetch( string $key)

Returns the value that is stored at $key.
  • Return: the requested value on success, false on failure
  • Access: public

Parameters:

string   $key   —  key to examine

[ Top ]

firstkey   [line 399]

mixed firstkey( )

Returns the first key in the database
  • Return: string on success, false on failure
  • Access: public

[ Top ]

getkeys   [line 436]

mixed getkeys( )

Returns all keys in the database
  • Return: array
  • Access: public

[ Top ]

getName   [line 302]

string getName( )

Returns the name of the opened database. Assumes database is open
  • Return: the name of the opened database

[ Top ]

insert   [line 473]

object PEAR_Error insert( string $key, string $value)

Inserts a new value at $key. Will not overwrite if the key/value pair already exist
  • Return: on failure
  • Access: public

Parameters:

string   $key   —  key to insert
string   $value   —  value to store

[ Top ]

isOpen   [line 315]

boolean isOpen( )

Returns the current open status for the database
  • Return: true if the database is open, false if it is closed
  • Access: public

[ Top ]

isReadable   [line 328]

boolean isReadable( )

Returns the current read status for the database
  • Return: true if the database is readable, false if it is not
  • Access: public

[ Top ]

isWritable   [line 341]

boolean isWritable( )

Returns the current write status for the database
  • Return: true if the database is writable, false if it is not
  • Access: public

[ Top ]

nextkey   [line 417]

mixed nextkey( )

Returns the next key in the database, false if there is a problem
  • Return: string on success, false on failure
  • Access: public

[ Top ]

open   [line 149]

object PEAR_Error open( [string $dbName = ''], [string $mode = 'r'], [boolean $persistent = false])

Opens a database.
  • Return: on failure
  • Access: public

Parameters:

string   $dbName   —  The name of a database
string   $mode   —  The mode in which to open a database. 'r' opens read-only. 'w' opens read-write. 'n' creates a new database and opens read-write. 'c' creates a new database if the database does not exist and opens read-write.
boolean   $persistent   —  Determines whether to open the database peristently. Not supported here.

[ Top ]

optimize   [line 728]

void optimize( )

Optimizes an open database
  • Access: public

[ Top ]

remove   [line 355]

object PEAR_Error remove( string $key)

Removes the value at location $key
  • Return: on failure
  • Access: public

Parameters:

string   $key   —  key to remove

[ Top ]

reopen   [line 265]

object PEAR_Error reopen( string $mode)

Reopens an already open database in read-only or write mode.

If the database is already in the requested mode, then this function does nothing.

  • Return: on failure
  • Access: public

Parameters:

string   $mode   —  'r' for read-only, 'w' for read/write

[ Top ]

replace   [line 494]

object PEAR_Error replace( $key $key, $val $value)

Inserts a new value at key. If the key/value pair already exist, overwrites the value
  • Return: on failure
  • Access: public

Parameters:

$key   $key   —  string the key to insert
$val   $value   —  string the value to store

[ Top ]

size   [line 453]

int size( )

Calculates the size of the database in number of keys
  • Return: number of keys in the database
  • Access: public

[ Top ]

sync   [line 714]

void sync( )

Synchronizes an open database to disk
  • Access: public

[ Top ]


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