/** * 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; }
/** * Generates our fixture test data, we need this so we can * loop through our fields array, to ascertain the data type * of each piece of test data. * * @access private * @param Int $numOfFixtures Number of fixtures to generate. * @return Array $results Our fixtures encapsulated in a array. * */ private function _generate($numOfFixtures) { if (0 === count($this->_fields)) { throw new ErrorException('Fields not defined, can not generate without it.'); } if (!is_int($numOfFixtures)) { throw new ErrorException('Must supply number of test data using an integer.'); } $results = array(); $this->_result = array(); for ($i = 0; $i < $numOfFixtures; $i++) { foreach ($this->getFields() as $field => $dataType) { DataTypeChecker::checkDataType($dataType); $this->_parseSchema($field, $dataType); } array_push($results, $this->_result); } return $results; }
/** * 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.'); } }