Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite3.OperationalError: database is locked #5

Closed
wanghaisheng opened this issue Sep 9, 2021 · 8 comments
Closed

sqlite3.OperationalError: database is locked #5

wanghaisheng opened this issue Sep 9, 2021 · 8 comments

Comments

@wanghaisheng
Copy link

wanghaisheng commented Sep 9, 2021

    db = itemdb.ItemDB(dbname)
    db.ensure_table("all","!videoid","status")
s_thread_fastlane
    db.ensure_table("all","!videoid","status")  
  File "D:\Program Files\anaconda3\lib\site-packages\itemdb.py", line 211, in ensure_table      
    self._ensure_table_helper1(table_name, indices, missing_indices)
  File "D:\Program Files\anaconda3\lib\site-packages\itemdb.py", line 217, in _ensure_table_helper1
    self._ensure_table_helper2(table_name, indices)
  File "D:\Program Files\anaconda3\lib\site-packages\itemdb.py", line 251, in _ensure_table_helper2
    cur.execute(text)
sqlite3.OperationalError: near "all": syntax error

all seem to be keyword change to others fixed that

@wanghaisheng wanghaisheng changed the title sqlite3.OperationalError: near "all": syntax error sqlite3.OperationalError: database is locked Sep 9, 2021
@wanghaisheng
Copy link
Author

wanghaisheng commented Sep 9, 2021

@almarklein

    dbname = os.path.join(os.getcwd()+os.sep+'data'+os.sep, "fastlaneall.db")

    # Open the database and make sure there is a table with appopriate indices
    db = itemdb.ItemDB(dbname)
    db.ensure_table("fastlaneall","!videoid","status")    
    print('\n==============', f)
    # logfile,len_list =process()
    if not  db.select_one("fastlaneall", "videoid ==?",
            videoid).get("scenepath"):
        logfile,posttext,title = convert_fastlanepost2script(f)

        with db:
            db.put_one("fastlaneall", videoid=videoid, status=0,scenepath=logfile,post_text=posttext,title=title
            ) 
        db.close()

@wanghaisheng
Copy link
Author

is there any wrong with this code @almarklein

    with db:

        if  db.count(dbname, "videoid ==?",
                            videoid)==1:
            logfile = db.select_one(dbname, "videoid ==?",
                                    videoid).get("scenepath")
            post_text = db.select_one(dbname, "videoid ==?",
                                    videoid).get("post_text")
            title = db.select_one(dbname, "videoid ==?",
                                videoid).get("title")
            if  logfile and logfile.endswith('.json') and  post_text and  title:
                pass
            else:            
                print('startign convert json to scene text',f)
                logfile, post_text, title = converr(f)
                nowtime = time.time()
                update_time = int(nowtime)
                olddata = db.select_one(dbname, "videoid ==?", videoid)
                olddata["scenepath"] = logfile
                olddata["post_text"] = post_text
                olddata["title"] = title
                olddata["update_time"] = update_time

                db.put(dbname, olddata)
                print('convert json to scene,video info  update', videoid, filename)

            raise RuntimeError()

@almarklein
Copy link
Owner

Hi @wanghaisheng, that looks good at first glance, but I don't fully understand the problem, do you get an error? If it is possible to create a small example that I can run as well, that will be great, because then I can reproduce the error, and better see what's going on.

@wanghaisheng
Copy link
Author

sqlite3.OperationalError: database is locked continue say this
i notice when this happens, there is journal file

@almarklein
Copy link
Owner

Ok, I found out that db.ensure_table("all","!videoid","status") raises a syntaxerror because sqlite gets confused about the table name "all". Similarly, "table" produces an error. I created #6 for this.

I also found that running that example twice in an interactive session locks the db as well, because you create a new db object, and the old db object may be holding on to the lock.

That said, I'm not sure if this is what you are experiencing. If you can provide a complete piece of code that I can run myself, then its easier to try it out.

@wanghaisheng
Copy link
Author

exactly what you say
what do you mean by a new db object? should i initialize db through path globally?

@almarklein
Copy link
Owner

I meant in an interactive session (like in an IDE or in a Jupyer notebook). But nevermind, what's more valuable if we have some code that we can both run, and examine to see what the issue is.

@wanghaisheng
Copy link
Author

I kindof fix that
only i need is to define them at the beginning so all method share this variable
for my case i define two path for 2 database ,and call them through name matching

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants