pysqlite error: Database locked?

Discussion in 'Python' started by Tommy B, Jun 7, 2006.

  1. Tommy  B

    Tommy B Guest

    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.
    Tommy B, Jun 7, 2006
    #1
    1. Advertising

  2. On 6 Jun 2006 19:30:37 -0700, "Tommy B" <> 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://wlfraed.home.netcom.com/
    (Bestiaria Support Staff: )
    HTTP://www.bestiaria.com/
    Dennis Lee Bieber, Jun 7, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hkappleorange

    database file locked by aspx

    hkappleorange, Nov 6, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    1,717
  2. F. GEIGER
    Replies:
    2
    Views:
    529
    F. GEIGER
    May 21, 2005
  3. Glen Buell
    Replies:
    5
    Views:
    1,028
    Billy Biro
    Feb 6, 2007
  4. Gerhard Häring
    Replies:
    3
    Views:
    367
    Gerhard Häring
    Mar 13, 2008
  5. Carlos Solis

    web database access locked

    Carlos Solis, Jun 9, 2004, in forum: ASP General
    Replies:
    1
    Views:
    98
    Aaron [SQL Server MVP]
    Jun 9, 2004
Loading...

Share This Page