robertohuertasm / SQLite4Unity3d

SQLite made easy for Unity3d
MIT License
1.27k stars 265 forks source link

NOT VALIDATING FOREING KEY RULES #104

Open daybson opened 4 years ago

daybson commented 4 years ago

I'm running this commands:

           var create = $"CREATE TABLE SuperPower" +
                         $"(" +
                             $"Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
                             $"Name VARCHAR(15) NOT NULL) ;";
            var create2 = $" CREATE TABLE Character" +
             $"(" +
                 $"Id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
                 $"Name VARCHAR(15) NOT NULL," +
                 $"Age INTEGER," +
                 $"Alive INTEGER," +
                 $"History VARCHAR(200)," +
                 $"Money FLOAT," +
                 $"SuperPowerID INTEGER REFERENCES SuperPower (Id)" +
             $");";
//THERE IS ONLY 2 RECORDS
            var sqlInsert1 = $"INSERT INTO SuperPower VALUES (null, 'FLY')";
            var sqlInsert2 = $"INSERT INTO SuperPower VALUES (null, 'POWER')";

//SET THE FIRST SUPERPOWER ID... OK!
            var sqlInsert3 = $"INSERT INTO Character VALUES (null, 'Kaz', 18, 1, 'Warrior', 125.2, 1)";
//**SHOULD THROW AND ERROR SINCE I'M REFERENCING THE SuperPowerID = 5, WICH DOESN'T EXISTS**
            var sqlInsert4 = $"INSERT INTO Character VALUES (null, 'Marker', 19, 1, 'Mage', 180.2, 5)";`

But the record at sqlInsert4 is being inserted at the database. If I try to insert violating the FK rule from SQLiteStudio, it throws an error of FK violation, wich is correct.

Why the framework is not respecting FK rules?