mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-25 12:12:54 +01:00
some more mods toward getting sqlite3 to work
This commit is contained in:
parent
11446c7cb5
commit
cc1f4ea015
@ -127,11 +127,13 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE ?", (key,))
|
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE ?", (key,))
|
||||||
if cursor.rowcount <= 0:
|
results = cursor.fetchall()
|
||||||
|
if len(results) == 0:
|
||||||
cursor.execute("""INSERT INTO keys VALUES (NULL, ?, 0)""", (key,))
|
cursor.execute("""INSERT INTO keys VALUES (NULL, ?, 0)""", (key,))
|
||||||
db.commit()
|
db.commit()
|
||||||
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE ?", (key,))
|
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE ?", (key,))
|
||||||
(id, locked) = map(int, cursor.fetchone())
|
results = cursor.fetchall()
|
||||||
|
(id, locked) = map(int, results[0])
|
||||||
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
capability = ircdb.makeChannelCapability(channel, 'factoids')
|
||||||
if not locked:
|
if not locked:
|
||||||
if ircdb.users.hasUser(msg.prefix):
|
if ircdb.users.hasUser(msg.prefix):
|
||||||
@ -297,7 +299,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
irc.error('%s factoids have that key. '
|
irc.error('%s factoids have that key. '
|
||||||
'Please specify which one to remove, '
|
'Please specify which one to remove, '
|
||||||
'or use * to designate all of them.' %
|
'or use * to designate all of them.' %
|
||||||
cursor.rowcount)
|
len(results))
|
||||||
forget = wrap(forget, ['channel', many('something')])
|
forget = wrap(forget, ['channel', many('something')])
|
||||||
|
|
||||||
def random(self, irc, msg, args, channel):
|
def random(self, irc, msg, args, channel):
|
||||||
@ -311,9 +313,10 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
cursor.execute("""SELECT fact, key_id FROM factoids
|
cursor.execute("""SELECT fact, key_id FROM factoids
|
||||||
ORDER BY random()
|
ORDER BY random()
|
||||||
LIMIT 3""")
|
LIMIT 3""")
|
||||||
if cursor.rowcount != 0:
|
results = cursor.fetchall()
|
||||||
|
if len(results) != 0:
|
||||||
L = []
|
L = []
|
||||||
for (factoid, id) in cursor.fetchall():
|
for (factoid, id) in results:
|
||||||
cursor.execute("""SELECT key FROM keys WHERE id=?""", (id,))
|
cursor.execute("""SELECT key FROM keys WHERE id=?""", (id,))
|
||||||
(key,) = cursor.fetchone()
|
(key,) = cursor.fetchone()
|
||||||
L.append('"%s": %s' % (ircutils.bold(key), factoid))
|
L.append('"%s": %s' % (ircutils.bold(key), factoid))
|
||||||
@ -332,10 +335,11 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
db = self.getDb(channel)
|
db = self.getDb(channel)
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE ?", (key,))
|
cursor.execute("SELECT id, locked FROM keys WHERE key LIKE ?", (key,))
|
||||||
if cursor.rowcount == 0:
|
results = cursor.fetchall()
|
||||||
|
if len(results) == 0:
|
||||||
irc.error('No factoid matches that key.')
|
irc.error('No factoid matches that key.')
|
||||||
return
|
return
|
||||||
(id, locked) = map(int, cursor.fetchone())
|
(id, locked) = map(int, results[0])
|
||||||
cursor.execute("""SELECT added_by, added_at FROM factoids
|
cursor.execute("""SELECT added_by, added_at FROM factoids
|
||||||
WHERE key_id=?
|
WHERE key_id=?
|
||||||
ORDER BY id""", (id,))
|
ORDER BY id""", (id,))
|
||||||
@ -413,16 +417,17 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
|
|||||||
criteria.append('TARGET LIKE ?')
|
criteria.append('TARGET LIKE ?')
|
||||||
formats.append(glob.translate(self._sqlTrans))
|
formats.append(glob.translate(self._sqlTrans))
|
||||||
cursor = db.cursor()
|
cursor = db.cursor()
|
||||||
sql = """SELECT keys.key FROM ? WHERE ?""" % \
|
sql = """SELECT keys.key FROM %s WHERE %s""" % \
|
||||||
(', '.join(tables), ' AND '.join(criteria))
|
(', '.join(tables), ' AND '.join(criteria))
|
||||||
sql = sql.replace('TARGET', target)
|
sql = sql.replace('TARGET', target)
|
||||||
cursor.execute(sql, formats)
|
cursor.execute(sql, formats)
|
||||||
if cursor.rowcount == 0:
|
results = cursor.fetchall()
|
||||||
|
if len(results) == 0:
|
||||||
irc.reply('No keys matched that query.')
|
irc.reply('No keys matched that query.')
|
||||||
elif cursor.rowcount == 1 and \
|
elif len(results) == 1 and \
|
||||||
self.registryValue('showFactoidIfOnlyOneMatch', channel):
|
self.registryValue('showFactoidIfOnlyOneMatch', channel):
|
||||||
self.whatis(irc, msg, [cursor.fetchone()[0]])
|
self.whatis(irc, msg, [cursor.fetchone()[0]])
|
||||||
elif cursor.rowcount > 100:
|
elif len(results) > 100:
|
||||||
irc.reply('More than 100 keys matched that query; '
|
irc.reply('More than 100 keys matched that query; '
|
||||||
'please narrow your query.')
|
'please narrow your query.')
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user