defquery_sql(self,sql): #执行select并返回数据的方法 result=self.c.execute(sql) for res in result: self.list1.append(res[0]) print(list(set(self.list1))) self.conn.commit() self.conn.close()
defexecute_sql(self,sql): #执行除select外语句的方法 result=self.c.execute(sql) print("the result is:",result) if"create table"instr(sql).lower(): print("Table created successfully") else: print("the createdb.sql execute is successfully") self.conn.commit() self.conn.close()
if __name__=="__main__": table1=''' create TABLE IF NOT EXISTS table0607( id INTEGER PRIMARY KEY AUTOINCREMENT, `qq_number` varchar(255) DEFAULT NULL, `qq_sex` varchar(255) DEFAULT NULL, `qq_years` varchar(255) DEFAULT NULL, `qq_injoin_time` varchar(255) DEFAULT NULL, `qq_say_time` varchar(255) DEFAULT NULL ); ''' insert_sql="INSERT INTO qq_infos (id,qq_number,qq_sex,qq_years,qq_injoin_time,qq_say_time) VALUES (1,'625888888','女','130年','2015/04/21','吐槽')" query_sql="select count(*) from qq_infos" delete_sql="delete from qq_infos where id=765" update_sql="update qq_infos set qq_number='625888888' where id=1" db=conndb() sql="select qq_number from table0607 where id>4366" db.execute_sql(table1) db.query_sql(sql)