You are viewing a single comment's thread.

view the rest of the comments →

0
0

[–] ScionOfZion ago  (edited ago)

COBOL never died. It just migrated to databases. Look at this shit.

CREATE TRIGGER check_book_pages    
    AFTER INSERT ON chapter
        FOR EACH ROW 
            BEGIN 
                DECLARE total_pages INTEGER;
                DECLARE new_pages INTEGER;

                SET @total_pages := (SELECT book_pages FROM book WHERE id = NEW.book_id);
                SET @new_pages := (SELECT SUM(chapter_pages) FROM chapter WHERE book_id = NEW.book_id);                

                IF @new_pages > @total_pages THEN                    
                        SIGNAL SQLSTATE '45000'
                        SET MESSAGE_TEXT='Adding this chapter is not allowed! The total number of pages is too high!';                    
                END IF;    
            END ^;

A book has a maximum number of pages? In the database? What? If a programmer can see something is invalid then the constraint belongs in the database. That's the best place for it. You suck it up and you write that COBOL look-alike beauty. But if only a manager can say something is invalid? Those constraints should go in a domain model somewhere. He's going to change his mind.