@@ -227,54 +227,41 @@ public void IrisSdcaMaximumEntropy()
227227 [ X86X64FactAttribute ( "The SQLite un-managed code, SQLite.interop, only supports x86/x64 architectures." ) ]
228228 public void TestLoadDatetimeColumnWithNullValue ( )
229229 {
230- try
230+ var connectionString = "DataSource=Dummy;Mode=Memory;Version=3;Timeout=120;Cache=Shared" ;
231+ using ( var connection = new SQLiteConnection ( connectionString ) )
231232 {
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 ) )
234235 {
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 = """
239238 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;
243240 COMMIT;
244241 """ ;
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 = """
270245 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');
272249 COMMIT;
273250 """ ;
274- command . ExecuteNonQuery ( ) ;
275- }
251+ command . ExecuteNonQuery ( ) ;
276252 }
277253 }
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 ) ) ;
278265 }
279266
280267 /// <summary>
0 commit comments