Example #1
0
        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
        /// </returns>
        /// <exception cref="InvalidQueryException">The query is invalid.</exception>
        public override string ToString()
        {
            var sb = new StringBuilder();

            // Parent
            if (Parent != null)
            {
                sb.Append(Parent);
            }

            // Base operator
            sb.Append(" ON DUPLICATE KEY UPDATE ");

            // Sets
            var values = ColumnValueCollectionBuilder.GetValues();

            if (values == null || values.Length == 0)
            {
                throw InvalidQueryException.CreateEmptyColumnList();
            }

            foreach (var kvp in values)
            {
                sb.Append("`");
                sb.Append(kvp.Key);
                sb.Append("`=");
                sb.Append(kvp.Value);
                sb.Append(",");
            }

            sb.Length--;

            return(sb.ToString().Trim());
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UpdateQueryBase"/> class.
        /// </summary>
        /// <param name="table">The table name.</param>
        /// <param name="settings">The <see cref="IQueryBuilderSettings"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="settings"/> is null.</exception>
        /// <exception cref="InvalidQueryException"><paramref name="table"/> is not a valid table name.</exception>
        protected UpdateQueryBase(string table, IQueryBuilderSettings settings)
        {
            if (settings == null)
                throw new ArgumentNullException("settings");

            _table = table;
            _settings = settings;

            Settings.IsValidTableName(table, true);

            _c = new ColumnValueCollectionBuilder<IUpdateQuery>(this, settings);
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InsertODKUQueryBase"/> class.
        /// </summary>
        /// <param name="parent">The parent.</param>
        /// <param name="settings">The <see cref="IQueryBuilderSettings"/>.</param>
        /// <exception cref="ArgumentNullException"><paramref name="parent"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="settings"/> is null.</exception>
        protected InsertODKUQueryBase(IInsertQuery parent, IQueryBuilderSettings settings)
        {
            if (parent == null)
                throw new ArgumentNullException("parent");
            if (settings == null)
                throw new ArgumentNullException("settings");

            _parent = parent;
            _settings = settings;

            _c = new ColumnValueCollectionBuilder<IInsertODKUQuery>(this, settings);
        }