Skip to content
Advertisement

Why is no error showing up when inserting a name that is not in the table sql/python

JavaScript

The problem that I am refering to is that if you insert something random in the USER_INP variable that is not in the database, it doesn’t show an error like THIS DOES NOT EXIST IN THE TABLE or something like that. What I want to achieve is when the user inserts something random in the USER_INP variable, the last message that should be displayed is

message='THIS DOES NOT EXIST IN THE TABLE '

Advertisement

Answer

SQL doesn’t generate an error if a WHERE clause doesn’t match anything, it just doesn’t do anything. In a SELECT query it returns an empty result set; in a DELETE or UPDATE it doesn’t change anything.

You can use the rowcount attribute to find out how many rows were deleted. If this is 0 you can display an error message.

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement