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