Exemplo n.º 1
0
        public override IReadOnlyList <INode> GetNodes(ISqlLoader loader, IGeneratorOption option, MethodInfo mi)
        {
            var parameters = BuildHelper.GetParameters(option, mi);
            var tableName  = table ??
                             (type != null ? BuildHelper.GetTableNameOfType(option, type) : null) ??
                             BuildHelper.GetTableName(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("INSERT INTO ");
            sql.Append(tableName);
            sql.Append(" (");
            BuildHelper.AddInsertColumns(sql, mi, parameters);
            sql.Append(") VALUES (");
            BuildHelper.AddInsertValues(sql, mi, parameters);
            sql.Append(")");

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

            return(builder.Build());
        }