Mysql Python eof然后在获取更多数据后返回

时间:2016-05-12 16:46:53

标签: python mysql

如何在选择完成(eof)后显示更多数据,但插入更多数据:

import MySQLdb
import MySQLdb.cursors
cnx = MySQLdb.connect(user="user", 
             passwd="password",
             db="mydb",
             cursorclass = MySQLdb.cursors.SSCursor
            )
cursor = cnx.cursor()
cursor.execute("SELECT * FROM individual_data")
while FOREVER:
    row = cursor.fetchone()
    if row is not None:
        print row

1 个答案:

答案 0 :(得分:0)

只需:

cursor.execute("SELECT * FROM individual_data where " +
             "datetimestamp >= TIMESTAMP '" + str(TOP_DT1) + "' and datetimestamp < TIMESTAMP '" + str(TOP_DT11) + "' order by datetimestamp, segment_id, user_id, id")

再次执行查询以获取更多数据。像这样;

    row1 = fetch_one(cur1)
    while row1 is not None:
        b = read_individual_data(row1)
        row = emit_individual_data(a, b)
        TOP_DT1 = TOP_DT11
        row1 = fetch_one(cur1)