/// <summary> /// Execute sql query /// </summary> /// <param name="queryString">query string</param> /// <param name="queryType">query command type</param> /// <param name="tblResult">result of query</param> public bool GetSqlResult(String queryString, QueryCommandType queryType, DataTable tblResult) { try { // create command and assign the query and connection from the constructor MySqlCommand cmd = new MySqlCommand(queryString, _connection); // execute command if (queryType != QueryCommandType.Select) { cmd.ExecuteNonQuery(); } else { // get data from select query MySqlDataAdapter da = new MySqlDataAdapter(); da.SelectCommand = cmd; da.Fill(tblResult); } return(true); } catch { return(false); } }
public IQueryCommand GetCommand(QueryCommandType type, IQueryCommandOptions options, IObjectMapping mapping) { switch (type) { case QueryCommandType.StandardCommand: return(new StandardQueryCommand(options, mapping)); case QueryCommandType.AnyCommand: return(new AnyQueryCommand(options, mapping)); case QueryCommandType.CountCommand: return(new CountQueryCommand(options, mapping)); case QueryCommandType.FirstOrDefaultCommand: return(new FirstOrDefaultQueryCommand(options, mapping)); case QueryCommandType.SingleCommand: return(new SingleQueryCommand(options, mapping)); case QueryCommandType.SingleOrDefaultCommand: return(new SingleOrDefaultQueryCommand(options, mapping)); case QueryCommandType.GetRequestCommand: return(new GetRequestCommand(options, mapping)); default: throw new NotSupportedException(string.Format("QueryCommandType '{0}' is not supported.", type)); } }
public IQueryCommand GetCommand(QueryCommandType type, IQueryCommandOptions options, IObjectMapping mapping) { Type = type; Options = options; Mapping = mapping; return(QueryCommandToReturn); }
private StatementQueryCommandType Convert(QueryCommandType source) { switch (source) { case QueryCommandType.Select: return(StatementQueryCommandType.Select); case QueryCommandType.Insert: return(StatementQueryCommandType.Insert); case QueryCommandType.Update: return(StatementQueryCommandType.Update); case QueryCommandType.Delete: return(StatementQueryCommandType.Delete); case QueryCommandType.Utility: return(StatementQueryCommandType.Utility); } return(StatementQueryCommandType.Unknown); }
private void VisitQueryableMethods(MethodCallExpression m) { switch (m.Method.Name) { case "Where": _exclusiveWhereCount++; foreach (Expression t in m.Arguments) { Visit(t); } _commandType = QueryCommandType.StandardCommand; break; case "WithoutPaging": foreach (Expression t in m.Arguments) { Visit(t); } _commandType = QueryCommandType.StandardCommand; _withoutPaging = true; break; case "GetRequest": foreach (Expression t in m.Arguments) { Visit(t); } _commandType = QueryCommandType.GetRequestCommand; break; case "Any": if (m.Arguments.Count > 1) { _exclusiveWhereCount++; } foreach (Expression t in m.Arguments) { Visit(t); } _commandType = QueryCommandType.AnyCommand; break; case "FirstOrDefault": case "First": if (m.Arguments.Count > 1) { _exclusiveWhereCount++; } foreach (Expression t in m.Arguments) { Visit(t); } _commandType = QueryCommandType.FirstOrDefaultCommand; break; case "SingleOrDefault": if (m.Arguments.Count > 1) { _exclusiveWhereCount++; } foreach (Expression t in m.Arguments) { Visit(t); } _commandType = QueryCommandType.SingleOrDefaultCommand; break; case "Single": if (m.Arguments.Count > 1) { _exclusiveWhereCount++; } foreach (Expression t in m.Arguments) { Visit(t); } _commandType = QueryCommandType.SingleCommand; break; case "LongCount": case "Count": _isLongCount = m.Method.Name == "LongCount"; if (m.Arguments.Count > 1) { _exclusiveWhereCount++; } foreach (Expression t in m.Arguments) { Visit(t); } _commandType = QueryCommandType.CountCommand; break; case "ListAttributes": Dictionary <string, string> attributes = null; foreach (Expression t in m.Arguments) { if (t.Type == typeof(string[])) { attributes = (((ConstantExpression)t).Value as string[]).ToDictionary(s => s); } else { Visit(t); } } _commandOptions = new ListAttributesQueryCommandOptions(attributes); _commandType = QueryCommandType.StandardCommand; break; case "FilterWith": foreach (Expression t in m.Arguments) { if (t.Type == typeof(string)) { _sbCustomFilter.Append(((ConstantExpression)t).Value.ToString()); _customFiltersCount++; } else { Visit(t); } } _commandType = QueryCommandType.StandardCommand; break; case "Select": foreach (Expression t in m.Arguments) { var lambda = StripQuotes(t) as LambdaExpression; if (lambda != null) { if (_commandOptions != null) { throw new FilterException("Cannot have multiple Select projections."); } if (IsDynamic) { var projection = new DynamicSelectProjector(_mapping.Properties) .ProjectProperties(lambda); _commandOptions = new DynamicQueryCommandOptions(projection); } else { var projection = new SelectProjector(_mapping.Properties) .ProjectProperties(lambda); _commandOptions = new ProjectionQueryCommandOptions(_mapping, projection); } } else if (t.Type == typeof(string[])) { if (!IsDynamic) { throw new FilterException( "Cannot use a string attribute projection with a static type."); } if (_commandOptions != null) { throw new FilterException("Cannot have multiple Select projections."); } _commandOptions = new DynamicQueryCommandOptions(((ConstantExpression)t).Value as string[]); } else { Visit(t); } } _commandType = QueryCommandType.StandardCommand; break; case "ToPage": int pageSize = 0; byte[] nextPage = null; foreach (Expression t in m.Arguments) { if (t.Type == typeof(int)) { pageSize = (int)((ConstantExpression)t).Value; } else if (t.Type == typeof(byte[])) { nextPage = (byte[])((ConstantExpression)t).Value; } else if (t.Type == typeof(string)) { _pagingFilter = (string)((ConstantExpression)t).Value; } else { Visit(t); } } _pagingOptions = new PagingOptions(pageSize, nextPage); break; case "InPagesOf": foreach (Expression t in m.Arguments) { if (t.Type == typeof(int)) { _toListPageSize = (int)((ConstantExpression)t).Value; } else { Visit(t); } } _commandType = QueryCommandType.StandardCommand; break; case "ToList": foreach (Expression t in m.Arguments) { Visit(t); } _commandType = QueryCommandType.StandardCommand; break; case "Take": int takeAmount = 0; foreach (Expression t in m.Arguments) { if (t.Type == typeof(int)) { takeAmount = (int)((ConstantExpression)t).Value; } else { Visit(t); } } _takeSize = takeAmount; break; case "Skip": int skipAmount = 0; foreach (Expression t in m.Arguments) { if (t.Type == typeof(int)) { skipAmount = (int)((ConstantExpression)t).Value; } else { Visit(t); } } if (skipAmount < 0) { throw new ArgumentException("Skip value must be greater than zero."); } _skipSize = skipAmount; break; case "WithControls": if (_controls == null) { _controls = new List <DirectoryControl>(); } foreach (Expression t in m.Arguments) { IEnumerable <DirectoryControl> controls; if (t is ConstantExpression && (controls = ((ConstantExpression)t).Value as IEnumerable <DirectoryControl>) != null) { _controls.AddRange(controls); } else { Visit(t); } } break; case "OrderByDescending": case "ThenByDescending": string descRule = null; if (_sortingOptions == null) { _sortingOptions = new SortingOptions(); } foreach (Expression t in m.Arguments) { var lambda = StripQuotes(t) as LambdaExpression; if (lambda != null) { var attribute = GetMemberName((MemberExpression)lambda.Body); _sortingOptions.AddSort(attribute, true); } else if (t.Type == typeof(string)) { if (m.Arguments.IndexOf(t) == 1) { _sortingOptions.AddSort(((ConstantExpression)t).Value.ToString(), true); } else { descRule = ((ConstantExpression)t).Value.ToString(); } } else { Visit(t); } } _sortingOptions.SetMatchingRule(descRule); break; case "OrderBy": case "ThenBy": if (_sortingOptions == null) { _sortingOptions = new SortingOptions(); } string ascRule = null; foreach (Expression t in m.Arguments) { var lambda = StripQuotes(t) as LambdaExpression; if (lambda != null) { var attribute = GetMemberName((MemberExpression)lambda.Body); _sortingOptions.AddSort(attribute, false); } else if (t.Type == typeof(string)) { if (m.Arguments.IndexOf(t) == 1) { _sortingOptions.AddSort(((ConstantExpression)t).Value.ToString(), false); } else { ascRule = ((ConstantExpression)t).Value.ToString(); } } else { Visit(t); } } _sortingOptions.SetMatchingRule(ascRule); break; case "IgnoreOC": foreach (Expression t in m.Arguments) { if (t.Type == typeof(OC)) { _ignoreOc = (OC)((ConstantExpression)t).Value; } else { Visit(t); } } break; case "IncludeOC": foreach (Expression t in m.Arguments) { if (t.Type == typeof(OC)) { _includeOc = (OC)((ConstantExpression)t).Value; } else { Visit(t); } } break; } }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="commandText"></param> /// <param name="commandType"></param> /// <param name="timeout"></param> public QueryCommand(string commandText, QueryCommandType commandType, int timeout) { _commandText = commandText; _commandType = commandType; _timeout = timeout; }
public DataSet LoadDataSet(string sqlQuery, QueryCommandType queryCommandType) { throw new NotImplementedException(); }