Uppercased sql statements
This commit is contained in:
parent
b13b68e26b
commit
deb8c3b985
|
@ -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)
|
||||
''', [item])
|
||||
self.con.commit()
|
||||
except Error:
|
||||
# Rollback transaction on error
|
||||
self.con.rollback()
|
||||
self.cur.execute('''
|
||||
INSERT INTO
|
||||
mcmaniacs (item)
|
||||
VALUES
|
||||
(%s)
|
||||
ON CONFLICT DO NOTHING
|
||||
''', [item])
|
||||
self.con.commit()
|
||||
|
|
Loading…
Reference in New Issue
Block a user