|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
import database
|
|
|
|
|
import sqlite3
|
|
|
|
|
|
|
|
|
|
import datetime
|
|
|
|
|
|
|
|
|
|
class DatabaseSQLite(database.Database):
|
|
|
|
|
conn = sqlite3.connect
|
|
|
|
@ -8,3 +8,93 @@ class DatabaseSQLite(database.Database):
|
|
|
|
|
def connection(self):
|
|
|
|
|
self.conn = sqlite3.connect("../../../data/lib_manager.db")
|
|
|
|
|
|
|
|
|
|
def init(self):
|
|
|
|
|
self.conn.cursor().execute('''CREATE TABLE user(account INTEGER, userid INTEGER, password INTEGER,
|
|
|
|
|
permission VARCHAR, nickname VARCHAR, PRIMARY KEY(account))''')
|
|
|
|
|
self.conn.cursor().execute('''CREATE TABLE book_type(type CHAR, PRIMARY KEY(type))''')
|
|
|
|
|
self.conn.cursor().execute(
|
|
|
|
|
'''CREATE TABLE book_main(unique_id INTEGER, isbn INTEGER, state INTEGER, PRIMARY KEY(unique_id))''')
|
|
|
|
|
self.conn.cursor().execute(
|
|
|
|
|
'''CREATE TABLE book_loc(unique_id INTEGER, loc INTEGER, Primary KEY(unique_id) FOREIGN KEY(unique_id)
|
|
|
|
|
REFERENCES(book_main))''')
|
|
|
|
|
self.conn.cursor().execute(
|
|
|
|
|
'''CREATE TABLE book_record(unique_id INTEGER, brown_time INTEGER, real_still_time INTEGER, expect_still_time
|
|
|
|
|
INTEGER, brown_user VARCHAR, PRIMARY KEY(unique_id) FOREIGN KEY(unique_id)REFERENCES(book_main))''')
|
|
|
|
|
self.conn.cursor().execute(
|
|
|
|
|
'''CREATE TABLE book_information(isbn INTEGER, author VARCHAR, description, price INTEGER, made_time
|
|
|
|
|
INTEGER, image VARCHAR, type CHAR ,PRIMARY KEY(isbn) FOREIGN KEY(unique_id)REFERENCES(book_main))''')
|
|
|
|
|
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
|
|
|
|
|
def addBook(self, unique_id, isbn, state):
|
|
|
|
|
self.conn.cursor().execute("INSERT INTO book_main(unique_id, isbn, state) VALUES("+unique_id+", "+isbn+", "+state+")")
|
|
|
|
|
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def removeBook(self, unique_id):
|
|
|
|
|
self.conn.cursor().execute("DELETE FORM book_main WHERE unique_id")
|
|
|
|
|
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def addUser(self, user_id, userpass_word, permission, nick_name):
|
|
|
|
|
self.conn.cursor().execute("INSERT INTO user(user_id, userpass_word, permission, nick_name) VALUES ("+user_id+", "+userpass_word+", "+permission+", "+nick_name+")")
|
|
|
|
|
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def removeUser(self, unique_id):
|
|
|
|
|
self.conn.cursor().execute("DELETE FORM user WHERE unique_id")
|
|
|
|
|
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def addBookInformation(self, isbn, author, description, price, made_time, image, category):
|
|
|
|
|
self.conn.cursor().execute("INSERT INTO book_information(isbn, author, description, price, made_time, image, "
|
|
|
|
|
"category) VALUES ("+isbn+", "+author+", "+description+","+price+", "+made_time+", "+image+","+category+")")
|
|
|
|
|
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def removeBookInformation(self, isbn):
|
|
|
|
|
self.conn.cursor().execute("DELETE FORM book_information WHERE isbn")
|
|
|
|
|
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
def brownBook(self, unique_id, brown_user):
|
|
|
|
|
flag = self.conn.cursor().execute("SELECT state FROM book_main")
|
|
|
|
|
if flag:
|
|
|
|
|
self.conn.cursor().execute("UPDATE book_main SET state = false")
|
|
|
|
|
self.conn.cursor().execute(
|
|
|
|
|
"INSERT INTO book_record(unique_id, brown_time, real_still_time, expect_still_time, brown_user) VALUES("+unique_id+", "+datetime.datetime.now()+","+0+", "+30+","+brown_user+")")
|
|
|
|
|
self.conn.commit()
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def stillBook(self, unique_id):
|
|
|
|
|
flag = self.conn.cursor().execute("SELECT state FROM book_main")
|
|
|
|
|
if not flag:
|
|
|
|
|
self.conn.cursor().execute("UPDATE book_main SET state = true")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|