18 using System.Collections.Generic;
19 using System.Globalization;
35 private int maxRowCount = Int32.MaxValue;
43 private int realIndex = Int32.MaxValue;
44 private int realIndexOffset = -1;
49 this.connection = connection;
59 public bool VerboseColumnNames {
63 public int MaxFetchSize {
get;
private set; }
65 public int DefaultFetchSize {
get;
private set; }
67 public bool Closed {
get;
private set; }
69 public int QueryTime {
get;
internal set; }
79 public int ResultId {
get;
private set; }
89 return System.Math.Min(resultRowCount, maxRowCount);
96 public int ColumnCount {
97 get {
return columns.Length; }
100 public bool HasLargeObject {
120 public bool IsUpdate {
124 return (ColumnCount == 1 && RowCount == 1 &&
125 columns[0].Name.
Equals(
"@aresult"));
141 int rowOffset = realIndex - blockTopRow;
142 if (rowOffset >= blockRowCount) {
144 Download(realIndex, fetchSize);
146 rowOffset = realIndex - blockTopRow;
147 realIndexOffset = rowOffset;
148 }
else if (rowOffset < 0) {
149 int fsDif =
System.Math.Min(fetchSize, 8);
151 Download(realIndex - fetchSize + fsDif, fetchSize);
153 rowOffset = realIndex - blockTopRow;
154 realIndexOffset = rowOffset;
172 if (columnHash == null) {
174 columnHash =
new Dictionary<string, int>(comparer);
178 if (!columnHash.TryGetValue(name, out index)) {
179 int colCount = ColumnCount;
181 String[] cols =
new String[colCount];
182 for (
int i = 0; i < colCount; ++i) {
183 String colName = columns[i].
Name;
184 if (colName.StartsWith(
"\"")) {
185 colName = colName.Substring(1, colName.Length - 2);
188 if (colName.StartsWith(
"@")) {
189 colName = colName.Substring(2);
195 for (
int i = 0; i < colCount; ++i) {
196 String colName = cols[i];
197 if (colName.Equals(name)) {
198 columnHash[name] = i ;
204 string pointName =
"." + name;
205 for (
int i = 0; i < colCount; ++i) {
206 String colName = cols[i];
207 if (colName.EndsWith(pointName)) {
208 columnHash[name] = i;
220 var value = GetRawColumn(ordinal);
222 if (value == null || value.IsNull)
225 var destType = GetColumn(ordinal).RuntimeType;
227 return Convert.ChangeType(value, destType, CultureInfo.InvariantCulture);
233 if (column < 0 || column >= ColumnCount)
234 throw new IndexOutOfRangeException(
"Column index out of bounds: 1 > " + column +
" > " + ColumnCount);
239 var row = resultBlock.
GetRow(realIndexOffset);
240 return row.
Values[column];
243 public int AffectedRows {
246 throw new DeveelDbException(
"Unable to format command result as an update value.");
248 var row = resultBlock.
GetRow(0);
251 return ((SqlNumber) ob).ToInt32();
259 columns = columnList;
260 resultRowCount = totalRowCount;
270 fetchSize = rows > 0 ?
System.Math.Min(rows, MaxFetchSize) : DefaultFetchSize;
274 maxRowCount = rowCount == 0 ? Int32.MaxValue : rowCount;
278 Download(0, resultRowCount);
288 if (rowIndex + rowCount < 0)
293 rowCount = rowCount + rowIndex;
296 if (rowIndex >= RowCount)
298 if (rowIndex + rowCount > RowCount)
299 rowCount = RowCount - rowIndex;
308 resultBlock = connection.
RowCache.
GetResultPart(ResultId, rowIndex, rowCount, ColumnCount, RowCount);
311 blockTopRow = rowIndex;
314 blockRowCount = rowCount;
317 }
catch (Exception ex) {
323 return columns[offset];
328 int rowOffset = realIndex - blockTopRow;
329 realIndexOffset = rowOffset;
335 return realIndex < RowCount;
339 int rowCount = RowCount;
340 if (realIndex < rowCount) {
342 if (realIndex < rowCount) {
346 return (realIndex < rowCount);
350 if (ResultId != -1) {
358 realIndex = Int32.MaxValue;
361 if (columnHash != null) {
369 GC.SuppressFinalize(
this);
int FindColumnIndex(string name)
Searches for the index of the column with the given name.
QueryResultRow GetRow(int index)
Dictionary< string, int > columnHash
void EnsureIndexLoaded()
Ensures that the row index pointed to by 'real_index' is actually loaded into the 'result_block'...
Defines the contract for a valid SQL Object
object GetRuntimeValue(int ordinal)
string Name
Returns the name of the field.
QueryResultPart resultBlock
void SetMaxRowCount(int rowCount)
void Download(int rowIndex, int rowCount)
override bool Equals(Object ob)
ISqlObject GetRawColumn(int column)
void Dispose(bool disposing)
LocalQueryResult(DeveelDbConnection connection)
void Setup(int id, QueryResultColumn[] columnList, int totalRowCount)
QueryResultColumn[] columns
DeveelDbConnectionStringBuilder Settings
DeveelDbConnection connection
void DisposeResult(int resultId)
void SetFetchSize(int rows)
QueryResultColumn GetColumn(int offset)
QueryResultPart GetResultPart(int resultId, int rowIndex, int rowCount, int colCount, int totalRowCount)
Requests a block of parts.
bool IgnoreIdentifiersCase