コード例 #1
0
        public async Task ExecuteNonQueryAndScalarAsyncAwait()
        {
            if (st.Version < new Version(5, 0))
            {
                return;
            }

            st.execSQL("CREATE TABLE NonQueryAndScalarAsyncAwaitTest (id int)");
            st.execSQL("CREATE PROCEDURE NonQueryAndScalarAsyncAwaitSpTest() BEGIN SET @x=0; REPEAT INSERT INTO NonQueryAndScalarAsyncAwaitTest VALUES(@x); " +
                       "SET @x=@x+1; UNTIL @x = 100 END REPEAT; END");

            EFMySqlCommand proc = new EFMySqlCommand()
            {
                CommandText = "NonQueryAndScalarAsyncAwaitSpTest", Connection = st.conn
            };

            proc.CommandType = CommandType.StoredProcedure;
            int result = await proc.ExecuteNonQueryAsync();

            Assert.NotEqual(-1, result);

            EFMySqlCommand cmd = new EFMySqlCommand()
            {
                CommandText = "SELECT COUNT(*) FROM NonQueryAndScalarAsyncAwaitTest;", Connection = st.conn
            };

            cmd.CommandType = CommandType.Text;
            object cnt = await cmd.ExecuteScalarAsync();

            Assert.Equal(100, Convert.ToInt32(cnt));
        }
コード例 #2
0
ファイル: InsertTests.cs プロジェクト: Arsslensoft/FleshHRMS
        public void ExecuteNonQueryAndScalarAsync()
        {
            if (st.Version < new Version(5, 0))
            {
                return;
            }

            st.execSQL("CREATE TABLE test (id int)");
            st.execSQL("DROP PROCEDURE IF EXISTS spTest");
            st.execSQL("CREATE PROCEDURE spTest() BEGIN SET @x=0; REPEAT INSERT INTO test VALUES(@x); " +
                       "SET @x=@x+1; UNTIL @x = 100 END REPEAT; END");

            EFMySqlCommand proc = new EFMySqlCommand()
            {
                CommandText = "spTest", Connection = st.conn
            };

            proc.CommandType = CommandType.StoredProcedure;
            System.Threading.Tasks.Task <int> result = proc.ExecuteNonQueryAsync();

            Assert.NotEqual(-1, result.Result);

            EFMySqlCommand cmd = new EFMySqlCommand()
            {
                CommandText = "SELECT COUNT(*) FROM test;", Connection = st.conn
            };

            cmd.CommandType = CommandType.Text;
            object cnt = cmd.ExecuteScalarAsync().Result;

            Assert.Equal(100, Convert.ToInt32(cnt));
        }