/** * Get database table info * * @param string $table Table name * @param null $field Filter on field name (not sure) * @param bool $reduce_strings Unquote strings and turns them to integer whenever possible * * @return string[][] Collection of properties */ function getDBstruct($table, $field = null, $reduce_strings = false) { $list_fields = $this->loadList("SHOW COLUMNS FROM `{$table}`"); $fields = array(); foreach ($list_fields as $curr_field) { if (!$field) { continue; } $field_name = $curr_field['Field']; $fields[$field_name] = array(); $_field =& $fields[$field_name]; $props = CMbFieldSpec::parseDBSpec($curr_field['Type']); $_field['type'] = $props['type']; $_field['unsigned'] = $props['unsigned']; $_field['zerofill'] = $props['zerofill']; $_field['null'] = $curr_field['Null'] != 'NO'; $_field['default'] = $curr_field['Default']; $_field['index'] = null; $_field['extra'] = $curr_field['Extra']; if ($reduce_strings && is_array($props['params'])) { foreach ($props['params'] as &$v) { if ($v[0] === "'") { $v = trim($v, "'"); } else { $v = (int) $v; } } } $_field['params'] = $props['params']; if ($field === $field_name) { return $_field; } } return $fields; }
/** * Build SQL spec * * @param bool $union Build full SQL spec * * @return string */ function getSQLSpec($union = true) { $spec_obj = $this->getSpecObject(); $spec_obj->default = null; $db_spec = $spec_obj->getFullDBSpec(); if ($union) { $ds = $this->_spec->ds; $db_parsed = CMbFieldSpec::parseDBSpec($db_spec, true); if ($db_parsed['type'] === "ENUM") { $prop_parsed = $ds->getDBstruct($this->getTableName(), $this->name, true); if (isset($prop_parsed[$this->name])) { $db_parsed['params'] = array_merge($db_parsed['params'], $prop_parsed['params']); } $db_parsed['params'] = array_unique($db_parsed['params']); $spec_obj->list = implode("|", $db_parsed['params']); $db_spec = $spec_obj->getFullDBSpec(); } } return $db_spec; }
$details['fields'][$k]['object']['spec'] = $v; } } // Extraction des champs de la BDD if ($ds && $object->_spec->table && $ds->loadTable($object->_spec->table)) { $details['no_table'] = false; $sql = "SHOW COLUMNS FROM `{$object->_spec->table}`"; $list_fields = $ds->loadList($sql); foreach ($list_fields as $curr_field) { $details['fields'][$curr_field['Field']]['db'] = array(); if (!isset($details['fields'][$curr_field['Field']]['object'])) { $details['fields'][$curr_field['Field']]['object'] = array(); $details['fields'][$curr_field['Field']]['object']['spec'] = null; } $field =& $details['fields'][$curr_field['Field']]['db']; $props = CMbFieldSpec::parseDBSpec($curr_field['Type']); $field['type'] = $props['type']; $field['params'] = $props['params']; $field['unsigned'] = $props['unsigned']; $field['zerofill'] = $props['zerofill']; $field['null'] = $curr_field['Null'] != 'NO'; $field['default'] = $curr_field['Default']; $field['index'] = null; $field['extra'] = $curr_field['Extra']; } // Extraction des Index $sql = "SHOW INDEX FROM `{$object->_spec->table}`"; $list_indexes = $ds->loadList($sql); $duplicates = array_duplicates($list_indexes, 'Column_name'); $details['duplicates'] = $duplicates; foreach ($list_indexes as $curr_index) {