@@ -21,6 +21,7 @@ class Columns
21
21
* @param string $columnType
22
22
* @param array $columnSchema
23
23
* @param BinaryDataReader $binaryDataReader
24
+ * @throws ConfigException
24
25
* @return array
25
26
*/
26
27
public static function parse ($ columnType , array $ columnSchema , BinaryDataReader $ binaryDataReader )
@@ -31,34 +32,36 @@ public static function parse($columnType, array $columnSchema, BinaryDataReader
31
32
self ::$ field ['collation_name ' ] = $ columnSchema ['COLLATION_NAME ' ];
32
33
self ::$ field ['character_set_name ' ] = $ columnSchema ['CHARACTER_SET_NAME ' ];
33
34
self ::$ field ['comment ' ] = $ columnSchema ['COLUMN_COMMENT ' ];
34
- self ::$ field ['unsigned ' ] = stripos ($ columnSchema ['COLUMN_TYPE ' ], 'unsigned ' ) === false ? false : true ;
35
+ self ::$ field ['unsigned ' ] = !( stripos ($ columnSchema ['COLUMN_TYPE ' ], 'unsigned ' ) === false ) ;
35
36
self ::$ field ['type_is_bool ' ] = false ;
36
37
self ::$ field ['is_primary ' ] = $ columnSchema ['COLUMN_KEY ' ] === 'PRI ' ;
37
38
38
- if (self ::$ field ['type ' ] == ConstFieldType::VARCHAR ) {
39
+ if (self ::$ field ['type ' ] === ConstFieldType::VARCHAR ) {
39
40
self ::$ field ['max_length ' ] = $ binaryDataReader ->readInt16 ();
40
- } elseif (self ::$ field ['type ' ] == ConstFieldType::DOUBLE ) {
41
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::DOUBLE ) {
41
42
self ::$ field ['size ' ] = $ binaryDataReader ->readUInt8 ();
42
- } elseif (self ::$ field ['type ' ] == ConstFieldType::FLOAT ) {
43
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::FLOAT ) {
43
44
self ::$ field ['size ' ] = $ binaryDataReader ->readUInt8 ();
44
- } elseif (self ::$ field ['type ' ] == ConstFieldType::TIMESTAMP2 ) {
45
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::TIMESTAMP2 ) {
45
46
self ::$ field ['fsp ' ] = $ binaryDataReader ->readUInt8 ();
46
- } elseif (self ::$ field ['type ' ] == ConstFieldType::DATETIME2 ) {
47
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::DATETIME2 ) {
47
48
self ::$ field ['fsp ' ] = $ binaryDataReader ->readUInt8 ();
48
- } elseif (self ::$ field ['type ' ] == ConstFieldType::TIME2 ) {
49
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::TIME2 ) {
49
50
self ::$ field ['fsp ' ] = $ binaryDataReader ->readUInt8 ();
50
- } elseif (self ::$ field ['type ' ] == ConstFieldType::TINY && $ columnSchema ['COLUMN_TYPE ' ] === 'tinyint(1) ' ) {
51
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::TINY && $ columnSchema ['COLUMN_TYPE ' ] === 'tinyint(1) ' ) {
51
52
self ::$ field ['type_is_bool ' ] = true ;
52
- } elseif (self ::$ field ['type ' ] == ConstFieldType::VAR_STRING || self ::$ field ['type ' ] == ConstFieldType::STRING ) {
53
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::VAR_STRING || self ::$ field ['type ' ] = == ConstFieldType::STRING ) {
53
54
self ::getFieldSpecial ($ binaryDataReader , $ columnSchema );
54
- } elseif (self ::$ field ['type ' ] == ConstFieldType::BLOB ) {
55
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::BLOB ) {
56
+ self ::$ field ['length_size ' ] = $ binaryDataReader ->readUInt8 ();
57
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::GEOMETRY ) {
55
58
self ::$ field ['length_size ' ] = $ binaryDataReader ->readUInt8 ();
56
- } elseif (self ::$ field ['type ' ] == ConstFieldType::GEOMETRY ) {
59
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::JSON ) {
57
60
self ::$ field ['length_size ' ] = $ binaryDataReader ->readUInt8 ();
58
- } elseif (self ::$ field ['type ' ] == ConstFieldType::NEWDECIMAL ) {
61
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::NEWDECIMAL ) {
59
62
self ::$ field ['precision ' ] = $ binaryDataReader ->readUInt8 ();
60
63
self ::$ field ['decimals ' ] = $ binaryDataReader ->readUInt8 ();
61
- } elseif (self ::$ field ['type ' ] == ConstFieldType::BIT ) {
64
+ } elseif (self ::$ field ['type ' ] === ConstFieldType::BIT ) {
62
65
$ bits = $ binaryDataReader ->readUInt8 ();
63
66
$ bytes = $ binaryDataReader ->readUInt8 ();
64
67
self ::$ field ['bits ' ] = ($ bytes * 8 ) + $ bits ;
@@ -77,7 +80,7 @@ private static function getFieldSpecial(BinaryDataReader $packet, array $columnS
77
80
{
78
81
$ metadata = ($ packet ->readUInt8 () << 8 ) + $ packet ->readUInt8 ();
79
82
$ real_type = $ metadata >> 8 ;
80
- if ($ real_type == ConstFieldType::SET || $ real_type == ConstFieldType::ENUM ) {
83
+ if ($ real_type === ConstFieldType::SET || $ real_type = == ConstFieldType::ENUM ) {
81
84
self ::$ field ['type ' ] = $ real_type ;
82
85
self ::$ field ['size ' ] = $ metadata & 0x00ff ;
83
86
self ::getFieldSpecialValues ($ columnSchema );
@@ -92,9 +95,9 @@ private static function getFieldSpecial(BinaryDataReader $packet, array $columnS
92
95
*/
93
96
private static function getFieldSpecialValues (array $ columnSchema )
94
97
{
95
- if (self ::$ field ['type ' ] == ConstFieldType::ENUM ) {
98
+ if (self ::$ field ['type ' ] === ConstFieldType::ENUM ) {
96
99
self ::$ field ['enum_values ' ] = explode (', ' , str_replace (['enum( ' , ') ' , '\'' ], '' , $ columnSchema ['COLUMN_TYPE ' ]));
97
- } else if (self ::$ field ['type ' ] == ConstFieldType::SET ) {
100
+ } else if (self ::$ field ['type ' ] === ConstFieldType::SET ) {
98
101
self ::$ field ['set_values ' ] = explode (', ' , str_replace (['set( ' , ') ' , '\'' ], '' , $ columnSchema ['COLUMN_TYPE ' ]));
99
102
} else {
100
103
throw new ConfigException ('Type not handled! - ' . self ::$ field ['type ' ]);
0 commit comments