我想从一个数据库中的3个表中一次获取数据。我使用了3 conn.cursor()它..有没有什么复杂的方法来做到这一点?使用多个connection.cursor()
conn = psycopg2.connect(database="plottest", user="postgres")
self.statusbar.showMessage("Database opened Sucessfully", 1000)
cur = conn.cursor()
cur1 = conn.cursor()
cur2 = conn.cursor()
cur.execute("SELECT id ,actual from \"%s\" " % date)
rows = cur.fetchall()
cur1.execute("SELECT qty from DAILY where date = \'%s\'" % date)
dailyqty = cur1.fetchone()
cur2.execute("SELECT qty from MONTHLY where month = \'%s\'" % month)
monthqty = cur2.fetchone()
非常感谢您的建议。我在2周前开始使用PostgreSQL,我仍然处于noob级别。我会学习并尝试你所说的。再次感谢!! – Bodhi94
@VibhuthaKumarage无后顾之忧。 SQL注入事件适用于所有SQL数据库。习惯于根据绑定参数进行思考,从查询文本中分离数据。请参阅http://bobby-tables.com/和https://en.wikipedia.org/wiki/SQL_injection。 –