|
@@ -80,6 +80,7 @@ trait TraitDatabase
|
|
|
$data = array(
|
|
|
'table' => $table,
|
|
|
'fields' => array(),
|
|
|
+ 'fields_type' => array(),
|
|
|
'rules' => array(
|
|
|
'pri' => array(),
|
|
|
'required' => array()
|
|
@@ -98,20 +99,37 @@ trait TraitDatabase
|
|
|
while ($row = $rs->fetch()) {
|
|
|
$data['fields'][] = $row['COLUMN_NAME'];
|
|
|
$data['type'][$row['DATA_TYPE']][] = $row['COLUMN_NAME'];
|
|
|
+ $fieldsType = array();
|
|
|
+ $fieldsType['type'] = strtolower($row['DATA_TYPE']);
|
|
|
+ $fieldsType['is_pri'] = false;
|
|
|
+ $fieldsType['is_uni'] = false;
|
|
|
+ $fieldsType['is_null'] = true;
|
|
|
+ $fieldsType['is_number'] = false;
|
|
|
+ $fieldsType['is_float'] = false;
|
|
|
+ $fieldsType['is_decimal'] = false;
|
|
|
+ $fieldsType['is_timestamp'] = false;
|
|
|
+ $fieldsType['is_set'] = false;
|
|
|
+ $fieldsType['default'] = false;
|
|
|
+ $fieldsType['comment'] = '';
|
|
|
if ($row['EXTRA']) {
|
|
|
$data['rules']['extra'][$row['EXTRA']][] = $row['COLUMN_NAME'];
|
|
|
+ $fieldsType['extra'] = $row['EXTRA'];
|
|
|
}
|
|
|
if ($row['COLUMN_KEY'] == 'PRI') {
|
|
|
$data['rules']['pri'][] = $row['COLUMN_NAME'];
|
|
|
$data['rules']['required'][] = $row['COLUMN_NAME'];
|
|
|
+ $fieldsType['is_pri'] = true;
|
|
|
} else if($row['COLUMN_KEY'] == 'UNI'){
|
|
|
//$data['rules']['uni'][] = $row['COLUMN_NAME'];
|
|
|
$data['rules']['required'][] = $row['COLUMN_NAME'];
|
|
|
+ $fieldsType['is_uni'] = true;
|
|
|
}else if ($row['IS_NULLABLE'] == 'NO') {
|
|
|
$data['rules']['required'][] = $row['COLUMN_NAME'];
|
|
|
+ $fieldsType['is_null'] = false;
|
|
|
}
|
|
|
if (in_array($row['DATA_TYPE'], array('varchar', 'char'))) {
|
|
|
$data['rules']['maxlength'][$row['COLUMN_NAME']] = $row['CHARACTER_MAXIMUM_LENGTH'];
|
|
|
+ $fieldsType['maxlength'] = $row['CHARACTER_MAXIMUM_LENGTH'];
|
|
|
}
|
|
|
if (in_array($row['DATA_TYPE'], array('mediumtext', 'tinytext', 'text', 'longtext'))) {
|
|
|
$data['rules']['text'][] = $row['COLUMN_NAME'];
|
|
@@ -121,26 +139,34 @@ trait TraitDatabase
|
|
|
if(!empty($matches)) {
|
|
|
$data['rules']['int'][$row['COLUMN_NAME']] = isset($matches[0]) && $matches[0] ? $matches[0] : $maxRange[$row['DATA_TYPE']];
|
|
|
$data['rules']['number'][] = $row['COLUMN_NAME'];
|
|
|
+ $fieldsType['is_number'] = true;
|
|
|
}
|
|
|
}
|
|
|
if (in_array($row['DATA_TYPE'], array('float', 'double'))) {
|
|
|
$data['rules']['float'][$row['COLUMN_NAME']] = $this->getValueFromBrackets($row['COLUMN_TYPE']);
|
|
|
+ $fieldsType['is_float'] = true;
|
|
|
}
|
|
|
if (in_array($row['DATA_TYPE'], array('decimal'))) {
|
|
|
$data['rules']['decimal'][$row['COLUMN_NAME']] = $this->getValueFromBrackets($row['COLUMN_TYPE']);
|
|
|
+ $fieldsType['is_decimal'] = true;
|
|
|
}
|
|
|
if (in_array($row['DATA_TYPE'], array('timestamp', 'datetime'))) {
|
|
|
$data['rules']['timestamp'][] = $row['COLUMN_NAME'];
|
|
|
+ $fieldsType['is_timestamp'] = true;
|
|
|
}
|
|
|
if (in_array($row['DATA_TYPE'], array('enum', 'set'))) {
|
|
|
$data['rules']['sets'][$row['COLUMN_NAME']] = $this->getValueFromBrackets($row['COLUMN_TYPE']);
|
|
|
+ $fieldsType['is_set'] = true;
|
|
|
}
|
|
|
if (isset($row['COLUMN_DEFAULT'])) {
|
|
|
$data['rules']['default'][$row['COLUMN_NAME']] = $row['COLUMN_DEFAULT'];
|
|
|
+ $fieldsType['default'] = $row['COLUMN_DEFAULT'];
|
|
|
}
|
|
|
if(isset($row['COLUMN_COMMENT'])) {
|
|
|
$data['comment'][$row['COLUMN_NAME']] = $row['COLUMN_COMMENT'];
|
|
|
+ $fieldsType['comment'] = $row['COLUMN_COMMENT'];
|
|
|
}
|
|
|
+ $data['fields_type'][$row['COLUMN_NAME']] = $fieldsType;
|
|
|
}
|
|
|
|
|
|
$sql = "SELECT * FROM information_schema.KEY_COLUMN_USAGE WHERE table_name = '" . $table . "'";
|