与python相比,sqlite查询在shell中给出了不同的结果

时间:2015-11-06 15:17:05

标签: python sql sqlite

我在sqlite3 shell中运行查询

(抱歉图片,但由于某种原因我无法从windows命令shell复制文本)

enter image description here

但是从python内部(在同一个数据库上)运行的相同查询不返回任何行。

def strange_test(dbf=DBF):
    con = lite.connect(dbf)
    con.row_factory = lite.Row
    with con:
        inputs_sql = "SELECT id, linefill_end FROM T1 WHERE CAST(linefill_end as integer) != linefill_end"
        #inputs_sql = "SELECT id, linefill_end FROM T1 WHERE id = 2307"



        cur = con.cursor()
        cur.execute(inputs_sql)
        row = cur.fetchone()
        if row:
            print row[0], row[1]
        else:
            print "Nothing found"

    return row    

没有结果:

%run "C:/Users/foo/Dropbox/parity_checking.py"
Nothing found

我从sql shell结果知道记录号2307有一个非整数值“not found”。如果我特意从Python内部查询该记录,它还会将值显示为“未找到”。我认为这证明他们正在查看相同的记录。那么为什么查询会在shell中产生结果,而不是在python里面?!?!?从python调用时,以某种方式c​​ast()无法正常工作吗?

def strange_test(dbf=DBF):
    con = lite.connect(dbf)
    con.row_factory = lite.Row
    with con:
        #inputs_sql = "SELECT id, linefill_end FROM T1 WHERE CAST(linefill_end as integer) != linefill_end"

        """search for a record I know has a non-integer linefill_end value"""
        inputs_sql = "SELECT id, linefill_end FROM T1 WHERE id = 2307"



        cur = con.cursor()
        cur.execute(inputs_sql)
        row = cur.fetchone()
        if row:
            print row[0], row[1]
        else:
            print "Nothing found"

    return row



%run "C:/Users/foo/Dropbox/_python/parity_checking.py"
2307 not found

0 个答案:

没有答案