Beispiel #1
0
        public static void T_StoreProcMultiResultSet3()
        {
            var connStr = GetMySqlConnString();
            var conn    = new MySqlConnection(connStr);

            //Console.WriteLine("1");
            conn.Open();
            PrepareTable1(conn);
            // Console.WriteLine("2");
            {
                string createStoreProcSql = @"DROP PROCEDURE IF EXISTS multi;";
                var    cmd = new MySqlCommand(createStoreProcSql, conn);
                // Console.WriteLine("3");
                cmd.ExecuteNonQuery();
            }
            {
                string createStoreProcSql = @"CREATE PROCEDURE multi() BEGIN
                              SELECT 1011 as A;
                              SELECT 1022 as B;
                              select col_id from test001;
                              END";
                //Console.WriteLine("4");
                var cmd = new MySqlCommand(createStoreProcSql, conn);
                cmd.ExecuteNonQuery();
            }
            {
                // Console.WriteLine("5");
                string callProc = "call multi();";
                var    cmd      = new MySqlCommand(callProc, conn);

                //access to sub table
                var currentSubTable = MySqlSubTable.Empty;

                cmd.ExecuteSubTableReader(reader =>
                {
                    if (reader.CurrentSubTable.Header != currentSubTable.Header)
                    {
                        //change main table
                        //some table may split into many sub table
                    }
                    currentSubTable = reader.CurrentSubTable;
                    //on each subtable
                    //create data reader for the subtable
                    while (reader.Read())
                    {
                        Console.WriteLine(reader.GetInt32(0));
                    }

                    //last table

                    if (currentSubTable.IsLastTable)
                    {
                        conn.Close();
                    }
                });
            }
        }
Beispiel #2
0
 public static ActionTask AsyncExecuteSubTableReader(this MySqlCommand cmd, TaskChain ch, Action <MySqlDataReader> readerReady)
 {
     return(ch.AddTask(() =>
     {
         ch.AutoCallNext = false;
         cmd.ExecuteSubTableReader(subtable =>
         {
             //this method is respond for call next ***
             ch.AutoCallNext = true;
             readerReady(subtable);
             if (ch.AutoCallNext)
             {
                 ch.Next();
             }
         });
     }));
     //not use autocall next task, let the cmd call it when ready ***
 }