@@ -1454,6 +1454,74 @@ public void QueryAttributeAndParameter(bool prepare)
1454
1454
}
1455
1455
}
1456
1456
1457
+ [ Fact ]
1458
+ public void GetBytesByOrdinal ( )
1459
+ {
1460
+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
1461
+ connection . Open ( ) ;
1462
+ using var cmd = new MySqlCommand ( "select X'0123456789ABCDEF';" , connection ) ;
1463
+ using var reader = cmd . ExecuteReader ( ) ;
1464
+ Assert . True ( reader . Read ( ) ) ;
1465
+
1466
+ Assert . Equal ( 8 , reader . GetBytes ( 0 , 0 , null , 0 , 0 ) ) ;
1467
+ var buffer = new byte [ 10 ] ;
1468
+ #if BASELINE
1469
+ Assert . Throws < IndexOutOfRangeException > ( ( ) => reader . GetBytes ( 0 , - 1 , buffer , 0 , 8 ) ) ;
1470
+ Assert . Throws < IndexOutOfRangeException > ( ( ) => reader . GetBytes ( 0 , 0x1_0000_0000L , buffer , 0 , 8 ) ) ;
1471
+ Assert . Throws < IndexOutOfRangeException > ( ( ) => reader . GetBytes ( 0 , 0 , buffer , - 1 , 8 ) ) ;
1472
+ #else
1473
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => reader . GetBytes ( 0 , - 1 , buffer , 0 , 8 ) ) ;
1474
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => reader . GetBytes ( 0 , 0x1_0000_0000L , buffer , 0 , 8 ) ) ;
1475
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => reader . GetBytes ( 0 , 0 , buffer , - 1 , 8 ) ) ;
1476
+ #endif
1477
+ Assert . Throws < ArgumentException > ( ( ) => reader . GetBytes ( 0 , 0 , buffer , 0 , 11 ) ) ;
1478
+
1479
+ #if BASELINE
1480
+ Assert . Throws < IndexOutOfRangeException > ( ( ) => reader . GetBytes ( 0 , 9 , buffer , 0 , 10 ) ) ;
1481
+ #else
1482
+ Assert . Equal ( 0 , reader . GetBytes ( 0 , 9 , buffer , 0 , 10 ) ) ;
1483
+ #endif
1484
+
1485
+ Assert . Equal ( 8 , reader . GetBytes ( 0 , 0 , buffer , 1 , 9 ) ) ;
1486
+ Assert . Equal ( new byte [ ] { 0 , 0x01 , 0x23 , 0x45 , 0x67 , 0x89 , 0xAB , 0xCD , 0xEF , 0 } , buffer ) ;
1487
+
1488
+ Assert . Equal ( 5 , reader . GetBytes ( 0 , 0 , buffer , 5 , 5 ) ) ;
1489
+ Assert . Equal ( new byte [ ] { 0 , 0x01 , 0x23 , 0x45 , 0x67 , 0x01 , 0x23 , 0x45 , 0x67 , 0x89 } , buffer ) ;
1490
+
1491
+ Assert . Equal ( 5 , reader . GetBytes ( 0 , 3 , buffer , 0 , 5 ) ) ;
1492
+ Assert . Equal ( new byte [ ] { 0x67 , 0x89 , 0xAB , 0xCD , 0xEF , 0x01 , 0x23 , 0x45 , 0x67 , 0x89 } , buffer ) ;
1493
+ }
1494
+
1495
+ #if ! BASELINE
1496
+ [ Fact ]
1497
+ public void GetBytesByName ( )
1498
+ {
1499
+ using var connection = new MySqlConnection ( AppConfig . ConnectionString ) ;
1500
+ connection . Open ( ) ;
1501
+ using var cmd = new MySqlCommand ( "select X'0123456789ABCDEF' as tmp;" , connection ) ;
1502
+ using var reader = cmd . ExecuteReader ( ) ;
1503
+ Assert . True ( reader . Read ( ) ) ;
1504
+
1505
+ Assert . Equal ( 8 , reader . GetBytes ( "tmp" , 0 , null , 0 , 0 ) ) ;
1506
+ var buffer = new byte [ 10 ] ;
1507
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => reader . GetBytes ( "tmp" , - 1 , buffer , 0 , 8 ) ) ;
1508
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => reader . GetBytes ( "tmp" , 0x1_0000_0000L , buffer , 0 , 8 ) ) ;
1509
+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => reader . GetBytes ( "tmp" , 0 , buffer , - 1 , 8 ) ) ;
1510
+ Assert . Throws < ArgumentException > ( ( ) => reader . GetBytes ( "tmp" , 0 , buffer , 0 , 11 ) ) ;
1511
+
1512
+ Assert . Equal ( 0 , reader . GetBytes ( "tmp" , 9 , buffer , 0 , 10 ) ) ;
1513
+
1514
+ Assert . Equal ( 8 , reader . GetBytes ( "tmp" , 0 , buffer , 1 , 9 ) ) ;
1515
+ Assert . Equal ( new byte [ ] { 0 , 0x01 , 0x23 , 0x45 , 0x67 , 0x89 , 0xAB , 0xCD , 0xEF , 0 } , buffer ) ;
1516
+
1517
+ Assert . Equal ( 5 , reader . GetBytes ( "tmp" , 0 , buffer , 5 , 5 ) ) ;
1518
+ Assert . Equal ( new byte [ ] { 0 , 0x01 , 0x23 , 0x45 , 0x67 , 0x01 , 0x23 , 0x45 , 0x67 , 0x89 } , buffer ) ;
1519
+
1520
+ Assert . Equal ( 5 , reader . GetBytes ( "tmp" , 3 , buffer , 0 , 5 ) ) ;
1521
+ Assert . Equal ( new byte [ ] { 0x67 , 0x89 , 0xAB , 0xCD , 0xEF , 0x01 , 0x23 , 0x45 , 0x67 , 0x89 } , buffer ) ;
1522
+ }
1523
+ #endif
1524
+
1457
1525
class BoolTest
1458
1526
{
1459
1527
public int Id { get ; set ; }
0 commit comments