BlueShoes Application Framework made with PHP http://www.blueshoes.org/


Packageindex Classtrees Modulegroups Elementlist Report XML Files

File: C:/usr/local/lib/php/blueshoes-4.2/core/db/Bs_ArrayDb.class.php
BlueShoes Application Framework - db

Bs_ArrayDb

Bs_Object
   |
  +-- Bs_ArrayDb

**********************************************************************

 

public class Bs_ArrayDb extends Bs_Object

**********************************************************************
Array-DB class. makes it possible to execute sql queries on a array.ever had a structured array and wanted to remove some elements, add some, and order it bymultiple columns? it's a nap using this class.---------------------------------------------------------------------------------------------------------example usage:$array = array(array('name' => 'rick lee-morlang', 'birthday' => '31.07.1976', 'city' => 'vancouver', 'bikes' => 7),array('name' => 'chaher viola', 'birthday' => '09.05.1960', 'city' => 'zurich', 'bikes' => 1),array('name' => 'andrej arn', 'birthday' => '05.01.1977', 'city' => 'solothurn', 'bikes' => 0),array('name' => 'sam blume', 'birthday' => '25.12.1964', 'city' => 'pfäffikon zh', 'bikes' => 2),);$adb =& new Bs_ArrayDb();$status = $adb->init($array);if ($status) {dump($adb->query("select * from [array] WHERE bikes >= 1"));}//that is my output:array(3) {[0]=>&array(4) {["name"]=> string(16) "rick lee-morlang"["birthday"]=> string(10) "31.07.1976"["city"]=> string(9) "vancouver"["bikes"]=> string(1) "7"}[1]=>&array(4) {["name"]=> string(12) "chaher viola"["birthday"]=> string(10) "09.05.1960"["city"]=> string(6) "zurich"["bikes"]=> string(1) "1"}[2]=>&array(4) {["name"]=> string(9) "sam blume"["birthday"]=> string(10) "25.12.1964"["city"]=> string(12) "pfäffikon zh"["bikes"]=> string(1) "2"}}---------------------------------------------------------------------------------------------------------

Authors
Version4.0.$Revision: 1.1.1.1 $
Copyrightblueshoes.org

 

Methods inherited from Bs_Object

isex, isexception, tostring, tohtml, persist, unpersist, bs_object, bbsetoutput, bbawake, bbisawake, bbxmsg, bbxfunctionstart, bbxfunctionend, bbxecho, bbxvar, bbxvardump, bbforcetrace, bbbufferstart, bbbufferget, bbbufferendflush, bbbufferendclean

Public Method Summary

void

Bs_ArrayDb()

constructor.
mixed

query(string $sqlQuery)

executes the given sql query on your data.

Private Method Summary

bool

init(array $data)

inits the object with the given data.
array

_determineArrayStructure()

determines the structure of the data array.
bool

_createTempTable(array $struct)

creates the mysql heap table.
bool

_feedDb()

inserts the user data into the newly created database.
string

_createRandomTableName()

creates a random table name, prefixed with 'bs_'.
string

_getInternalFieldName(string $externalFieldName)

converts the external (coder) writing of a field name into our internal one.

Private Field Summary

array

$_dataArray

the data we got from the user in init().
unknown

$_bsDb

the db object that is in use.
string

$_tableName

the db table name.

Private Constant Summary

BS_ARRAYDB_VERSION >>4.0.$x$<< Warning: documentation is missing.

Public Method Details

Bs_ArrayDb

public void Bs_ArrayDb( )

  constructor.

Returns void


query

public mixed query( string $sqlQuery )

  executes the given sql query on your data.
examples:1) "select * from [array]"2) "select * from [array] WHERE bikes >= 1"as you can see you need to call the table name '[array]'.

Parameter
string $sqlQuery
Returns mixed

(hrm...)


Private Method Details

init

private bool init( array $data )

  inits the object with the given data.

Parameter
array $data
Returns bool

(TRUE on success and the object is ready to take queries, FALSE otherwise.)


_determineArrayStructure

private array _determineArrayStructure( )

  determines the structure of the data array.
returned value:hash where key is the field name, value is an array (hash again) with the keys:'type' => one of 'number' or 'string'. 'number' only if all elements are numeric.'size' => the length (number of chars) of the longest value.

Returns array

(hash, see above)


_createTempTable

private bool _createTempTable( array $struct )

  creates the mysql heap table.

Parameter
array $struct
(result from _determineArrayStructure())
Returns bool

(status)


_feedDb

private bool _feedDb( )

  inserts the user data into the newly created database.

Returns bool


_createRandomTableName

private string _createRandomTableName( )

  creates a random table name, prefixed with 'bs_'.

Returns string

See Also $_tableName

_getInternalFieldName

private string _getInternalFieldName( string $externalFieldName )

  converts the external (coder) writing of a field name into our internal one.
all field names are prefixed with 'bs_' internally. otherwise we'd have to checkevery field if it's not a reserved word, and then prefix just some fields. that wouldbe even worse.also we have to deal with other unsupported things like special chars and spaces.

Parameter
string $externalFieldName
Returns string


Private Field Details

$_dataArray

private array $_dataArray

>><<

the data we got from the user in init().


$_bsDb

private unknown $_bsDb

>><<

the db object that is in use.


$_tableName

private string $_tableName

>><<

the db table name.
that is a randomly created name, prefixed with 'bs_'.


Private Constant Details

BS_ARRAYDB_VERSION

define( BS_ARRAYDB_VERSION, >>4.0.$x$<< )
Case: default: case sensitive




Packageindex Classtrees Modulegroups Elementlist Report XML Files
PHPDoc 1.0beta