Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DDL [drop table] causes MySql transactions to fail to roll back #4439

Open
loonylins opened this issue Mar 1, 2024 · 1 comment
Open

DDL [drop table] causes MySql transactions to fail to roll back #4439

loonylins opened this issue Mar 1, 2024 · 1 comment

Comments

@loonylins
Copy link

Steps to reproduce

using LinqToDB;
using LinqToDB.Mapping;
using System.Diagnostics;

namespace Linq2dbTestMySqlTempTable.Tests
{
    [Table("TMP_MIN_TEMPORARY")]
    public partial class TMP_MIN_TEMPORARY
    {
        [Column(IsPrimaryKey = true, IsIdentity = true, CanBeNull = false)]
        public int IDX { get; set; }

        [Column(CanBeNull = false, Length = 80)]
        public string KEY_A { get; set; }
    }

    [Table("TEST_TB_A1")]
    public class TEST_TB_AA
    {
        [Column(IsPrimaryKey = true, IsIdentity = true, CanBeNull = false)]
        public int AID { get; set; }

        [Column(CanBeNull = false, Length = 80)]
        public string CODE_AA { get; set; }
    }

    [TestClass()]
    public class ProgramTests
    {
        [TestMethod()]
        public void TestMySqlTranTest()
        {
            using (var db = new MyDataConn())
            {
                db.CreateTable<TEST_TB_AA>(tableOptions: TableOptions.CreateIfNotExists);
            }
            var code = $"{DateTime.Now:HH:mm:ss.fffff}.{Guid.NewGuid():N}";
            using (var db = new MyDataConn())
            {
                try
                {
                    db.BeginTransaction();
                    db.Insert(new TEST_TB_AA() { CODE_AA = code });
                    using (var tempTB = db.CreateTempTable<TMP_MIN_TEMPORARY>(tableOptions: TableOptions.IsTemporary | TableOptions.CheckExistence))
                    {
                        Debug.WriteLine(db.LastQuery);
                    }
                    //expected: DROP TEMPORARY TABLE IF EXISTS `TMP_MIN_TEMPORARY`
                    //actual:             DROP TABLE IF EXISTS `TMP_MIN_TEMPORARY`
                    Debug.WriteLine(db.LastQuery);
                    db.Insert(new TEST_TB_AA() { CODE_AA = code });
                    throw new Exception("Need Call RollbackTransaction!");
                    db.CommitTransaction();
                }
                catch (Exception ex)
                {
                    db.RollbackTransaction();
                }
            }

            using (var db = new MyDataConn())
            {
                //DDL [drop table] causes MySql transactions to fail to roll back, and all DML statements in the context have been committed
                var exists = db.GetTable<TEST_TB_AA>().Any(x => x.CODE_AA == code);
                Assert.IsFalse(exists);
            }
        }


        [TestMethod()]
        public void TestDropTamporaryTable()
        {
            using (var db = new MyDataConn())
            {
                db.DropTable<TMP_MIN_TEMPORARY>(tableOptions: TableOptions.DropIfExists | TableOptions.IsTemporary);
                Assert.IsTrue(db.LastQuery.Contains(" TEMPORARY "), db.LastQuery);
            }
        }
    }
}

Environment details

Linq To DB version: 5.4

Database (with version): MySql 8.0.16

ADO.NET Provider (with version): MySqlConnector 2.3.5

Operating system: any

.NET Version: .net6

@AppChenX
Copy link

DDL is not transaction-controlled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants