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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:04:29+00:00 2026-05-24T21:04:29+00:00

I’m developing a system in C that commits updates into a MySQL database. The

  • 0

I’m developing a system in C that commits updates into a MySQL database. The client isn’t always online and therefore the application will save the SQL commands that would be executed into a *.sql when the server is inaccessible.

I’m thinking of adding a BOOLEAN field named late_commit to the tables used so I’ll know that those were inserted into the database later when the connection was restored.

I could alter the programming logic within the program to include the late_commit field in the insert queries but I’d rather have it with a default value of false and somehow have it set to true only when the .sql file is be executed.

I thought of intercalating the inserts with alter statements, but this seems a bit clumsy and will offer poor performance.

I’ve never used triggers but from what I see in this SO question they could work. They seem, however, not to be temporary or local to the session, which would interfere with the concurrent inserts from other clients.

Do you have any idea on how you did/would do this? Not necessarily the query(ies) to use, but the technology/approach that would apply the best.

EDIT:
I think that a solution, if no other comes up, could be the creation of a temporary table with the same structure and a late_commit default to true, insert the data into it, then copy into the main table.

NOTICE:
I’ve added an answer with some approaches that I’ve found. I’m still looking for the permanent solution though. So please if you know how to do it better please comment or answer. thank you!

  • 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-24T21:04:30+00:00Added an answer on May 24, 2026 at 9:04 pm

    I thought i’d leave here what i found so far in order to answer the question.

    As stated in the question i’m looking preferably to a sql only approach, that avoids using injectors.
    Prepared statements won’t work as they require a connection to the database that might not exist in the first place.


    IFNULL() SOLUTION:

    I’m inclined to use a solution I came up with using the IFNULL mysql statement which by setting a local variable would allow me to configure the late_commit column using the same query while doing it live (late_commit = false) or when doing it later (late_commit = true).

    so using the query:

    INSERT INTO `tmp`.`new_table` (`a`,`b`,`late_commit`)    
    VALUES ('abc','def', IFNULL(@LATECOMMIT, FALSE) );
    

    I can insert the values with the late_commit column set to false, making use of the IFNULL statement: because the session variable @latecommit is not defined the code will configure the column to false.

    on the other hand, if we are actually doing an offline commit, we just need to preceed all the inserts with:

    SET @LATECOMMIT = TRUE;
    

    and then proceed with all the necessary inserts, which in my case include several different tables, but in all of them there is a late_commit field that is set to IFNULL(@LATECOMMIT, FALSE):

    INSERT INTO `tmp`.`new_table` (`a`,`b`,`latecommit`)
    VALUES ('abc','def', IFNULL(@LATECOMMIT, FALSE) );
    

    I like this solution because the variable only set for the current session, and its quite easy to implement (eg. you just prepend your .sql file with the SET instruction and proceed executing it).


    TIMEDIFF() or Timestamp subtraction SOLUTION:

    When discussing this in the chat, @TehShrike also provided me with a sql only solution, my making use of the difference between the time when the query was first generated and the time when it was inserted.

    This could be done because my tables are actually being inserted with a clientdate timestamp variable, which is the local unix timestamp.

    So for this solution all that would be needed is to determine what would be considered a late_commit (eg. 60 seconds, one hour, ..) and then make our inserts like this:

    INSERT INTO `tmp`.`new_table` (`a`,`b`,`clientdate`,`latecommit`)
    VALUES ('abc','def', FROM_UNIXTIME(1313489338),
     IF( CURRENT_TIMESTAMP() - clientdate > 3600, TRUE, FALSE) );
    

    In this insert we consider a insert that was generated more than an hour ago (3600 seconds) to be a late_commit.

    If you are not using timestamps you could also use datetime fields in which case you probably would use the DATEDIFF() or TIMEDIFF() functions.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I need a function that will clean a strings' special characters. I do NOT
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a reasonable size flat file database of text documents mostly saved in

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.