/// <summary>
        /// 
        /// </summary>
        /// <param name="database"></param>
        /// <returns></returns>
        public IEnumerable<StoredProcedureResultSet> EnumerateResultSets(Database database)
        {
            if (database == null) throw new ArgumentNullException("database");
            DbDataReader dr = null;
            var previousState = database.ConnectionState;

            try
            {
                var resultsets = new List<StoredProcedureResultSet>();
                var cm = CreateCommand();
                dr = database.ExecuteReader(cm);
                while (dr.Read())
                {
                    var rs = CreateResultSets(dr);
                    resultsets.Add(rs);
                    yield return rs;
                }
                dr.Close();
                this.SetOutputParameterValue(cm);
            }
            finally
            {
                if (dr != null) { dr.Dispose(); }
                if (previousState == ConnectionState.Closed && database.ConnectionState == ConnectionState.Open) { database.Close(); }
                if (previousState == ConnectionState.Closed && database.OnTransaction == false) { database.Dispose(); }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="transactionKey"></param>
 /// <param name="isolationLevel"></param>
 public DatabaseContext(Database database, String transactionKey, IsolationLevel isolationLevel)
 {
     this.Initialize(database, transactionKey, isolationLevel);
 }
Esempio n. 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="transactionKey"></param>
 public DatabaseContext(Database database, String transactionKey)
 {
     this.Initialize(database, transactionKey, null);
 }
Esempio n. 4
0
 /// <summary>
 /// 
 /// </summary>
 public DatabaseContext(Database database)
 {
     this.Initialize(database, "", null);
 }
Esempio n. 5
0
 private void Initialize(Database database, String transactionKey, IsolationLevel? isolationLevel)
 {
     this.TransactionKey = transactionKey;
     this.Database = database;
     DatabaseContext.SetDatabaseContext(this.TransactionKey, this);
     if (isolationLevel.HasValue == true)
     {
         this.BeginTransaction(isolationLevel.Value);
     }
 }
 protected override void ExecuteCommand(Database database, string query)
 {
     var db = database as MySqlDatabase;
     var script = new MySqlScript();
     script.Delimiter = "//";
     script.Query = query;
     db.ExecuteCommand(script);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="database"></param>
 /// <returns></returns>
 public DataTable GetDataTable(Database database)
 {
     if (database == null) throw new ArgumentNullException("database");
     var previousState = database.ConnectionState;
     try
     {
         var cm = CreateCommand();
         var dt = database.GetDataTable(cm);
         return dt;
     }
     finally
     {
         if (previousState == ConnectionState.Closed && database.OnTransaction == false) { database.Dispose(); }
     }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="database"></param>
 /// <returns></returns>
 public List<StoredProcedureResultSet> GetResultSets(Database database)
 {
     return EnumerateResultSets(database).ToList();
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="database"></param>
 /// <returns></returns>
 public StoredProcedureResultSet GetFirstResultSet(Database database)
 {
     return this.GetResultSets(database).FirstOrDefault();
 }