Proper handling of NextResult in Cached Reader
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
using System;
|
||||
using DynamORM.Helpers;
|
||||
using DynamORM.Mapper;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Dynamic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using DynamORM.Helpers;
|
||||
using DynamORM.Mapper;
|
||||
|
||||
namespace DynamORM
|
||||
{
|
||||
@@ -15,16 +15,23 @@ namespace DynamORM
|
||||
{
|
||||
#region Constructor and Data
|
||||
|
||||
private DataTable _schema;
|
||||
private int _fields;
|
||||
private int _rows;
|
||||
private int _position;
|
||||
private int _cachePos;
|
||||
private class Data
|
||||
{
|
||||
internal DataTable _schema;
|
||||
internal int _fields;
|
||||
internal int _rows;
|
||||
internal int _rowsAffected;
|
||||
internal int _position = -1;
|
||||
internal int _cachePos = -1;
|
||||
|
||||
private IList<string> _names;
|
||||
private IDictionary<string, int> _ordinals;
|
||||
private IList<Type> _types;
|
||||
private IList<object> _cache;
|
||||
internal IList<string> _names;
|
||||
internal IDictionary<string, int> _ordinals;
|
||||
internal IList<Type> _types;
|
||||
internal IList<object> _cache;
|
||||
}
|
||||
|
||||
private List<Data> _data = new List<Data>();
|
||||
private int _currentDataPosition = 0;
|
||||
|
||||
private DynamicCachedReader()
|
||||
{
|
||||
@@ -58,8 +65,12 @@ namespace DynamORM
|
||||
var r = new DynamicCachedReader();
|
||||
r.Init(firstDict.Keys.Count);
|
||||
|
||||
r._data.Add(new Data());
|
||||
|
||||
var data = r._data[r._currentDataPosition];
|
||||
|
||||
for (int i = 0; i < firstDict.Keys.Count; i++)
|
||||
r._types.Add(null);
|
||||
data._types.Add(null);
|
||||
|
||||
foreach (dynamic elem in (objects as IEnumerable<dynamic>))
|
||||
{
|
||||
@@ -70,60 +81,60 @@ namespace DynamORM
|
||||
{
|
||||
object val = dict[k];
|
||||
|
||||
r._cache.Add(val);
|
||||
data._cache.Add(val);
|
||||
|
||||
if (r._types[c] == null && val != null)
|
||||
r._types[c] = val.GetType();
|
||||
if (data._types[c] == null && val != null)
|
||||
data._types[c] = val.GetType();
|
||||
|
||||
c++;
|
||||
}
|
||||
|
||||
r._rows++;
|
||||
data._rows++;
|
||||
}
|
||||
|
||||
for (int i = 0; i < firstDict.Keys.Count; i++)
|
||||
if (r._types[i] == null)
|
||||
r._types[i] = typeof(string);
|
||||
if (data._types[i] == null)
|
||||
data._types[i] = typeof(string);
|
||||
|
||||
r._schema = new DataTable("DYNAMIC");
|
||||
r._schema.Columns.Add(new DataColumn("ColumnName", typeof(string)));
|
||||
r._schema.Columns.Add(new DataColumn("ColumnOrdinal", typeof(int)));
|
||||
r._schema.Columns.Add(new DataColumn("ColumnSize", typeof(int)));
|
||||
r._schema.Columns.Add(new DataColumn("NumericPrecision", typeof(short)));
|
||||
r._schema.Columns.Add(new DataColumn("NumericScale", typeof(short)));
|
||||
r._schema.Columns.Add(new DataColumn("DataType", typeof(Type)));
|
||||
r._schema.Columns.Add(new DataColumn("ProviderType", typeof(int)));
|
||||
r._schema.Columns.Add(new DataColumn("NativeType", typeof(int)));
|
||||
r._schema.Columns.Add(new DataColumn("AllowDBNull", typeof(bool)));
|
||||
r._schema.Columns.Add(new DataColumn("IsUnique", typeof(bool)));
|
||||
r._schema.Columns.Add(new DataColumn("IsKey", typeof(bool)));
|
||||
r._schema.Columns.Add(new DataColumn("IsAutoIncrement", typeof(bool)));
|
||||
data._schema = new DataTable("DYNAMIC");
|
||||
data._schema.Columns.Add(new DataColumn("ColumnName", typeof(string)));
|
||||
data._schema.Columns.Add(new DataColumn("ColumnOrdinal", typeof(int)));
|
||||
data._schema.Columns.Add(new DataColumn("ColumnSize", typeof(int)));
|
||||
data._schema.Columns.Add(new DataColumn("NumericPrecision", typeof(short)));
|
||||
data._schema.Columns.Add(new DataColumn("NumericScale", typeof(short)));
|
||||
data._schema.Columns.Add(new DataColumn("DataType", typeof(Type)));
|
||||
data._schema.Columns.Add(new DataColumn("ProviderType", typeof(int)));
|
||||
data._schema.Columns.Add(new DataColumn("NativeType", typeof(int)));
|
||||
data._schema.Columns.Add(new DataColumn("AllowDBNull", typeof(bool)));
|
||||
data._schema.Columns.Add(new DataColumn("IsUnique", typeof(bool)));
|
||||
data._schema.Columns.Add(new DataColumn("IsKey", typeof(bool)));
|
||||
data._schema.Columns.Add(new DataColumn("IsAutoIncrement", typeof(bool)));
|
||||
|
||||
int ordinal = 0;
|
||||
DataRow dr = null;
|
||||
|
||||
foreach (var column in firstDict.Keys)
|
||||
{
|
||||
dr = r._schema.NewRow();
|
||||
dr = data._schema.NewRow();
|
||||
|
||||
dr[0] = column;
|
||||
dr[1] = ordinal;
|
||||
dr[2] = 0;
|
||||
dr[3] = 0;
|
||||
dr[4] = 0;
|
||||
dr[5] = r._types[ordinal];
|
||||
dr[6] = r._types[ordinal].ToDbType();
|
||||
dr[7] = r._types[ordinal].ToDbType();
|
||||
dr[5] = data._types[ordinal];
|
||||
dr[6] = data._types[ordinal].ToDbType();
|
||||
dr[7] = data._types[ordinal].ToDbType();
|
||||
dr[8] = true;
|
||||
dr[9] = false;
|
||||
dr[10] = false;
|
||||
dr[11] = false;
|
||||
|
||||
r._schema.Rows.Add(dr);
|
||||
data._schema.Rows.Add(dr);
|
||||
|
||||
r._names.Add(dr[0].ToString());
|
||||
r._ordinals.Add(dr[0].ToString().ToUpper(), ordinal++);
|
||||
r._types.Add((Type)dr[5]);
|
||||
data._names.Add(dr[0].ToString());
|
||||
data._ordinals.Add(dr[0].ToString().ToUpper(), ordinal++);
|
||||
data._types.Add((Type)dr[5]);
|
||||
|
||||
dr.AcceptChanges();
|
||||
}
|
||||
@@ -150,8 +161,6 @@ namespace DynamORM
|
||||
r.FillFromEnumerable(objects, mapper);
|
||||
|
||||
r.IsClosed = false;
|
||||
r._position = -1;
|
||||
r._cachePos = -1;
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -173,64 +182,68 @@ namespace DynamORM
|
||||
r.FillFromEnumerable(elementType, objects, mapper);
|
||||
|
||||
r.IsClosed = false;
|
||||
r._position = -1;
|
||||
r._cachePos = -1;
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
private void InitDataReader(IDataReader reader, int offset = 0, int limit = -1, Func<DynamicCachedReader, int, bool> progress = null)
|
||||
{
|
||||
_schema = reader.GetSchemaTable();
|
||||
RecordsAffected = reader.RecordsAffected;
|
||||
|
||||
Init(reader.FieldCount);
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < _fields; i++)
|
||||
do
|
||||
{
|
||||
_names.Add(reader.GetName(i));
|
||||
_types.Add(reader.GetFieldType(i));
|
||||
Init(reader.FieldCount);
|
||||
|
||||
if (!_ordinals.ContainsKey(reader.GetName(i).ToUpper()))
|
||||
_ordinals.Add(reader.GetName(i).ToUpper(), i);
|
||||
}
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
int current = 0;
|
||||
while (reader.Read())
|
||||
{
|
||||
if (current < offset)
|
||||
data._schema = reader.GetSchemaTable();
|
||||
data._rowsAffected = reader.RecordsAffected;
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < data._fields; i++)
|
||||
{
|
||||
current++;
|
||||
continue;
|
||||
data._names.Add(reader.GetName(i));
|
||||
data._types.Add(reader.GetFieldType(i));
|
||||
|
||||
if (!data._ordinals.ContainsKey(reader.GetName(i).ToUpper()))
|
||||
data._ordinals.Add(reader.GetName(i).ToUpper(), i);
|
||||
}
|
||||
|
||||
for (i = 0; i < _fields; i++)
|
||||
_cache.Add(reader[i]);
|
||||
int current = 0;
|
||||
while (reader.Read())
|
||||
{
|
||||
if (current < offset)
|
||||
{
|
||||
current++;
|
||||
continue;
|
||||
}
|
||||
|
||||
_rows++;
|
||||
current++;
|
||||
for (i = 0; i < data._fields; i++)
|
||||
data._cache.Add(reader[i]);
|
||||
|
||||
if (limit >= 0 && _rows >= limit)
|
||||
break;
|
||||
data._rows++;
|
||||
current++;
|
||||
|
||||
if (progress != null && !progress(this, _rows))
|
||||
break;
|
||||
}
|
||||
if (limit >= 0 && data._rows >= limit)
|
||||
break;
|
||||
|
||||
IsClosed = false;
|
||||
_position = -1;
|
||||
_cachePos = -1;
|
||||
if (progress != null && !progress(this, data._rows))
|
||||
break;
|
||||
}
|
||||
|
||||
if (progress != null)
|
||||
progress(this, _rows);
|
||||
IsClosed = false;
|
||||
data._position = -1;
|
||||
data._cachePos = -1;
|
||||
|
||||
if (progress != null)
|
||||
progress(this, data._rows);
|
||||
} while (reader.NextResult());
|
||||
|
||||
reader.Close();
|
||||
}
|
||||
|
||||
private void FillFromEnumerable<T>(IEnumerable<T> objects, DynamicTypeMap mapper)
|
||||
{
|
||||
var data = _data[_currentDataPosition];
|
||||
foreach (var elem in objects)
|
||||
{
|
||||
foreach (var col in mapper.ColumnsMap)
|
||||
@@ -240,17 +253,19 @@ namespace DynamORM
|
||||
if (col.Value.Get != null)
|
||||
val = col.Value.Get(elem);
|
||||
|
||||
_cache.Add(val);
|
||||
data._cache.Add(val);
|
||||
}
|
||||
|
||||
_cache.Add(elem);
|
||||
data._cache.Add(elem);
|
||||
|
||||
_rows++;
|
||||
data._rows++;
|
||||
}
|
||||
}
|
||||
|
||||
private void FillFromEnumerable(Type elementType, IEnumerable objects, DynamicTypeMap mapper)
|
||||
{
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
foreach (var elem in objects)
|
||||
{
|
||||
foreach (var col in mapper.ColumnsMap)
|
||||
@@ -260,37 +275,38 @@ namespace DynamORM
|
||||
if (col.Value.Get != null)
|
||||
val = col.Value.Get(elem);
|
||||
|
||||
_cache.Add(val);
|
||||
data._cache.Add(val);
|
||||
}
|
||||
|
||||
_cache.Add(elem);
|
||||
data._cache.Add(elem);
|
||||
|
||||
_rows++;
|
||||
data._rows++;
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateSchemaTable(DynamicTypeMap mapper)
|
||||
{
|
||||
_schema = new DataTable("DYNAMIC");
|
||||
_schema.Columns.Add(new DataColumn("ColumnName", typeof(string)));
|
||||
_schema.Columns.Add(new DataColumn("ColumnOrdinal", typeof(int)));
|
||||
_schema.Columns.Add(new DataColumn("ColumnSize", typeof(int)));
|
||||
_schema.Columns.Add(new DataColumn("NumericPrecision", typeof(short)));
|
||||
_schema.Columns.Add(new DataColumn("NumericScale", typeof(short)));
|
||||
_schema.Columns.Add(new DataColumn("DataType", typeof(Type)));
|
||||
_schema.Columns.Add(new DataColumn("ProviderType", typeof(int)));
|
||||
_schema.Columns.Add(new DataColumn("NativeType", typeof(int)));
|
||||
_schema.Columns.Add(new DataColumn("AllowDBNull", typeof(bool)));
|
||||
_schema.Columns.Add(new DataColumn("IsUnique", typeof(bool)));
|
||||
_schema.Columns.Add(new DataColumn("IsKey", typeof(bool)));
|
||||
_schema.Columns.Add(new DataColumn("IsAutoIncrement", typeof(bool)));
|
||||
var data = _data[_currentDataPosition];
|
||||
data._schema = new DataTable("DYNAMIC");
|
||||
data._schema.Columns.Add(new DataColumn("ColumnName", typeof(string)));
|
||||
data._schema.Columns.Add(new DataColumn("ColumnOrdinal", typeof(int)));
|
||||
data._schema.Columns.Add(new DataColumn("ColumnSize", typeof(int)));
|
||||
data._schema.Columns.Add(new DataColumn("NumericPrecision", typeof(short)));
|
||||
data._schema.Columns.Add(new DataColumn("NumericScale", typeof(short)));
|
||||
data._schema.Columns.Add(new DataColumn("DataType", typeof(Type)));
|
||||
data._schema.Columns.Add(new DataColumn("ProviderType", typeof(int)));
|
||||
data._schema.Columns.Add(new DataColumn("NativeType", typeof(int)));
|
||||
data._schema.Columns.Add(new DataColumn("AllowDBNull", typeof(bool)));
|
||||
data._schema.Columns.Add(new DataColumn("IsUnique", typeof(bool)));
|
||||
data._schema.Columns.Add(new DataColumn("IsKey", typeof(bool)));
|
||||
data._schema.Columns.Add(new DataColumn("IsAutoIncrement", typeof(bool)));
|
||||
|
||||
int ordinal = 0;
|
||||
DataRow dr = null;
|
||||
|
||||
foreach (var column in mapper.ColumnsMap)
|
||||
{
|
||||
dr = _schema.NewRow();
|
||||
dr = data._schema.NewRow();
|
||||
|
||||
dr[0] = column.Value.Column.NullOr(x => x.Name ?? column.Value.Name, column.Value.Name);
|
||||
dr[1] = ordinal;
|
||||
@@ -305,16 +321,16 @@ namespace DynamORM
|
||||
dr[10] = column.Value.Column.NullOr(x => x.IsKey, false);
|
||||
dr[11] = false;
|
||||
|
||||
_schema.Rows.Add(dr);
|
||||
data._schema.Rows.Add(dr);
|
||||
|
||||
_names.Add(dr[0].ToString());
|
||||
_ordinals.Add(dr[0].ToString().ToUpper(), ordinal++);
|
||||
_types.Add((Type)dr[5]);
|
||||
data._names.Add(dr[0].ToString());
|
||||
data._ordinals.Add(dr[0].ToString().ToUpper(), ordinal++);
|
||||
data._types.Add((Type)dr[5]);
|
||||
|
||||
dr.AcceptChanges();
|
||||
}
|
||||
|
||||
dr = _schema.NewRow();
|
||||
dr = data._schema.NewRow();
|
||||
|
||||
dr[0] = "#O";
|
||||
dr[1] = ordinal;
|
||||
@@ -329,33 +345,38 @@ namespace DynamORM
|
||||
dr[10] = false;
|
||||
dr[11] = false;
|
||||
|
||||
_schema.Rows.Add(dr);
|
||||
data._schema.Rows.Add(dr);
|
||||
|
||||
_names.Add("#O");
|
||||
_ordinals.Add("#O".ToUpper(), ordinal++);
|
||||
_types.Add(mapper.Type);
|
||||
data._names.Add("#O");
|
||||
data._ordinals.Add("#O".ToUpper(), ordinal++);
|
||||
data._types.Add(mapper.Type);
|
||||
|
||||
dr.AcceptChanges();
|
||||
}
|
||||
|
||||
private void Init(int fieldCount)
|
||||
{
|
||||
_rows = 0;
|
||||
_fields = fieldCount;
|
||||
_names = new List<string>(_fields);
|
||||
_ordinals = new Dictionary<string, int>(_fields);
|
||||
_types = new List<Type>(_fields);
|
||||
_cache = new List<object>(_fields * 100);
|
||||
_data.Add(new Data()
|
||||
{
|
||||
_rows = 0,
|
||||
_fields = fieldCount,
|
||||
_names = new List<string>(fieldCount),
|
||||
_ordinals = new Dictionary<string, int>(fieldCount),
|
||||
_types = new List<Type>(fieldCount),
|
||||
_cache = new List<object>(fieldCount * 100),
|
||||
});
|
||||
|
||||
_currentDataPosition = _data.Count - 1;
|
||||
}
|
||||
|
||||
/// <summary>Sets the current position in reader.</summary>
|
||||
/// <param name="pos">The position.</param>
|
||||
public void SetPosition(int pos)
|
||||
{
|
||||
if (pos >= -1 && pos < _rows)
|
||||
if (pos >= -1 && pos < _data[_currentDataPosition]._rows)
|
||||
{
|
||||
_position = pos;
|
||||
_cachePos = _position * _fields;
|
||||
_data[_currentDataPosition]._position = pos;
|
||||
_data[_currentDataPosition]._cachePos = _data[_currentDataPosition]._position * _data[_currentDataPosition]._fields;
|
||||
}
|
||||
else
|
||||
throw new IndexOutOfRangeException();
|
||||
@@ -369,15 +390,14 @@ namespace DynamORM
|
||||
public void Close()
|
||||
{
|
||||
IsClosed = true;
|
||||
_position = _rows;
|
||||
_cachePos = -1;
|
||||
_currentDataPosition = -1;
|
||||
}
|
||||
|
||||
/// <summary>Gets a value indicating the depth of nesting for the current row.</summary>
|
||||
/// <remarks>This implementation use this field to indicate row count.</remarks>
|
||||
public int Depth
|
||||
{
|
||||
get { return _rows; }
|
||||
get { return _data[_currentDataPosition]._rows; }
|
||||
}
|
||||
|
||||
/// <summary>Returns a System.Data.DataTable that describes the column metadata of the
|
||||
@@ -386,7 +406,7 @@ namespace DynamORM
|
||||
/// The System.Data.IDataReader is closed.</exception>
|
||||
public DataTable GetSchemaTable()
|
||||
{
|
||||
return _schema;
|
||||
return _data[_currentDataPosition]._schema;
|
||||
}
|
||||
|
||||
/// <summary>Gets a value indicating whether the data reader is closed.</summary>
|
||||
@@ -396,24 +416,26 @@ namespace DynamORM
|
||||
/// <returns>Returns true if there are more rows; otherwise, false.</returns>
|
||||
public bool NextResult()
|
||||
{
|
||||
_cachePos = (++_position) * _fields;
|
||||
_currentDataPosition++;
|
||||
|
||||
return _position < _rows;
|
||||
return _data.Count < _currentDataPosition;
|
||||
}
|
||||
|
||||
/// <summary>Advances the System.Data.IDataReader to the next record.</summary>
|
||||
/// <returns>Returns true if there are more rows; otherwise, false.</returns>
|
||||
public bool Read()
|
||||
{
|
||||
_cachePos = (++_position) * _fields;
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
return _position < _rows;
|
||||
data._cachePos = (++data._position) * data._fields;
|
||||
|
||||
return data._position < data._rows;
|
||||
}
|
||||
|
||||
/// <summary>Gets the number of rows changed, inserted, or deleted by execution of the SQL statement.</summary>
|
||||
/// <returns>The number of rows changed, inserted, or deleted; 0 if no rows were affected or the statement
|
||||
/// failed; and -1 for SELECT statements.</returns>
|
||||
public int RecordsAffected { get; private set; }
|
||||
public int RecordsAffected { get { return _data[_currentDataPosition]._rowsAffected; } }
|
||||
|
||||
#endregion IDataReader Members
|
||||
|
||||
@@ -423,10 +445,15 @@ namespace DynamORM
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_names.Clear();
|
||||
_types.Clear();
|
||||
_cache.Clear();
|
||||
_schema.Dispose();
|
||||
foreach (var data in _data)
|
||||
{
|
||||
data._names.Clear();
|
||||
data._types.Clear();
|
||||
data._cache.Clear();
|
||||
data._schema.Dispose();
|
||||
}
|
||||
|
||||
_data.Clear();
|
||||
}
|
||||
|
||||
#endregion IDisposable Members
|
||||
@@ -435,14 +462,15 @@ namespace DynamORM
|
||||
|
||||
/// <summary>Gets the number of columns in the current row.</summary>
|
||||
/// <remarks>When not positioned in a valid record set, 0; otherwise, the number of columns in the current record. The default is -1.</remarks>
|
||||
public int FieldCount { get { return _fields; } }
|
||||
public int FieldCount { get { return _data[_currentDataPosition]._fields; } }
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
/// <param name="i">The index of the field to find.</param>
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public bool GetBoolean(int i)
|
||||
{
|
||||
return (bool)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (bool)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -450,7 +478,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public byte GetByte(int i)
|
||||
{
|
||||
return (byte)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (byte)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Reads a stream of bytes from the specified column offset into the buffer
|
||||
@@ -463,7 +492,9 @@ namespace DynamORM
|
||||
/// <returns>The actual number of bytes read.</returns>
|
||||
public long GetBytes(int i, long fieldOffset, byte[] buffer, int bufferoffset, int length)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream((byte[])_cache[_cachePos + i]))
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
using (MemoryStream ms = new MemoryStream((byte[])data._cache[data._cachePos + i]))
|
||||
return ms.Read(buffer, bufferoffset, length);
|
||||
}
|
||||
|
||||
@@ -472,7 +503,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public char GetChar(int i)
|
||||
{
|
||||
return (char)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (char)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Reads a stream of characters from the specified column offset into the buffer
|
||||
@@ -485,7 +517,9 @@ namespace DynamORM
|
||||
/// <returns>The actual number of characters read.</returns>
|
||||
public long GetChars(int i, long fieldoffset, char[] buffer, int bufferoffset, int length)
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream((byte[])_cache[_cachePos + i]))
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
using (MemoryStream ms = new MemoryStream((byte[])data._cache[data._cachePos + i]))
|
||||
{
|
||||
byte[] buff = new byte[buffer.Length];
|
||||
long ret = ms.Read(buff, bufferoffset, length);
|
||||
@@ -510,7 +544,7 @@ namespace DynamORM
|
||||
/// <returns>The data type information for the specified field.</returns>
|
||||
public string GetDataTypeName(int i)
|
||||
{
|
||||
return _types[i].Name;
|
||||
return _data[_currentDataPosition]._types[i].Name;
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -518,7 +552,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public DateTime GetDateTime(int i)
|
||||
{
|
||||
return (DateTime)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (DateTime)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -526,7 +561,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public decimal GetDecimal(int i)
|
||||
{
|
||||
return (decimal)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (decimal)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -534,7 +570,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public double GetDouble(int i)
|
||||
{
|
||||
return (double)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (double)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Gets the System.Type information corresponding to the type of System.Object
|
||||
@@ -544,7 +581,7 @@ namespace DynamORM
|
||||
/// would be returned from System.Data.IDataRecord.GetValue(System.Int32).</returns>
|
||||
public Type GetFieldType(int i)
|
||||
{
|
||||
return _types[i];
|
||||
return _data[_currentDataPosition]._types[i];
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -552,7 +589,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public float GetFloat(int i)
|
||||
{
|
||||
return (float)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (float)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -560,7 +598,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public Guid GetGuid(int i)
|
||||
{
|
||||
return (Guid)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (Guid)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -568,7 +607,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public short GetInt16(int i)
|
||||
{
|
||||
return (short)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (short)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -576,7 +616,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public int GetInt32(int i)
|
||||
{
|
||||
return (int)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (int)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -584,7 +625,8 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public long GetInt64(int i)
|
||||
{
|
||||
return (long)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
return (long)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Gets the name for the field to find.</summary>
|
||||
@@ -592,7 +634,7 @@ namespace DynamORM
|
||||
/// <returns>The name of the field or the empty string (""), if there is no value to return.</returns>
|
||||
public string GetName(int i)
|
||||
{
|
||||
return _names[i];
|
||||
return _data[_currentDataPosition]._names[i];
|
||||
}
|
||||
|
||||
/// <summary>Return the index of the named field.</summary>
|
||||
@@ -600,8 +642,10 @@ namespace DynamORM
|
||||
/// <returns>The index of the named field.</returns>
|
||||
public int GetOrdinal(string name)
|
||||
{
|
||||
if (_ordinals.ContainsKey(name.ToUpper()))
|
||||
return _ordinals[name.ToUpper()];
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
if (data._ordinals.ContainsKey(name.ToUpper()))
|
||||
return data._ordinals[name.ToUpper()];
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -611,7 +655,9 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public string GetString(int i)
|
||||
{
|
||||
return (string)_cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
return (string)data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Return the value of the specified field.</summary>
|
||||
@@ -619,7 +665,9 @@ namespace DynamORM
|
||||
/// <returns>Field value upon return.</returns>
|
||||
public object GetValue(int i)
|
||||
{
|
||||
return _cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
return data._cache[data._cachePos + i];
|
||||
}
|
||||
|
||||
/// <summary>Gets all the attribute fields in the collection for the current record.</summary>
|
||||
@@ -627,10 +675,12 @@ namespace DynamORM
|
||||
/// <returns>The number of instances of System.Object in the array.</returns>
|
||||
public int GetValues(object[] values)
|
||||
{
|
||||
for (int i = 0; i < _fields; i++)
|
||||
values[i] = _cache[_cachePos + i];
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
return _fields;
|
||||
for (int i = 0; i < data._fields; i++)
|
||||
values[i] = data._cache[data._cachePos + i];
|
||||
|
||||
return data._fields;
|
||||
}
|
||||
|
||||
/// <summary>Return whether the specified field is set to null.</summary>
|
||||
@@ -638,7 +688,8 @@ namespace DynamORM
|
||||
/// <returns>Returns true if the specified field is set to null; otherwise, false.</returns>
|
||||
public bool IsDBNull(int i)
|
||||
{
|
||||
return _cache[_cachePos + i] == null || _cache[_cachePos + i] == DBNull.Value;
|
||||
var data = _data[_currentDataPosition];
|
||||
return data._cache[data._cachePos + i] == null || data._cache[data._cachePos + i] == DBNull.Value;
|
||||
}
|
||||
|
||||
/// <summary>Gets or sets specified value in current record.</summary>
|
||||
@@ -648,8 +699,10 @@ namespace DynamORM
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ordinals.ContainsKey(name.ToUpper()))
|
||||
return _cache[_cachePos + _ordinals[name.ToUpper()]];
|
||||
var data = _data[_currentDataPosition];
|
||||
|
||||
if (data._ordinals.ContainsKey(name.ToUpper()))
|
||||
return data._cache[data._cachePos + data._ordinals[name.ToUpper()]];
|
||||
|
||||
throw new IndexOutOfRangeException(String.Format("Field '{0}' not found.", name));
|
||||
}
|
||||
@@ -660,7 +713,10 @@ namespace DynamORM
|
||||
/// <returns>Value of specified column.</returns>
|
||||
public object this[int i]
|
||||
{
|
||||
get { return _cache[_cachePos + i]; }
|
||||
get {
|
||||
var data = _data[_currentDataPosition];
|
||||
return data._cache[data._cachePos + i];
|
||||
}
|
||||
}
|
||||
|
||||
#endregion IDataRecord Members
|
||||
|
||||
Reference in New Issue
Block a user