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 7904587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:08:57+00:00 2026-06-03T10:08:57+00:00

I am writing a call centre program in C# where multiple agents load the

  • 0

I am writing a call centre program in C# where multiple agents load the customers one by one from a table. In order to prevent more than one agent to load the same customer, I have added a new field to the table to show that the row is locked. When I select a row, I update that row and set the lock field to the ID of the agent who has selected that row. But the problem is during the time that I select the row and I lock it, another agent can select the same row since it’s not locked yet ! Is there a way I can handle this situation ? The database is MySQL 5 / InnoDB

  • 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-06-03T10:08:59+00:00Added an answer on June 3, 2026 at 10:08 am

    Assuming you can only lock 1 profile per agent:

    --Check for no lock
    UPDATE T SET LockField = 'abc' WHERE ProfileId = 1 AND LockField IS NULL;
    
    --Check to see if we updated anything. 
    --If not, we can't show this row because someone else has it locked
    SELECT ROW_COUNT();
    

    Before i execute the update i have to select the id…

    If you do the UPDATE in 1 statement, you don’t. We’re getting a little past my knowledge of MySQL syntax – but something like:

    --Check for no lock
    UPDATE T SET LockField = 'abc' WHERE ProfileId = (
       SELECT ProfileId FROM T WHERE LockField IS NULL LIMIT 1
    );
    
    --Check to see what we updated
    SELECT * FROM T WHERE LockField = 'abc';
    

    works pretty easily.

    If you want to get a little more complicated (or MySQL doesn’t support the subquery), you can use an update lock with SELECT…FOR UPDATE:

    START TRANSACTION;
    
    --Put an update lock on the row till the xaction ends
    --any other SELECT wanting an update lock will block until we're out of the xaction
    SELECT @id = ID FROM T WHERE LockField IS NULL LIMIT 1 FOR UPDATE;
    
    UPDATE T SET LockField = 'abc' WHERE ID = @id;
    
    COMMIT TRANSACTION;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple program to call a Java function from my C program.
Suppose we are writing a class (let's call it Class) in an iPhone program.
I'm writing a DLL that needs to call a separate DLL dynamically multiple times.
I'm writing a reusable control - lets call it MyListView - inherited from standard
I'm writing code that will call a C function from Fortran using Fortran's C
I'm writing a simple templatetag that gets one item and call one of its
I wrote a program which includes writing and reading from database. When I run
I'm writing a software for a call-center. It's somewhat like a ATM program: user
I am writing jquery ajax code to call wcf service. In this case WCf
I am writing a procedure where each call it needs to get a single

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.