开发者

Sqlite3 / Webpy: "no such column" with double left join

I am trying to do Sqlite3 query via webpy framework.The query works in SQLiteManager. But with web.db i get "sqlite3.OperationalError no such column a.id". Is this a webpy bug?

import web
db = web.database(dbn='sqlite', db='data/feed.db')
account = 1
qu开发者_开发问答ery='''
    SELECT a.id, a.url, a.title, a.description, a.account_count, b.id subscribed FROM
    (SELECT feed.id, feed.url, feed.title, feed.description, count(account_feed.id) account_count
    FROM feed
    LEFT OUTER JOIN account_feed
    ON feed.id=account_feed.feed_id AND feed.actived=1
    GROUP BY feed.id, feed.url, feed.title, feed.description
    ORDER BY count(account_feed.id) DESC, feed.id DESC)
    a LEFT OUTER JOIN account_feed b ON a.id=b.feed_id AND b.account_id=$account'''

return list(self._db.query(query,vars=locals()))

Traceback is here:http://pastebin.com/pUA7zB9H


Not sure why you are getting the error "no such column a.id", but it may help to

  1. use a multiline string (easier to read),
  2. use a parametrized argument for account (Was $account a Perl-hangover?)

query = '''
        SELECT a.id, a.url, a.title, a.description, a.account_count, b.id subscribed 
        FROM ( {q} ) a 
        LEFT OUTER JOIN account_feed b 
            ON a.id=b.feed_id 
               AND b.account_id = ?'''.format(q=query)

args=[account]
cursor.execute(query,args)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜