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

From Woozle Writes Code
< Ferreteria‎ | v2‎ | usage‎ | db
Jump to navigation Jump to search
(notes)
m (Woozle moved page Ferreteria/usage/db/records to Ferreteria/v2/usage/db/records without leaving a redirect: this is all v2 documentation)
(No difference)

Revision as of 14:38, 19 January 2019

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)