Important: Please read the Qt Code of Conduct -

2-3 secs Delay when SqlRecord is Executing

  • Hi Guyz,
    I have been working on database for quite a time. I ran into an issue like this. Inserting an record into database takes 2-3 secs of time. Data gets inserted properly. I dont understand why exec() is taking such a long to return ? Here is my code.

    void DataBaseManager::insertHealthStatusDetails(HealthStatusDetailsStruct* instance)
        QSqlQuery eventsQuery;
        eventsQuery.prepare("INSERT into HealthStatusDetails (AlarmName, AlarmType, AlarmDateTime,AlarmDateTimeEpoch,AlarmAck,AlarmBriefDesc,AlarmDetailedDesc,AlarmChecked,AlarmRecovery) "
                                                             " VALUES (:AlarmName, :AlarmType, :AlarmDateTime, :AlarmDateTimeEpoch, :AlarmAck, :AlarmBriefDesc, :AlarmDetailedDesc, :AlarmChecked, :AlarmRecovery)");
        qDebug()<<"Inserting ne wrecord alarm: "<<eventsQuery.lastQuery();
        if (eventsQuery.exec()){
            qDebug()<<"Events Query is   Executed.";
        else {
            qDebug()<<"Query is Not Executed."<<eventsQuery.lastError();

    I have checked with positional binding as well.Everthing takes a time delay to return
    Can i know the reason and the best way to do ?

    Bala B

  • Lifetime Qt Champion


    What kind of database are you working with ?
    What driver are you using ?
    What size is it ?

  • it is an sqlite database on Embedded Linux

  • Lifetime Qt Champion

    What size is the database ?
    What are you using as storage ?
    What are the spec of your device ?

    1. The size of DB is it can accomodate up to 1 TB of records
    2. I did not understand. Can you brief more ?
    3. 512MB ram, dual core processor

  • @Beemaneni-Bala said in 2-3 secs Delay when SqlRecord is Executing:

    it is an sqlite database

    In addition to @SGaist's questions, do you have any other processes using the database at all?

  • Lifetime Qt Champion

    1. What is the current size ? Also, you plan to work on sqlite files in the TeraByte size ?
    2. What are you using as mass storage device ? SSD ? Mechanical hard drive ? etc.
    3. What speed ? Architecture ?

  • I have my threads running apart from this. this happens when i try to insert a record, it blocks all threads as well and it takes 5 secs to come back from exec()

  • @SGaist

    1. It is a fresh database of 20 to 30 KB. and we limited the size to some 300 to 400 MB file.
    2. Hard drive with 256 MB.
    3. 1GHz arm processor

  • Lifetime Qt Champion

    What do the other threads do when you are blocking them before writing the record ?

  • The other thread shud have the serial communication that interacts with the other module.Even that is blocked during that time. Does exec() function runs in loop until it saves all the records. ?

  • There are 2 threads one is main and other is communication thread. So database manager is a member of main thread. So when comm thread emits a signal, it is caught in main thread and the records are inserted into database. Thats how it goes for now

  • Lifetime Qt Champion

    Are you doing anything heavy in the GUI thread ?

  • Nope..Onr thing i dont understand is only at that point (when exec() is called ) alone i have that lag. If i just comment that , it works perfect.

  • Lifetime Qt Champion

    Nothing else is accessing that database ? Even an external process ?

    How is insertHealthStatusDetails called ?

  • So to answer all the questions...Here i go sir.
    I have created a test app for inserting a record into database. I compiled for device and i ran on that and it gives me same results.Hence i am not worried about all the processes and threads for now.
    Am i correct ?

  • Lifetime Qt Champion

    Looks like there's something else at play.

    I'd check with a profiler to see where's the bottleneck.

Log in to reply