/** * Returns SQL types string. * Type specification chars: * i - corresponding variable has type integer * d - corresponding variable has type double * s - corresponding variable has type string * b - corresponding variable is a blob and will be sent in packets * * @param array<mixed> $fieldsList List of the table fields (syntax: array[fieldName] = fieldValue) * @param string $idFieldName Name of the primary key field. * @return string */ public static function sqlTypesString($fieldsList, $idFieldName = "") { $typesString = ""; foreach ($fieldsList as $fieldName => $fieldValue) { if ($fieldName != $idFieldName) { if (Tools::isDouble($fieldValue)) { $typesString .= "d"; } elseif (Tools::isInteger($fieldValue)) { $typesString .= "i"; } else { $typesString .= "s"; } } } return $typesString; }
/** * Returns type of the parameter by value. * * @param mixed $fieldValue * * @return string Types of the parameter ("idsb"). * @throws DBFieldTypeException If can't detect field type by value. */ public static function getType($fieldValue) { if (Tools::isInteger($fieldValue)) { return "i"; } elseif (Tools::isDouble($fieldValue)) { return "d"; } elseif (Tools::isBoolean($fieldValue)) { return "b"; } elseif (Tools::isString($fieldValue)) { return "s"; } else { throw new DBFieldTypeException("Invalid field value type"); } }
/** * Returns type of the parameter by value. * * @param mixed $fieldValue * * @return string Types of the parameter ("idsb"). * @throws DBFieldTypeException If can't detect field type by value. */ public static function getType($fieldValue) { if (is_null($fieldValue)) { // Type is not principled for NULL return "i"; } elseif (Tools::isInteger($fieldValue)) { return "i"; } elseif (Tools::isDouble($fieldValue)) { return "d"; } elseif (Tools::isBoolean($fieldValue)) { return "b"; } elseif (Tools::isString($fieldValue)) { return "s"; } else { throw new DBFieldTypeException("Can't detect field value type for value '" . (string) $fieldValue . "'"); } }