2013-03-20 38 views
-1

工作,我有這樣的代碼:鎖定MySQL表不龍捲風

# Retreive the users that can obtain permission on the network except the admin 
self.lock_tables("read", ['nets_permissions as n', 'users as u']) 
usrs = self.db.query("SELECT distinct u.id FROM users as u \ 
     left outer join nets_permissions as n on u.id = n.user_id \ 
     where u.id not in \ 
     (select users.id from users left outer join nets_permissions \ 
     on users.id = nets_permissions.user_id \ 
     where nets_permissions.network_id=%s and nets_permissions.perm=3)", netid) 
self.unlock_tables() 

但我在龍捲風屏幕獲得此錯誤:

File "./wsn.py", line 571, in get where nets_permissions.network_id=%s and nets_permissions.perm=3)", netid) raise errorclass, errorvalue OperationalError: (1100, "Table 'users' was not locked with LOCK TABLES")

哪裏錯誤?

+0

'lock_tables'看起來像的罪魁禍首;它看起來也是你的代碼,而不是Tornado。 – 2013-03-21 16:22:00

回答

0

的解決方案是:

# Retreive the users that can obtain permission on the network except the admin 
    self.lock_tables("read", ['nets_permissions as n', 'users as u', 'nets_permissions as m', 'users as v']) 
    usrs = self.db.query("SELECT distinct u.id FROM users as u \ 
          left outer join nets_permissions as n on u.id = n.user_id \ 
          where u.id not in \ 
          (select v.id from users as v left outer join nets_permissions as m \ 
          on v.id = m.user_id \ 
          where m.network_id=%s and m.perm=3)", netid) 
    self.unlock_tables()