Welcome Guest, Not a member yet? Register   Sign In
Change Request for Database\MySQLi getFieldData function
#1

Good day.
I would like to suggest a change to the getFieldData function. I wanted to post via github but dunno the best method, thus hope this will help.
Basically the type value comes back as a numeric, but in SQlite and Postgres it comes back as a word that describe the type. Thus my suggestion will be to use the following code to map it.

I would also like to suggest that one considers to also return the
length
value that comes back from the mysqli , I have not added that yet, but if one can it will actually help my current project alot.
Thank you, hope it helps somebody

Code:
public function getFieldData(): array
{
static $data_types = [
MYSQLI_TYPE_DECIMAL => 'decimal',
MYSQLI_TYPE_NEWDECIMAL => 'newdecimal',
MYSQLI_TYPE_FLOAT => 'float',
MYSQLI_TYPE_DOUBLE => 'double',
MYSQLI_TYPE_BIT => 'bit',
MYSQLI_TYPE_TINY => 'tiny',
MYSQLI_TYPE_SHORT => 'short',
MYSQLI_TYPE_LONG => 'long',
MYSQLI_TYPE_LONGLONG => 'longlong',
MYSQLI_TYPE_INT24 => 'int24',
MYSQLI_TYPE_YEAR => 'year',
MYSQLI_TYPE_ENUM => 'enum',
MYSQLI_TYPE_TIMESTAMP => 'timestamp',
MYSQLI_TYPE_DATE => 'date',
MYSQLI_TYPE_TIME => 'time',
MYSQLI_TYPE_DATETIME => 'datetime',
MYSQLI_TYPE_NEWDATE => 'newdate',
MYSQLI_TYPE_INTERVAL => 'interval',
MYSQLI_TYPE_SET => 'set',
MYSQLI_TYPE_VAR_STRING => 'var_string',
MYSQLI_TYPE_STRING => 'string',
MYSQLI_TYPE_CHAR => 'char',
MYSQLI_TYPE_GEOMETRY => 'geometry',
MYSQLI_TYPE_TINY_BLOB => 'tiny_blob',
MYSQLI_TYPE_MEDIUM_BLOB => 'medium_blob',
MYSQLI_TYPE_LONG_BLOB => 'long_blob',
MYSQLI_TYPE_BLOB => 'blob',
];

$retVal    = [];
$fieldData = $this->resultID->fetch_fields();

foreach ($fieldData as $i => $data)
{
$retVal[$i]              = new \stdClass();
$retVal[$i]->name        = $data->name;
$retVal[$i]->type        = $data_types[$data->type];
$retVal[$i]->max_length  = $data->max_length;
$retVal[$i]->primary_key = (int) ($data->flags & 2);
$retVal[$i]->default    = $data->def;
}

return $retVal;
}
Reply
#2

I added a change request for this if people are happy with it
https://github.com/codeigniter4/CodeIgniter4/pull/3273
Reply




Theme © iAndrew 2016 - Forum software by © MyBB