/// <summary> /// Get the query result data for the current expression. /// </summary> /// <param name="model">Expression tree model containing the expression inspector data.</param> /// <returns>The collection of message data.</returns> private Message[] GetQueryData(Nequeo.Model.ExpressionTreeModel model) { List <Message> data = new List <Message>(); List <Exception> exceptions = new List <System.Exception>(); // Get all the expression model data. Nequeo.Model.ExpressionModel expressionModel = model.GetExpression(true); // If where query expression data exists. if (expressionModel.Where.Length > 0) { // For each where query expression. foreach (string item in expressionModel.Where) { // Get the name and value and operator information. string[] split = item.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); string name = split[0]; string operatorNode = split[1]; string value = split[2].Trim(new char[] { '"' }); // If the current item is the 'Message' model 'Name' property. if (name.ToLower().Trim() == "name") // "name" = This is the 'Name' property in the 'Message' model { // Create a new message. Message messageData = new Message() { Name = value, Data = _message.Data }; try { // Get the message data. data.Add(SendMessage(messageData)); } catch (Exception ex) { exceptions.Add(ex); } } } } // get the list of exceptions. _exceptions = exceptions.ToArray(); // Return the collection of data. return(data.ToArray()); }
/// <summary> /// Create the query string. /// </summary> /// <param name="model">The expression tree model containing the query data.</param> /// <param name="take">The amount of data to take.</param> /// <returns>The query; else null.</returns> private string GetQuery(Nequeo.Model.ExpressionTreeModel model, out int take) { string query = ""; int takeInternal = 0; string select = "*"; take = Int32.MaxValue; // Get all the expression model data. Nequeo.Model.ExpressionModel expressionModel = model.GetExpression(true); // Get the select. if (!String.IsNullOrEmpty(model.Select)) { // Get the select query. select = model.Select.Replace("[", "").Replace("]", ""); query += " SELECT " + select; } else { // Get the default select. query += " SELECT " + select; } // From query += " FROM " + _domainName; // Get the where. if (!String.IsNullOrEmpty(model.Where)) { // Set the where. query += " WHERE " + model.Where. Replace("[", "").Replace("]", ""). Replace("\"", "'").Replace("==", "="). Replace("&&", "AND").Replace("||", "OR"); } // Get the orderby. if (!String.IsNullOrEmpty(model.Orderby)) { // Set the order by. query += " ORDER BY " + model.Orderby.Replace("[", "").Replace("]", ""); } else if (!String.IsNullOrEmpty(model.OrderbyDescending)) { // Set the order by descending. query += " ORDER BY " + model.OrderbyDescending.Replace("[", "").Replace("]", ""); } // Is there a take. bool isTakeSet = Int32.TryParse(model.Take, out takeInternal); if (isTakeSet) { // If take has been set. if (takeInternal > 0) { take = takeInternal; } query += " LIMIT " + take.ToString(); } // Return the query. return(query.Trim()); }