Hi..i 텍스트와 정수 values..my 코드를 모두 잘 작동 보유하고 내 테이블에서 항목을 검색하려고 sqlite3를 데이터베이스에 ... 그러나 이것은 당신이 원하는psycopg2.Data 오류 : 정수에 대한 잘못된 입력 구문 ""
import psycopg2
class database:
def __init__(self):
self.con=psycopg2.connect("dbname='book_store' user='postgres' password='5283' host='localhost' port='5432' ")
self.cur=self.con.cursor()
self.cur.execute("CREATE TABLE if not exists books(id SERIAL PRIMARY KEY,title TEXT NOT NULL UNIQUE,author TEXT NOT NULL,year integer NOT NULL,isbn integer NOT NULL UNIQUE)")
self.con.commit()
def insert(self,title,author,year,isbn):
try:
self.cur.execute("INSERT INTO books(title,author,year,isbn) VALUES(%s,%s,%s,%s)",(title,author,year,isbn))
self.con.commit()
except:
#print("already exists..")
pass
def view(self):
self.cur.execute("SELECT * FROM books")
rows=self.cur.fetchall()
print(rows)
def search(self,title="",author="",year="",isbn=""):
self.cur.execute("SELECT * FROM books WHERE title=%s or author=%s or year=%s or isbn=%s",(title,author,year,isbn))
row=self.cur.ferchall()
print(row)
db=database()
#db.insert("The Naughty","AparnaKumar",1995,234567654)
db.view()
db.search(year=1995)
공백 문자열이 아닌 null로 isbn 전달 –
ISBN은 길이가 10 또는 13 자이며 0으로 시작할 가능성이있는 10 자리 버전입니다. 당신의 테이블에있는 데이터 타입에 대해'integer'를 사용하는 것은 좋은 생각입니다. – Nicarus