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

Public Member Functions

 DeveelDbCommand ()
 
 DeveelDbCommand (DeveelDbConnection connection)
 
 DeveelDbCommand (string commandText)
 
 DeveelDbCommand (DeveelDbConnection connection, string commandText)
 
override void Prepare ()
 
override void Cancel ()
 
new DeveelDbParameter CreateParameter ()
 
new DeveelDbDataReader ExecuteReader (CommandBehavior behavior)
 
new DeveelDbDataReader ExecuteReader ()
 
override int ExecuteNonQuery ()
 
override object ExecuteScalar ()
 

Protected Member Functions

override DbParameter CreateDbParameter ()
 
override DbDataReader ExecuteDbDataReader (CommandBehavior behavior)
 
override void Dispose (bool disposing)
 

Package Functions

bool NextResult ()
 

Properties

LocalQueryResult CurrentResult [get]
 
override string CommandText [get, set]
 
override int CommandTimeout [get, set]
 
override CommandType CommandType [get, set]
 
override UpdateRowSource UpdatedRowSource [get, set]
 
override DbConnection DbConnection [get, set]
 
new DeveelDbConnection Connection [get, set]
 
override DbParameterCollection DbParameterCollection [get]
 
new DeveelDbParameterCollection Parameters [get]
 
override DbTransaction DbTransaction [get, set]
 
new DeveelDbTransaction Transaction [get, set]
 
override bool DesignTimeVisible [get, set]
 

Private Member Functions

QueryParameterDirection GetParamDirection (SysParameterDirection direction)
 
QueryParameter PrepareParameter (DeveelDbParameter parameter)
 
void ExecuteQuery ()
 
void CreateResults (IQueryResponse[] response)
 
SqlQuery CreateQuery ()
 
void PrepareCommand ()
 
void AssertConnectionOpen ()
 

Private Attributes

int timeout
 
DeveelDbConnection connection
 
DeveelDbTransaction transaction
 
bool prepared
 
List< QueryParameterpreparedParameters
 
DeveelDbParameterCollection parameters
 
int resultIndex
 
LocalQueryResult[] results
 

Detailed Description

Definition at line 31 of file DeveelDbCommand.cs.

Constructor & Destructor Documentation

Deveel.Data.Client.DeveelDbCommand.DeveelDbCommand ( )
inline

Definition at line 44 of file DeveelDbCommand.cs.

45  : this((DeveelDbConnection)null) {
46  }
Deveel.Data.Client.DeveelDbCommand.DeveelDbCommand ( DeveelDbConnection  connection)
inline

Definition at line 48 of file DeveelDbCommand.cs.

49  : this(connection, null) {
50  }
Deveel.Data.Client.DeveelDbCommand.DeveelDbCommand ( string  commandText)
inline

Definition at line 52 of file DeveelDbCommand.cs.

53  : this(null, commandText) {
54  }
Deveel.Data.Client.DeveelDbCommand.DeveelDbCommand ( DeveelDbConnection  connection,
string  commandText 
)
inline

Definition at line 56 of file DeveelDbCommand.cs.

56  {
58  CommandText = commandText;
59 
60  parameters = new DeveelDbParameterCollection(this);
61  }
new DeveelDbConnection Connection
DeveelDbParameterCollection parameters

Member Function Documentation

void Deveel.Data.Client.DeveelDbCommand.AssertConnectionOpen ( )
inlineprivate

Definition at line 294 of file DeveelDbCommand.cs.

294  {
295  if (Connection == null)
296  throw new DeveelDbException("The command is not associated to any connection.");
297 
298  if (Connection.State == ConnectionState.Closed) {
299  try {
300  Connection.Open();
301  } catch (DeveelDbException) {
302  throw;
303  } catch (Exception ex) {
304  throw new DeveelDbException("Failed to open the underlying connection", ex);
305  }
306  }
307  }
new DeveelDbConnection Connection
override void Deveel.Data.Client.DeveelDbCommand.Cancel ( )
inline

Definition at line 260 of file DeveelDbCommand.cs.

260  {
261  try {
262  if (results != null) {
263  foreach (var result in results) {
264  connection.DisposeResult(result.ResultId);
265  }
266  }
267  } finally {
269  }
270  }
override DbParameter Deveel.Data.Client.DeveelDbCommand.CreateDbParameter ( )
inlineprotected

Definition at line 286 of file DeveelDbCommand.cs.

286  {
287  return CreateParameter();
288  }
new DeveelDbParameter CreateParameter()
new DeveelDbParameter Deveel.Data.Client.DeveelDbCommand.CreateParameter ( )
inline

Definition at line 290 of file DeveelDbCommand.cs.

290  {
291  return new DeveelDbParameter();
292  }
SqlQuery Deveel.Data.Client.DeveelDbCommand.CreateQuery ( )
inlineprivate

Definition at line 139 of file DeveelDbCommand.cs.

139  {
140  QueryParameter[] queryParameters;
141  if (prepared && preparedParameters != null) {
142  queryParameters = preparedParameters.ToArray();
143  } else {
144  queryParameters = new QueryParameter[parameters.Count];
145  for (int i = 0; i < parameters.Count; i++) {
146  var parameter = parameters[i];
147  var queryParam = PrepareParameter(parameter);
148  queryParameters[i] = queryParam;
149  }
150  }
151 
152  var query = new SqlQuery(CommandText);
153 
154  // now verify all parameter names are consistent
155  foreach (var parameter in queryParameters) {
157  if (!String.IsNullOrEmpty(parameter.Name) &&
158  parameter.Name != QueryParameter.Marker)
159  throw new InvalidOperationException();
161  if (String.IsNullOrEmpty(parameter.Name))
162  throw new InvalidOperationException("Named parameters must have a name defined.");
163 
164  if (parameter.Name == QueryParameter.Marker)
165  throw new InvalidOperationException();
166  if (parameter.Name.Length <= 1)
167  throw new InvalidOperationException();
168  if (!Char.IsLetter(parameter.Name[0]) &&
169  parameter.Name[0] != QueryParameter.NamePrefix)
170  throw new InvalidOperationException();
171  }
172 
173  query.Parameters.Add(parameter);
174  }
175 
176  return query;
177  }
A long string in the system.
QueryParameter PrepareParameter(DeveelDbParameter parameter)
List< QueryParameter > preparedParameters
QueryParameterStyle
In a SQL query object, this is the form of parameters passed from the client side to the server side...
DeveelDbConnectionStringBuilder Settings
DeveelDbParameterCollection parameters
void Deveel.Data.Client.DeveelDbCommand.CreateResults ( IQueryResponse[]  response)
inlineprivate

Definition at line 105 of file DeveelDbCommand.cs.

105  {
106  results = new LocalQueryResult[response.Length];
107 
108  for (int i = 0; i < response.Length; i++) {
109  var r = response[i];
110  var columns = new QueryResultColumn[r.ColumnCount];
111  for (int j = 0; j < columns.Length; j++) {
112  columns[j] = r.GetColumn(j);
113  }
114 
115  var result = new LocalQueryResult(connection);
116  result.QueryTime = r.QueryTimeMillis;
117 
118  result.Setup(r.ResultId, columns, r.RowCount);
119  result.SetFetchSize(connection.Settings.FetchSize);
120  result.SetMaxRowCount(connection.Settings.MaxFetchSize);
121 
122  // Does the result set contain large objects? We can't cache a
123  // result that contains binary data.
124 
125  bool hasLargeObject = result.HasLargeObject;
126 
127  // If the result row count < 40 then download and store locally in the
128  // result set and dispose the resources on the server.
129  if (!hasLargeObject && result.RowCount < 40) {
130  result.DownloadAndClose();
131  } else {
132  result.Download(0, System.Math.Min(10, result.RowCount));
133  }
134 
135  results[i] = result;
136  }
137  }
DeveelDbConnectionStringBuilder Settings
override void Deveel.Data.Client.DeveelDbCommand.Dispose ( bool  disposing)
inlineprotected

Definition at line 384 of file DeveelDbCommand.cs.

384  {
385  if (disposing) {
386  if (results != null) {
387  foreach (var result in results) {
388  result.Dispose();
389  }
390  }
391 
392  if (parameters != null) {
393  foreach (IDbDataParameter parameter in parameters) {
394  if (parameter.Value is IDisposable) {
395  try {
396  ((IDisposable)parameter.Value).Dispose();
397  } catch (Exception) {
398  }
399  }
400  }
401 
402  parameters.Clear();
403  }
404 
405  if (preparedParameters != null) {
406  foreach (var parameter in preparedParameters) {
407  if (parameter.Value is IDisposable) {
408  try {
409  ((IDisposable)parameter.Value).Dispose();
410  } catch (Exception) {
411  }
412  }
413  }
414  }
415  }
416 
417  preparedParameters = null;
418  parameters = null;
419  results = null;
420 
421  base.Dispose(disposing);
422  }
List< QueryParameter > preparedParameters
DeveelDbParameterCollection parameters
override DbDataReader Deveel.Data.Client.DeveelDbCommand.ExecuteDbDataReader ( CommandBehavior  behavior)
inlineprotected

Definition at line 309 of file DeveelDbCommand.cs.

309  {
310  return ExecuteReader(behavior);
311  }
new DeveelDbDataReader ExecuteReader()
override int Deveel.Data.Client.DeveelDbCommand.ExecuteNonQuery ( )
inline

Definition at line 335 of file DeveelDbCommand.cs.

335  {
336  try {
338 
339  connection.ChangeState(ConnectionState.Executing);
340 
341  ExecuteQuery();
342 
343  if (results == null || results.Length == 0)
344  return -1;
345 
346  var result = results[0];
347  if (!result.IsUpdate)
348  return -1;
349 
350  return result.AffectedRows;
351  } catch (Exception ex) {
352  throw new DeveelDbException("An error occurred while executing the non-query command.", ex);
353  } finally {
355  }
356  }
void ChangeState(ConnectionState newState)
void Deveel.Data.Client.DeveelDbCommand.ExecuteQuery ( )
inlineprivate

Definition at line 97 of file DeveelDbCommand.cs.

97  {
98  var query = CreateQuery();
99 
100  int commitId = Transaction != null ? Transaction.CommitId : -1;
101  var response = connection.ExecuteQuery(commitId, query);
102  CreateResults(response);
103  }
new DeveelDbTransaction Transaction
void CreateResults(IQueryResponse[] response)
IQueryResponse[] ExecuteQuery(int commitId, SqlQuery query)
new DeveelDbDataReader Deveel.Data.Client.DeveelDbCommand.ExecuteReader ( CommandBehavior  behavior)
inline

Definition at line 313 of file DeveelDbCommand.cs.

313  {
314  try {
316 
317  if (connection.State == ConnectionState.Fetching)
318  throw new InvalidOperationException("Another reader is already open for the connection.");
319 
320  if (connection.State != ConnectionState.Open)
321  throw new InvalidOperationException("The connection is not open.");
322 
323  ExecuteQuery();
324 
325  return new DeveelDbDataReader(this, behavior);
326  } catch (Exception ex) {
327  throw new DeveelDbException("An error occurred when executing the reader.", ex);
328  }
329  }
new DeveelDbDataReader Deveel.Data.Client.DeveelDbCommand.ExecuteReader ( )
inline

Definition at line 331 of file DeveelDbCommand.cs.

331  {
332  return ExecuteReader(CommandBehavior.Default);
333  }
new DeveelDbDataReader ExecuteReader()
override object Deveel.Data.Client.DeveelDbCommand.ExecuteScalar ( )
inline

Definition at line 358 of file DeveelDbCommand.cs.

358  {
359  try {
361 
362  connection.ChangeState(ConnectionState.Executing);
363 
364  ExecuteQuery();
365 
366  if (results == null || results.Length == 0)
367  return null;
368 
369  var result = results[0];
370  if (!result.First())
371  return null;
372 
373  if (result.RowCount == 0)
374  return null;
375 
376  return result.GetRuntimeValue(0);
377  } catch (Exception ex) {
378  throw new DeveelDbException("Error when selecting a scalar value.", ex);
379  } finally {
381  }
382  }
void ChangeState(ConnectionState newState)
QueryParameterDirection Deveel.Data.Client.DeveelDbCommand.GetParamDirection ( SysParameterDirection  direction)
inlineprivate

Definition at line 63 of file DeveelDbCommand.cs.

63  {
64  if (direction == SysParameterDirection.Input)
65  return QueryParameterDirection.In;
66  if (direction == SysParameterDirection.Output)
67  return QueryParameterDirection.Out;
68  if (direction == SysParameterDirection.InputOutput)
69  return QueryParameterDirection.InOut;
70 
71  throw new NotSupportedException();
72  }
bool Deveel.Data.Client.DeveelDbCommand.NextResult ( )
inlinepackage

Definition at line 272 of file DeveelDbCommand.cs.

272  {
273  // If we are at the end then return false
274  if (results == null ||
275  resultIndex + 1 >= results.Length) {
276  return false;
277  }
278 
279  // Move to the next result set.
280  ++resultIndex;
281 
282  // We successfully moved to the next result
283  return true;
284  }
override void Deveel.Data.Client.DeveelDbCommand.Prepare ( )
inline

Definition at line 179 of file DeveelDbCommand.cs.

179  {
180  if (!prepared) {
181  try {
182  PrepareCommand();
183  } finally {
184  prepared = true;
185  }
186  }
187  }
void Deveel.Data.Client.DeveelDbCommand.PrepareCommand ( )
inlineprivate

Definition at line 189 of file DeveelDbCommand.cs.

189  {
190 
191  }
QueryParameter Deveel.Data.Client.DeveelDbCommand.PrepareParameter ( DeveelDbParameter  parameter)
inlineprivate

Definition at line 74 of file DeveelDbCommand.cs.

74  {
75  // TODO: If we have a Value that is a Stream object, upload it and get
76  // back the object ID to replace the value
77 
78  var name = parameter.ParameterName;
79  if (String.IsNullOrEmpty(name))
80  name = QueryParameter.Marker;
81 
82  var meta = new [] {
83  new DataTypeMeta("MaxSize", parameter.Size.ToString()),
84  new DataTypeMeta("Precision", parameter.Precision.ToString()),
85  new DataTypeMeta("Scale", parameter.Scale.ToString()),
86  new DataTypeMeta("Locale", parameter.Locale)
87  };
88 
89  var dataType = SqlType.Resolve(parameter.SqlType, meta);
90  var value = dataType.CreateFrom(parameter.Value);
91 
92  var queryParameter = new QueryParameter(name, dataType, value);
93  queryParameter.Direction = GetParamDirection(parameter.Direction);
94  return queryParameter;
95  }
A long string in the system.
QueryParameterDirection GetParamDirection(SysParameterDirection direction)
Defines the properties of a specific SQL Type and handles the values compatible.
Definition: SqlType.cs:33
static SqlType Resolve(SqlTypeCode typeCode)
Definition: SqlType.cs:441
virtual ISqlObject CreateFrom(object value)
Definition: SqlType.cs:437
IQToolkit.Data.Common.QueryParameter QueryParameter

Member Data Documentation

DeveelDbConnection Deveel.Data.Client.DeveelDbCommand.connection
private

Definition at line 33 of file DeveelDbCommand.cs.

DeveelDbParameterCollection Deveel.Data.Client.DeveelDbCommand.parameters
private

Definition at line 39 of file DeveelDbCommand.cs.

bool Deveel.Data.Client.DeveelDbCommand.prepared
private

Definition at line 36 of file DeveelDbCommand.cs.

List<QueryParameter> Deveel.Data.Client.DeveelDbCommand.preparedParameters
private

Definition at line 37 of file DeveelDbCommand.cs.

int Deveel.Data.Client.DeveelDbCommand.resultIndex
private

Definition at line 41 of file DeveelDbCommand.cs.

LocalQueryResult [] Deveel.Data.Client.DeveelDbCommand.results
private

Definition at line 42 of file DeveelDbCommand.cs.

int Deveel.Data.Client.DeveelDbCommand.timeout
private

Definition at line 32 of file DeveelDbCommand.cs.

DeveelDbTransaction Deveel.Data.Client.DeveelDbCommand.transaction
private

Definition at line 34 of file DeveelDbCommand.cs.

Property Documentation

override string Deveel.Data.Client.DeveelDbCommand.CommandText
getset

Definition at line 204 of file DeveelDbCommand.cs.

override int Deveel.Data.Client.DeveelDbCommand.CommandTimeout
getset

Definition at line 206 of file DeveelDbCommand.cs.

override CommandType Deveel.Data.Client.DeveelDbCommand.CommandType
getset

Definition at line 218 of file DeveelDbCommand.cs.

new DeveelDbConnection Deveel.Data.Client.DeveelDbCommand.Connection
getset

Definition at line 227 of file DeveelDbCommand.cs.

LocalQueryResult Deveel.Data.Client.DeveelDbCommand.CurrentResult
getpackage

Definition at line 193 of file DeveelDbCommand.cs.

override DbConnection Deveel.Data.Client.DeveelDbCommand.DbConnection
getsetprotected

Definition at line 222 of file DeveelDbCommand.cs.

override DbParameterCollection Deveel.Data.Client.DeveelDbCommand.DbParameterCollection
getprotected

Definition at line 232 of file DeveelDbCommand.cs.

override DbTransaction Deveel.Data.Client.DeveelDbCommand.DbTransaction
getsetprotected

Definition at line 240 of file DeveelDbCommand.cs.

override bool Deveel.Data.Client.DeveelDbCommand.DesignTimeVisible
getset

Definition at line 258 of file DeveelDbCommand.cs.

new DeveelDbParameterCollection Deveel.Data.Client.DeveelDbCommand.Parameters
get

Definition at line 236 of file DeveelDbCommand.cs.

new DeveelDbTransaction Deveel.Data.Client.DeveelDbCommand.Transaction
getset

Definition at line 245 of file DeveelDbCommand.cs.

override UpdateRowSource Deveel.Data.Client.DeveelDbCommand.UpdatedRowSource
getset

Definition at line 220 of file DeveelDbCommand.cs.


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