【问题标题】:I can't see the output of postgresql database access program我看不到postgresql数据库访问程序的输出
【发布时间】:2017-01-03 16:58:45
【问题描述】:
def bul():

    global entry_bul
    pencere = Toplevel()

    etiket= Label(pencere,text="\n# Which record do you want to find?Please enter the Student ID number.\n")
    etiket.pack()

    entry_bul=Entry(pencere)
    entry_bul.pack()

    btn = Button(pencere,text="Find the student",bg="orange",fg="navy",command=sorgula)
    btn.pack()

def sorgula():

    conn = connect(database="dorm", user="postgres", password="605394", host="127.0.0.1", port="5432")
    print "Opened database successfully"
    cur = conn.cursor()
    cur.execute("SELECT * FROM pers_info, school_info, room_info WHERE ID_num = (%s) ;", (entry_bul.get(),));
    rows = cur.fetchall()
    for row in rows:
       print row[0], row[1], row[2], row[3],row[4]

    print "Operation done successfully";
    conn.commit()
    conn.close()

这些函数运行没有错误。但它没有在屏幕上给出 for 循环的输出。 屏幕上的结果是:

Opened database successfully
Operation done successfully

【问题讨论】:

  • 您输入的数据是否类似代码?那么没有数据也就不足为奇了:你不打电话给conn.commit;通过(): conn.commit() 调用函数。如果您只从数据库中读取,则无需提交。
  • 使用更好的标题——“我看不到输出”对于潜在的答案不是很有用。
  • 我修复了 commit() 但它仍然在做同样的事情。我认为 "WHERE ID_num = (%s) ;", (entry_bul.get(),)" 部分有问题。就像它没有看到 entry_bul.get()
  • 我也尝试了类似的基本代码。有用。正如我所说,我认为 t 与 "ID_num = (%s) ;", (entry_bul.get(),));" 部分有关。
  • 这是在做什么? cur.execute("SELECT * FROM pers_info, school_info, room_info WHERE ID_num = (%s) ;", (entry_bul.get(),));

标签: python postgresql python-2.7


【解决方案1】:

基于“成功打开数据库”和“成功完成操作”之间的空白行,我假设 for 循环中的打印语句只运行一次,并且第一行也是唯一一行中没有值。

【讨论】:

  • 其实没有空行就好了
  • @SerdarDarende 这实际上对调试很有帮助。这意味着你的 for 循环没有运行,所以我会检查以确保你的“rows”变量正在被填充。希望这会有所帮助并让我保持最新状态
  • 我检查了,但没有变化。我认为问题出在 "ID_num = (%s) ;", (entry_bul.get(),)" 但我无法解决问题。
  • 尝试将该 SQL 语句保存到一个变量中,然后将其打印出来并传递给 curr.execute()。这将帮助您开始追溯它以查看该字符串是否是您想要的字符串
  • 很遗憾没有变化
猜你喜欢
  • 2015-08-30
  • 2016-06-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-04
  • 2021-12-28
  • 1970-01-01
  • 2013-09-05
  • 1970-01-01
相关资源
最近更新 更多