2010-07-23 96 views
0

好人, 我已经在我的django项目中安装了djangoratings,我想直接使用djangoratings表中的原始sql选择记录,我遵循给定的指令here,但似乎没有任何工作。为什么Django原始查询不起作用

我的代码看起来像这样;

def InsertRecord(): 
    from django.db import connection, transaction 
    cursor = connection.cursor() 

    cursor.execute(" Select ip_address from djangoratings_vote where id=%d ",[3]) 
    row = cursor.fetchone() 
    print row # row has None at this point 

该函数不会选择行,尽管它存在于表中。 正在使用,django 1.2.1,sqlite3

我在做什么?

迦特

回答

2

我想只有字符串会的工作,所以替换为%s%d,它应该工作

cursor.execute(" Select ip_address from djangoratings_vote where id=%s ",[3,]) 
1

善良的人,

对不起,我看到这里的错误是,

对于sql字符串,格式占位符应为​​“%s”而不是“%d”

谢谢