| core_storage

# Class: Bs_ObjPersisterForMySql Source Location: /core/storage/objectpersister/Bs_ObjPersisterForMySql.class.php
### Class Overview
    Bs_Object
       |
       --Bs_ObjPersister
          |
          --Bs_ObjPersisterForMySql
dependencies: Bs_ObjPersister, Bs_MySql (which requires Bs_Db) #### Author(s): andrej arn <at blueshoes dot org> Sam Blum <sam at blueshoes dot org> #### Version: 4.3.$Revision: 1.2 $ $Date: 2003/08/09 15:17:49 $ #### Copyright: blueshoes.org | ### Variables $bsDb $_dbName $_dbTableName | ### Methods Bs_ObjPersisterForMySql createTable dropTable persist setDbName setDbTableName unPersist updateTableStructure
### Inherited Variables #### Class: Bs_ObjPersister Bs_ObjPersister::$Bs_Rc4Crypt Bs_ObjPersister::$rc4key Bs_ObjPersister::$_objToPersist Bs_ObjPersister::$_persistInfo | ### Inherited Methods #### Class: Bs_ObjPersister Bs_ObjPersister::Bs_ObjPersister() Constuctor. Bs_ObjPersister::getPersistInfo() Returns a hash with the *cleaned* persist information thst was retrieved from the persist hint hash and by analysing the target object itself. Bs_ObjPersister::isReservedWord() The following words are explicitly reserved in MySQL and most of them are forbidden by ANSI SQL92 Bs_ObjPersister::persist() Persist the object that is handeled by this object. Bs_ObjPersister::setPersisterID() Write back the persisterID to the objToPersist. Bs_ObjPersister::setVarSettings() Set the '_persistInfo hash'. See header for details. Bs_ObjPersister::unPersist() Unpersist the object that is handeled by this object. Bs_ObjPersister::_persistTrigger() Is triggered just befor we try to get the persist data from the object. Bs_ObjPersister::_unpersistTrigger() Is triggered just after we initialized the object successfully. #### Class: Bs_Object Bs_Object::Bs_Object() Bs_Object::getErrors() Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack. Bs_Object::getLastError() Basic error handling: Get last error string from the global Bs_Error-error stack. Bs_Object::getLastErrors() Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors(). Bs_Object::persist() Persists this object by serializing it and saving it to a file with unique name. Bs_Object::setError() Basic error handling: Push an error string on the global Bs_Error-error stack. Bs_Object::toHtml() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::toString() Dumps the content of this object to a string using PHP's var_dump(). Bs_Object::unpersist() Fetches an object that was persisted with persist()
### Class Details [line 21] dependencies: Bs_ObjPersister, Bs_MySql (which requires Bs_Db) subclass of Bs_ObjPersister. #### Tags:
copyright: | blueshoes.org
pattern: | singleton: (pseudostatic)
access: | public
version: | 4.3.$Revision: 1.2 $ $Date: 2003/08/09 15:17:49 $
author: | andrej arn <at blueshoes dot org> Sam Blum <sam at blueshoes dot org>
[ Top ] ### Class Variables #### $bsDb = [line 26] Reference to the db object.
Type: | object
[ Top ] #### $_dbName = [line 34] The database to use. If not specified, the default db from the main db connection will be used. That should be the sites db. #### Tags:
see: | Bs_ObjPersisterForMySql::setDbName()
Type: | string
[ Top ] #### $_dbTableName = [line 41] The db table name to use. #### Tags:
see: | Bs_ObjPersisterForMySql::setDbTableName()
Type: | string
[ Top ] ### Class Methods ### constructor Bs_ObjPersisterForMySql [line 49]
`Bs_ObjPersisterForMySql Bs_ObjPersisterForMySql( object &$obj, [array $varSettings = NULL], [object $dbObject = NULL])`
Constuctor. #### Parameters:
object | &$obj |
array | $varSettings |
object | $dbObject | you can give your own db object here, otherwise the global main connection will be used. (pass it by ref if possible)
[ Top ] ### method createTable [line 160]
`bool createTable( )`
Create the db table. #### Tags:
return: | true on success.
throws: | bs_exception on failure.
access: | public
[ Top ] ### method dropTable [line 143]
`bool dropTable( )`
Drop the db table (if it exists). #### Tags:
return: | true on success
throws: | bs_exception on failure. It's not a failure if the table doesn't exist.
access: | public
[ Top ] ### method persist [line 297]
`bool persist( )`
Persist the desired object data into the db table. if the object data is persisted for the first time, an ID is generated and written back as object var with the name 'persisterID'. !!!note: before the above line said "with the name 'ID'" but i'm sure it's 'persisterID'. !!! --andrej #### Tags:
return: | true on success
throws: | bs_exception on error (db exception)
access: | public
Overrides Bs_ObjPersister::persist() (Persist the object that is handeled by this object.) [ Top ] ### method setDbName [line 67]
`void setDbName( string $string)`
Sets the database name to use. NOTE I: The sites default users need access rights to this db. #### Tags:
see: | var $this->_dbName
access: | public
#### Parameters:
string | $string |
[ Top ] ### method setDbTableName [line 90]
`void setDbTableName( [string $string = NULL])`
Sets the db table name to use. If not specified, the class name of the object (we persist) is used as table name. E.g. if you want to persist an instance of the class Bs_FormFieldText, the tablename will be 'Persist_bs_formfieldtext' (yes, lowercase). see constants. I highly recommend that you prefix your tables with 'Persist_'. NOTE I: The sites default users need access rights to this db table. NOTE II: If you want to set a db name, do it before setting the table name. #### Tags:
see: | var $this->_dbTableName
access: | public
#### Parameters:
string | $string | for default see above
[ Top ] ### method unPersist [line 381]
`bool unPersist( [mixed $sqlSomething = NULL], [bool $fullQuery = FALSE])`
(Get the data from db) and push it into the object. If $sqlSomething is a recordset (hash) it will be used. If it's a string it will be used for the sql query. If NULL, the $persisterID of the object is used to fetch the data. NOTE: Only the first found record set is used. #### Tags:
return: | TRUE on success, FALSE if (no valid ID available and $sqlWhere not given) or no record found.
throws: | bs_exception on a db error.
access: | public
Overrides Bs_ObjPersister::unPersist() (Unpersist the object that is handeled by this object.) #### Parameters:
mixed | $sqlSomething | can be a string (something like "WHERE field = 'value'"), or a hash (recordset) directly, or NULL.
bool | $fullQuery | default is FALSE. if $sqlSomething is a string (and thus a query), this var tells if the query is just a part (like 'WHERE x = 'b') or a full query. this is useful if you want to join multiple tables because of more complex relations.
[ Top ] ### method updateTableStructure [line 240]
`bool updateTableStructure( [bool $checkOnly = FALSE])`
checks if the db table structure is up-to-date and updates what's needed. #### Tags:
return: | TRUE if we have made changes, FALSE if not
todo: | finish this code. it already adds missing fields, but doesn't alter fields that need to be changed.
throws: | bs_exception
access: | public
#### Parameters:
bool | $checkOnly | default is FALSE. if set to true, no changes will be made.
[ Top ] Documentation generated on Mon, 29 Dec 2003 21:12:13 +0100 by phpDocumentor 1.2.3