@@ -227,54 +227,41 @@ public void IrisSdcaMaximumEntropy()
227
227
[ X86X64FactAttribute ( "The SQLite un-managed code, SQLite.interop, only supports x86/x64 architectures." ) ]
228
228
public void TestLoadDatetimeColumnWithNullValue ( )
229
229
{
230
- try
230
+ var connectionString = "DataSource=Dummy;Mode=Memory;Version=3;Timeout=120;Cache=Shared" ;
231
+ using ( var connection = new SQLiteConnection ( connectionString ) )
231
232
{
232
- var connectionString = "DataSource=Dummy;Mode=Memory;Version=3;Timeout=120;Cache=Shared" ;
233
- using ( var connection = new SQLiteConnection ( connectionString ) )
233
+ connection . Open ( ) ;
234
+ using ( var command = new SQLiteCommand ( connection ) )
234
235
{
235
- connection . Open ( ) ;
236
- using ( var command = new SQLiteCommand ( connection ) )
237
- {
238
- command . CommandText = """
236
+ // Make sure the table doesn't exist.
237
+ command . CommandText = """
239
238
BEGIN;
240
- CREATE TABLE IF NOT EXISTS Datetime (datetime Datetime NULL);
241
- INSERT INTO Datetime VALUES (NULL);
242
- INSERT INTO Datetime VALUES ('2018-01-01 00:00:00');
239
+ DROP TABLE IF EXISTS Datetime;
243
240
COMMIT;
244
241
""" ;
245
- command . ExecuteNonQuery ( ) ;
246
- }
247
- }
248
- var mlContext = new MLContext ( seed : 1 ) ;
249
- var loader = mlContext . Data . CreateDatabaseLoader ( new DatabaseLoader . Column ( "datetime" , DbType . DateTime , 0 ) ) ;
250
- var source = new DatabaseSource ( SQLiteFactory . Instance , connectionString , "SELECT datetime FROM Datetime" ) ;
251
- var data = loader . Load ( source ) ;
252
- var datetimes = data . GetColumn < DateTime > ( "datetime" ) . ToArray ( ) ;
253
- datetimes . Count ( ) . Should ( ) . Be ( 2 ) ;
254
-
255
- // Convert null value to DateTime.MinValue, aka 0001-01-01 00:00:00
256
- // This is the default behavior of TextLoader as well.
257
- datetimes [ 0 ] . Should ( ) . Be ( DateTime . MinValue ) ;
258
- datetimes [ 1 ] . Should ( ) . Be ( new DateTime ( 2018 , 1 , 1 , 0 , 0 , 0 ) ) ;
259
- }
260
- finally
261
- {
262
- //Clean up in memory db if anything happens
263
- var connectionString = "DataSource=Dummy;Mode=Memory;Version=3;Timeout=120;Cache=Shared" ;
264
- using ( var connection = new SQLiteConnection ( connectionString ) )
265
- {
266
- connection . Open ( ) ;
267
- using ( var command = new SQLiteCommand ( connection ) )
268
- {
269
- command . CommandText = """
242
+ command . ExecuteNonQuery ( ) ;
243
+
244
+ command . CommandText = """
270
245
BEGIN;
271
- DROP TABLE IF EXISTS Datetime;
246
+ CREATE TABLE IF NOT EXISTS Datetime (datetime Datetime NULL);
247
+ INSERT INTO Datetime VALUES (NULL);
248
+ INSERT INTO Datetime VALUES ('2018-01-01 00:00:00');
272
249
COMMIT;
273
250
""" ;
274
- command . ExecuteNonQuery ( ) ;
275
- }
251
+ command . ExecuteNonQuery ( ) ;
276
252
}
277
253
}
254
+ var mlContext = new MLContext ( seed : 1 ) ;
255
+ var loader = mlContext . Data . CreateDatabaseLoader ( new DatabaseLoader . Column ( "datetime" , DbType . DateTime , 0 ) ) ;
256
+ var source = new DatabaseSource ( SQLiteFactory . Instance , connectionString , "SELECT datetime FROM Datetime" ) ;
257
+ var data = loader . Load ( source ) ;
258
+ var datetimes = data . GetColumn < DateTime > ( "datetime" ) . ToArray ( ) ;
259
+ datetimes . Count ( ) . Should ( ) . Be ( 2 ) ;
260
+
261
+ // Convert null value to DateTime.MinValue, aka 0001-01-01 00:00:00
262
+ // This is the default behavior of TextLoader as well.
263
+ datetimes [ 0 ] . Should ( ) . Be ( DateTime . MinValue ) ;
264
+ datetimes [ 1 ] . Should ( ) . Be ( new DateTime ( 2018 , 1 , 1 , 0 , 0 , 0 ) ) ;
278
265
}
279
266
280
267
/// <summary>
0 commit comments