Beispiel #1
0
        public object ExecuteScalar(DbCommand command, GenericTransaction transaction)
        {
            CheckAndCloseConnection(command);
            var r = _database.ExecuteScalar(command, transaction.Transaction);

            SaveExecutedQuery(command);
            return(r);
        }
Beispiel #2
0
        public DataSet ExecuteDataSet(DbCommand command, GenericTransaction transaction)
        {
            CheckAndCloseConnection(command);
            var ds = _database.ExecuteDataSet(command, transaction.Transaction);

            if (ds != null)
            {
                SetDatasetCommandToCache(command, ds);
                SaveExecutedQuery(command);
            }
            return(ds);
        }
Beispiel #3
0
        public int UpdateDataTable(DataTable dataTable, GenericTransaction tran, int commandTimeout, bool acceptChangesDuringUpdate)
        {
            var cmd = GetDataTableCommandFromCache(dataTable);

            if (cmd == null)
            {
                //get select command : read from cache if exist, otherwise use basic select query.
                string cmdSelect = string.Format("select * from {0} WITH(NOLOCK) ", GetFullTableName(dataTable));
                cmd = GetSqlStringSqlCommand(cmdSelect);
                cmd.CommandTimeout = commandTimeout;
            }
            return(UpdateDataTable(dataTable, cmd, tran, acceptChangesDuringUpdate));
        }
Beispiel #4
0
        public int UpdateDataTable(DataTable dataTable, DbCommand cmd, GenericTransaction tran, bool acceptChangesDuringUpdate)
        {
            var rowsAffected = 0;

            using (var da = _database.GetDataAdapter())
            {
                if (da != null)
                {
                    var mCommandBuilder = GetCommandBuilder(da);
                    //Specifies whether all column values in an update statement are included or only changed ones.
                    mCommandBuilder.SetAllValues   = false;
                    mCommandBuilder.ConflictOption = ConflictOption.CompareAllSearchableValues;

                    da.SelectCommand = cmd;
                    if (da.SelectCommand != null && tran != null)
                    {
                        da.SelectCommand.Connection  = tran.Connection as DbConnection;
                        da.SelectCommand.Transaction = tran.Transaction;
                    }
                    else if (da.SelectCommand != null)
                    {
                        da.SelectCommand.Connection = _database.CreateConnection();
                    }

                    string sIdentityColumnName = GetIdentityColumnName(dataTable);
                    da.InsertCommand = mCommandBuilder.GetInsertCommand();
                    string insertCommandText = mCommandBuilder.GetInsertCommand().CommandText;

                    if (!String.IsNullOrEmpty(sIdentityColumnName))
                    {
                        insertCommandText += string.Format(";declare @id bigint;set @id=SCOPE_IDENTITY(); {0} WHERE {1} = @id;", cmd.CommandText, sIdentityColumnName);
                    }

                    da.InsertCommand.CommandText      = insertCommandText;
                    da.InsertCommand.UpdatedRowSource = UpdateRowSource.Both;
                    da.UpdateCommand = mCommandBuilder.GetUpdateCommand();
                    da.DeleteCommand = mCommandBuilder.GetDeleteCommand();
                    da.InsertCommand.CommandTimeout = cmd.CommandTimeout;
                    da.UpdateCommand.CommandTimeout = cmd.CommandTimeout;
                    da.AcceptChangesDuringUpdate    = acceptChangesDuringUpdate;
                    da.MissingSchemaAction          = MissingSchemaAction.AddWithKey;
                    var dtCopy = dataTable.Copy();
                    rowsAffected = da.Update(dataTable);
                    SaveDataChanges(dtCopy, dataTable);// audit old state
                }
            }

            return(rowsAffected);
        }
Beispiel #5
0
 public int UpdateDataSet(DataSet dataSet, string tableName, UpdateBehavior updateBehavior, int?updateBatchSize,
                          GenericTransaction tran, int commandTimeout)
 {
     return(UpdateDataSet(dataSet, tableName, updateBehavior, updateBatchSize, tran, commandTimeout, true));
 }
Beispiel #6
0
 public int UpdateDataSet(DataSet dataSet, GenericTransaction transaction, int commandTimeout, bool acceptChanges)
 {
     return(UpdateDataSet(dataSet, string.Empty, UpdateBehavior.Standard, null, transaction, commandTimeout, acceptChanges));
 }
Beispiel #7
0
 public int UpdateDataSet(DataSet dataSet, GenericTransaction transaction, int commandTimeout)
 {
     return(UpdateDataSet(dataSet, transaction, commandTimeout, true));
 }
Beispiel #8
0
 public int UpdateDataSet(DataSet dataSet, GenericTransaction transaction)
 {
     return(UpdateDataSet(dataSet, transaction, CommandTimeOut));
 }
Beispiel #9
0
 public int UpdateDataSet(DataSet dataSet, GenericTransaction transaction, int?updateBatchSize)
 {
     return(UpdateDataSet(dataSet, transaction, updateBatchSize, CommandTimeOut));
 }
Beispiel #10
0
 public DataSet ExecuteDataSet(GenericTransaction transaction, CommandType commandType, string commandText)
 {
     return(_database.ExecuteDataSet(transaction.Transaction, commandType, commandText));
 }
Beispiel #11
0
 public int UpdateDataTable(DataTable dataTable, GenericTransaction tran, int commandTimeout)
 {
     return(UpdateDataTable(dataTable, tran, commandTimeout, true));
 }
Beispiel #12
0
 public int UpdateDataTable(DataTable dataTable, GenericTransaction tran)
 {
     return(UpdateDataTable(dataTable, tran, CommandTimeOut));
 }
Beispiel #13
0
 public object ExecuteScalar(GenericTransaction transaction, CommandType commandType, string commandText)
 {
     return(_database.ExecuteScalar(transaction.Transaction, commandType, commandText));
 }
Beispiel #14
0
 public object ExecuteScalar(GenericTransaction transaction, string storedProcedureName, params object[] parameterValues)
 {
     return(_database.ExecuteScalar(transaction.Transaction, storedProcedureName, parameterValues));
 }
Beispiel #15
0
 public int ExecuteNonQuery(GenericTransaction transaction, CommandType commandType, string commandText)
 {
     return(_database.ExecuteNonQuery(transaction.Transaction, commandType, commandText));
 }
Beispiel #16
0
        public int UpdateDataSet(DataSet dataSet, string tableName, UpdateBehavior updateBehavior, int?updateBatchSize, GenericTransaction tran, int commandTimeout, bool acceptChanges)
        {
            var cmd = GetDataSetCommandFromCache(dataSet);

            if (string.IsNullOrEmpty(tableName) && dataSet.Tables.Count > 0)
            {
                tableName = GetTableName(dataSet.Tables[0]);
            }
            var rowsAffected = 0;

            if (dataSet.Tables.Count == 0)
            {
                throw new InvalidOperationException(string.Format("There is no table in dataset"));
            }

            string cmdSelect = string.Format("select * from {0} WITH(NOLOCK) ", GetFullTableName(dataSet.Tables[0]));

            if (cmd == null)
            {
                //get select command : read from cache if exist, otherwise use basic select query.
                cmd = GetSqlStringSqlCommand(cmdSelect);
            }
            cmd.CommandTimeout = commandTimeout;
            using (var da = _database.GetDataAdapter())
            {
                if (da != null)
                {
                    var mCommandBuilder = GetCommandBuilder(da);
                    //Specifies whether all column values in an update statement are included or only changed ones.
                    mCommandBuilder.SetAllValues = false;
                    da.SelectCommand             = cmd;
                    if (da.SelectCommand != null && tran != null)
                    {
                        da.SelectCommand.Connection  = tran.Connection as DbConnection;
                        da.SelectCommand.Transaction = tran.Transaction;
                    }
                    else if (da.SelectCommand != null)
                    {
                        da.SelectCommand.Connection = _database.CreateConnection();
                    }
                    var    dtCopy = dataSet.Tables[0].Copy();
                    string sIdentityColumnName = GetIdentityColumnName(dataSet.Tables[0]);
                    da.InsertCommand = mCommandBuilder.GetInsertCommand();
                    string insertCommandText = mCommandBuilder.GetInsertCommand().CommandText;

                    if (!String.IsNullOrEmpty(sIdentityColumnName))
                    {
                        insertCommandText += string.Format(";declare @id bigint;set @id=SCOPE_IDENTITY(); {0} WHERE {1} = @id;", cmdSelect, sIdentityColumnName);
                    }

                    da.InsertCommand.CommandText      = insertCommandText;
                    da.InsertCommand.UpdatedRowSource = UpdateRowSource.Both;
                    da.UpdateCommand = mCommandBuilder.GetUpdateCommand();
                    da.DeleteCommand = mCommandBuilder.GetDeleteCommand();
                    da.InsertCommand.CommandTimeout = cmd.CommandTimeout;
                    da.UpdateCommand.CommandTimeout = cmd.CommandTimeout;
                    da.AcceptChangesDuringUpdate    = acceptChanges;


                    //da.Update(dataSet.Tables[0]); //kapatildi
                    //tek data adapter kullanildiginda update isleminden sonra data adapter insert command i bozuluyor scope identity siliniyor
                    //bu sebeple
                    //new adapter for performing the update
                    using (var daAutoNum = _database.GetDataAdapter())
                    {
                        if (daAutoNum != null)
                        {
                            //new adaptor for performing the update
                            daAutoNum.DeleteCommand = da.DeleteCommand;
                            daAutoNum.InsertCommand = da.InsertCommand;
                            daAutoNum.UpdateCommand = da.UpdateCommand;
                            daAutoNum.InsertCommand.CommandTimeout = cmd.CommandTimeout;
                            daAutoNum.UpdateCommand.CommandTimeout = cmd.CommandTimeout;
                            daAutoNum.AcceptChangesDuringUpdate    = acceptChanges;

                            //kapatildi
                            //if (tran != null)
                            //    rowsAffected = _database.UpdateDataSet(dataSet, tableName, daAutoNum.InsertCommand,
                            //                                           daAutoNum.UpdateCommand, daAutoNum.DeleteCommand,
                            //                                           tran.Transaction, updateBatchSize);
                            //else
                            //    rowsAffected = _database.UpdateDataSet(dataSet, tableName, daAutoNum.InsertCommand,
                            //                                           daAutoNum.UpdateCommand, daAutoNum.DeleteCommand,
                            //
                            //updateBehavior, updateBatchSize);


                            rowsAffected = daAutoNum.Update(dataSet.Tables[0]);

                            if (acceptChanges)
                            {
                                dataSet.AcceptChanges();
                            }
                            SaveDataChanges(dtCopy, dataSet.Tables[0]);
                        }
                    }
                }
            }

            return(rowsAffected);
        }
Beispiel #17
0
 public GenericTransaction BeginTransaction()
 {
     return(_transaction = new GenericTransaction(_database, IsolationLevel.ReadCommitted));
 }
Beispiel #18
0
 public int UpdateDataTable(DataTable dataTable, DbCommand cmd, GenericTransaction tran)
 {
     return(UpdateDataTable(dataTable, cmd, tran, true));
 }