Esempio n. 1
0
        internal override string CreateSqlString(CommandFactory factory, bool isFullName, CreateSqlState state)
        {
            string sql = state.GetDataSql(this, isFullName);

            if (sql != null)
            {
                return(sql);
            }

            string tableName   = factory.CreateDataTableMappingSql(TableMapping, state);
            string selectField = _selectField.CreateSqlString(factory, true, state);

            string field = _field.CreateSqlString(factory, isFullName, state);

            string query = null;

            if (_expression != null)
            {
                query = _expression.CreateSqlString(factory, true, state);
            }
            sql = factory.CreateSubQuerySql(field, _predicate, selectField, tableName, query);

            state.SetDataSql(this, isFullName, sql);
            return(sql);
        }
        internal override string CreateSqlString(CommandFactory factory, bool isFullName, CreateSqlState state)
        {
            var sql = state.GetDataSql(this, isFullName);

            if (sql != null)
            {
                return(sql);
            }

            object obj    = _baseFieldInfo.CreateSqlString(factory, isFullName, state);
            var    values = (IEnumerable)LambdaExpressionExtend.ConvertLambdaObject(_collection);
            var    list   = new List <string>();

            foreach (var item in values)
            {
                list.Add(state.AddDataParameter(factory, _baseFieldInfo.ToParameter(item.AdjustValue())));
            }

            if (list.Count > 0)
            {
                sql = factory.CreateCollectionParamsQuerySql(obj,
                                                             _isNot ? QueryCollectionPredicate.NotIn : QueryCollectionPredicate.In, list);
            }
            else
            {
                var value = _isNot;
                sql = factory.CreateBooleanConstantSql(value);
            }
            state.SetDataSql(this, isFullName, sql);
            return(sql);
        }
Esempio n. 3
0
        internal override string CreateSqlString(CommandFactory factory, bool isFullName, CreateSqlState state)
        {
            string sql = state.GetDataSql(this, isFullName);

            if (sql != null)
            {
                return(sql);
            }

            object        left;
            object        right;
            DataFieldInfo leftInfo  = _left as DataFieldInfo;
            DataFieldInfo rightInfo = _right as DataFieldInfo;

            if (!Object.Equals(leftInfo, null) && !Object.Equals(rightInfo, null))
            {
                left  = leftInfo.CreateSqlString(factory, isFullName, state);
                right = rightInfo.CreateSqlString(factory, isFullName, state);
            }
            else if (!Object.Equals(leftInfo, null))
            {
                left = leftInfo.CreateSqlString(factory, isFullName, state);
                object rightObject = LambdaExpressionExtend.ConvertLambdaObject(_right);
                right = state.AddDataParameter(factory, rightObject);
            }
            else if (!Object.Equals(rightInfo, null))
            {
                right = rightInfo.CreateSqlString(factory, isFullName, state);
                object leftObject = LambdaExpressionExtend.ConvertLambdaObject(_left);
                left = state.AddDataParameter(factory, leftObject);
            }
            else
            {
                throw new LightDataException(SR.DataFieldContentError);
            }
            sql = factory.CreateLikeMatchQuerySql(left, right, _starts, _ends, _isNot);
            state.SetDataSql(this, isFullName, sql);
            return(sql);
        }
Esempio n. 4
0
        internal override string CreateSqlString(CommandFactory factory, bool isFullName, CreateSqlState state)
        {
            string sql = state.GetDataSql(this, isFullName);

            if (sql != null)
            {
                return(sql);
            }

            object        obj    = _baseFieldInfo.CreateSqlString(factory, isFullName, state);
            IEnumerable   values = (IEnumerable)LambdaExpressionExtend.ConvertLambdaObject(_collection);
            List <string> list   = new List <string>();

            foreach (object item in values)
            {
                list.Add(state.AddDataParameter(factory, _baseFieldInfo.ToParameter(item)));
            }

            sql = factory.CreateCollectionParamsQuerySql(obj, _isNot ? QueryCollectionPredicate.NotIn : QueryCollectionPredicate.In, list);
            state.SetDataSql(this, isFullName, sql);
            return(sql);
        }
Esempio n. 5
0
        internal override string CreateSqlString(CommandFactory factory, bool isFullName, CreateSqlState state)
        {
            var sql = state.GetDataSql(this, isFullName);

            if (sql != null)
            {
                return(sql);
            }

            var objectList = new List <object> ();

            foreach (var item in _values)
            {
                object obj1;
                var    info1 = item as DataFieldInfo;
                if (!Equals(info1, null))
                {
                    obj1 = info1.CreateSqlString(factory, isFullName, state);
                }
                else
                {
                    obj1 = LambdaExpressionExtend.ConvertLambdaObject(item);
                    if (obj1 == null)
                    {
                        obj1 = string.Empty;
                    }
                    else if (!(obj1 is string))
                    {
                        obj1 = obj1.ToString();
                    }
                    obj1 = state.AddDataParameter(factory, obj1);
                }
                objectList.Add(obj1);
            }
            sql = factory.CreateConcatSql(objectList.ToArray());
            state.SetDataSql(this, isFullName, sql);
            return(sql);
        }
		internal override string CreateSqlString (CommandFactory factory, bool isFullName, CreateSqlState state)
		{
			string sql = state.GetDataSql (this, isFullName);
			if (sql != null) {
				return sql;
			}

			string query = _query.CreateSqlString (factory, isFullName, state);

			object ifTrue;
			object ifFalse;
			DataFieldInfo ifTrueInfo = _ifTrue as DataFieldInfo;
			DataFieldInfo ifFalseInfo = _ifFalse as DataFieldInfo;
			if (!Object.Equals (ifTrueInfo, null) && !Object.Equals (ifFalseInfo, null)) {
				ifTrue = ifTrueInfo.CreateSqlString (factory, isFullName, state);
				ifFalse = ifFalseInfo.CreateSqlString (factory, isFullName, state);
			}
			else if (!Object.Equals (ifTrueInfo, null)) {
				ifTrue = ifTrueInfo.CreateSqlString (factory, isFullName, state);
				object ifFalseObject = LambdaExpressionExtend.ConvertLambdaObject (_ifFalse);
				ifFalse = state.AddDataParameter (factory, ifFalseObject);
			}
			else if (!Object.Equals (ifFalseInfo, null)) {
				ifFalse = ifFalseInfo.CreateSqlString (factory, isFullName, state);
				object ifTrueObject = LambdaExpressionExtend.ConvertLambdaObject (_ifTrue);
				ifTrue = state.AddDataParameter (factory, ifTrueObject);
			}
			else {
				object ifTrueObject = LambdaExpressionExtend.ConvertLambdaObject (_ifTrue);
				object ifFalseObject = LambdaExpressionExtend.ConvertLambdaObject (_ifFalse);
				ifTrue = state.AddDataParameter (factory, ifTrueObject);
				ifFalse = state.AddDataParameter (factory, ifFalseObject);
			}

			sql = factory.CreateConditionSql (query, ifTrue, ifFalse);
			state.SetDataSql (this, isFullName, sql);
			return sql;
		}
Esempio n. 7
0
        internal override string CreateSqlString(CommandFactory factory, bool isFullName, CreateSqlState state)
        {
            string sql = state.GetDataSql(this, isFullName);

            if (sql != null)
            {
                return(sql);
            }

            List <object> objectList = new List <object> ();

            object        obj;
            DataFieldInfo info = _callObject as DataFieldInfo;

            if (!Object.Equals(info, null))
            {
                obj = info.CreateSqlString(factory, isFullName, state);
            }
            else
            {
                obj = LambdaExpressionExtend.ConvertLambdaObject(_callObject);
                obj = state.AddDataParameter(factory, obj);
            }
            if (_argsObjects != null)
            {
                foreach (object item in _argsObjects)
                {
                    object        obj1;
                    DataFieldInfo info1 = item as DataFieldInfo;
                    if (!Object.Equals(info1, null))
                    {
                        obj1 = info1.CreateSqlString(factory, isFullName, state);
                    }
                    else
                    {
                        obj1 = LambdaExpressionExtend.ConvertLambdaObject(item);
                        obj1 = state.AddDataParameter(factory, obj1);
                    }
                    objectList.Add(obj1);
                }
            }
            switch (_function)
            {
            case StringFunction.Substring:
                if (objectList.Count == 2)
                {
                    sql = factory.CreateSubStringSql(obj, objectList [0], objectList [1]);
                }
                else
                {
                    sql = factory.CreateSubStringSql(obj, objectList [0], null);
                }
                break;

            case StringFunction.IndexOf:
                if (objectList.Count == 2)
                {
                    sql = factory.CreateIndexOfSql(obj, objectList [0], objectList [1]);
                }
                else
                {
                    sql = factory.CreateIndexOfSql(obj, objectList [0], null);
                }
                break;

            case StringFunction.Replace:
                sql = factory.CreateReplaceSql(obj, objectList [0], objectList [1]);
                break;

            case StringFunction.ToLower:
                sql = factory.CreateToLowerSql(obj);
                break;

            case StringFunction.ToUpper:
                sql = factory.CreateToUpperSql(obj);
                break;

            case StringFunction.Trim:
                sql = factory.CreateTrimSql(obj);
                break;
            }
            state.SetDataSql(this, isFullName, sql);
            return(sql);
        }
        internal override string CreateSqlString(CommandFactory factory, bool isFullName, CreateSqlState state)
        {
            string sql = state.GetDataSql(this, isFullName);

            if (sql != null)
            {
                return(sql);
            }

            List <object> objectList = new List <object> ();

            foreach (object item in _argsObjects)
            {
                object        obj1;
                DataFieldInfo info1 = item as DataFieldInfo;
                if (!Object.Equals(info1, null))
                {
                    obj1 = info1.CreateSqlString(factory, isFullName, state);
                }
                else
                {
                    obj1 = LambdaExpressionExtend.ConvertLambdaObject(item);
                    obj1 = state.AddDataParameter(factory, obj1);
                }
                objectList.Add(obj1);
            }
            switch (_function)
            {
            case MathFunction.Abs:
                sql = factory.CreateAbsSql(objectList [0]);
                break;

            case MathFunction.Sign:
                sql = factory.CreateSignSql(objectList [0]);
                break;

            case MathFunction.Sin:
                sql = factory.CreateSinSql(objectList [0]);
                break;

            case MathFunction.Cos:
                sql = factory.CreateCosSql(objectList [0]);
                break;

            case MathFunction.Tan:
                sql = factory.CreateTanSql(objectList [0]);
                break;

            case MathFunction.Atan:
                sql = factory.CreateAtanSql(objectList [0]);
                break;

            case MathFunction.Asin:
                sql = factory.CreateAsinSql(objectList [0]);
                break;

            case MathFunction.Acos:
                sql = factory.CreateAcosSql(objectList [0]);
                break;

            case MathFunction.Atan2:
                sql = factory.CreateAtan2Sql(objectList [0], objectList [1]);
                break;

            case MathFunction.Ceiling:
                sql = factory.CreateCeilingSql(objectList [0]);
                break;

            case MathFunction.Floor:
                sql = factory.CreateFloorSql(objectList [0]);
                break;

            case MathFunction.Round:
                if (objectList.Count == 2)
                {
                    sql = factory.CreateRoundSql(objectList [0], objectList [1]);
                }
                else
                {
                    sql = factory.CreateRoundSql(objectList [0], 0);
                }
                break;

            case MathFunction.Truncate:
                sql = factory.CreateTruncateSql(objectList [0]);
                break;

            case MathFunction.Log:
                if (objectList.Count == 2)
                {
                    sql = factory.CreateLogSql(objectList [0], objectList [1]);
                }
                else
                {
                    sql = factory.CreateLogSql(objectList [0]);
                }
                break;

            case MathFunction.Log10:
                sql = factory.CreateLog10Sql(objectList [0]);
                break;

            case MathFunction.Exp:
                sql = factory.CreateExpSql(objectList [0]);
                break;

            case MathFunction.Pow:
                sql = factory.CreatePowSql(objectList [0], objectList [1]);
                break;

            case MathFunction.Sqrt:
                sql = factory.CreateSqrtSql(objectList [0]);
                break;

            case MathFunction.Max:
                sql = factory.CreateMaxSql(objectList [0], objectList [1]);
                break;

            case MathFunction.Min:
                sql = factory.CreateMinSql(objectList [0], objectList [1]);
                break;
            }
            state.SetDataSql(this, isFullName, sql);
            return(sql);
        }
        internal override string CreateSqlString(CommandFactory factory, bool isFullName, CreateSqlState state)
        {
            string sql = state.GetDataSql(this, isFullName);

            if (sql != null)
            {
                return(sql);
            }

            object        left;
            object        right;
            DataFieldInfo leftInfo  = _left as DataFieldInfo;
            DataFieldInfo rightInfo = _right as DataFieldInfo;

            if (!Object.Equals(leftInfo, null) && !Object.Equals(rightInfo, null))
            {
                left  = leftInfo.CreateSqlString(factory, isFullName, state);
                right = rightInfo.CreateSqlString(factory, isFullName, state);
            }
            else if (!Object.Equals(leftInfo, null))
            {
                left = leftInfo.CreateSqlString(factory, isFullName, state);
                object rightObject = LambdaExpressionExtend.ConvertLambdaObject(_right);
                right = state.AddDataParameter(factory, rightObject);
            }
            else if (!Object.Equals(rightInfo, null))
            {
                right = rightInfo.CreateSqlString(factory, isFullName, state);
                object leftObject = LambdaExpressionExtend.ConvertLambdaObject(_left);
                left = state.AddDataParameter(factory, leftObject);
            }
            else
            {
                throw new LightDataException(SR.DataFieldContentError);
            }

            switch (_opera)
            {
            case MathOperator.Puls:
                sql = factory.CreatePlusSql(left, right);
                break;

            case MathOperator.Minus:
                sql = factory.CreateMinusSql(left, right);
                break;

            case MathOperator.Multiply:
                sql = factory.CreateMultiplySql(left, right);
                break;

            case MathOperator.Divided:
                sql = factory.CreateDividedSql(left, right);
                break;

            case MathOperator.Mod:
                sql = factory.CreateModSql(left, right);
                break;

            case MathOperator.Power:
                sql = factory.CreatePowerSql(left, right);
                break;
            }
            state.SetDataSql(this, isFullName, sql);
            return(sql);
        }