/// <summary> /// Begins a new bulk copy operation in which one or more data tables are uploaded to the <paramref name="targetTable"/>. The API entrypoint for this is /// <see cref="DiscoveredTable.BeginBulkInsert(IManagedTransaction)"/>. /// /// </summary> /// <param name="targetTable"></param> /// <param name="connection"></param> protected BulkCopy(DiscoveredTable targetTable, IManagedConnection connection) { TargetTable = targetTable; Connection = connection; InvalidateTableSchema(); AllowUnmatchedInputColumns = false; DateTimeDecider = new DateTimeTypeDecider(); }
public FlatFileToDataTablePusher(FlatFileToLoad fileToLoad, FlatFileColumnCollection headers, Func <string, object> hackValuesFunc, bool attemptToResolveNewlinesInRecords, CultureInfo culture) { _fileToLoad = fileToLoad; _headers = headers; _hackValuesFunc = hackValuesFunc; _attemptToResolveNewlinesInRecords = attemptToResolveNewlinesInRecords; _culture = culture; _dateTimeParser = new DateTimeTypeDecider(); if (culture != null) { _dateTimeParser.Culture = culture; } }
public void DateTimeTypeDecider_ExplicitDateTimeFormat(string value, string format, int yy, int mm, int dd) { var decider = new DateTimeTypeDecider(CultureInfo.InvariantCulture); Assert.IsFalse(decider.IsAcceptableAsType(value, new DatabaseTypeRequest(typeof(DateTime), null, null))); decider.Settings.ExplicitDateFormats = new [] { format }; Assert.IsTrue(decider.IsAcceptableAsType(value, new DatabaseTypeRequest(typeof(DateTime), null, null))); Assert.AreEqual(new DateTime(yy, mm, dd), decider.Parse(value)); var g = new Guesser(); g.AdjustToCompensateForValue(value); Assert.IsTrue(g.Guess.CSharpType == typeof(Int32) || g.Guess.CSharpType == typeof(string) /*0 prefixed numbers are usually treated as strings*/); var g2 = new Guesser(); g2.Settings.ExplicitDateFormats = new string[] { format }; g2.AdjustToCompensateForValue(value); Assert.AreEqual(typeof(DateTime), g2.Guess.CSharpType); }