我有4列hotel_name,is_pool,is_wifi,is_gym。第一次启动循环时,酒店将在hotel_name列中添加10个酒店,并将1添加到is_pool列。第二次当wifi循环启动时,它将检查hotel_name列中是否已经存在酒店然后它将在is_spa中添加1(在下面的示例中已经存在的avari-hotel之前的那个酒店的面前),如果这些酒店不存在那么它将在hotel_name列中添加新酒店,并在is_gym等栏中为is_wifi列添加1 ...
Hotel_name Is_pool Is_wifi Is_gym
Grand_hayat 1 0 0
Royal-marria 1 0 0
Peart-continent 1 0 0
Sub-hotelways 1 0 0
Grand_marqs 1 0 0
Avari hotels 1 1 0
Chenone hotels 1 0 0
Savoey hotels 1 0 0
The grand 1 0 0
Hotel-range 1 0 0
Sub-marry 0 1 0
Royal-reside 0 1 0
Xyz 0 1 0
Abc 0 1 0
. . . .
. . . .
我如何实现这一任务,请帮助:)提前感谢
CREATE TABLE "Hotels" (
`hotel_id` INTEGER PRIMARY KEY AUTOINCREMENT,
`hotel_name` TEXT NOT NULL,
`is_pool` INTEGER DEFAULT 0,
`is_wifi` INTEGER DEFAULT 0,
`is_gym` INTEGER DEFAULT 0,
)
if(prefrence[i]=='pool'):
c.execute("INSERT INTO hotels (Hotel_name,is_pool) VALUES (?,?)" , [hotel], 1)
答案 0 :(得分:1)
尝试更新行。如果找不到该行,请将其插入:
c.execute("UPDATE hotels SET is_wifi = 1 WHERE hotel_name = ?", [hotel])
if c.rowcount == 0:
c.execute("INSERT INTO hotels..."...)