/** * Converts a Datatype array into SQL. * We only are only creating these one at a time * so we need to make sure we only have 1 array. * * @access public * @param Array $dataTypeInfo Our data type array, which will be used to create our SQL. * @param String $tablename The name of our DB table. * @return String $stmt Portion of SQL, which will be used to construct query. * */ public function convertDataType($dataTypeInfo, $tablename = 'default') { if (!is_array($dataTypeInfo)) { throw new ErrorException('DataType is invalid.'); } $stmt = 'CREATE TABLE ' . $tablename . ' ('; $query = ''; foreach ($dataTypeInfo as $field => $dataType) { DataTypeChecker::checkDataType($dataType); $data = $this->_checkDataTypes($dataType); $query .= $field . $data . ', '; } // remove the trailing ', ' and replace with ');' $stmt .= eregi_replace(', $', ');', $query); return $stmt; }
/** * Sets PHPUnit_Fixture's field property. * * @access public * @param Array $fields The Fields we want to set for our fixture. * @return bool True if set, false otherwise. * */ public function setFields(array $fields) { if (0 === count($fields)) { throw new ErrorException('Illegal field format.'); } foreach ($fields as $name => $data) { if (!is_string($name)) { throw new ErrorException('Field name must be a string.'); } if (!is_array($data)) { throw new ErrorException('Data must be in an associative array.'); } DataTypeChecker::validateDataTypeFields($data); } $this->_fields = $fields; return true; }
/** * Checks our field types for us, strings & integer must have a length. * * @access public * @param Array $fixture The fixture we want to check. * */ static function checkFieldsType($fixture) { DataTypeChecker::checkDataType($fixture); if ($fixture['type'] === 'integer' || $fixture['type'] === 'string') { if (!array_key_exists('length', $fixture)) { throw new ErrorException('String & Integer must have a length specified.'); } } elseif ('date' === $fixture['type'] || 'datetime' === $fixture['type']) { } else { throw new ErrorException('Invalid data type.'); } }