mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 17:23:27 -05:00
* WIP for buffering in temporary file * Adding support for writing to disk for buffering * WIP - Adding file reader, factory for reader/writer * Making long list use generics and implement IEnumerable * Reading/Writing from file is working * Removing unused 'skipValue' logic * More tweaks to file buffer Adding logic for cleaning up the temp files Adding fix for empty/null column names * Adding comments and cleanup * Unit tests for FileStreamWrapper * WIP adding more unit tests, and finishing up wiring up the output writers * Finishing up initial unit tests * Fixing bugs with long fields * Squashed commit of the following: commit df0ffc12a46cb286d801d08689964eac08ad71dd Author: Benjamin Russell <beruss@microsoft.com> Date: Wed Sep 7 14:45:39 2016 -0700 Removing last bit of async for file writing. We're seeing a 8x improvement of file write speeds! commit 08a4b9f32e825512ca24d5dc03ef5acbf7cc6d94 Author: Benjamin Russell <beruss@microsoft.com> Date: Wed Sep 7 11:23:06 2016 -0700 Removing async wrappers * Rolling back test code for Program.cs * Changes as per code review * Fixing broken unit tests * More fixes for codereview
217 lines
5.8 KiB
C#
217 lines
5.8 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Data.Common;
|
|
using System.Linq;
|
|
using Moq;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
|
{
|
|
public class TestDbDataReader : DbDataReader, IDbColumnSchemaGenerator
|
|
{
|
|
|
|
#region Test Specific Implementations
|
|
|
|
private Dictionary<string, string>[][] Data { get; set; }
|
|
|
|
public IEnumerator<Dictionary<string, string>[]> ResultSet { get; private set; }
|
|
|
|
private IEnumerator<Dictionary<string, string>> Rows { get; set; }
|
|
|
|
public TestDbDataReader(Dictionary<string, string>[][] data)
|
|
{
|
|
Data = data;
|
|
if (Data != null)
|
|
{
|
|
ResultSet = ((IEnumerable<Dictionary<string, string>[]>) Data).GetEnumerator();
|
|
ResultSet.MoveNext();
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
public override bool HasRows
|
|
{
|
|
get { return ResultSet != null && ResultSet.Current.Length > 0; }
|
|
}
|
|
|
|
public override bool Read()
|
|
{
|
|
if (Rows == null)
|
|
{
|
|
Rows = ((IEnumerable<Dictionary<string, string>>) ResultSet.Current).GetEnumerator();
|
|
}
|
|
return Rows.MoveNext();
|
|
}
|
|
|
|
public override bool NextResult()
|
|
{
|
|
if (Data == null || !ResultSet.MoveNext())
|
|
{
|
|
return false;
|
|
}
|
|
Rows = ((IEnumerable<Dictionary<string, string>>)ResultSet.Current).GetEnumerator();
|
|
return true;
|
|
}
|
|
|
|
public override object GetValue(int ordinal)
|
|
{
|
|
return this[ordinal];
|
|
}
|
|
|
|
public override int GetValues(object[] values)
|
|
{
|
|
for(int i = 0; i < Rows.Current.Count; i++)
|
|
{
|
|
values[i] = this[i];
|
|
}
|
|
return Rows.Current.Count;
|
|
}
|
|
|
|
public override object this[string name]
|
|
{
|
|
get { return Rows.Current[name]; }
|
|
}
|
|
|
|
public override object this[int ordinal]
|
|
{
|
|
get { return Rows.Current[Rows.Current.Keys.AsEnumerable().ToArray()[ordinal]]; }
|
|
}
|
|
|
|
public ReadOnlyCollection<DbColumn> GetColumnSchema()
|
|
{
|
|
if (ResultSet?.Current == null || ResultSet.Current.Length <= 0)
|
|
{
|
|
return new ReadOnlyCollection<DbColumn>(new List<DbColumn>());
|
|
}
|
|
|
|
List<DbColumn> columns = new List<DbColumn>();
|
|
for (int i = 0; i < ResultSet.Current[0].Count; i++)
|
|
{
|
|
columns.Add(new TestDbColumn());
|
|
}
|
|
return new ReadOnlyCollection<DbColumn>(columns);
|
|
}
|
|
|
|
public override bool IsDBNull(int ordinal)
|
|
{
|
|
return this[ordinal] == null;
|
|
}
|
|
|
|
public override int FieldCount { get { return Rows?.Current.Count ?? 0; } }
|
|
|
|
public override int RecordsAffected
|
|
{
|
|
// Mimics the behavior of SqlDataReader
|
|
get { return Rows != null ? -1 : 1; }
|
|
}
|
|
|
|
#region Not Implemented
|
|
|
|
public override bool GetBoolean(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override byte GetByte(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override char GetChar(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override string GetDataTypeName(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override DateTime GetDateTime(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override decimal GetDecimal(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override double GetDouble(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override int GetOrdinal(string name)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override string GetName(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override long GetInt64(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override int GetInt32(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override short GetInt16(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override Guid GetGuid(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override float GetFloat(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override Type GetFieldType(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override string GetString(int ordinal)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override IEnumerator GetEnumerator()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public override int Depth { get; }
|
|
public override bool IsClosed { get; }
|
|
|
|
#endregion
|
|
}
|
|
}
|