8
8
using System . IO ;
9
9
using System . Linq ;
10
10
using System . Numerics ;
11
+ using Dapper ;
11
12
12
13
namespace DuckDB . NET . Test ;
13
14
@@ -83,8 +84,7 @@ public void CommonTypes()
83
84
public void UnicodeTests ( )
84
85
{
85
86
var words = new List < string > { "hello" , "안녕하세요" , "Ø3mm CHAIN" , null , "" } ;
86
- var table = "CREATE TABLE UnicodeAppenderTestTable (index INTEGER, words VARCHAR);" ;
87
- Command . CommandText = table ;
87
+ Command . CommandText = "CREATE TABLE UnicodeAppenderTestTable (index INTEGER, words VARCHAR);" ;
88
88
Command . ExecuteNonQuery ( ) ;
89
89
90
90
using ( var appender = Connection . CreateAppender ( "UnicodeAppenderTestTable" ) )
@@ -157,8 +157,7 @@ public void ByteArray()
157
157
[ Fact ]
158
158
public void Decimals ( )
159
159
{
160
- var table = "CREATE TABLE managedAppenderDecimals(a INTEGER, b decimal(3, 1), c decimal (9, 4), d decimal (18, 6), e decimal(38, 12));" ;
161
- Command . CommandText = table ;
160
+ Command . CommandText = "CREATE TABLE managedAppenderDecimals(a INTEGER, b decimal(3, 1), c decimal (9, 4), d decimal (18, 6), e decimal(38, 12));" ;
162
161
Command . ExecuteNonQuery ( ) ;
163
162
164
163
var rows = 20 ;
@@ -194,8 +193,7 @@ public void Decimals()
194
193
[ Fact ]
195
194
public void GuidValues ( )
196
195
{
197
- var table = "CREATE TABLE managedAppenderGuids(a UUID);" ;
198
- Command . CommandText = table ;
196
+ Command . CommandText = "CREATE TABLE managedAppenderGuids(a UUID);" ;
199
197
Command . ExecuteNonQuery ( ) ;
200
198
201
199
var guids = Enumerable . Range ( 0 , 20 ) . Select ( i => ( Guid ? ) Guid . NewGuid ( ) ) . ToList ( ) ;
@@ -209,19 +207,14 @@ public void GuidValues()
209
207
}
210
208
}
211
209
212
- Command . CommandText = "SELECT * FROM managedAppenderGuids" ;
213
- using ( var reader = Command . ExecuteReader ( ) )
214
- {
215
- var result = reader . Cast < IDataRecord > ( ) . Select ( record => record . IsDBNull ( 0 ) ? ( Guid ? ) null : record . GetGuid ( 0 ) ) . ToList ( ) ;
216
- result . Should ( ) . BeEquivalentTo ( guids ) ;
217
- }
210
+ var result = Connection . Query < Guid ? > ( "SELECT * FROM managedAppenderGuids" ) ;
211
+ result . Should ( ) . BeEquivalentTo ( guids ) ;
218
212
}
219
213
220
214
[ Fact ]
221
215
public void IntervalValues ( )
222
216
{
223
- var table = "CREATE TABLE managedAppenderInterval(a INTERVAL);" ;
224
- Command . CommandText = table ;
217
+ Command . CommandText = "CREATE TABLE managedAppenderInterval(a INTERVAL);" ;
225
218
Command . ExecuteNonQuery ( ) ;
226
219
227
220
var timeSpans = Enumerable . Range ( 0 , 20 ) . Select ( i => TimeSpan . FromSeconds ( Random . Shared . Next ( 1_000_000 , 1_000_000 * 10 ) ) ) . ToList ( ) ;
@@ -234,13 +227,39 @@ public void IntervalValues()
234
227
}
235
228
}
236
229
237
- Command . CommandText = "SELECT * FROM managedAppenderInterval" ;
238
- using ( var reader = Command . ExecuteReader ( ) )
239
- {
240
- var result = reader . Cast < IDataRecord > ( ) . Select ( record => ( TimeSpan ) record . GetValue ( 0 ) ) . ToList ( ) ;
230
+ var result = Connection . Query < TimeSpan > ( "SELECT * FROM managedAppenderInterval" ) ;
231
+
232
+ result . Should ( ) . BeEquivalentTo ( timeSpans ) ;
233
+ }
241
234
242
- result . Should ( ) . BeEquivalentTo ( timeSpans ) ;
235
+ [ Fact ]
236
+ public void TemporalValues ( )
237
+ {
238
+ Command . CommandText = "CREATE TABLE managedAppenderTemporal(a Date, b TimeStamp, c TIMESTAMP_NS, d TIMESTAMP_MS, e TIMESTAMP_S, f TIMESTAMPTZ);" ;
239
+ Command . ExecuteNonQuery ( ) ;
240
+
241
+ var dates = Enumerable . Range ( 0 , 20 ) . Select ( i => new DateTime ( 1900 , 1 , 1 ) . AddDays ( Random . Shared . Next ( 1 , 50000 ) ) ) . ToList ( ) ;
242
+
243
+ using ( var appender = Connection . CreateAppender ( "managedAppenderTemporal" ) )
244
+ {
245
+ foreach ( var value in dates )
246
+ {
247
+ appender . CreateRow ( )
248
+ . AppendValue ( value ) . AppendValue ( value )
249
+ . AppendValue ( value ) . AppendValue ( value )
250
+ . AppendValue ( value ) . AppendValue ( value )
251
+ . EndRow ( ) ;
252
+ }
243
253
}
254
+
255
+ var result = Connection . Query < ( DateOnly , DateTime , DateTime , DateTime , DateTime , DateTime ) > ( "SELECT a, b, c, d, e, f FROM managedAppenderTemporal" ) . ToList ( ) ;
256
+
257
+ result . Select ( tuple => tuple . Item1 ) . Should ( ) . BeEquivalentTo ( dates . Select ( DateOnly . FromDateTime ) ) ;
258
+ result . Select ( tuple => tuple . Item2 ) . Should ( ) . BeEquivalentTo ( dates ) ;
259
+ result . Select ( tuple => tuple . Item3 ) . Should ( ) . BeEquivalentTo ( dates ) ;
260
+ result . Select ( tuple => tuple . Item4 ) . Should ( ) . BeEquivalentTo ( dates ) ;
261
+ result . Select ( tuple => tuple . Item5 ) . Should ( ) . BeEquivalentTo ( dates ) ;
262
+ result . Select ( tuple => tuple . Item6 ) . Should ( ) . BeEquivalentTo ( dates ) ;
244
263
}
245
264
246
265
[ Fact ]
0 commit comments