@@ -280,6 +280,122 @@ public Task ExecuteReaderAsync_WhenEmptyList_ReturnEmptyResultSet() => RunTestWi
280280 Assert . False ( await reader . ReadAsync ( ) ) ;
281281 } ) ;
282282
283+ [ Fact ]
284+ public Task Write_ReadRowValue_When_Date32_Datetime64_Timestamp64_Interval64_WithGetInt32_GetInt64 ( ) =>
285+ RunTestWithTemporaryTable ( """
286+ CREATE TABLE `{0}` (
287+ Id Serial,
288+ Date32Column Date32,
289+ Datetime64Column Datetime64,
290+ Timestamp64Column Timestamp64,
291+ Interval64Column Interval64,
292+ PRIMARY KEY (Id)
293+ )
294+ """ , $ "ReadRowValue_ExtendedDateTypes_{ Guid . NewGuid ( ) } ",
295+ async ( ydbConnection , tableName ) =>
296+ {
297+ const int minDate32 = - 53375809 ;
298+ const long minDatetime64 = - 4611669897600 ;
299+ const long minTimestamp64 = - 4611669897600000000 ;
300+ const int maxDate32 = 53375807 ;
301+ const long maxDatetime64 = 4611669811199 ;
302+ const long maxTimestamp64 = 4611669811199999999 ;
303+ const long maxInterval64 = maxTimestamp64 - minTimestamp64 ;
304+
305+ await new YdbCommand ( $ """
306+ INSERT INTO `{ tableName } `
307+ (Date32Column, Datetime64Column, Timestamp64Column, Interval64Column)
308+ VALUES
309+ (@Date32Min, @Datetime64Min, @Timestamp64Min, @Interval64Min),
310+ (@Date32Max, @Datetime64Max, @Timestamp64Max, @Interval64Max);
311+ """ ,
312+ ydbConnection )
313+ {
314+ Parameters =
315+ {
316+ new YdbParameter ( "@Date32Min" , YdbDbType . Date32 , minDate32 ) ,
317+ new YdbParameter ( "@Datetime64Min" , YdbDbType . Datetime64 , minDatetime64 ) ,
318+ new YdbParameter ( "@Timestamp64Min" , YdbDbType . Timestamp64 , minTimestamp64 ) ,
319+ new YdbParameter ( "@Interval64Min" , YdbDbType . Interval64 , - maxInterval64 ) ,
320+ new YdbParameter ( "@Date32Max" , YdbDbType . Date32 , maxDate32 ) ,
321+ new YdbParameter ( "@Datetime64Max" , YdbDbType . Datetime64 , maxDatetime64 ) ,
322+ new YdbParameter ( "@Timestamp64Max" , YdbDbType . Timestamp64 , maxTimestamp64 ) ,
323+ new YdbParameter ( "@Interval64Max" , YdbDbType . Interval64 , maxInterval64 )
324+ }
325+ } . ExecuteNonQueryAsync ( ) ;
326+
327+ var ydbDataReader = await new YdbCommand (
328+ $ """
329+ SELECT Date32Column, Datetime64Column, Timestamp64Column, Interval64Column
330+ FROM `{ tableName } ` ORDER BY Id
331+ """ , ydbConnection ) . ExecuteReaderAsync ( ) ;
332+
333+ await ydbDataReader . ReadAsync ( ) ;
334+ Assert . Equal ( minDate32 , ydbDataReader . GetInt32 ( 0 ) ) ;
335+ Assert . Throws < OverflowException > ( ( ) => ydbDataReader . GetDateTime ( 0 ) ) ;
336+ Assert . Equal ( minDatetime64 , ydbDataReader . GetInt64 ( 1 ) ) ;
337+ Assert . Throws < OverflowException > ( ( ) => ydbDataReader . GetDateTime ( 1 ) ) ;
338+ Assert . Equal ( minTimestamp64 , ydbDataReader . GetInt64 ( 2 ) ) ;
339+ Assert . Throws < OverflowException > ( ( ) => ydbDataReader . GetDateTime ( 2 ) ) ;
340+ Assert . Equal ( - maxInterval64 , ydbDataReader . GetInt64 ( 3 ) ) ;
341+ Assert . Throws < OverflowException > ( ( ) => ydbDataReader . GetInterval ( 3 ) ) ;
342+
343+ await ydbDataReader . ReadAsync ( ) ;
344+ Assert . Equal ( maxDate32 , ydbDataReader . GetInt32 ( 0 ) ) ;
345+ Assert . Throws < OverflowException > ( ( ) => ydbDataReader . GetDateTime ( 0 ) ) ;
346+ Assert . Equal ( maxDatetime64 , ydbDataReader . GetInt64 ( 1 ) ) ;
347+ Assert . Throws < OverflowException > ( ( ) => ydbDataReader . GetDateTime ( 1 ) ) ;
348+ Assert . Equal ( maxTimestamp64 , ydbDataReader . GetInt64 ( 2 ) ) ;
349+ Assert . Throws < OverflowException > ( ( ) => ydbDataReader . GetDateTime ( 2 ) ) ;
350+ Assert . Equal ( maxInterval64 , ydbDataReader . GetInt64 ( 3 ) ) ;
351+ Assert . Throws < OverflowException > ( ( ) => ydbDataReader . GetInterval ( 3 ) ) ;
352+
353+ Assert . False ( await ydbDataReader . ReadAsync ( ) ) ;
354+
355+ Assert . Equal ( 2ul , await new YdbCommand (
356+ $ """
357+ SELECT COUNT(*) FROM `{ tableName } ` WHERE
358+ Date32Column IN @Date32List AND
359+ Datetime64Column IN @Datetime64List AND
360+ Timestamp64Column IN @Timestamp64List AND
361+ Interval64Column IN @Interval64List;
362+ """ , ydbConnection )
363+ {
364+ Parameters =
365+ {
366+ new YdbParameter ( "@Date32List" , YdbDbType . List | YdbDbType . Date32 ,
367+ new [ ] { minDate32 , maxDate32 } ) ,
368+ new YdbParameter ( "@Datetime64List" , YdbDbType . List | YdbDbType . Datetime64 ,
369+ new [ ] { minDatetime64 , maxDatetime64 } ) ,
370+ new YdbParameter ( "@Timestamp64List" , YdbDbType . List | YdbDbType . Timestamp64 ,
371+ new [ ] { minTimestamp64 , maxTimestamp64 } ) ,
372+ new YdbParameter ( "@Interval64List" , YdbDbType . List | YdbDbType . Interval64 ,
373+ new [ ] { - maxInterval64 , maxInterval64 } )
374+ }
375+ } . ExecuteScalarAsync ( ) ) ;
376+ }
377+ ) ;
378+
379+ [ Fact ]
380+ public async Task OutsideOfDateTime_ThrowsArgumentOutOfRangeException ( )
381+ {
382+ await using var ydbConnection = await CreateOpenConnectionAsync ( ) ;
383+ var ydbDataReader = await new YdbCommand ( """
384+ SELECT
385+ CAST(-1000000 AS Date32),
386+ CAST(-100000000000 AS Datetime64),
387+ CAST(-100000000000000000 AS Timestamp64)
388+ """ , ydbConnection ) . ExecuteReaderAsync ( ) ;
389+
390+ await ydbDataReader . ReadAsync ( ) ;
391+ Assert . Equal ( - 1000000 , ydbDataReader . GetInt32 ( 0 ) ) ;
392+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => ydbDataReader . GetDateTime ( 0 ) ) ;
393+ Assert . Equal ( - 100000000000 , ydbDataReader . GetInt64 ( 1 ) ) ;
394+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => ydbDataReader . GetDateTime ( 1 ) ) ;
395+ Assert . Equal ( - 100000000000000000 , ydbDataReader . GetInt64 ( 2 ) ) ;
396+ Assert . Throws < ArgumentOutOfRangeException > ( ( ) => ydbDataReader . GetDateTime ( 2 ) ) ;
397+ }
398+
283399 public static readonly TheoryData < DbType , object , bool > DbTypeTestCases = new ( )
284400 {
285401 { DbType . Boolean , true , false } ,
0 commit comments