Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > pysqlite error: Database locked?

Reply
Thread Tools

pysqlite error: Database locked?

 
 
Tommy B
Guest
Posts: n/a
 
      06-07-2006
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.

 
Reply With Quote
 
 
 
 
Dennis Lee Bieber
Guest
Posts: n/a
 
      06-07-2006
On 6 Jun 2006 19:30:37 -0700, "Tommy B" <(E-Mail Removed)> declaimed
the following in comp.lang.python:

> 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.
>

<snip>
> 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
http://www.velocityreviews.com/forums/(E-Mail Removed) (E-Mail Removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (E-Mail Removed))
HTTP://www.bestiaria.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Database Database Database Database scott93727@gmail.com Computer Information 0 09-27-2012 02:43 AM
DataBase DataBase DataBase DataBase scott93727@gmail.com Computer Information 0 09-26-2012 09:40 AM
Data wont stay saved in Database using Pysqlite azrael Python 1 10-12-2008 06:53 PM
Re: [pysqlite] [ANN] pysqlite and APSW projects moved Gerhard Häring Python 3 03-13-2008 10:03 PM
[pysqlite] How do I use pysqlite in a multi-threading env.? F. GEIGER Python 2 05-21-2005 07:42 AM



Advertisments