mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-03 16:51:40 +09:00
Implement getColumnInfo()
This commit is contained in:
parent
58133573b3
commit
47bb30c535
2 changed files with 29 additions and 4 deletions
|
|
@ -813,12 +813,36 @@ class DB
|
|||
*
|
||||
* @param string $table_name
|
||||
* @param string $column_name
|
||||
* @return Parsers\DBTable\Column;
|
||||
* @return object
|
||||
*/
|
||||
public function getColumnInfo(string $table_name, string $column_name): Parsers\DBTable\Column
|
||||
public function getColumnInfo(string $table_name, string $column_name)
|
||||
{
|
||||
// TODO
|
||||
return new Parsers\DBTable\Column;
|
||||
// If column information is not found, return false.
|
||||
$stmt = $this->_query(sprintf("SHOW FIELDS FROM `%s` WHERE Field = '%s'", $this->addQuotes($this->_prefix . $table_name), $this->addQuotes($column_name)));
|
||||
$column_info = $this->_fetch($stmt);
|
||||
if (!$column_info)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reorganize the type information.
|
||||
$dbtype = strtolower($column_info->{'Type'});
|
||||
if (preg_match('/^([a-z0-9_]+)\(([0-9,\s]+)\)$/i', $dbtype, $matches))
|
||||
{
|
||||
$dbtype = $matches[1];
|
||||
$size = $matches[2];
|
||||
}
|
||||
$xetype = Parsers\DBTableParser::getXEType($dbtype, $size ?: '');
|
||||
|
||||
// Return the result as an object.
|
||||
return (object)array(
|
||||
'name' => $column_name,
|
||||
'dbtype' => $dbtype,
|
||||
'xetype' => $xetype,
|
||||
'size' => $size,
|
||||
'default_value' => $column_info->{'Default'},
|
||||
'notnull' => strncmp($column_info->{'Null'}, 'NO', 2) == 0 ? true : false,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -226,6 +226,7 @@ class DBTableParser extends BaseParser
|
|||
*/
|
||||
public static function getXEType(string $type, string $size): string
|
||||
{
|
||||
$type = strtolower($type);
|
||||
switch ($type)
|
||||
{
|
||||
case 'bigint':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue