Example #1
0
 public void Push(SQLComponent componect)
 {
     if (this._allowFlag != 0)
     {
         this._buffer.Enqueue(componect);
     }
 }
        public IDriver <T> OrWhere(Expression <Func <T, Boolean> > predicate)
        {
            this.SQLComponent.AppendWhere(false);
            SQLComponent component = new SQLComponent();

            LambdaToSqlConverter <T> .WhereConvert(this.DbProvider, predicate, component);

            this.SQLComponent.AppendSQLFormat(CommonFormat.BRACKET_FORMAT, component.SQL);
            this.SQLComponent.AddParameters(component.Parameters);
            return(this);
        }
        public static IDriver <T> CETSelect <T>(this Table <T> tableObj, SQLComponent start, SQLComponent body) where T : class
        {
            IDriver <T> driver      = tableObj.DbProvider.Driver <T>();
            String      columnNames = tableObj.GetColumnNames();
            String      sql         = String.Format(BasicSqlFormat.CET_QUERY_FORMAT, columnNames, start.SQL, body.SQL);

            driver.SQLComponent.AppendSQL(sql);
            driver.SQLComponent.AddParameters(start.Parameters);
            driver.SQLComponent.AddParameters(body.Parameters);
            return(driver);
        }
Example #4
0
        public static void InsertConvert(DbProvider dbProvider, T obj, SQLComponent component)
        {
            String        columnName     = null;
            String        parameterName  = null;
            Object        value          = null;
            DbParameter   dbParameter    = null;
            StringBuilder parameterNames = new StringBuilder();
            StringBuilder columnNames    = new StringBuilder();
            Int32         length         = Table <T> .Schema.PropertyInfos.Length;

            for (Int32 i = 0; i < length; ++i)
            {
                PropertyInfo info      = Table <T> .Schema.PropertyInfos[i];
                var          colSchema = Table <T> .Schema.GetColumnSchema(info.Name);

                if (colSchema.IsJoinColumn)
                {
                    continue;
                }
                columnName = colSchema.Name;
                value      = Table <T> .Schema.PropertyAccessor.GetValue(i, obj);

                if (value == null)
                {
                    continue;
                }
                parameterName = dbProvider.Prefix + columnName + ParaCounter <T> .CountString;
                dbParameter   = dbProvider.DbParameter(parameterName, value ?? DBNull.Value, colSchema.DbType);

                columnNames.Append(String.Format(dbProvider.ConflictFreeFormat, columnName));
                parameterNames.Append(dbParameter.ParameterName);
                columnNames.Append(SqlKeyWord.COMMA);
                parameterNames.Append(SqlKeyWord.COMMA);
                component.AddParameter(dbParameter);
            }
            Int32 commaLength = SqlKeyWord.COMMA.Length;

            columnNames.Remove(columnNames.Length - commaLength, commaLength);
            parameterNames.Remove(parameterNames.Length - commaLength, commaLength);

            component.AppendSQLFormat(BasicSqlFormat.INSERT_FORMAT,
                                      Table <T> .Schema.TableName,
                                      columnNames.ToString(),
                                      parameterNames.ToString());
        }
Example #5
0
        public static void UpdateConvert(DbProvider dbProvider, T obj, SQLComponent component)
        {
            StringBuilder updateColumnNames = new StringBuilder();
            Int32         length            = Table <T> .Schema.PropertyInfos.Length;

            for (Int32 i = 0; i < length; ++i)
            {
                PropertyInfo info      = Table <T> .Schema.PropertyInfos[i];
                ColumnSchema colSchema = Table <T> .Schema.GetColumnSchema(info.Name);

                if (colSchema.IsPrimaryKey)
                {
                    continue;
                }
                if (colSchema.IsJoinColumn)
                {
                    continue;
                }
                Object value = Table <T> .Schema.PropertyAccessor.GetValue(i, obj);

                if (value == null)
                {
                    continue;
                }
                String      columnName    = colSchema.Name;
                String      parameterName = dbProvider.Prefix + columnName + ParaCounter <T> .CountString;
                DbParameter dbParameter   = dbProvider.DbParameter
                                            (
                    parameterName,
                    value ?? DBNull.Value,
                    colSchema.DbType
                                            );
                updateColumnNames.Append(String.Format(dbProvider.ConflictFreeFormat, columnName));
                updateColumnNames.Append(SqlKeyWord.EQUAL);
                updateColumnNames.Append(parameterName);
                updateColumnNames.Append(SqlKeyWord.COMMA);
                component.AddParameter(dbParameter);
            }
            updateColumnNames.Remove(updateColumnNames.Length - SqlKeyWord.COMMA.Length, SqlKeyWord.COMMA.Length);
            component.AppendSQLFormat(BasicSqlFormat.UPDATE_FORMAT, Table <T> .Schema.TableName, updateColumnNames.ToString());
        }
Example #6
0
        public static void ReplaceConvert(DbProvider dbProvider, T obj, SQLComponent component)
        {
            String        columnName     = null;
            String        parameterName  = null;
            Object        value          = null;
            DbParameter   dbParameter    = null;
            StringBuilder parameterNames = new StringBuilder();
            StringBuilder columnNames    = new StringBuilder();
            Int32         length         = Table <T> .Schema.PropertyInfos.Length;

            for (Int32 i = 0; i < length; ++i)
            {
                PropertyInfo info      = Table <T> .Schema.PropertyInfos[i];
                var          colSchema = Table <T> .Schema.GetColumnSchema(info.Name);

                columnName = colSchema.Name;
                value      = Table <T> .Schema.PropertyAccessor.GetValue(i, obj);

                //主键、默认值、可空判断
                parameterName = dbProvider.Prefix + columnName + ParaCounter <T> .CountString;

                dbParameter = dbProvider.DbParameter(
                    parameterName,
                    value ?? DBNull.Value,
                    colSchema.DbType);
                columnNames.Append(String.Format(dbProvider.ConflictFreeFormat, columnName));
                parameterNames.Append(dbParameter.ParameterName);
                if (i != (length - 1))
                {
                    columnNames.Append(SqlKeyWord.COMMA);
                    parameterNames.Append(SqlKeyWord.COMMA);
                }

                component.AddParameter(dbParameter);
            }
            component.AppendSQLFormat(BasicSqlFormat.REPLACE_FORMAT,
                                      Table <T> .Schema.TableName,
                                      columnNames.ToString(),
                                      parameterNames.ToString());
        }
Example #7
0
 public static void BatchInsertConvert(DbProvider dbProvider, IEnumerable <T> objs, SQLComponent component)
 {
     foreach (T obj in objs)
     {
         InsertConvert(dbProvider, obj, component);
         component.AppendSQL(SqlKeyWord.SEMICOLON);
     }
 }
Example #8
0
 /// <summary>
 /// 将另一个<see cref="SQLComponent"/>组件包含的SQ、L参数等信息附加到末尾
 /// </summary>
 /// <param name="component"></param>
 public void Append(SQLComponent component)
 {
     this.AppendSQL(component.SQL);
     this.AddParameters(component.Parameters);
 }
Example #9
0
        internal static void AnalyingIn <T>(DbProvider dbProvider, String columnName, SQLComponent component, Object[] values)
            where T : class
        {
            StringBuilder inParaNames = new StringBuilder();
            Int32         count       = values.Length;
            String        paraSymbol  = "inPara";

            for (Int32 i = 0; i < count; ++i)
            {
                String paraName = dbProvider.Prefix + paraSymbol + ParaCounter <T> .CountString;
                inParaNames.Append(paraName);
                if (i != (count - 1))
                {
                    inParaNames.Append(SqlKeyWord.COMMA);
                }
                DbParameter parameter = dbProvider.DbParameter(
                    paraName, values[i]
                    );
                component.AddParameter(parameter);
            }
            component.AppendSQL(columnName);
            component.AppendSQL(SqlKeyWord.IN);
            component.AppendSQLFormat(CommonFormat.BRACKET_FORMAT, inParaNames.ToString());
        }
Example #10
0
        internal static void AnalyingIn <T>(DbProvider dbProvider, Expression <Func <T, Object> > filter, SQLComponent component, Object[] values)
            where T : class
        {
            MemberExpression expression;
            ExpressionType   noteType = filter.Body.NodeType;;

            switch (noteType)
            {
            case ExpressionType.Convert:
                UnaryExpression unary = filter.Body as UnaryExpression;
                expression = (MemberExpression)unary.Operand;
                break;

            case ExpressionType.MemberAccess:
            {
                expression = filter.Body as MemberExpression;
            }
            break;

            default:
                throw new ArgumentException(nameof(filter));;
            }


            SchemaCache schema     = Table <T> .Schema;
            var         colSchema  = schema.GetColumnSchema(expression.Member.Name);
            String      columnName = colSchema.Name;

            columnName = String.Format(dbProvider.ConflictFreeFormat, columnName);
            columnName = String.Format(CommonFormat.COLUMN_FORMAT, schema.TableName, columnName);

            StringBuilder inParaNames = new StringBuilder();
            Int32         count       = values.Length;
            String        paraSymbol  = "inPara";

            for (Int32 i = 0; i < count; ++i)
            {
                String paraName = dbProvider.Prefix + paraSymbol + ParaCounter <T> .CountString;
                inParaNames.Append(paraName);
                if (i != (count - 1))
                {
                    inParaNames.Append(SqlKeyWord.COMMA);
                }
                DbParameter parameter = dbProvider.DbParameter(
                    paraName, values[i], colSchema.DbType
                    );
                component.AddParameter(parameter);
            }
            component.AppendSQL(columnName);
            component.AppendSQL(SqlKeyWord.IN);
            component.AppendSQLFormat(CommonFormat.BRACKET_FORMAT, inParaNames.ToString());
        }