- Joined
- Sep 27, 2009
- Messages
- 1,973
I was trying to delete two test games for Rj.
I did the first one by hand, no problem
Then I wrote a sql script to do the second one. (Which emulated what I had done by hand).
I wrote the script thinking that I could add the feature to the admin tool in case some games need to be deleted in the future
well, when I ran the script, it deleted all the games
I reviewed it a thousand times and it seemed like what was happening was impossible
Finally I figured it out. The script did in fact kill all the games.
For the technical folks around, what happened is this:
I wrote a stored procedure to delete a game. The procedure accepted a "gameid" as an argument. It then executed sql delete statements such as "delete from Games where GameId = gameid".
I figured, with the where clause, there was no way it could delete anything more than it was supposed to. I had forgotten, that while mysql is usually case-sensitive, it is not in this case with regard to the column name in the where clause. So "gameid" wasn't returning the passed argument to the clause, but instead was reference the GameId column itself.
In other words, delete every row in teh Games table where the GameId column equals the GameId column, i.e., every single row.
I did the first one by hand, no problem
Then I wrote a sql script to do the second one. (Which emulated what I had done by hand).
I wrote the script thinking that I could add the feature to the admin tool in case some games need to be deleted in the future
well, when I ran the script, it deleted all the games
I reviewed it a thousand times and it seemed like what was happening was impossible
Finally I figured it out. The script did in fact kill all the games.
For the technical folks around, what happened is this:
I wrote a stored procedure to delete a game. The procedure accepted a "gameid" as an argument. It then executed sql delete statements such as "delete from Games where GameId = gameid".
I figured, with the where clause, there was no way it could delete anything more than it was supposed to. I had forgotten, that while mysql is usually case-sensitive, it is not in this case with regard to the column name in the where clause. So "gameid" wasn't returning the passed argument to the clause, but instead was reference the GameId column itself.
In other words, delete every row in teh Games table where the GameId column equals the GameId column, i.e., every single row.