@@ -1069,11 +1069,12 @@ public function testTinyTextColumn()
10691069 public static function binaryToBlobAutomaticConversionData ()
10701070 {
10711071 return [
1072- // limit, expected type, expected limit
1073- [null , 'binary ' , null ],
1074- [64 , 'binary ' , 255 ],
1072+ // When creating binary with limit > 255, MySQL auto-converts to BLOB
1073+ // input limit, expected SQL type name, expected column limit after round-trip
1074+ [null , 'blob ' , MysqlAdapter::BLOB_REGULAR ], // binary(null) becomes BLOB
1075+ [64 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // binary(64) becomes TINYBLOB
10751076 [MysqlAdapter::BLOB_REGULAR - 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
1076- [MysqlAdapter::BLOB_REGULAR , 'binary ' , null ],
1077+ [MysqlAdapter::BLOB_REGULAR , 'blob ' , MysqlAdapter:: BLOB_REGULAR ],
10771078 [MysqlAdapter::BLOB_REGULAR + 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
10781079 [MysqlAdapter::BLOB_MEDIUM , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
10791080 [MysqlAdapter::BLOB_MEDIUM + 20 , 'longblob ' , MysqlAdapter::BLOB_LONG ],
@@ -1096,11 +1097,12 @@ public function testBinaryToBlobAutomaticConversion(?int $limit, string $expecte
10961097 public static function varbinaryToBlobAutomaticConversionData ()
10971098 {
10981099 return [
1099- // limit, expected type, expected limit
1100- [null , 'binary ' , null ],
1101- [64 , 'binary ' , 255 ],
1100+ // When creating varbinary with limit > 255, MySQL auto-converts to BLOB
1101+ // input limit, expected SQL type name, expected column limit after round-trip
1102+ [null , 'blob ' , MysqlAdapter::BLOB_REGULAR ], // varbinary(null) becomes BLOB
1103+ [64 , 'tinyblob ' , MysqlAdapter::BLOB_TINY ], // varbinary(64) becomes TINYBLOB
11021104 [MysqlAdapter::BLOB_REGULAR - 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
1103- [MysqlAdapter::BLOB_REGULAR , 'binary ' , null ],
1105+ [MysqlAdapter::BLOB_REGULAR , 'blob ' , MysqlAdapter:: BLOB_REGULAR ],
11041106 [MysqlAdapter::BLOB_REGULAR + 20 , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
11051107 [MysqlAdapter::BLOB_MEDIUM , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
11061108 [MysqlAdapter::BLOB_MEDIUM + 20 , 'longblob ' , MysqlAdapter::BLOB_LONG ],
@@ -1123,28 +1125,29 @@ public function testVarbinaryToBlobAutomaticConversion(?int $limit, string $expe
11231125 public static function blobColumnsData ()
11241126 {
11251127 return [
1126- // type, expected type, limit, expected limit
1128+ // BLOB columns with various limits - MySQL auto-selects appropriate BLOB subtype
1129+ // input type, expected SQL type, input limit, expected column limit after round-trip
11271130 // Tiny blobs
1128- ['tinyblob ' , 'binary ' , null , MysqlAdapter::BLOB_TINY ],
1129- ['tinyblob ' , 'binary ' , MysqlAdapter::BLOB_TINY , MysqlAdapter::BLOB_TINY ],
1131+ ['tinyblob ' , 'tinyblob ' , null , MysqlAdapter::BLOB_TINY ],
1132+ ['tinyblob ' , 'tinyblob ' , MysqlAdapter::BLOB_TINY , MysqlAdapter::BLOB_TINY ],
11301133 ['tinyblob ' , 'mediumblob ' , MysqlAdapter::BLOB_TINY + 20 , MysqlAdapter::BLOB_MEDIUM ],
11311134 ['tinyblob ' , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM , MysqlAdapter::BLOB_MEDIUM ],
11321135 ['tinyblob ' , 'longblob ' , MysqlAdapter::BLOB_LONG , MysqlAdapter::BLOB_LONG ],
1133- // // Regular blobs
1134- ['blob ' , 'binary ' , MysqlAdapter::BLOB_TINY , MysqlAdapter::BLOB_TINY ],
1135- ['blob ' , 'binary ' , null , null ],
1136- ['blob ' , 'binary ' , MysqlAdapter::BLOB_REGULAR , null ],
1136+ // Regular blobs
1137+ ['blob ' , 'tinyblob ' , MysqlAdapter::BLOB_TINY , MysqlAdapter::BLOB_TINY ],
1138+ ['blob ' , 'blob ' , null , MysqlAdapter:: BLOB_REGULAR ],
1139+ ['blob ' , 'blob ' , MysqlAdapter::BLOB_REGULAR , MysqlAdapter:: BLOB_REGULAR ],
11371140 ['blob ' , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM , MysqlAdapter::BLOB_MEDIUM ],
11381141 ['blob ' , 'longblob ' , MysqlAdapter::BLOB_LONG , MysqlAdapter::BLOB_LONG ],
1139- // // medium blobs
1140- ['mediumblob ' , 'binary ' , MysqlAdapter::BLOB_TINY , MysqlAdapter::BLOB_TINY ],
1141- ['mediumblob ' , 'binary ' , MysqlAdapter::BLOB_REGULAR , null ],
1142+ // Medium blobs
1143+ ['mediumblob ' , 'tinyblob ' , MysqlAdapter::BLOB_TINY , MysqlAdapter::BLOB_TINY ],
1144+ ['mediumblob ' , 'blob ' , MysqlAdapter::BLOB_REGULAR , MysqlAdapter:: BLOB_REGULAR ],
11421145 ['mediumblob ' , 'mediumblob ' , null , MysqlAdapter::BLOB_MEDIUM ],
11431146 ['mediumblob ' , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM , MysqlAdapter::BLOB_MEDIUM ],
11441147 ['mediumblob ' , 'longblob ' , MysqlAdapter::BLOB_LONG , MysqlAdapter::BLOB_LONG ],
1145- // long blobs
1146- ['longblob ' , 'binary ' , MysqlAdapter::BLOB_TINY , MysqlAdapter::BLOB_TINY ],
1147- ['longblob ' , 'binary ' , MysqlAdapter::BLOB_REGULAR , null ],
1148+ // Long blobs
1149+ ['longblob ' , 'tinyblob ' , MysqlAdapter::BLOB_TINY , MysqlAdapter::BLOB_TINY ],
1150+ ['longblob ' , 'blob ' , MysqlAdapter::BLOB_REGULAR , MysqlAdapter:: BLOB_REGULAR ],
11481151 ['longblob ' , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM , MysqlAdapter::BLOB_MEDIUM ],
11491152 ['longblob ' , 'longblob ' , null , MysqlAdapter::BLOB_LONG ],
11501153 ['longblob ' , 'longblob ' , MysqlAdapter::BLOB_LONG , MysqlAdapter::BLOB_LONG ],
@@ -1163,6 +1166,42 @@ public function testblobColumns(string $type, string $expectedType, ?int $limit,
11631166 $ this ->assertSame ($ expectedLimit , $ columns [1 ]->getLimit ());
11641167 }
11651168
1169+ public static function blobRoundTripData ()
1170+ {
1171+ return [
1172+ // type, limit, expected type after round-trip, expected limit after round-trip
1173+ ['blob ' , null , 'blob ' , MysqlAdapter::BLOB_REGULAR ],
1174+ ['blob ' , MysqlAdapter::BLOB_REGULAR , 'blob ' , MysqlAdapter::BLOB_REGULAR ],
1175+ ['tinyblob ' , null , 'tinyblob ' , MysqlAdapter::BLOB_TINY ],
1176+ ['mediumblob ' , null , 'mediumblob ' , MysqlAdapter::BLOB_MEDIUM ],
1177+ ['longblob ' , null , 'longblob ' , MysqlAdapter::BLOB_LONG ],
1178+ ];
1179+ }
1180+
1181+ #[DataProvider('blobRoundTripData ' )]
1182+ public function testBlobRoundTrip (string $ type , ?int $ limit , string $ expectedType , int $ expectedLimit )
1183+ {
1184+ // Create a table with a BLOB column
1185+ $ table = new Table ('blob_round_trip_test ' , [], $ this ->adapter );
1186+ $ table ->addColumn ('blob_col ' , $ type , ['limit ' => $ limit ])
1187+ ->save ();
1188+
1189+ // Read the column back from the database
1190+ $ columns = $ this ->adapter ->getColumns ('blob_round_trip_test ' );
1191+
1192+ $ blobColumn = $ columns [1 ];
1193+ $ this ->assertNotNull ($ blobColumn , 'BLOB column not found ' );
1194+ $ this ->assertSame ($ expectedType , $ blobColumn ->getType (), 'Type mismatch after round-trip ' );
1195+ $ this ->assertSame ($ expectedLimit , $ blobColumn ->getLimit (), 'Limit mismatch after round-trip ' );
1196+
1197+ // Verify that the SQL type is correct
1198+ $ sqlType = $ this ->adapter ->getSqlType ($ blobColumn ->getType (), $ blobColumn ->getLimit ());
1199+ $ this ->assertSame ($ type , $ sqlType ['name ' ]);
1200+
1201+ // Clean up
1202+ $ this ->adapter ->dropTable ('blob_round_trip_test ' );
1203+ }
1204+
11661205 public function testBigIntegerColumn ()
11671206 {
11681207 $ table = new Table ('t ' , [], $ this ->adapter );
@@ -1289,7 +1328,7 @@ public static function columnsProvider()
12891328 ['column9 ' , 'time ' , []],
12901329 ['column10 ' , 'timestamp ' , []],
12911330 ['column11 ' , 'date ' , []],
1292- ['column12 ' , 'binary ' , []],
1331+ ['column12 ' , 'blob ' , []], // binary with no limit becomes BLOB in MySQL
12931332 ['column13 ' , 'boolean ' , ['comment ' => 'Lorem ipsum ' ]],
12941333 ['column14 ' , 'string ' , ['limit ' => 10 ]],
12951334 ['column16 ' , 'geometry ' , []],
0 commit comments