首页 > 解决方案 > 我在做后端时遇到错误,错误是它没有显示这样的列:year(sqlite3)

问题描述

我在这里遇到问题我无法找到我的错误,我的错误显示no such column :year)

       import sqlite3
        def connect():
            conn=sqlite3.connect("books.db")
            cur=conn.cursor()
            cur.execute("CREATE TABLE IF NOT EXISTS book (id INTEGER PRIMARY KEY,title text,author text,year integer,isbn integer)")
            conn.commit()
            conn.close()
        def insert(title,author,year,isbn):
            conn=sqlite3.connect("books.db")
            cur=conn.cursor()
            cur.execute("INSERT INTO book VALUES (NULL,?,?,?,?)",(title,author,year,isbn))
            conn.commit()
            conn.close()
        def view():
            conn=sqlite3.connect("books.db")
            cur=conn.cursor()
            cur.execute("SELECT * FROM book")
            rows=cur.fetchall()
            conn.close()
            return rows 
        def search(title="",author="",year="",isbn=""):
            conn=sqlite3.connect("books.db")
            cur=conn.cursor()
            cur.execute("SELECT * FROM book WHERE title=? OR author=? OR year=? OR isbn=?",(title,author,year,isbn))
            rows=cur.fetchall()
            conn.close()
            return rows 
        connect()
        #insert("The Earth","John Smith",1918,913123133)
        print(view())
        print(search(author="John Smith"))

标签: sqlite

解决方案


推荐阅读