Integrity breach not released in BD Sqlite

Asked

Viewed 72 times

0

CRUD in C# is not throwing integrity breach error while deleting BD Sqlite dependent record.

        query = "DELETE FROM "+ table +
                " WHERE id = '" + id + "';";
        int returnValue = 0;
        try
        {
            conn = new SQLiteConnection(connStr);
            conn.Open();
            cmd = conn.CreateCommand();
            cmd.CommandText = query;
            returnValue = cmd.ExecuteNonQuery();                
            conn.Close();                
        }
        catch (Exception e)
        {
            MessageBox.Show("O seguinte erro está impedindo o correto " +
                "funcionamento do aplicativo: \r\n" + e.Message);
        }

When I delete a client that has dependent records no error is thrown. In Sqlite Studio you can notice that the Client has been deleted but the dependent record still has the inherited client key. Another observation is that the return value of Executenonquery() is always 1.

1 answer

1


You need to enable foreign key verification support with the following command:

PRAGMA foreign_keys = ON;

So the Sqlite will know that you need to check the foreign keys. You can check this in the item 2 of this link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.