Ejemplo n.º 1
0
        public ITableRow GetMetaRow(
			long                    requestId,
			long                    sessionId,
			DateTime                timestamp,
			QueryInstanceResultInfo queryInstanceResult,
			long?                   queryId,
			long?                   rowsSaved
		)
        {
            string    errorNumber    = null;
            string    errorCode      = null;
            string    errorMessage   = null;
            Int64     recordSetCount = 0L;
            ITableRow row            = this.NewRow();

            row.Values.Add(QueryDirectory.TableName.AsFk(),      queryId);
            row.Values.Add(QueryGroupDirectory.TableName.AsFk(), null);
            row.Values.Add(RequestIdFieldName,                   requestId);
            row.Values.Add(SessionIdFieldName,                   sessionId);
            row.Values.Add(TableDefinition.DateCreated,          timestamp);

            if (queryInstanceResult != null)
            {
                if (queryInstanceResult.ErrorInfo == null)
                {
                    if (queryInstanceResult.DatabasesResult.ContainsKey("")) //group.Name))
                    {
                        QueryDatabaseResultInfo databaseResult = queryInstanceResult.DatabasesResult[""]; //group.Name];

                        if (rowsSaved == null)
                        {
                            rowsSaved = databaseResult.DataTables != null
                                ? databaseResult.DataTables.Select(x => x.Rows).Sum(x => x.Count)
                                : 0L;
                        }

                        recordSetCount = (databaseResult.DataTables == null)
                            ? 0L
                            : databaseResult.DataTables.Length;

                        if (databaseResult.ErrorInfo != null)
                        {
                            errorNumber  = databaseResult.ErrorInfo.Number;
                            errorCode    = databaseResult.ErrorInfo.Code;
                            errorMessage = databaseResult.ErrorInfo.Message;
                        }
                    }
                }
                else
                {
                    errorNumber  = queryInstanceResult.ErrorInfo.Number;
                    errorCode    = queryInstanceResult.ErrorInfo.Code;
                    errorMessage = queryInstanceResult.ErrorInfo.Message;
                    rowsSaved    = 0L;
                }
            }

            row.Values.Add(RowCountFieldName,       rowsSaved);
            row.Values.Add(RecordSetCountFieldName, recordSetCount);
            row.Values.Add(ErrorIdFieldName,        errorNumber);
            row.Values.Add(ErrorCodeFieldName,      errorCode);
            row.Values.Add(ErrorMessageFieldName,   errorMessage);

            return row;
        }
Ejemplo n.º 2
0
		private QueryInstanceResultInfo GetInstanceResult(
			MultyQueryResultInfo  result,
			InstanceInfo          instance,
			Int64                 queryId,
			TemplateNodeQueryInfo templateNodeQueryInfo,
			List<QueryInfo>       queries
		)
		{
			QueryInstanceResultInfo instanceResult = null;
			Int64                   recordSetCount = 0L;
			ITableRow               meta           = Storage.ReadLastMeta(queryId);

			if (meta != null)
			{
				DateTime timestamp = (DateTime)meta.Values[TableDefinition.DateCreated];

				result.RefreshTimestamp(timestamp);

				if (!string.IsNullOrEmpty(meta.Values[MetaResultTable.ErrorMessageFieldName].ToString()))
				{
					instanceResult = new QueryInstanceResultInfo(
						new ErrorInfo(
							meta.Values[MetaResultTable.ErrorIdFieldName].ToString(),
							meta.Values[MetaResultTable.ErrorCodeFieldName].ToString(),
							meta.Values[MetaResultTable.ErrorMessageFieldName].ToString(),
							(DateTime)meta.Values[TableDefinition.DateCreated]
						),
						instance
					);
				}
				else
				{
					instanceResult = new QueryInstanceResultInfo(instance);
				}

				recordSetCount = (Int64) meta.Values[MetaResultTable.RecordSetCountFieldName];

				DataTable[] dataTables = GetDataTables(
					recordSetCount,
					queryId,
					instance,
					templateNodeQueryInfo
				);

				QueryInfo query = queries.FirstOrDefault(x => x.Source == instance.Type || x.Source == QuerySource.SQLite);

				if (query != null)
				{
					QueryDatabaseResultInfo databaseResult = new QueryDatabaseResultInfo(
						dataTables,
						query.Items.GetQueryItemForVersion(instance.GetServerPropertiesSafe().Version),
						base.GroupDefinition.Name,
						base.GroupDefinition.Id
					);

					instanceResult.AddDatabaseResult(databaseResult);
				}
			}

			return instanceResult;
		}
Ejemplo n.º 3
0
		/// <summary>
		/// Add instance result
		/// </summary>
		/// <param name="instanceResult">Instance result</param>
		public void AddInstanceResult(QueryInstanceResultInfo instanceResult)
		{
			this._instancesResult.TryAdd(instanceResult.Instance, instanceResult);
		}
Ejemplo n.º 4
0
		public QueryInstanceResultInfo GetConnectionSelectResults(
			InstanceInfo          selectConnectionInstance,
			QueryInfo             queryInfo,
			QueryItemInfo         queryItem,
			TemplateNodeQueryInfo query
		)
		{
			QueryDatabaseResultInfo dbResultInfo;

			try
			{
				DataTable[] tables = ExecuteSql(
					selectConnectionInstance,
					queryItem,
					query.TemplateNode.GetDefaultDatabase(),
					queryInfo.Parameters,
					query.ParameterValues
				);

				if (tables != null && tables.Length < 0)
				{
					throw new InvalidTemplateException(query + " returned no recordsets.");
				}

				dbResultInfo = new QueryDatabaseResultInfo(tables, queryItem);
			}
			catch (Exception exc)
			{
				ErrorInfo error = new ErrorInfo(exc);

				dbResultInfo = new QueryDatabaseResultInfo(error, queryItem);
			}

			QueryInstanceResultInfo instanceResultInfo = new QueryInstanceResultInfo(selectConnectionInstance);

			instanceResultInfo.AddDatabaseResult(dbResultInfo);

			return instanceResultInfo;
		}
		private void ProcessCodeGuardQuery(
			MultyQueryResultInfo          result,
			TemplateNodeSqlGuardQueryInfo guardQueryInfo)
		{
			var queryResultInfo = result.List.First(item => item.TemplateNodeQuery.Id == guardQueryInfo.SqlQueryId);
			var templateNodeQueryInfo = queryResultInfo.TemplateNodeQuery;
			var userParams = new List<ParameterValue>();

			if (base.Settings != null)
			{
				var querySettings = base.Settings.Connection.Activity.Parameters
					.Where(i => i.Key == guardQueryInfo.IdsHierarchy && i.Value != null);

				foreach (var info in querySettings)
				{
					switch (info.Type)
					{
						case ParameterInfoType.Attribute:
							guardQueryInfo.GetType().GetProperty("User" + info.Parameter)
								.SetValue(guardQueryInfo, info.Value, null);
							break;

						case ParameterInfoType.Parameter:
							var parameter =
								templateNodeQueryInfo.ParameterValues.FirstOrDefault(p => p.Name == info.Parameter);
							if (parameter != null)
							{
								parameter.UserValue = info.Value;
							}
							break;

						case ParameterInfoType.EditableParameter:
							var editparameter = new ParameterValue
							{
								Name = info.Parameter,
								StringValue = info.Default,
								UserValue = info.Value
							};
							userParams.Add(editparameter);
							break;
					}
				}
			}

			var guardQueryResult = new QueryResultInfo();

			foreach (var instanceResult in queryResultInfo.QueryResult.InstancesResult)
			{
				var instance = instanceResult.Key;
				var queryTable = instanceResult.Value.DatabasesResult.First().Value.DataTables.First();

				if (!queryTable.Columns.Contains(guardQueryInfo.QueryCodeColumn))
				{
					continue;
				}

				//var meta = ReadMeta(connectionGroup, templateNode, instance, database, templateNodeQueryInfo).FirstOrDefault();
				var meta = Storage.ReadLastMeta(
					base.TemplateNode,
					instance,
					templateNodeQueryInfo
				);

				if (meta == null)
				{
					continue;
				}

				QueryInstanceResultInfo guardInstanceResult;
				var timestamp = (DateTime)meta.Values[TableDefinition.DateCreated];

				result.RefreshTimestamp(timestamp);

				if (!string.IsNullOrEmpty(meta.Values[MetaResultTable.ErrorMessageFieldName].ToString()))
				{
					guardInstanceResult = new QueryInstanceResultInfo(
						new ErrorInfo(
							meta.Values[MetaResultTable.ErrorIdFieldName].ToString(),
							meta.Values[MetaResultTable.ErrorCodeFieldName].ToString(),
							meta.Values[MetaResultTable.ErrorMessageFieldName].ToString(),
							timestamp
						),
						instance
					);
				}
				else
				{
					guardInstanceResult = new QueryInstanceResultInfo(instance);
				}

				var dataTables = Storage.ReadSqlCodeGuardResult(guardQueryInfo, queryTable, userParams);

				QueryItemInfo queryItemInfo = new QueryItemInfo
				{
					ParentQuery = new QueryInfo { Name = guardQueryInfo.QueryName }
				};

				QueryDatabaseResultInfo databaseResult = new QueryDatabaseResultInfo(
					dataTables,
					queryItemInfo,
					base.GroupDefinition.Name,
					base.GroupDefinition.Id
				);

				guardInstanceResult.AddDatabaseResult(databaseResult);
				guardQueryResult.AddInstanceResult(guardInstanceResult);
			}

			var templateNodeResultItem = new TemplateNodeResultItem(guardQueryInfo, guardQueryResult);

			result.Add(templateNodeResultItem);
		}