Uppercased sql statements

This commit is contained in:
mrhanky 2017-08-22 20:05:32 +02:00
parent b13b68e26b
commit deb8c3b985
No known key found for this signature in database
GPG Key ID: 67D772C481CB41B8

View File

@ -3,7 +3,6 @@ import irc3
from docopt import Dict
from irc3.plugins.command import command
from irc3.utils import IrcString
from psycopg2 import Error
from . import DatabasePlugin
from .utils import parse_int
@ -24,23 +23,23 @@ class McManiac(DatabasePlugin):
return
index, order = index
order = 'id {order}'.format(order=order)
offset = 'offset %s'
offset = 'OFFSET %s'
else:
order = 'random()'
offset = ''
# Fetch result from database
self.cur.execute('''
select
SELECT
item,
rank() over (order by id),
count(*) over (rows between unbounded preceding
and unbounded following) as total
from
rank() OVER (ORDER BY id),
count(*) OVER (ROWS BETWEEN UNBOUNDED PRECEDING
AND UNBOUNDED FOLLOWING) AS total
FROM
mcmaniacs
order by
ORDER BY
{order}
limit
LIMIT
1
{offset}
'''.format(order=order, offset=offset), [index])
@ -53,15 +52,11 @@ class McManiac(DatabasePlugin):
@irc3.event(r'^:(?P<mask>\S+) PRIVMSG \S+ :.*(?P<item>Mc\S+iaC).*')
def save(self, mask: str, item: str):
if IrcString(mask).nick != self.bot.nick:
try:
# Insert into database
self.cur.execute('''
INSERT INTO
mcmaniacs (item)
VALUES
(%s)
ON CONFLICT DO NOTHING
''', [item])
self.con.commit()
except Error:
# Rollback transaction on error
self.con.rollback()