Ferreteria/v2/usage/db/records: Difference between revisions

From Woozle Writes Code
< Ferreteria‎ | v2‎ | usage‎ | db
Jump to navigation Jump to search
(saving work for now)
 
m (5 revisions imported: moving this project here)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
The routines for writing data from a recordset object back to the database are simple by default but can be overridden in several ways behind the scenes.
The top layer of routines for writing data from a recordset object back to the database is pretty simple and consists of two main functions:
* table: <code>public function Insert(array $arData)</code>
* table: <code>public function Update(array $arChg,$sqlWhere,$isNativeData=FALSE)</code>
* recordset: <code>public function Update(array $arChg,$isNativeData=FALSE)</code>


''documentation in progress''
The <code>Save()</code> function adds some automation by detecting whether an Insert() or Update() is needed and automatically figuring out which fields need to be written (and only updating those fields, to minimize database server usage). This involves several additional functions, some of which are intended to be overridden:
* <code>protected function FigureSQL_forInsert(array $arData)</code>
* <code>public function FigureSQL_forUpdate(array $arChg,$sqlWhere,$isNativeData=self::KFMT_NATIVE)</code>
* <code>public function ChangeFieldValues(array $ar)</code>
* <code>public function GetStorableValues_Changed()</code>
* <code>public function GetStorableValues_toInsert()</code> defaults to <code>GetStorableValues_Changed()</code>
* <code>public function GetStorableValues_toUpdate()</code> defaults to <code>GetStorableValues_Changed()</code>
* <code>public function GetInsertStorageOverrides()</code> defaults to array()
* <code>public function GetUpdateStorageOverrides()</code> defaults to array()
 
Notes:
* All of the override functions currently output in '''stored''' format (typically SQL) rather than raw/native '''value''' format, so strings must be escaped and quoted.
* [[../../forms|Forms]] don't currently use the Recordset version of <code>Save()</code> but implement their own version (<code>public function SaveRecord(array $arStor)</code>), which is why these functions need to be public. Possibly this methodology should be re-examined; if it's necessary, document why.
==Method Index==
==Method Index==
* <code>ftName_forTable</code>
* <code>ftName_forTable</code>
Line 9: Line 24:
** <code>public function Insert(array $arData)</code>
** <code>public function Insert(array $arData)</code>
** <code>public function Update(array $arChg,$sqlWhere,$isNativeData=FALSE)</code>
** <code>public function Update(array $arChg,$sqlWhere,$isNativeData=FALSE)</code>
* <code>trait ftSaveableRecord</code>
** <code>protected function TouchField($sKey)</code>
** <code>protected function TouchedArray()</code>
** <code>public function ChangeFieldValues(array $ar)</code>
** <code>public function GetStorableValues_Changed()</code>
** <code>public function GetStorableValues_toInsert()</code> defaults to <code>GetStorableValues_Changed()</code>
** <code>public function GetStorableValues_toUpdate()</code> defaults to <code>GetStorableValues_Changed()</code>
** <code>public function GetInsertStorageOverrides()</code> defaults to array()
** <code>public function GetUpdateStorageOverrides()</code> defaults to array()
** <code>public function SetFieldValue($sKey,$val)</code> adds call to TouchField()
** <code>public function Save($arSave=NULL)</code>

Latest revision as of 16:45, 22 May 2022

The top layer of routines for writing data from a recordset object back to the database is pretty simple and consists of two main functions:

  • table: public function Insert(array $arData)
  • table: public function Update(array $arChg,$sqlWhere,$isNativeData=FALSE)
  • recordset: public function Update(array $arChg,$isNativeData=FALSE)

The Save() function adds some automation by detecting whether an Insert() or Update() is needed and automatically figuring out which fields need to be written (and only updating those fields, to minimize database server usage). This involves several additional functions, some of which are intended to be overridden:

  • protected function FigureSQL_forInsert(array $arData)
  • public function FigureSQL_forUpdate(array $arChg,$sqlWhere,$isNativeData=self::KFMT_NATIVE)
  • public function ChangeFieldValues(array $ar)
  • public function GetStorableValues_Changed()
  • public function GetStorableValues_toInsert() defaults to GetStorableValues_Changed()
  • public function GetStorableValues_toUpdate() defaults to GetStorableValues_Changed()
  • public function GetInsertStorageOverrides() defaults to array()
  • public function GetUpdateStorageOverrides() defaults to array()

Notes:

  • All of the override functions currently output in stored format (typically SQL) rather than raw/native value format, so strings must be escaped and quoted.
  • Forms don't currently use the Recordset version of Save() but implement their own version (public function SaveRecord(array $arStor)), which is why these functions need to be public. Possibly this methodology should be re-examined; if it's necessary, document why.

Method Index

  • ftName_forTable
    • protected function FigureSQL_forInsert(array $arData)
    • public function FigureSQL_forUpdate(array $arChg,$sqlWhere,$isNativeData=self::KFMT_NATIVE)
  • trait ftWriteableTable
    • public function Insert(array $arData)
    • public function Update(array $arChg,$sqlWhere,$isNativeData=FALSE)
  • trait ftSaveableRecord
    • protected function TouchField($sKey)
    • protected function TouchedArray()
    • public function ChangeFieldValues(array $ar)
    • public function GetStorableValues_Changed()
    • public function GetStorableValues_toInsert() defaults to GetStorableValues_Changed()
    • public function GetStorableValues_toUpdate() defaults to GetStorableValues_Changed()
    • public function GetInsertStorageOverrides() defaults to array()
    • public function GetUpdateStorageOverrides() defaults to array()
    • public function SetFieldValue($sKey,$val) adds call to TouchField()
    • public function Save($arSave=NULL)