Пример #1
0
        public override IReadOnlyList <INode> GetNodes(ISqlLoader loader, IGeneratorOption option, MethodInfo mi)
        {
            var parameters = BuildHelper.GetParameters(option, mi);
            var keys       = BuildHelper.GetKeyParameters(parameters);
            var tableName  = table ??
                             (type != null ? BuildHelper.GetTableNameOfType(option, type) : null) ??
                             BuildHelper.GetTableName(option, mi);
            var conditions = keys.Count > 0 ? keys : parameters;

            if (String.IsNullOrEmpty(tableName))
            {
                throw new BuilderException($"Table name resolve failed. type=[{mi.DeclaringType.FullName}], method=[{mi.Name}]");
            }

            if (!Force && (conditions.Count == 0))
            {
                throw new BuilderException($"Delete all requires force option. type=[{mi.DeclaringType.FullName}], method=[{mi.Name}]");
            }

            var sql = new StringBuilder();

            sql.Append("DELETE FROM ");
            sql.Append(tableName);
            BuildHelper.AddCondition(sql, conditions);

            var tokenizer = new SqlTokenizer(sql.ToString());
            var builder   = new NodeBuilder(tokenizer.Tokenize());

            return(builder.Build());
        }
Пример #2
0
        public override IReadOnlyList <INode> GetNodes(ISqlLoader loader, IGeneratorOption option, MethodInfo mi)
        {
            var parameters = BuildHelper.GetParameters(option, mi);
            var order      = BuildHelper.PickParameter <OrderAttribute>(parameters);
            var tableName  = table ??
                             (type != null ? BuildHelper.GetTableNameOfType(option, type) : null) ??
                             BuildHelper.GetReturnTableName(option, mi);

            if (String.IsNullOrEmpty(tableName))
            {
                throw new BuilderException($"Table name resolve failed. type=[{mi.DeclaringType.FullName}], method=[{mi.Name}]");
            }

            var sql = new StringBuilder();

            sql.Append("SELECT * FROM ");
            sql.Append(tableName);
            BuildHelper.AddCondition(sql, parameters);

            if (order != null)
            {
                sql.Append(" ORDER BY ");
                sql.Append($"/*# {order.Name} */dummy");
            }
            else if (!String.IsNullOrEmpty(Order))
            {
                sql.Append(" ORDER BY ");
                sql.Append(Order);
            }
            else
            {
                var columns = BuildHelper.MakeKeyColumns(option, mi.ReturnType);
                if (!String.IsNullOrEmpty(columns))
                {
                    sql.Append(" ORDER BY ");
                    sql.Append(columns);
                }
            }

            var tokenizer = new SqlTokenizer(sql.ToString());
            var builder   = new NodeBuilder(tokenizer.Tokenize());

            return(builder.Build());
        }
Пример #3
0
        public override IReadOnlyList <INode> GetNodes(ISqlLoader loader, IGeneratorOption option, MethodInfo mi)
        {
            var parameters = BuildHelper.GetParameters(option, mi);
            var tableName  = table ?? BuildHelper.GetTableNameOfType(option, type);

            if (String.IsNullOrEmpty(tableName))
            {
                throw new BuilderException($"Table name resolve failed. type=[{mi.DeclaringType.FullName}], method=[{mi.Name}]");
            }

            var sql = new StringBuilder();

            sql.Append("SELECT ");
            sql.Append(field);
            sql.Append(" FROM ");
            sql.Append(tableName);
            BuildHelper.AddCondition(sql, parameters);

            var tokenizer = new SqlTokenizer(sql.ToString());
            var builder   = new NodeBuilder(tokenizer.Tokenize());

            return(builder.Build());
        }