Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        static string OnConflictDoUpdate(OnConflictDoUpdateClause doUpdate, ParamMode paramMode, SqlParamDic paramDic, string origTableName)
        {
            var b = new StringBuilder();

            b.AppendLine("DO UPDATE");
            b.AppendLine("SET");
            var exprAlias = new[]
            {
                new SqlFromList.ExprStrRawSql(doUpdate.Set.Parameters[0], "EXCLUDED"),
                new SqlFromList.ExprStrRawSql(doUpdate.Set.Parameters[1], $"\"{origTableName}\""),
            };
            var setSql = SqlUpdate.SetToSql(doUpdate.Set.Body, paramMode, paramDic, exprAlias);

            b.Append(SqlSelect.TabStr(setSql));

            if (doUpdate.Where != null)
            {
                b.AppendLine();

                var pars     = new SqlExprParams(null, null, false, "", new SqlFromList.ExprStrRawSql[0], paramMode, paramDic);
                var whereSql = SqlExpression.ExprToSql(doUpdate.Where.Body, pars, true);
                b.Append(whereSql);
            }

            return(b.ToString());
        }
Beispiel #2
0
        /// <summary>
        /// Convierte la cláusula RETURNING a SQL
        /// </summary>
        static (string sql, IReadOnlyList <string> cols) ReturningToString(LambdaExpression returning, ParamMode paramMode, SqlParamDic paramDic, string tableName)
        {
            var pars   = new SqlExprParams(returning.Parameters[0], null, false, tableName, new SqlFromList.ExprStrRawSql[0], paramMode, paramDic);
            var select = SqlSelect.SelectBodyToStr(returning.Body, pars);
            var sql    = $"RETURNING {Environment.NewLine}{SqlSelect.TabStr(SqlSelect.SelectExprToStr(select.Values))}";
            var cols   = select.Values.Select(x => x.Column).ToList();

            return(sql, cols);
        }