Esempio n. 1
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());
        }
Esempio n. 2
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());
        }
Esempio n. 3
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());
        }
Esempio n. 4
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());
        }
Esempio n. 5
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());
        }