コード例 #1
0
ファイル: SqlHelper.cs プロジェクト: Chainerenator/cherenity
        private static int CheckExpectedRows(ExpectedRows expectedRows, int affectedRows)
        {
            if (expectedRows == ExpectedRows.Ignore)
            {
                return(affectedRows);
            }

            if (expectedRows == ExpectedRows.One && affectedRows != 1)
            {
                throw new InvalidOperationException(String.Format(ExpectedRowsError, affectedRows, 1));
            }

            if (expectedRows == ExpectedRows.ZeroOrOne && affectedRows > 1)
            {
                throw new InvalidOperationException(String.Format(ExpectedRowsError, affectedRows, "0 or 1"));
            }

            return(affectedRows);
        }
コード例 #2
0
ファイル: SqlHelper.cs プロジェクト: VictorHenriquez/Serenity
        private static int CheckExpectedRows(ExpectedRows expectedRows, int affectedRows)
        {
            if (expectedRows == ExpectedRows.Ignore)
            {
                return(affectedRows);
            }

            if (expectedRows == ExpectedRows.One && affectedRows != 1)
            {
                throw new InvalidOperationException(String.Format("Query affected {0} rows while 1 expected!", affectedRows));
            }

            if (expectedRows == ExpectedRows.ZeroOrOne && affectedRows > 1)
            {
                throw new InvalidOperationException("Query affected {0} rows while 1 expected!");
            }

            return(affectedRows);
        }
コード例 #3
0
        public static int DeleteById <TRow>(this IDbConnection connection, object id, ExpectedRows expectedRows = ExpectedRows.One)
            where TRow : class, IRow, IIdRow, new()
        {
            var row = new TRow();

            return(new SqlDelete(row.Table)
                   .Where(row.IdField == new ValueCriteria(id))
                   .Execute(connection, expectedRows));
        }
コード例 #4
0
        public static void UpdateById <TRow>(this IDbConnection connection, TRow row, ExpectedRows expectedRows = ExpectedRows.One)
            where TRow : IIdRow
        {
            var idField = row.IdField;
            var r       = (IRow)(object)row;

            if (idField.IsNull(r))
            {
                throw new InvalidOperationException("ID field of row has null value!");
            }

            row.ToSqlUpdateById()
            .Execute(connection, expectedRows);
        }
コード例 #5
0
 /// <summary>
 ///   <see cref="SqlDelete"/> nesnesinin içerdiği sorguyu bağlantı üzerinde çalıştırır.</summary>
 /// <remarks>
 ///   <p>Bu bir extension metodu olduğundan direk query.Execute(connection) şeklinde de
 ///   çalıştırılabilir.</p></remarks>
 /// <param name="connection">
 ///   Sorgunun çalıştırılacağı bağlantı. Gerekirse otomatik olarak açılır.</param>
 /// <param name="query">
 ///   Sorguyu içeren <see cref="SqlDelete"/> nesnesi.</param>
 /// <param name="expectedRows">Expected number of rows to be deleted (defaults to one)</param>
 /// <param name="param">Parameters dictionary</param>
 /// <returns>
 ///   Etkilenen kayıt sayısı.</returns>
 public static int Execute(this SqlDelete query, IDbConnection connection, Dictionary param, ExpectedRows expectedRows = ExpectedRows.One)
 {
     return(CheckExpectedRows(expectedRows, ExecuteNonQuery(connection, query.ToString(), param)));
 }
コード例 #6
0
 /// <summary>
 ///   <see cref="SqlUpdate"/> nesnesinin içerdiği sorguyu bağlantı üzerinde çalıştırır.</summary>
 /// <remarks>
 ///   <p>Bu bir extension metodu olduğundan direk query.Execute(connection) şeklinde de
 ///   çalıştırılabilir.</p></remarks>
 /// <param name="connection">
 ///   Sorgunun çalıştırılacağı bağlantı. Gerekirse otomatik olarak açılır.</param>
 /// <param name="query">
 ///   Sorguyu içeren <see cref="SqlUpdate"/> nesnesi.</param>
 /// <param name="expectedRows">Expected number of rows to be updated (defaults to one)</param>
 /// <returns>
 ///   Etkilenen kayıt sayısı.</returns>
 public static int Execute(this SqlUpdate query, IDbConnection connection, ExpectedRows expectedRows = ExpectedRows.One)
 {
     return(CheckExpectedRows(expectedRows, ExecuteNonQuery(connection, query.ToString(), query.Params)));
 }
コード例 #7
0
        public static int DeleteById <TRow>(this IDbConnection connection, object id, ExpectedRows expectedRows = ExpectedRows.One)
            where TRow : Row, IIdRow, new()
        {
            var row = new TRow();

            return(new SqlDelete(connection.GetDialect(), row.Table, string.Empty)
                   .Where((Field)row.IdField == new ValueCriteria(id))
                   .Execute(connection, expectedRows));
        }
コード例 #8
0
ファイル: SqlHelper.cs プロジェクト: fzhenmei/Serenity
 /// <summary>
 ///   <see cref="SqlDelete"/> nesnesinin içerdiği sorguyu bağlantı üzerinde çalıştırır.</summary>
 /// <remarks>
 ///   <p>Bu bir extension metodu olduğundan direk query.Execute(connection) şeklinde de 
 ///   çalıştırılabilir.</p></remarks>
 /// <param name="connection">
 ///   Sorgunun çalıştırılacağı bağlantı. Gerekirse otomatik olarak açılır.</param>
 /// <param name="query">
 ///   Sorguyu içeren <see cref="SqlDelete"/> nesnesi.</param>
 /// <returns>
 ///   Etkilenen kayıt sayısı.</returns>
 public static int Execute(this SqlDelete query, IDbConnection connection, Dictionary param, ExpectedRows expectedRows = ExpectedRows.One)
 {
     return CheckExpectedRows(expectedRows, ExecuteNonQuery(connection, query.ToString(), param));
 }
コード例 #9
0
ファイル: SqlHelper.cs プロジェクト: fzhenmei/Serenity
        private static int CheckExpectedRows(ExpectedRows expectedRows, int affectedRows)
        {
            if (expectedRows == ExpectedRows.Ignore)
                return affectedRows;

            if (expectedRows == ExpectedRows.One && affectedRows != 1)
                throw new InvalidOperationException(String.Format("Query affected {0} rows while 1 expected!", affectedRows));

            if (expectedRows == ExpectedRows.ZeroOrOne && affectedRows > 1)
                throw new InvalidOperationException("Query affected {0} rows while 1 expected!");

            return affectedRows;
        }
コード例 #10
0
ファイル: SqlHelper.cs プロジェクト: fzhenmei/Serenity
 /// <summary>
 ///   <see cref="SqlUpdate"/> nesnesinin içerdiği sorguyu bağlantı üzerinde çalıştırır.</summary>
 /// <remarks>
 ///   <p>Bu bir extension metodu olduğundan direk query.Execute(connection) şeklinde de 
 ///   çalıştırılabilir.</p></remarks>
 /// <param name="connection">
 ///   Sorgunun çalıştırılacağı bağlantı. Gerekirse otomatik olarak açılır.</param>
 /// <param name="query">
 ///   Sorguyu içeren <see cref="SqlUpdate"/> nesnesi.</param>
 /// <returns>
 ///   Etkilenen kayıt sayısı.</returns>
 public static int Execute(this SqlUpdate query, IDbConnection connection, ExpectedRows expectedRows = ExpectedRows.One)
 {
     return CheckExpectedRows(expectedRows, ExecuteNonQuery(connection, query.ToString(), query.Params));
 }
コード例 #11
0
ファイル: SqlHelper.cs プロジェクト: volkanceylan/Serenity
        private static int CheckExpectedRows(ExpectedRows expectedRows, int affectedRows)
        {
            if (expectedRows == ExpectedRows.Ignore)
                return affectedRows;

            if (expectedRows == ExpectedRows.One && affectedRows != 1)
                throw new InvalidOperationException(String.Format(ExpectedRowsError, affectedRows, 1));

            if (expectedRows == ExpectedRows.ZeroOrOne && affectedRows > 1)
                throw new InvalidOperationException(String.Format(ExpectedRowsError, affectedRows, "0 or 1"));

            return affectedRows;
        }