DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Properties | Private Member Functions | Private Attributes | List of all members
Deveel.Data.Protocol.LocalQueryResult Class Reference
Inheritance diagram for Deveel.Data.Protocol.LocalQueryResult:

Public Member Functions

 LocalQueryResult (DeveelDbConnection connection)
 
int FindColumnIndex (string name)
 Searches for the index of the column with the given name. More...
 
object GetRuntimeValue (int ordinal)
 
ISqlObject GetRawColumn (int column)
 
void Setup (int id, QueryResultColumn[] columnList, int totalRowCount)
 
void SetFetchSize (int rows)
 
void SetMaxRowCount (int rowCount)
 
void DownloadAndClose ()
 
void Download (int rowIndex, int rowCount)
 
QueryResultColumn GetColumn (int offset)
 
bool First ()
 
bool Next ()
 
void Close ()
 
void Dispose ()
 

Properties

bool VerboseColumnNames [get]
 
int MaxFetchSize [get, private set]
 
int DefaultFetchSize [get, private set]
 
bool Closed [get, private set]
 
int QueryTime [get, set]
 
int ResultId [get, private set]
 Returns the identificator that is used as a key to refer to the result set on the server that is the result of the command. More...
 
int RowCount [get]
 The total number of rows in the result set. More...
 
int ColumnCount [get]
 The column count of columns in the result set. More...
 
bool HasLargeObject [get]
 
bool IsUpdate [get]
 Returns true if this result set contains 1 column and 1 row and the name of the column is result. More...
 
int AffectedRows [get]
 

Private Member Functions

 ~LocalQueryResult ()
 
void EnsureIndexLoaded ()
 Ensures that the row index pointed to by 'real_index' is actually loaded into the 'result_block'. More...
 
void RealIndexUpdate ()
 
void Dispose (bool disposing)
 

Private Attributes

DeveelDbConnection connection
 
QueryResultColumn[] columns
 
int resultRowCount
 
int maxRowCount = Int32.MaxValue
 
int blockTopRow
 
int blockRowCount
 
int fetchSize
 
Dictionary< string, int > columnHash
 
int realIndex = Int32.MaxValue
 
int realIndexOffset = -1
 
QueryResultPart resultBlock
 

Detailed Description

Definition at line 25 of file LocalQueryResult.cs.

Constructor & Destructor Documentation

Deveel.Data.Protocol.LocalQueryResult.LocalQueryResult ( DeveelDbConnection  connection)
inline
Deveel.Data.Protocol.LocalQueryResult.~LocalQueryResult ( )
inlineprivate

Definition at line 55 of file LocalQueryResult.cs.

55  {
56  Dispose(false);
57  }

Member Function Documentation

void Deveel.Data.Protocol.LocalQueryResult.Close ( )
inline

Definition at line 349 of file LocalQueryResult.cs.

349  {
350  if (ResultId != -1) {
351  if (!Closed) {
352  // Request to close the current result set
354  Closed = true;
355  }
356 
357  ResultId = -1;
358  realIndex = Int32.MaxValue;
359 
360  // Clear the column name -> index mapping,
361  if (columnHash != null) {
362  columnHash.Clear();
363  }
364  }
365  }
int ResultId
Returns the identificator that is used as a key to refer to the result set on the server that is the ...
Dictionary< string, int > columnHash
void Deveel.Data.Protocol.LocalQueryResult.Dispose ( )
inline

Definition at line 367 of file LocalQueryResult.cs.

367  {
368  Dispose(true);
369  GC.SuppressFinalize(this);
370  }
void Deveel.Data.Protocol.LocalQueryResult.Dispose ( bool  disposing)
inlineprivate

Definition at line 372 of file LocalQueryResult.cs.

372  {
373  if (disposing) {
374  try {
375  Close();
376  } catch (DeveelDbException) {
377  // Ignore
378  // We ignore exceptions because handling cases where the server
379  // connection has broken for many ResultSets would be annoying.
380  }
381  }
382 
383  connection = null;
384  columns = null;
385  resultBlock = null;
386  }
void Deveel.Data.Protocol.LocalQueryResult.Download ( int  rowIndex,
int  rowCount 
)
inline

Definition at line 283 of file LocalQueryResult.cs.

283  {
284  // If row_count is 0 then we don't need to do anything.
285  if (rowCount == 0)
286  return;
287 
288  if (rowIndex + rowCount < 0)
289  throw new DeveelDbException("Result row index is before the start of the set.");
290 
291  if (rowIndex < 0) {
292  rowIndex = 0;
293  rowCount = rowCount + rowIndex;
294  }
295 
296  if (rowIndex >= RowCount)
297  throw new DeveelDbException("Result row index is after the end of the set.");
298  if (rowIndex + rowCount > RowCount)
299  rowCount = RowCount - rowIndex;
300 
301  if (ResultId == -1)
302  throw new DeveelDbException("Result ID is invalid.");
303 
304  try {
305 
306  // Request the result via the RowCache. If the information is not found
307  // in the row cache then the request is forwarded onto the database.
309 
310  // Set the row that's at the top
311  blockTopRow = rowIndex;
312 
313  // Set the number of rows in the block.
314  blockRowCount = rowCount;
315  } catch(DeveelDbException) {
316  throw;
317  } catch (Exception ex) {
318  throw new DeveelDbException("Error while downloading the result data.", ex);
319  }
320  }
int ResultId
Returns the identificator that is used as a key to refer to the result set on the server that is the ...
int ColumnCount
The column count of columns in the result set.
int RowCount
The total number of rows in the result set.
QueryResultPart GetResultPart(int resultId, int rowIndex, int rowCount, int colCount, int totalRowCount)
Requests a block of parts.
void Deveel.Data.Protocol.LocalQueryResult.DownloadAndClose ( )
inline

Definition at line 277 of file LocalQueryResult.cs.

277  {
280  Closed = true;
281  }
int ResultId
Returns the identificator that is used as a key to refer to the result set on the server that is the ...
void Download(int rowIndex, int rowCount)
void Deveel.Data.Protocol.LocalQueryResult.EnsureIndexLoaded ( )
inlineprivate

Ensures that the row index pointed to by 'real_index' is actually loaded into the 'result_block'.

If not, we send a request to the database to get it.

Definition at line 136 of file LocalQueryResult.cs.

136  {
137  if (realIndex == -1)
138  throw new DeveelDbException("Row index out of bounds.");
139 
140  // Offset into our block
141  int rowOffset = realIndex - blockTopRow;
142  if (rowOffset >= blockRowCount) {
143  // Need to download the next block from the server.
145  // Set up the index into the downloaded block.
146  rowOffset = realIndex - blockTopRow;
147  realIndexOffset = rowOffset;
148  } else if (rowOffset < 0) {
149  int fsDif = System.Math.Min(fetchSize, 8);
150  // Need to download the next block from the server.
152  // Set up the index into the downloaded block.
153  rowOffset = realIndex - blockTopRow;
154  realIndexOffset = rowOffset;
155  }
156  }
void Download(int rowIndex, int rowCount)
int Deveel.Data.Protocol.LocalQueryResult.FindColumnIndex ( string  name)
inline

Searches for the index of the column with the given name.

Parameters
name
Returns
Returns a zero-based index representing the position of the column with the given name among those in the result.
Exceptions
DatabaseExceptionIf no column with the given name was found within the result.

Definition at line 169 of file LocalQueryResult.cs.

169  {
170  // For speed, we keep column name -> column index mapping in the hashtable.
171  // This makes column reference by string faster.
172  if (columnHash == null) {
173  var comparer = connection.Settings.IgnoreIdentifiersCase ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal;
174  columnHash = new Dictionary<string, int>(comparer);
175  }
176 
177  int index;
178  if (!columnHash.TryGetValue(name, out index)) {
179  int colCount = ColumnCount;
180  // First construct an unquoted list of all column names
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);
186  }
187  // Strip any codes from the name
188  if (colName.StartsWith("@")) {
189  colName = colName.Substring(2);
190  }
191 
192  cols[i] = colName;
193  }
194 
195  for (int i = 0; i < colCount; ++i) {
196  String colName = cols[i];
197  if (colName.Equals(name)) {
198  columnHash[name] = i ;
199  return i;
200  }
201  }
202 
203  // If not found then search for column name ending,
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;
209  return i;
210  }
211  }
212 
213  throw new DeveelDbException("Couldn't find column with name: " + name);
214  }
215 
216  return index;
217  }
A long string in the system.
Dictionary< string, int > columnHash
string Name
Returns the name of the field.
int ColumnCount
The column count of columns in the result set.
DeveelDbConnectionStringBuilder Settings
bool Deveel.Data.Protocol.LocalQueryResult.First ( )
inline

Definition at line 332 of file LocalQueryResult.cs.

332  {
333  realIndex = 0;
334  RealIndexUpdate();
335  return realIndex < RowCount;
336  }
int RowCount
The total number of rows in the result set.
QueryResultColumn Deveel.Data.Protocol.LocalQueryResult.GetColumn ( int  offset)
inline

Definition at line 322 of file LocalQueryResult.cs.

322  {
323  return columns[offset];
324  }
ISqlObject Deveel.Data.Protocol.LocalQueryResult.GetRawColumn ( int  column)
inline

Definition at line 230 of file LocalQueryResult.cs.

230  {
231  // ASSERTION -
232  // Is the given column in bounds?
233  if (column < 0 || column >= ColumnCount)
234  throw new IndexOutOfRangeException("Column index out of bounds: 1 > " + column + " > " + ColumnCount);
235 
236  // Ensure the current indexed row is fetched from the server.
238 
240  return row.Values[column];
241  }
QueryResultRow GetRow(int index)
void EnsureIndexLoaded()
Ensures that the row index pointed to by 'real_index' is actually loaded into the 'result_block'...
int ColumnCount
The column count of columns in the result set.
object Deveel.Data.Protocol.LocalQueryResult.GetRuntimeValue ( int  ordinal)
inline

Definition at line 219 of file LocalQueryResult.cs.

219  {
220  var value = GetRawColumn(ordinal);
221 
222  if (value == null || value.IsNull)
223  return DBNull.Value;
224 
225  var destType = GetColumn(ordinal).RuntimeType;
226 
227  return Convert.ChangeType(value, destType, CultureInfo.InvariantCulture);
228  }
QueryResultColumn GetColumn(int offset)
bool Deveel.Data.Protocol.LocalQueryResult.Next ( )
inline

Definition at line 338 of file LocalQueryResult.cs.

338  {
339  int rowCount = RowCount;
340  if (realIndex < rowCount) {
341  ++realIndex;
342  if (realIndex < rowCount) {
343  RealIndexUpdate();
344  }
345  }
346  return (realIndex < rowCount);
347  }
int RowCount
The total number of rows in the result set.
void Deveel.Data.Protocol.LocalQueryResult.RealIndexUpdate ( )
inlineprivate

Definition at line 326 of file LocalQueryResult.cs.

326  {
327  // Set up the index into the downloaded block.
328  int rowOffset = realIndex - blockTopRow;
329  realIndexOffset = rowOffset;
330  }
void Deveel.Data.Protocol.LocalQueryResult.SetFetchSize ( int  rows)
inline
void Deveel.Data.Protocol.LocalQueryResult.SetMaxRowCount ( int  rowCount)
inline

Definition at line 273 of file LocalQueryResult.cs.

273  {
274  maxRowCount = rowCount == 0 ? Int32.MaxValue : rowCount;
275  }
void Deveel.Data.Protocol.LocalQueryResult.Setup ( int  id,
QueryResultColumn[]  columnList,
int  totalRowCount 
)
inline

Definition at line 257 of file LocalQueryResult.cs.

257  {
258  ResultId = id;
259  columns = columnList;
260  resultRowCount = totalRowCount;
261  blockTopRow = -1;
262  resultBlock = null;
263 
264  realIndex = -1;
266  Closed = false;
267  }
int ResultId
Returns the identificator that is used as a key to refer to the result set on the server that is the ...
DeveelDbConnectionStringBuilder Settings

Member Data Documentation

int Deveel.Data.Protocol.LocalQueryResult.blockRowCount
private

Definition at line 38 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.blockTopRow
private

Definition at line 37 of file LocalQueryResult.cs.

Dictionary<string, int> Deveel.Data.Protocol.LocalQueryResult.columnHash
private

Definition at line 41 of file LocalQueryResult.cs.

QueryResultColumn [] Deveel.Data.Protocol.LocalQueryResult.columns
private

Definition at line 31 of file LocalQueryResult.cs.

DeveelDbConnection Deveel.Data.Protocol.LocalQueryResult.connection
private

Definition at line 26 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.fetchSize
private

Definition at line 39 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.maxRowCount = Int32.MaxValue
private

Definition at line 35 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.realIndex = Int32.MaxValue
private

Definition at line 43 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.realIndexOffset = -1
private

Definition at line 44 of file LocalQueryResult.cs.

QueryResultPart Deveel.Data.Protocol.LocalQueryResult.resultBlock
private

Definition at line 46 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.resultRowCount
private

Definition at line 33 of file LocalQueryResult.cs.

Property Documentation

int Deveel.Data.Protocol.LocalQueryResult.AffectedRows
get

Definition at line 243 of file LocalQueryResult.cs.

bool Deveel.Data.Protocol.LocalQueryResult.Closed
getprivate set

Definition at line 67 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.ColumnCount
get

The column count of columns in the result set.

Definition at line 96 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.DefaultFetchSize
getprivate set

Definition at line 65 of file LocalQueryResult.cs.

bool Deveel.Data.Protocol.LocalQueryResult.HasLargeObject
get

Definition at line 100 of file LocalQueryResult.cs.

bool Deveel.Data.Protocol.LocalQueryResult.IsUpdate
get

Returns true if this result set contains 1 column and 1 row and the name of the column is result.

This indicates the result set is a DDL command ( UPDATE, INSERT, CREATE, ALTER, etc ).

NOTE: This is a minor hack because there is no real indication that this is a DML statement. Theoretically a SQL command could be constructed that meets a ll these requirements and is processed incorrectly.

Definition at line 120 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.MaxFetchSize
getprivate set

Definition at line 63 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.QueryTime
getset

Definition at line 69 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.ResultId
getprivate set

Returns the identificator that is used as a key to refer to the result set on the server that is the result of the command.

An identificator of -1 means there is no server side result set associated with this object.

Definition at line 79 of file LocalQueryResult.cs.

int Deveel.Data.Protocol.LocalQueryResult.RowCount
get

The total number of rows in the result set.

Definition at line 84 of file LocalQueryResult.cs.

bool Deveel.Data.Protocol.LocalQueryResult.VerboseColumnNames
get

Definition at line 59 of file LocalQueryResult.cs.


The documentation for this class was generated from the following file: