@@ -227,6 +227,12 @@ public void TestQueryAllDataTypes()
227227 Console . WriteLine ( $ "Value mismatch: Got '{ gotTimestamp . ToString ( format ) } ', Want: '{ wantTimestamp . ToString ( format ) } '") ;
228228 return ;
229229 }
230+ if ( ! reader . GetFieldValue < NpgsqlInterval > ( ++ index ) . Equals ( new NpgsqlInterval ( 14 , 3 , 14400000000L + 300000000L + 6789000L ) ) )
231+ {
232+ NpgsqlInterval interval = reader . GetFieldValue < NpgsqlInterval > ( index ) ;
233+ Console . WriteLine ( $ "Value mismatch: Got '{ interval . Months } M{ interval . Days } DT{ interval . Time } MU', Want: 'P1Y2M3DT4H5M6.789S'") ;
234+ return ;
235+ }
230236 if ( reader . GetDateTime ( ++ index ) != DateTime . Parse ( "2022-03-29" ) )
231237 {
232238 Console . WriteLine ( $ "Value mismatch: Got '{ reader . GetDateTime ( index ) } ', Want: '2022-03-29'") ;
@@ -287,8 +293,8 @@ public void TestInsertAllDataTypes()
287293 connection . Open ( ) ;
288294
289295 var sql =
290- "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_date, col_varchar, col_jsonb)"
291- + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)" ;
296+ "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_interval, col_date, col_varchar, col_jsonb)"
297+ + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 )" ;
292298 using var cmd = new NpgsqlCommand ( sql , connection )
293299 {
294300 Parameters =
@@ -301,6 +307,7 @@ public void TestInsertAllDataTypes()
301307 new ( ) { Value = 100 } ,
302308 new ( ) { Value = 6.626m } ,
303309 new ( ) { Value = DateTime . Parse ( "2022-03-24T08:39:10.1234568+02:00" ) . ToUniversalTime ( ) , DbType = DbType . DateTimeOffset } ,
310+ new ( ) { Value = new NpgsqlInterval ( 14 , 3 , 14400000000L + 300000000L + 6789000L ) } ,
304311 new ( ) { Value = DateTime . Parse ( "2022-04-02" ) , DbType = DbType . Date } ,
305312 new ( ) { Value = "test_string" } ,
306313 new ( ) { Value = JsonDocument . Parse ( "{\" key\" :\" value\" }" ) } ,
@@ -322,8 +329,8 @@ public void TestInsertNullsAllDataTypes()
322329
323330 var sql =
324331 "INSERT INTO all_types "
325- + "(col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_date, col_varchar, col_jsonb) "
326- + "values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)" ;
332+ + "(col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_interval, col_date, col_varchar, col_jsonb) "
333+ + "values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 )" ;
327334 using var cmd = new NpgsqlCommand ( sql , connection )
328335 {
329336 Parameters =
@@ -339,6 +346,7 @@ public void TestInsertNullsAllDataTypes()
339346 new ( ) { Value = DBNull . Value } ,
340347 new ( ) { Value = DBNull . Value } ,
341348 new ( ) { Value = DBNull . Value } ,
349+ new ( ) { Value = DBNull . Value } ,
342350 }
343351 } ;
344352 var updateCount = cmd . ExecuteNonQuery ( ) ;
@@ -356,8 +364,8 @@ public void TestInsertAllDataTypesReturning()
356364 connection . Open ( ) ;
357365
358366 var sql =
359- "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_date, col_varchar, col_jsonb)"
360- + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) returning *" ;
367+ "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_interval, col_date, col_varchar, col_jsonb)"
368+ + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 ) returning *" ;
361369 using var cmd = new NpgsqlCommand ( sql , connection )
362370 {
363371 Parameters =
@@ -370,6 +378,7 @@ public void TestInsertAllDataTypesReturning()
370378 new ( ) { Value = 100 } ,
371379 new ( ) { Value = 6.626m } ,
372380 new ( ) { Value = DateTime . Parse ( "2022-02-16T13:18:02.123456789Z" ) . ToUniversalTime ( ) , DbType = DbType . DateTimeOffset } ,
381+ new ( ) { Value = new NpgsqlInterval ( 14 , 3 , 14400000000L + 300000000L + 6789000L ) } ,
373382 new ( ) { Value = DateTime . Parse ( "2022-03-29" ) , DbType = DbType . Date } ,
374383 new ( ) { Value = "test" } ,
375384 new ( ) { Value = JsonDocument . Parse ( "{\" key\" :\" value\" }" ) } ,
@@ -428,6 +437,12 @@ public void TestInsertAllDataTypesReturning()
428437 Console . WriteLine ( $ "Timestamp value mismatch: Got '{ gotTimestamp . ToString ( format ) } ', Want: '{ wantTimestamp . ToString ( format ) } '") ;
429438 return ;
430439 }
440+ if ( ! reader . GetFieldValue < NpgsqlInterval > ( ++ index ) . Equals ( new NpgsqlInterval ( 14 , 3 , 14400000000L + 300000000L + 6789000L ) ) )
441+ {
442+ NpgsqlInterval interval = reader . GetFieldValue < NpgsqlInterval > ( index ) ;
443+ Console . WriteLine ( $ "Value mismatch: Got '{ interval . Months } M{ interval . Days } DT{ interval . Time } MU', Want: 'P1Y2M3DT4H5M6.789S'") ;
444+ return ;
445+ }
431446 if ( reader . GetDateTime ( ++ index ) != DateTime . Parse ( "2022-03-29" ) )
432447 {
433448 Console . WriteLine ( $ "Date value mismatch: Got '{ reader . GetDateTime ( index ) } ', Want: '2022-03-29'") ;
@@ -454,8 +469,8 @@ public void TestInsertBatch()
454469 connection . Open ( ) ;
455470
456471 var sql =
457- "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_date, col_varchar, col_jsonb)"
458- + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)" ;
472+ "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_interval, col_date, col_varchar, col_jsonb)"
473+ + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 )" ;
459474
460475 var batchSize = 10 ;
461476 using var batch = new NpgsqlBatch ( connection ) ;
@@ -473,6 +488,7 @@ public void TestInsertBatch()
473488 new ( ) { Value = i } ,
474489 new ( ) { Value = i + 0.123m } ,
475490 new ( ) { Value = DateTime . Parse ( $ "2022-03-24 { i : D2} :39:10.123456000+00") . ToUniversalTime ( ) , DbType = DbType . DateTimeOffset } ,
491+ new ( ) { Value = new NpgsqlInterval ( 14 , 3 , 14400000000L + 300000000L + 6789000L ) } ,
476492 new ( ) { Value = DateTime . Parse ( $ "2022-04-{ i + 1 : D2} ") , DbType = DbType . Date } ,
477493 new ( ) { Value = "test_string" + i } ,
478494 new ( ) { Value = JsonDocument . Parse ( $ "{{\" key\" :\" value{ i } \" }}") } ,
@@ -494,8 +510,8 @@ public void TestMixedBatch()
494510 connection . Open ( ) ;
495511
496512 var sql =
497- "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_date, col_varchar, col_jsonb)"
498- + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)" ;
513+ "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_interval, col_date, col_varchar, col_jsonb)"
514+ + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 )" ;
499515
500516 var batchSize = 5 ;
501517 using var batch = new NpgsqlBatch ( connection ) ;
@@ -513,6 +529,7 @@ public void TestMixedBatch()
513529 new ( ) { Value = i } ,
514530 new ( ) { Value = i + 0.123m } ,
515531 new ( ) { Value = DateTime . Parse ( $ "2022-03-24 { i : D2} :39:10.123456000+00") . ToUniversalTime ( ) , DbType = DbType . DateTimeOffset } ,
532+ new ( ) { Value = new NpgsqlInterval ( 14 , 3 , 14400000000L + 300000000L + 6789000L ) } ,
516533 new ( ) { Value = DateTime . Parse ( $ "2022-04-{ i + 1 : D2} ") , DbType = DbType . Date } ,
517534 new ( ) { Value = "test_string" + i } ,
518535 new ( ) { Value = JsonDocument . Parse ( $ "{{\" key\" :\" value{ i } \" }}") } ,
@@ -580,8 +597,8 @@ public void TestBatchExecutionError()
580597 connection . Open ( ) ;
581598
582599 var sql =
583- "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_date, col_varchar, col_jsonb)"
584- + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)" ;
600+ "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_interval, col_date, col_varchar, col_jsonb)"
601+ + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 )" ;
585602
586603 var batchSize = 3 ;
587604 using var batch = new NpgsqlBatch ( connection ) ;
@@ -599,6 +616,7 @@ public void TestBatchExecutionError()
599616 new ( ) { Value = i } ,
600617 new ( ) { Value = i + 0.123m } ,
601618 new ( ) { Value = DateTime . Parse ( $ "2022-03-24 { i : D2} :39:10.123456000+00") . ToUniversalTime ( ) , DbType = DbType . DateTimeOffset } ,
619+ new ( ) { Value = new NpgsqlInterval ( 14 , 3 , 14400000000L + 300000000L + 6789000L ) } ,
602620 new ( ) { Value = DateTime . Parse ( $ "2022-04-{ i + 1 : D2} ") , DbType = DbType . Date } ,
603621 new ( ) { Value = "test_string" + i } ,
604622 new ( ) { Value = JsonDocument . Parse ( $ "{{\" key\" :\" value{ i } \" }}") } ,
@@ -941,6 +959,17 @@ public void TestBinaryCopyOut()
941959 reader . Skip ( ) ;
942960 }
943961 else
962+ {
963+ var interval = reader . Read < NpgsqlInterval > ( NpgsqlDbType . Interval ) ;
964+ Console . Write ( $ "{ interval . Months } M{ interval . Days } DT{ interval . Time } ") ;
965+ }
966+ Console . Write ( "\t " ) ;
967+ if ( reader . IsNull )
968+ {
969+ Console . Write ( "NULL" ) ;
970+ reader . Skip ( ) ;
971+ }
972+ else
944973 {
945974 Console . Write ( reader . Read < DateTime > ( NpgsqlDbType . Date ) . ToString ( "yyyyMMdd" ) ) ;
946975 }
@@ -1057,6 +1086,17 @@ public void TestBinaryCopyOut()
10571086 reader . Skip ( ) ;
10581087 }
10591088 else
1089+ {
1090+ var intervals = reader . Read < List < NpgsqlInterval ? > > ( NpgsqlDbType . Array | NpgsqlDbType . Interval ) ;
1091+ Console . Write ( "[" + string . Join ( ", " , intervals . Select ( d => d == null ? "NULL" : $ "{ d . Value . Months } M{ d . Value . Days } DT{ d . Value . Time } ") ) + "]" ) ;
1092+ }
1093+ Console . Write ( "\t " ) ;
1094+ if ( reader . IsNull )
1095+ {
1096+ Console . Write ( "NULL" ) ;
1097+ reader . Skip ( ) ;
1098+ }
1099+ else
10601100 {
10611101 var dates = reader . Read < List < DateTime ? > > ( NpgsqlDbType . Array | NpgsqlDbType . Date ) ;
10621102 Console . Write ( "[" + string . Join ( ", " , dates . Select ( d => d ? . ToString ( "yyyyMMdd" ) ) ) + "]" ) ;
@@ -1130,8 +1170,8 @@ public void TestPrepareAndExecute()
11301170 for ( var i = 0 ; i < 2 ; i ++ )
11311171 {
11321172 var sql =
1133- "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_date, col_varchar, col_jsonb)"
1134- + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)" ;
1173+ "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_interval, col_date, col_varchar, col_jsonb)"
1174+ + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 )" ;
11351175 var cmd = new NpgsqlCommand ( sql , connection ) ;
11361176#pragma warning disable CS8625
11371177 cmd . Parameters . Add ( null , NpgsqlDbType . Bigint ) ;
@@ -1142,6 +1182,7 @@ public void TestPrepareAndExecute()
11421182 cmd . Parameters . Add ( null , NpgsqlDbType . Integer ) ;
11431183 cmd . Parameters . Add ( null , NpgsqlDbType . Numeric ) ;
11441184 cmd . Parameters . Add ( null , NpgsqlDbType . TimestampTz ) ;
1185+ cmd . Parameters . Add ( null , NpgsqlDbType . Interval ) ;
11451186 cmd . Parameters . Add ( null , NpgsqlDbType . Date ) ;
11461187 cmd . Parameters . Add ( null , NpgsqlDbType . Varchar ) ;
11471188 cmd . Parameters . Add ( null , NpgsqlDbType . Jsonb ) ;
@@ -1157,6 +1198,7 @@ public void TestPrepareAndExecute()
11571198 cmd . Parameters [ index ++ ] . Value = 100 ;
11581199 cmd . Parameters [ index ++ ] . Value = 6.626m ;
11591200 cmd . Parameters [ index ++ ] . Value = DateTime . Parse ( "2022-03-24T08:39:10.1234568+02:00" ) . ToUniversalTime ( ) ;
1201+ cmd . Parameters [ index ++ ] . Value = new NpgsqlInterval ( 14 , 3 , 14400000000L + 300000000L + 6789000L ) ;
11601202 cmd . Parameters [ index ++ ] . Value = DateTime . Parse ( "2022-04-02" ) ;
11611203 cmd . Parameters [ index ++ ] . Value = "test_string" ;
11621204 cmd . Parameters [ index ++ ] . Value = JsonDocument . Parse ( "{\" key\" :\" value\" }" ) ;
@@ -1193,8 +1235,8 @@ public void TestReadWriteTransaction()
11931235 }
11941236
11951237 var insertSql =
1196- "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_date, col_varchar, col_jsonb)"
1197- + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11)" ;
1238+ "INSERT INTO all_types (col_bigint, col_bool, col_bytea, col_float4, col_float8, col_int, col_numeric, col_timestamptz, col_interval, col_date, col_varchar, col_jsonb)"
1239+ + " values ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12 )" ;
11981240 foreach ( var id in new [ ] { 10 , 20 } )
11991241 {
12001242 using var insertCommand = new NpgsqlCommand ( insertSql , connection )
@@ -1213,6 +1255,7 @@ public void TestReadWriteTransaction()
12131255 Value = DateTime . Parse ( "2022-03-24T08:39:10.1234568+02:00" ) . ToUniversalTime ( ) ,
12141256 DbType = DbType . DateTimeOffset
12151257 } ,
1258+ new ( ) { Value = new NpgsqlInterval ( 14 , 3 , 14400000000L + 300000000L + 6789000L ) } ,
12161259 new ( ) { Value = DateTime . Parse ( "2022-04-02" ) , DbType = DbType . Date } ,
12171260 new ( ) { Value = "test_string" } ,
12181261 new ( ) { Value = JsonDocument . Parse ( "{\" key\" :\" value\" }" ) } ,
0 commit comments