pysqlite error: Database locked?

T

Tommy B

I'm currently working on a casino script for an IRC bot. I was going to
make a flat file database, but I decided to make it sqlite after some
suggestions. I'm using pysqlite.

http://pastebin.com/764315 < Source. The lines that have @@ (pastebin
doesn't like me) in front of them are important.

ERROR 2006-06-06T22:20:34 Uncaught exception in ['diceroll'].
Traceback (most recent call last):
File "G:\Python24\Lib\site-packages\supybot\callbacks.py", line 1170,
in _call
Command
self.callCommand(command, irc, msg, *args, **kwargs)
File "G:\Python24\Lib\site-packages\supybot\utils\python.py", line
62, in g
f(self, *args, **kwargs)
File "G:\Python24\Lib\site-packages\supybot\callbacks.py", line 1156,
in callCommand
method(irc, msg, *args, **kwargs)
File "G:\Python24\Lib\site-packages\supybot\commands.py", line 906,
in newf
f(self, irc, msg, args, *state.args, **state.kwargs)
File "G:\Python24\Scripts\plugins\Casino\plugin.py", line 160, in
diceroll
money_file_update(msg.nick, wager)
File "G:\Python24\Scripts\plugins\Casino\plugin.py", line 43, in
money_file_update
cur2.execute('UPDATE players SET cash = ' + str(newcash) + ' WHERE
name = \' ' + user + '\'')
OperationalError: database is locked
ERROR 2006-06-06T22:20:34 Exception id: 0x486de ' + user + '\'')
OperationalError: database is locked
ERROR 2006-06-06T22:20:34 Exception id: 0x486de

That's the error.
 
D

Dennis Lee Bieber

I'm currently working on a casino script for an IRC bot. I was going to
make a flat file database, but I decided to make it sqlite after some
suggestions. I'm using pysqlite.

http://pastebin.com/764315 < Source. The lines that have @@ (pastebin
doesn't like me) in front of them are important.
said:
OperationalError: database is locked
ERROR 2006-06-06T22:20:34 Exception id: 0x486de

That's the error.

Well, first a general comment on the code...

#
def money_file_update(user, newcash):
#
cur.execute('UPDATE players SET cash = ' + str(newcash) + '
WHERE name = \'' + user + '\'')
#

DON'T DO THAT! USE...

cur.execute("update players set cash = ? where name = ? ",
(newcash, user) )

Let the db-api logic figure out when things need to be quoted,
etc... (I think pysqlite uses ? for placeholder) You should only need to
put query strings together when the tables and columns themselves are
parameters -- and for those it is much cleaner to use (for example):

cur.execute("update %s set %s = ? where name = ?"
% ("players", "cash"),
(newcash, user) )

Heck, even your method could be cleaned up lots by using " for the
literal -- then you wouldn't need to \' embedded ones.

"update players set cash = %s where name = '%s'" % (newcash, user)

Now, I notice that at the top of your code you create TWO connection
objects.

DATABASE LOCKED essentially means that you have an open transaction
(one that is trying to make changes to data and has not been committed
or rolled-back) and are trying to begin another transaction; the second
transaction gave up waiting for the database to become free.

I would suspect you have one transaction open on the other
connection object BUT: the traceback you list does NOT match the code
that is at the reference URL. That code doesn't use cur2 or con2!

The use of "callbacks" implies single-threaded logic, so you
shouldn't have multiple users conflicting...
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top