diff --git a/plugins/Factoids/plugin.py b/plugins/Factoids/plugin.py index a143a0311..d6c968ca8 100644 --- a/plugins/Factoids/plugin.py +++ b/plugins/Factoids/plugin.py @@ -583,10 +583,10 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): """ db = self.getDb(channel) cursor = db.cursor() - cursor.execute("UPDATE factoids, keys, relations " - "SET factoids.locked=1 WHERE key LIKE ? AND " - "factoids.id=relations.fact_id AND " - "keys.id=relations.key_id", (key,)) + cursor.execute("UPDATE factoids " + "SET locked=1 WHERE factoids.id IN " + "(SELECT fact_id FROM relations WHERE key_id IN " + "(SELECT id FROM keys WHERE key LIKE ?));", (key,)) db.commit() irc.replySuccess() lock = wrap(lock, ['channel', 'text']) @@ -601,10 +601,10 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): """ db = self.getDb(channel) cursor = db.cursor() - cursor.execute("""UPDATE factoids, keys, relations - SET factoids.locked=1 WHERE key LIKE ? AND - factoids.id=relations.fact_id AND - keys.id=relations.key_id""", (key,)) + cursor.execute("UPDATE factoids " + "SET locked=0 WHERE factoids.id IN " + "(SELECT fact_id FROM relations WHERE key_id IN " + "(SELECT id FROM keys WHERE key LIKE ?));", (key,)) db.commit() irc.replySuccess() unlock = wrap(unlock, ['channel', 'text']) diff --git a/plugins/Factoids/test.py b/plugins/Factoids/test.py index d41c573e3..e6c843d78 100644 --- a/plugins/Factoids/test.py +++ b/plugins/Factoids/test.py @@ -208,4 +208,10 @@ class FactoidsTestCase(ChannelPluginTestCase): self.assertNotError('learn foo as "\\"bar\\""') self.assertRegexp('whatis foo', r'"bar"') + def testLock(self): + self.assertNotError('learn foo as bar') + self.assertNotError('lock foo') + self.assertNotError('unlock foo') + + # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: