public override string Parse(Gale.REST.Queryable.Primitive.Reflected.Field field, string value) { if (field.Type == typeof(String) || field.Type == typeof(Int32) || field.Type == typeof(System.Guid)) { List <String> values = value.Split('|').ToList(); String in_values = string.Join("','", values); return(String.Format("{0} IN ('{1}')", field.Key, in_values)); } else { throw new Exception.GaleException("API018"); } }
public override string Parse(Gale.REST.Queryable.Primitive.Reflected.Field field, string value) { String format = "{0} <= {1}"; if (field.Type == typeof(String)) { format = "LEN({0}) <= {1}"; } if (field.Type == typeof(DateTime) || field.Type == typeof(DateTime?)) { format = "{0} <= '{1}'"; } return(String.Format(format, field.Key, value)); }
public override string Parse(Gale.REST.Queryable.Primitive.Reflected.Field field, string value) { if (field.Type == typeof(String) || field.Type == typeof(System.Guid)) { return(String.Format("{0} like '%{1}%'", field.Key, value)); } else if (field.Type == typeof(Int32)) { //convert(varchar(10),StandardCost) return(String.Format("CONVERT(VARCHAR(8000), {0}) like '%{1}%'", field.Key, value)); } else { throw new Exception.GaleException("API018"); } }
/// <summary> /// Parse SQL String /// </summary> /// <param name="query"></param> /// <param name="model"></param> /// <returns></returns> public override string Parse(GQLConfiguration configuration, Gale.REST.Queryable.Primitive.Reflected.Model model) { if (configuration.orderBy == null) { return("SYSDATETIME() desc \n\n"); } else { Gale.REST.Queryable.Primitive.Reflected.Field _field = model.Fields.FirstOrDefault((field) => { return(field.Name.ToLower() == configuration.orderBy.name.ToLower()); }); if (_field == null) { throw new Exception.GaleException("API015", configuration.orderBy.name); } return(String.Format("{0} {1} \n\n", _field.Key, configuration.orderBy.order.ToString())); } }
public abstract string Parse(Gale.REST.Queryable.Primitive.Reflected.Field field, string value);
/// <summary> /// Parse SELECT /// </summary> /// <param name="configuration">Gale Query Language Configuration</param> /// <param name="model">Model</param> /// <returns></returns> public override string Parse(GQLConfiguration configuration, Gale.REST.Queryable.Primitive.Reflected.Model model) { //SELECT PARSER QUERY List <String> builder = new List <string>(); if (configuration.fields.Count == 0) { configuration.fields.Add("*"); } #region SELECT FIELD //---- SELECT FIELD Action <Gale.REST.Queryable.Primitive.Reflected.Field> SelectField = new Action <Gale.REST.Queryable.Primitive.Reflected.Field>((field) => { //The Main Primary Key , dont'need to add to the selection if (field.Specification == Gale.REST.Queryable.Primitive.Reflected.Field.SpecificationEnum.Pk) { return; } //Only if, his, from the primary Table, add to selection, //because all Foreign key Table, are Getting from the source (ForeignTable.*) if (field.Table.IsForeign == false) { builder.Add(field.Key); } field.Select(); }); //--------------------------------- #endregion //--- FIRST ADD THE PK builder.Insert(0, model.Tables.First().PrimaryKey.Key); //--- foreach (String fieldName in configuration.fields) { string _fieldName = fieldName.Trim(); //---[ Get all field from all tables :P if (_fieldName == "*.*") { model.Fields.ForEach((f) => { SelectField(f); }); break; } //If query is * , bring all field's if (_fieldName.Contains("*")) { Type searchedTable = null; //Get all field from the Primary Table if (_fieldName == "*") { searchedTable = model.Tables.First().Type; //Main Table } else { //try to get all field from a foreign table if (!_fieldName.Contains(":(")) { throw new Exception.GaleException("API012", _fieldName); } _fieldName = _fieldName.Substring(0, _fieldName.IndexOf(":(")); var fk = model.Constraints.FirstOrDefault(constraint => constraint.ThisField.Name == _fieldName); if (fk == null) { throw new Exception.GaleException("API013", _fieldName); } searchedTable = fk.Table.Type; } model.Fields.ForEach((f) => { if (f.Table.Type == searchedTable) { SelectField(f); } }); continue; } //Check if field exist's Gale.REST.Queryable.Primitive.Reflected.Field field = model.Fields.FirstOrDefault((f) => { return(f.Name.ToLower() == _fieldName); }); //If field is not exists, throw exception if (field == null) { throw new Exception.GaleException("API013", _fieldName); } //Primary Key if (field.Specification == Gale.REST.Queryable.Primitive.Reflected.Field.SpecificationEnum.Pk) { throw new Exception.GaleException("API014", _fieldName); } //Select Field SelectField(field); } return(String.Join(",", builder)); }