18 using System.Collections.Generic;
30 namespace Deveel.Data.Client {
49 : this(connection, null) {
53 : this(null, commandText) {
57 Connection = connection;
58 CommandText = commandText;
71 throw new NotSupportedException();
79 if (
String.IsNullOrEmpty(name))
90 var value = dataType.
CreateFrom(parameter.Value);
93 queryParameter.Direction = GetParamDirection(parameter.Direction);
94 return queryParameter;
98 var query = CreateQuery();
100 int commitId = Transaction != null ? Transaction.CommitId : -1;
101 var response = connection.
ExecuteQuery(commitId, query);
102 CreateResults(response);
108 for (
int i = 0; i < response.Length; i++) {
111 for (
int j = 0; j < columns.Length; j++) {
112 columns[j] = r.GetColumn(j);
116 result.QueryTime = r.QueryTimeMillis;
118 result.Setup(r.ResultId, columns, r.RowCount);
125 bool hasLargeObject = result.HasLargeObject;
129 if (!hasLargeObject && result.RowCount < 40) {
130 result.DownloadAndClose();
132 result.Download(0,
System.Math.Min(10, result.RowCount));
141 if (prepared && preparedParameters != null) {
142 queryParameters = preparedParameters.ToArray();
145 for (
int i = 0; i < parameters.
Count; i++) {
146 var parameter = parameters[i];
147 var queryParam = PrepareParameter(parameter);
148 queryParameters[i] = queryParam;
152 var query =
new SqlQuery(CommandText);
155 foreach (var parameter
in queryParameters) {
157 if (!
String.IsNullOrEmpty(parameter.Name) &&
159 throw new InvalidOperationException();
161 if (
String.IsNullOrEmpty(parameter.Name))
162 throw new InvalidOperationException(
"Named parameters must have a name defined.");
165 throw new InvalidOperationException();
166 if (parameter.Name.Length <= 1)
167 throw new InvalidOperationException();
168 if (!
Char.IsLetter(parameter.Name[0]) &&
170 throw new InvalidOperationException();
173 query.Parameters.Add(parameter);
195 if (results != null) {
196 if (resultIndex < results.Length) {
197 return results[resultIndex];
204 public override string CommandText {
get; set; }
206 public override int CommandTimeout {
208 if (timeout == null && connection != null)
213 return timeout.Value;
215 set { timeout = value; }
218 public override CommandType CommandType {
get; set; }
220 public override UpdateRowSource UpdatedRowSource {
get; set; }
222 protected override DbConnection DbConnection {
223 get {
return Connection; }
228 get {
return connection; }
229 set { connection = value; }
232 protected override DbParameterCollection DbParameterCollection {
233 get {
return Parameters; }
237 get {
return parameters; }
240 protected override DbTransaction DbTransaction {
241 get {
return Transaction; }
246 get {
return transaction; }
248 if (value == null && transaction != null)
250 else if (transaction != null &&
251 (value != null && value.CommitId!= transaction.
CommitId))
252 throw new ArgumentException(
"The command is already bound to another transaction.");
258 public override bool DesignTimeVisible {
get; set; }
262 if (results != null) {
263 foreach (var result
in results) {
274 if (results == null ||
275 resultIndex + 1 >= results.Length) {
287 return CreateParameter();
295 if (Connection == null)
298 if (Connection.State == ConnectionState.Closed) {
303 }
catch (Exception ex) {
310 return ExecuteReader(behavior);
315 AssertConnectionOpen();
317 if (connection.
State == ConnectionState.Fetching)
318 throw new InvalidOperationException(
"Another reader is already open for the connection.");
320 if (connection.
State != ConnectionState.Open)
321 throw new InvalidOperationException(
"The connection is not open.");
326 }
catch (Exception ex) {
332 return ExecuteReader(CommandBehavior.Default);
337 AssertConnectionOpen();
343 if (results == null || results.Length == 0)
346 var result = results[0];
347 if (!result.IsUpdate)
351 }
catch (Exception ex) {
352 throw new DeveelDbException(
"An error occurred while executing the non-query command.", ex);
360 AssertConnectionOpen();
366 if (results == null || results.Length == 0)
369 var result = results[0];
373 if (result.RowCount == 0)
377 }
catch (Exception ex) {
384 protected override void Dispose(
bool disposing) {
386 if (results != null) {
387 foreach (var result
in results) {
392 if (parameters != null) {
393 foreach (IDbDataParameter parameter
in parameters) {
394 if (parameter.Value is IDisposable) {
396 ((IDisposable)parameter.Value).Dispose();
397 }
catch (Exception) {
405 if (preparedParameters != null) {
406 foreach (var parameter
in preparedParameters) {
407 if (parameter.Value is IDisposable) {
409 ((IDisposable)parameter.Value).Dispose();
410 }
catch (Exception) {
417 preparedParameters = null;
DeveelDbCommand(DeveelDbConnection connection)
DeveelDbCommand(string commandText)
new DeveelDbDataReader ExecuteReader()
LocalQueryResult[] results
A long string in the system.
QueryParameterDirection GetParamDirection(SysParameterDirection direction)
new DeveelDbParameter CreateParameter()
void ChangeState(ConnectionState newState)
override void Dispose(bool disposing)
QueryParameter PrepareParameter(DeveelDbParameter parameter)
The response to a command executed via the IDatabaseInterface.ExecuteQuery method in the IDatabaseInt...
override ConnectionState State
QueryParameterStyle ParameterStyle
List< QueryParameter > preparedParameters
void AssertConnectionOpen()
new DeveelDbDataReader ExecuteReader(CommandBehavior behavior)
object GetRuntimeValue(int ordinal)
override string ParameterName
byte IDbDataParameter. Precision
override object ExecuteScalar()
void CreateResults(IQueryResponse[] response)
QueryParameterStyle
In a SQL query object, this is the form of parameters passed from the client side to the server side...
Defines the properties of a specific SQL Type and handles the values compatible.
override DbDataReader ExecuteDbDataReader(CommandBehavior behavior)
DeveelDbConnectionStringBuilder Settings
void DisposeResult(int resultId)
override int ExecuteNonQuery()
override DbParameter CreateDbParameter()
DeveelDbParameterCollection parameters
static SqlType Resolve(SqlTypeCode typeCode)
virtual ISqlObject CreateFrom(object value)
DeveelDbCommand(DeveelDbConnection connection, string commandText)
byte IDbDataParameter. Scale
IQToolkit.Data.Common.QueryParameter QueryParameter
DeveelDbTransaction transaction
IQueryResponse[] ExecuteQuery(int commitId, SqlQuery query)
DeveelDbConnection connection