Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1043177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T15:37:36+00:00 2026-05-16T15:37:36+00:00

I am trying to select all the records from a sqlite db I have

  • 0

I am trying to select all the records from a sqlite db I have with sqlalchemy, loop over each one and do an update on it. I am doing this because I need to reformat ever record in my name column.

Here is the code I am using to do a simple test:

   def loadDb(name):    

        sqlite3.connect(name)    
        engine = create_engine('sqlite:///'+dbPath(), echo=False)      
        metadata = MetaData(bind=engine)

        return metadata

    db = database("dealers.db")
    metadata = db.loadDb()
    dealers = Table('dealers', metadata, autoload=True)

    dealer = dealers.select().order_by(asc(dealers.c.id)).execute()

    for d in dealer:
        u = dealers.update(dealers.c.id==d.id)
        u.execute(name="hi")

        break

I’m getting the error:

sqlalchemy.exc.OperationalError: (OperationalError) database table is locked u'UPDATE dealers SET name=? WHERE dealers.id = ?' ('hi', 1)

I’m very new to sqlalchemy and I’m not sure what this error means or how to fix it. This seems like it should be a really simple task, so I know I am doing something wrong.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T15:37:37+00:00Added an answer on May 16, 2026 at 3:37 pm

    With SQLite, you can’t update the database while you are still performing the select. You need to force the select query to finish and store all of the data, then perform your loop. I think this would do the job (untested):

    dealer = list(dealers.select().order_by(asc(dealers.c.id)).execute())
    

    Another option would be to make a slightly more complicated SQL statement so that the loop executes inside the database instead of in Python. That will certainly give you a big performance boost.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write a query to select all records from users table
I am trying to SELECT records from two MySql tables. I would like all
I am trying to list out all records from a database that have not
I'm trying to select all records from a table Table1 but I want a
I'm trying to select all records from table A which are related to X
This may look complicated, but I am really just trying to select all records
I am trying to load all records from the database that have been created
I need some help with SQL Query. I am trying to select all records
I'm trying to return all records from my database where the userID is equal
I'm trying to figure out the way to get all records from a table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.