Ejemplo n.º 1
0
        /// <summary>
        /// Builds and finalizes the SQL statement
        /// </summary>
        /// <param name="sb">StringBuilder that contains the final SQL statement</param>
        /// <param name="args">SQL statement parameters</param>
        /// <param name="lhs">Left hand side SQL statement</param>
        private void Build(StringBuilder sb, List<object> args, Sql lhs)
        {
            if (!String.IsNullOrEmpty(_sql))
            {
                // --- Add SQL to the string
                if (sb.Length > 0)
                {
                    sb.Append("\n");
                }

                var sql = Database.ProcessParams(_sql, _args, args);

                if (Is(lhs, "WHERE ") && Is(this, "WHERE "))
                    sql = "AND " + sql.Substring(6);
                if (Is(lhs, "ORDER BY ") && Is(this, "ORDER BY "))
                    sql = ", " + sql.Substring(9);

                sb.Append(sql);
            }

            // Now do rhs
            if (_rhs != null)
                _rhs.Build(sb, args, this);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Checks if the specified Sql instance is the given clause
 /// </summary>
 /// <param name="sql">Sql instance</param>
 /// <param name="sqltype">SQL clause (e.g. WHERE, ORDER BY, etc.)</param>
 /// <returns>True, if the Sql instance is the specified clause; otherwise, false.</returns>
 static bool Is(Sql sql, string sqltype)
 {
     return sql != null && sql._sql != null && sql._sql.StartsWith(sqltype, StringComparison.InvariantCultureIgnoreCase);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Creates a new instance using the specified Sql instance
 /// </summary>
 /// <param name="sql">Sql instance this instance belongs to</param>
 public SqlJoinClause(Sql sql)
 {
     _sql = sql;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Appends a new chunk of SQL to the current statement
        /// </summary>
        /// <param name="sql">Sql object representing the statement to append</param>
        /// <returns>The Sql object representing the merged SQL statement</returns>
        public Sql Append(Sql sql)
        {
            _sqlFinal = null;

            if (_rhs != null)
            {
                _rhs.Append(sql);
            }
            else if (_sql != null)
            {
                _rhs = sql;
            }
            else
            {
                _sql = sql._sql;
                _args = sql._args;
                _rhs = sql._rhs;
            }
            return this;
        }