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

  • SEARCH
  • Home
  • 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 4246396
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:58:03+00:00 2026-05-21T03:58:03+00:00

I write a lot of parallel scripts in python for research purposes and was

  • 0

I write a lot of parallel scripts in python for research purposes and was wondering if it is possible to obtain a read/write lock manually in sqlite for a specific set of commands. Here is an oversimplified example of why I need it:

Simple Example:
Suppose I have a table (A) and I want to simply count the number of rows in it and store the result in another table (B) in parallel. To do so, I run 10 instances of a program that counts rows for a certain range of A and adds the sum of the rows to the property in B.

The problem is that I need to read the property in B, add it to the instance’s count, and save it; all while making sure none of the other instances are doing this process. Normally it is only a write lock that is needed – in this case I need a read lock as well…

I was hoping I could do something like this:

  1. read/write lock
  2. Grab current value in B, add it to the
    instance count
  3. save new value
  4. unlock

Is there a way to do this?

Thanks.

  • 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-21T03:58:04+00:00Added an answer on May 21, 2026 at 3:58 am

    You can increment an integer value using a single UPDATE statement:

    sqlite> CREATE TABLE B(Id INTEGER, Value INTEGER);
    sqlite> INSERT INTO B VALUES(0, 15);
    sqlite> UPDATE B SET Value=Value + 23 WHERE Id = 0;
    sqlite> SELECT * FROM B;
    0|38
    sqlite> 
    

    Using a single UPDATE statement makes this operation atomic, making any extra locking unnecessary.

    If you need more complex processing, you can use SQL transactions to ensure that any complex database operations are performed atomically.

    In general, you should avoid any locking external to SQLite or messing with the SQLite locking subsystem – doing so is a very good recipe for deadlocks…

    EDIT:

    To append to a string, you can use the || concatenation operator:

    sqlite> CREATE TABLE C(Id INTEGER, Value TEXT);
    sqlite> INSERT INTO C VALUES(0, 'X');
    sqlite> UPDATE C SET Value=Value || 'Y' WHERE Id = 0;
    sqlite> SELECT * FROM C;
    0|XY
    sqlite> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I write a lot of Python code where I just want to read a
I write a lot of scripts in Python to analyze and plot experimental data
Im using Markdown in Vim to write a lot of text. I'm wondering if
I write a lot of shell scripts and I am constantly having to enter
I write a lot of meta-programs. Scripts in Ruby and PHP that generate different
I write a lot of little scripts that process files on a line-by-line basis.
I am getting ready to write lot of small experimental java programs as I
I write a lot of .NET based plug-ins for other programs which are usually
I have to write a lot of helper classes for some reasons like below:
I'm using Visual Studio to write a lot of data to a file. It's

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.