'Trigger is not created in sqlite

I'm building a database for a library management system, so I have created three tables: books, members and borrow(describe the relation between the two tables). for each book I store in the books table, I store it's quantity. for each member that want to borrow a book, I store his id and the book id in the borrow table. for every time a member want to borrow a book, I want to check that borrowed quantity is equal or less than the quantity stored for that book in the books table(in case it was more it will rise an error and will not accept the new data) , so I tried to achieve this using a trigger the problem is that when I try to run the trigger it's not created, and it does not even give an error message, when I try even to see the trigger that is created in the database using the command:(select name from sqlite_master where type = 'trigger';) it does not show any thing

here is the code:

CREATE TABLE books(
book_id INTEGER CHECK (book_id>0999) PRIMARY KEY AUTOINCREMENT,
book_title VARCHAR(20) NOT NULL,
author_name VARCHAR(20),
quantity INT NOT NULL,
genre VARCHAR(20) NOT NULL,
book_place VARCHAR(20) NOT NULL,
UNIQUE(book_title,author_name)
);

CREATE TABLE members(
member_id INTEGER  PRIMARY KEY AUTOINCREMENT CHECK(member_id<1000) , 
member_name VARCHAR(20) NOT NULL,
member_phone TEXT NOT NULL UNIQUE 
CHECK (LENGTH(member_phone)==11 AND member_phone NOT GLOB '*[^0-9]*'
AND (SUBSTR(member_phone,1,3)=='010' OR SUBSTR(member_phone,1,3)=='011' 
OR SUBSTR(member_phone,1,3)=='012' OR SUBSTR(member_phone,1,3)=='015' )),
sub_startDate TEXT NOT NULL CHECK(sub_startDate IS DATE(sub_startDate)),
sub_endDate TEXT NOT NULL CHECK(sub_endDate IS DATE(sub_endDate)) 
);





CREATE TABLE borrow(
member_id INTEGER NOT NULL,
book_id INTEGER NOT NULL,
borrowed_date TEXT NOT NULL CHECK(borrowed_date IS DATE(borrowed_date)),
return_date TEXT NOT NULL CHECK (return_date IS DATE(return_date)),
FOREIGN KEY(member_id) REFERENCES members(member_id) ON DELETE CASCADE ,
FOREIGN KEY(book_id) REFERENCES books(book_id) ON DELETE CASCADE,
PRIMARY KEY(member_id,book_id)
);



CREATE TRIGGER not_enough_copies
BEFORE INSERT, UPDATE 
ON borrow
WHEN 
(SELECT((SELECT 
COUNT(*) 
FROM borrow
WHERE book_id=NEW.book_id)
NOT BETWEEN 1 AND 
(SELECT quantity FROM books WHERE books.book_id==NEW.book_id)))
BEGIN
RAISE(ABORT,'ERROR!..This book is not available in the library right now')   
END;


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source