|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Soluble\Metadata\Reader\Mapping; |
|
6
|
|
|
|
|
7
|
|
|
use Soluble\Datatype\Column; |
|
8
|
|
|
use ArrayObject; |
|
9
|
|
|
|
|
10
|
|
|
class MysqliMapping |
|
11
|
|
|
{ |
|
12
|
4 |
|
public static function getDatatypeMapping(): ArrayObject |
|
13
|
|
|
{ |
|
14
|
|
|
/* |
|
15
|
|
|
// ALL the following fields are not supported yet |
|
16
|
|
|
// Maybe todo in a later release or choose to map them to approximative |
|
17
|
|
|
// types |
|
18
|
|
|
MYSQLI_TYPE_YEAR -> int |
|
19
|
|
|
MYSQLI_TYPE_ENUM -> string |
|
20
|
|
|
MYSQLI_TYPE_SET -> string |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
4 |
|
$mapping = new ArrayObject([ |
|
24
|
4 |
|
MYSQLI_TYPE_STRING => ['type' => Column\Type::TYPE_STRING, 'native' => 'VARCHAR'], |
|
25
|
4 |
|
MYSQLI_TYPE_CHAR => ['type' => Column\Type::TYPE_STRING, 'native' => 'CHAR'], |
|
26
|
4 |
|
MYSQLI_TYPE_VAR_STRING => ['type' => Column\Type::TYPE_STRING, 'native' => 'VARCHAR'], |
|
27
|
4 |
|
MYSQLI_TYPE_ENUM => ['type' => Column\Type::TYPE_STRING, 'native' => 'ENUM'], |
|
28
|
|
|
// BLOBS ARE CURRENTLY SENT AS TEXT |
|
29
|
|
|
// I DIDN'T FIND THE WAY TO MAKE THE DIFFERENCE !!! |
|
30
|
4 |
|
MYSQLI_TYPE_TINY_BLOB => ['type' => Column\Type::TYPE_BLOB, 'native' => 'TINYBLOB'], |
|
31
|
4 |
|
MYSQLI_TYPE_MEDIUM_BLOB => ['type' => Column\Type::TYPE_BLOB, 'native' => 'MEDIUMBLOB'], |
|
32
|
4 |
|
MYSQLI_TYPE_LONG_BLOB => ['type' => Column\Type::TYPE_BLOB, 'native' => 'LONGBLOB'], |
|
33
|
4 |
|
MYSQLI_TYPE_BLOB => ['type' => Column\Type::TYPE_BLOB, 'native' => 'BLOB'], |
|
34
|
|
|
// integer |
|
35
|
4 |
|
MYSQLI_TYPE_TINY => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'TINYINT'], |
|
36
|
4 |
|
MYSQLI_TYPE_YEAR => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'YEAR'], |
|
37
|
4 |
|
MYSQLI_TYPE_SHORT => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'SMALLINT'], |
|
38
|
4 |
|
MYSQLI_TYPE_INT24 => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'MEDIUMINT'], |
|
39
|
4 |
|
MYSQLI_TYPE_LONG => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'INTEGER'], |
|
40
|
4 |
|
MYSQLI_TYPE_LONGLONG => ['type' => Column\Type::TYPE_INTEGER, 'native' => 'BIGINT'], |
|
41
|
|
|
// timestamps |
|
42
|
4 |
|
MYSQLI_TYPE_TIMESTAMP => ['type' => Column\Type::TYPE_DATETIME, 'native' => 'TIMESTAMP'], |
|
43
|
4 |
|
MYSQLI_TYPE_DATETIME => ['type' => Column\Type::TYPE_DATETIME, 'native' => 'DATETIME'], |
|
44
|
|
|
// dates |
|
45
|
4 |
|
MYSQLI_TYPE_DATE => ['type' => Column\Type::TYPE_DATE, 'native' => 'DATE'], |
|
46
|
4 |
|
MYSQLI_TYPE_NEWDATE => ['type' => Column\Type::TYPE_DATE, 'native' => 'DATE'], |
|
47
|
|
|
// time |
|
48
|
4 |
|
MYSQLI_TYPE_TIME => ['type' => Column\Type::TYPE_TIME, 'native' => 'TIME'], |
|
49
|
|
|
// decimals |
|
50
|
4 |
|
MYSQLI_TYPE_DECIMAL => ['type' => Column\Type::TYPE_DECIMAL, 'native' => 'DECIMAL'], |
|
51
|
4 |
|
MYSQLI_TYPE_NEWDECIMAL => ['type' => Column\Type::TYPE_DECIMAL, 'native' => 'DECIMAL'], |
|
52
|
4 |
|
MYSQLI_TYPE_FLOAT => ['type' => Column\Type::TYPE_FLOAT, 'native' => 'FLOAT'], |
|
53
|
4 |
|
MYSQLI_TYPE_DOUBLE => ['type' => Column\Type::TYPE_FLOAT, 'native' => 'DOUBLE'], |
|
54
|
4 |
|
MYSQLI_TYPE_BIT => ['type' => Column\Type::TYPE_BIT, 'native' => 'BIT'], |
|
55
|
|
|
//MYSQLI_TYPE_BOOLEAN => array('type' => Column\Type::TYPE_BOOLEAN, 'native' => 'BOOLEAN'), |
|
56
|
4 |
|
MYSQLI_TYPE_GEOMETRY => ['type' => Column\Type::TYPE_SPATIAL_GEOMETRY, 'native' => null], |
|
57
|
|
|
// This type is really annoying, it's when the select contains an aliased null constant |
|
58
|
|
|
// like 'select null as test_alias' |
|
59
|
4 |
|
MYSQLI_TYPE_NULL => ['type' => Column\Type::TYPE_NULL, 'native' => 'NULL'] |
|
60
|
|
|
]); |
|
61
|
|
|
|
|
62
|
4 |
|
return $mapping; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|