public static function setsStatement($tableName, $data, $db = null) { if ($db == null) { $db = self::$_db; } $struct = Lms_Item_Store::getStruct($tableName); $columns = $struct->getColumns(); $sets = array(); foreach ($columns as $fieldName => $meta) { if (array_key_exists($fieldName, $data)) { $statement = $db->escape($fieldName, true) . '='; if ($data[$fieldName] === null) { $statement .= 'NULL'; } else { switch ($meta['escape']) { case Lms_Item_Struct::ESCAPE_AS_INT: $statement .= intval($data[$fieldName]); break; case Lms_Item_Struct::ESCAPE_AS_FLOAT: $statement .= str_replace(',', '.', floatval($data[$fieldName])); break; case Lms_Item_Struct::ESCAPE_AS_STRING: default: $statement .= $db->escape($data[$fieldName]); break; } } $sets[] = $statement; } } return implode(', ', $sets); }
public function getStruct() { return Lms_Item_Store::getStruct($this->getTableName()); }
public static function getStruct($itemName) { $tableName = self::getTableName($itemName); return Lms_Item_Store::getStruct($tableName); }
private static function _fillData($tableName, $rows, $foreignKey) { $newScalarPKs = array(); if (!count($rows)) { return $newScalarPKs; } $struct = Lms_Item_Store::getStruct($tableName); $pk = $struct->getPk(); for ($i = count($rows) - 1; $i >= 0; $i--) { if (is_array($pk)) { $assocPK = array(); foreach ($pk as $pkFieldName) { $assocPK[$pkFieldName] = $rows[$i][$pkFieldName]; } $scalarPk = Lms_Item_Scalar::scalarize($assocPK); } else { $scalarPk = $rows[$i][$pk]; } $newScalarPKs[] = $scalarPk; Lms_Item_Store::setValues($tableName, $scalarPk, $rows[$i], true); if ($foreignKey && isset($rows[$i][$foreignKey])) { $indexKey = $rows[$i][$foreignKey]; Lms_Item_Store::setIndexStatus($tableName, $foreignKey, $indexKey, Lms_Item_Struct::FULL_INDEX); } } Lms_Item_Store::rebuildIndex($tableName); return $newScalarPKs; }