/// <summary> /// Prepara para executar Comandos de Select e Count /// </summary> public void PrepareSelectCountCommands() { _Parameters = new Dictionary <string, ParameterStruct>(); CreateParameters(); Select = new TableCommand("SELECT {SQL_Select} FROM " + SqlFrom + " {SQL_Where} {SQL_OrderBy}", GetParametersNames(ParameterType.Select), Dao); Count = new TableCommand("SELECT COUNT(*) FROM " + SqlFrom, new string[] { }, Dao); }
private ResultSegment <TElement> ParseTableQueryResponse( IEnumerable <TElement> dataServiceQueryResponse, RequestResult reqResult, TableCommand <ResultSegment <TElement>, IEnumerable <TElement> > cmd) { if (reqResult.Exception != null) { DataServiceClientException dsce = TableUtilities.FindInnerExceptionOfType <DataServiceClientException>(reqResult.Exception); if (this.IgnoreResourceNotFoundException && dsce != null && (HttpStatusCode)dsce.StatusCode == HttpStatusCode.NotFound) { return(new ResultSegment <TElement>(new List <TElement>())); } throw reqResult.Exception; } QueryOperationResponse response = dataServiceQueryResponse as QueryOperationResponse; ResultSegment <TElement> retSeg = new ResultSegment <TElement>(dataServiceQueryResponse.ToList()); // Get continuation token from response retSeg.ContinuationToken = TableUtilities.ContinuationFromResponse(response); return(retSeg); }
public DataServiceResponse SaveChangesWithRetries(SaveChangesOptions options, TableRequestOptions requestOptions = null, OperationContext operationContext = null) { requestOptions = TableRequestOptions.ApplyDefaults(requestOptions, this.ServiceClient); operationContext = operationContext ?? new OperationContext(); TableCommand <DataServiceResponse, DataServiceResponse> cmd = this.GenerateSaveChangesCommand(options, requestOptions); return(TableExecutor.ExecuteSync(cmd, requestOptions.RetryPolicy, operationContext)); }
public ICancellableAsyncResult BeginSaveChangesWithRetries(SaveChangesOptions options, TableRequestOptions requestOptions, OperationContext operationContext, AsyncCallback callback, object state) { requestOptions = TableRequestOptions.ApplyDefaults(requestOptions, this.ServiceClient); operationContext = operationContext ?? new OperationContext(); TableCommand <DataServiceResponse, DataServiceResponse> cmd = this.GenerateSaveChangesCommand(options, requestOptions); return(TableExecutor.BeginExecuteAsync(cmd, requestOptions.RetryPolicy, operationContext, callback, state)); }
internal ResultSegment <TElement> ExecuteSegmentedCore( TableContinuationToken continuationToken, TableRequestOptions requestOptions, OperationContext operationContext) { TableCommand <ResultSegment <TElement>, IEnumerable <TElement> > cmd = this.GenerateExecuteCommand(continuationToken, requestOptions); return(TableExecutor.ExecuteSync(cmd, requestOptions.RetryPolicy, operationContext)); }
public ICancellableAsyncResult BeginExecuteSegmented(TableContinuationToken currentToken, TableRequestOptions requestOptions, OperationContext operationContext, AsyncCallback callback, object state) { requestOptions = TableRequestOptions.ApplyDefaults(requestOptions, this.Context.ServiceClient); operationContext = operationContext ?? new OperationContext(); TableCommand <ResultSegment <TElement>, IEnumerable <TElement> > cmd = this.GenerateExecuteCommand( currentToken, requestOptions); return(TableExecutor.BeginExecuteAsync(cmd, requestOptions.RetryPolicy, operationContext, callback, state)); }
internal void ApplyToStorageCommand <T, INTERMEDIATE_TYPE>(TableCommand <T, INTERMEDIATE_TYPE> cmd) { if (this.LocationMode.HasValue && (this.LocationMode.Value != RetryPolicies.LocationMode.PrimaryOnly)) { throw new InvalidOperationException(SR.PrimaryOnlyCommand); } this.ApplyToStorageCommandCommon(cmd); }
private void SetParameters(TableCommand Command, ParameterType ParamType, bool KeepCurrentRecord, GeneralDataProvider Provider) { if (!IsView) { if (BasePage != null) { BasePage.GetParameters(KeepCurrentRecord, Provider); } SetParameters(Command, ParamType); } }
internal TableCommand <DataServiceResponse, DataServiceResponse> GenerateSaveChangesCommand(SaveChangesOptions options, TableRequestOptions requestOptions) { TableCommand <DataServiceResponse, DataServiceResponse> cmd = new TableCommand <DataServiceResponse, DataServiceResponse>(); if (requestOptions.ServerTimeout.HasValue) { this.Timeout = (int)requestOptions.ServerTimeout.Value.TotalSeconds; } cmd.ExecuteFunc = () => this.SaveChanges(options); cmd.Begin = (callback, state) => this.BeginSaveChanges(options, callback, state); cmd.End = this.EndSaveChanges; cmd.ParseResponse = this.ParseDataServiceResponse; cmd.ApplyRequestOptions(requestOptions); cmd.Context = this; return(cmd); }
protected void SetParameters(TableCommand Command, ParameterType ParamType) { foreach (string ParamKey in _Parameters.Keys) { ParameterStruct Param = _Parameters[ParamKey]; if ((ParamType == ParameterType.Select && Param.Select) || (ParamType == ParameterType.Update && Param.Update) || (ParamType == ParameterType.Delete && Param.Delete) || (ParamType == ParameterType.Relation && Param.Relation || ParamType == ParameterType.Relation && Param.Select)) { string paramformat = ""; if (Param.Parameter is DateParameter) { paramformat = Select.DateFormat; } Command.AddParameter(ParamKey, Param.Parameter, paramformat, Dao.PoeColAspas(Param.Name), Condition.Equal, false); } } }
private TableCommand <ResultSegment <TElement>, IEnumerable <TElement> > GenerateExecuteCommand(TableContinuationToken continuationToken, TableRequestOptions requestOptions) { DataServiceQuery <TElement> localQuery = this.Query; // Continuation localQuery = TableUtilities.ApplyContinuationToQuery <TElement>(continuationToken, localQuery); if (requestOptions.ServerTimeout.HasValue) { localQuery = localQuery.AddQueryOption("timeout", Convert.ToString(requestOptions.ServerTimeout.Value.TotalSeconds)); } TableCommand <ResultSegment <TElement>, IEnumerable <TElement> > cmd = new TableCommand <ResultSegment <TElement>, IEnumerable <TElement> >(); cmd.ExecuteFunc = localQuery.Execute; cmd.Begin = (callback, state) => localQuery.BeginExecute(callback, state); cmd.End = localQuery.EndExecute; cmd.ParseResponse = this.ParseTableQueryResponse; cmd.ApplyRequestOptions(requestOptions); cmd.Context = this.Context; return(cmd); }
private DataSet GetDataGrid(int CurrentPageIndex, int PageSize, out int TotalRecords) { string ViewName = HttpContext.Current.Request["page"].ToString(); ViewSettings Sql = (ViewSettings)Deserialize(Server.MapPath("../Views/" + ViewName)); DataAccessObject Dao = Settings.GetDataAccessObject(((COMPONENTS.Databases)HttpContext.Current.Application["Databases"])[Sql.DataBase]); DataCommand Select = new TableCommand(Sql.GenerateSqlQuery(), new string[0], Dao); DataCommand Count = new TableCommand("SELECT COUNT(*) FROM (" + Sql.GenerateSqlQuery() + ") t", new string[] { }, Dao); TotalRecords = (int)Count.ExecuteScalar(); if (CurrentPageIndex == -1) { CurrentPageIndex = (int)Math.Ceiling((decimal)TotalRecords / (decimal)PageSize) - 1; } if (TotalRecords > 0) { return(Select.Execute(CurrentPageIndex * PageSize, PageSize)); } return(Select.Execute()); }
/// <summary> /// Efetua o select no banco de acordo com o filtro e numero da pagina /// </summary> /// <returns>Retorna item com o conteudo da celula que retornou no select</returns> public int InsertItem(GeneralDataProviderItem Item) { if (IsView) { return(0); } this.Item = Item; this.Item.IsNew = true; string fieldsList = ""; string valuesList = ""; Insert = new TableCommand("INSERT INTO " + Dao.PoeColAspas(TableName) + "{Fields}{Values}", new string[0], Dao); foreach (FieldBase Field in Item.Fields.Values) { string FieldName = Field.Name; string format = (Field.FieldType == FieldType.Date ? Insert.DateFormat : ""); if (Field.FieldType == FieldType.Boolean) { format = Insert.BoolFormat; } if (!Field.IsEmpty && Field.IsUpdatable && (Field is BinaryField || Insert.Dao.ToSql(Field.GetFormattedValue(format), Field.FieldType, Field.AllowEmpty) != "NULL")) { if (!(Field is BinaryField) || ((BinaryField)Field).BinaryValue != null) { fieldsList += Dao.PoeColAspas(FieldName) + ","; } if (Field is BinaryField) { if (((BinaryField)Field).BinaryValue != null) { valuesList += Dao.ParameterDelimiter + Utility.PoeUnderLines(FieldName).ToUpper() + ","; Insert.Images.Add(Utility.PoeUnderLines(FieldName).ToUpper(), (byte[])((BinaryField)Field).BinaryValue); } } else { valuesList += Insert.Dao.ToSql(Field.GetFormattedValue(format), Field.FieldType, Field.AllowEmpty) + ","; } } } if (fieldsList.Length > 0) { Insert.SqlQuery.Replace("{Fields}", "(" + fieldsList.TrimEnd(',') + ")"); Insert.SqlQuery.Replace("{Values}", " VALUES (" + valuesList.TrimEnd(',') + ")"); } else { Insert.SqlQuery.Replace("{Fields}{Values}", " DEFAULT VALUES"); } object result = 0; bool InTransaction = false; try { Dao.OpenConnection(); if (Dao.Transaction == null) { Dao.BeginTrans(); InTransaction = true; } result = ExecuteInsert(); int i = 0; if (InTransaction) { BasePage.OnCommiting(); Dao.CommitTrans(); } } catch (Exception e) { if (InTransaction) { BasePage.OnRollbacking(); Dao.RollBack(); } throw (e); } finally { Dao.CloseConnection(); } return((int)result); }
protected void PrepareUpdateCommand() { Update = new TableCommand("UPDATE " + Dao.PoeColAspas(TableName) + " SET {Values}", GetParametersNames(ParameterType.Update), Dao); }
private DataServiceResponse ParseDataServiceResponse(DataServiceResponse resp, RequestResult reqResult, TableCommand<DataServiceResponse, DataServiceResponse> cmd) { if (reqResult.Exception != null) { throw reqResult.Exception; } return resp; }
internal TableCommand<DataServiceResponse, DataServiceResponse> GenerateSaveChangesCommand(SaveChangesOptions options, TableRequestOptions requestOptions) { TableCommand<DataServiceResponse, DataServiceResponse> cmd = new TableCommand<DataServiceResponse, DataServiceResponse>(); if (requestOptions.ServerTimeout.HasValue) { this.Timeout = (int)requestOptions.ServerTimeout.Value.TotalSeconds; } cmd.ExecuteFunc = () => this.SaveChanges(options); cmd.Begin = (callback, state) => this.BeginSaveChanges(options, callback, state); cmd.End = this.EndSaveChanges; cmd.ParseResponse = this.ParseDataServiceResponse; cmd.ParseDataServiceError = StorageExtendedErrorInformation.ReadDataServiceResponseFromStream; cmd.Context = this; requestOptions.ApplyToStorageCommand(cmd); return cmd; }
protected void PrepareDeleteCommand() { Delete = new TableCommand("DELETE FROM " + Dao.PoeColAspas(TableName), GetParametersNames(ParameterType.Delete), Dao); }
private DataServiceResponse ParseDataServiceResponse(DataServiceResponse resp, RequestResult reqResult, TableCommand <DataServiceResponse, DataServiceResponse> cmd) { if (reqResult.Exception != null) { throw reqResult.Exception; } return(resp); }
internal TableCommand<DataServiceResponse, DataServiceResponse> GenerateSaveChangesCommand(SaveChangesOptions options, TableRequestOptions requestOptions) { TableCommand<DataServiceResponse, DataServiceResponse> cmd = new TableCommand<DataServiceResponse, DataServiceResponse>(); if (requestOptions.ServerTimeout.HasValue) { this.Timeout = (int)requestOptions.ServerTimeout.Value.TotalSeconds; } cmd.ExecuteFunc = () => this.SaveChanges(options); cmd.Begin = (callback, state) => this.BeginSaveChanges(options, callback, state); cmd.End = this.EndSaveChanges; cmd.ParseResponse = this.ParseDataServiceResponse; cmd.ApplyRequestOptions(requestOptions); cmd.Context = this; return cmd; }