Integrity violation not released in BD Sqlite

0

CRUD in C # is not releasing integrity violation error while deleting dependent registry in SQLite DB.

        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 see that the Client has been deleted but the dependent record still has the inherited client key. Another note is that the return value of ExecuteNonQuery () is always 1.

    
asked by anonymous 30.08.2016 / 02:11

1 answer

1

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

PRAGMA foreign_keys = ON;

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

    
30.08.2016 / 02:15