def insert(username,password): sql = "insert into user (username,password) values ('%s','%s')"%(username,password) conn = sqlconnect.db_connect() cur = conn.cursor() cur.execute(sql) conn.commit() cur.close() conn.close()
def select(username,password): # username ='******' and sql = "select username, password from public.user where username ='******' and password ='******'"%(username,password) conn = sqlconnect.db_connect() cur = conn.cursor() cur.execute(sql) result = cur.fetchall() conn.commit() cur.close() conn.close() if(len(result)==0): print ("用户名和密码不正确") return False else: return True
def docker_add(): conn = sqlconnect.db_connect() cur = conn.cursor() # 执行的添加sql语句 sql = """INSERT INTO "public"."docker" ("container_name", "container_id", "image_name", "container_status", "container_createtime", "container_ip", "container_port1", "container_port2", "container_port3", "container_process_status", "container_group") VALUES ( %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s); """ # 获取python执行后返回的字典信息 docker_dict = docker_ssh.docker_ssh_exec() print(type(docker_dict)) # 传递参数到字典 container_name = docker_dict['container_name'] container_id = docker_dict['container_id'] image_name = docker_dict['image_name'] container_status = docker_dict['container_status'] container_createtime = docker_dict['container_createtime'] container_ip = docker_dict['container_ip'] container_port1 = docker_dict['container_port1'] container_port2 = docker_dict['container_port2'] container_port3 = docker_dict['container_port3'] container_process_status = docker_dict['container_process_status'] container_group = docker_dict['container_group'] # 将上面的值赋给变量 values = (container_name, container_id, image_name, container_status, container_createtime, container_ip, container_port1, container_port2, container_port3, container_process_status, container_group) # 执行sql cur.execute(sql, values) # 提交,并关闭连接 conn.commit() cur.close() conn.close()
def main(): global cnx global interface global antena_id if len(sys.argv) != 3: print 'Usage: ' + sys.argv[0] + ': interface antenna_id' return interface = str(sys.argv[1]) antena_id = str(sys.argv[2]) #connect to DB cnx = sqlc.db_connect(host, user, pwd, db) print "Antena " + str(antena_id) + ":" sniff(iface=interface, prn=sniffProbes) #close db sqlc.db_close(cnx)
def situation_docker(): conn = sqlconnect.db_connect() cur = conn.cursor() # 待执行的查询sql语句 sql = """select id, container_name, container_id, image_name, container_status, container_createtime, container_ip, container_port1, container_port2, container_port3, container_process_status, container_group from docker;""" # 执行语句 cur.execute(sql) # fetchall返回多个记录 result_dict = cur.fetchall() # 提交并关闭连接 conn.commit() cur.close() conn.close() print(type(result_dict)) # 将结果返回到html页面中,并传递包含值的结果集u return render_template('success.html', result_dict=result_dict)