Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. 2-3 secs Delay when SqlRecord is Executing
Forum Update on Monday, May 27th 2025

2-3 secs Delay when SqlRecord is Executing

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
17 Posts 3 Posters 2.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Beemaneni Bala
    wrote on 26 Jan 2017, 20:29 last edited by
    #1

    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)");
    
        eventsQuery.bindValue(":AlarmName",instance->AlarmName);
        eventsQuery.bindValue(":AlarmType",instance->AlarmType);
        eventsQuery.bindValue(":AlarmDateTime",instance->AlarmDateTime);
        eventsQuery.bindValue(":AlarmDateTimeEpoch",instance->AlarmDateTimeEpoch);
        eventsQuery.bindValue(":AlarmAck",instance->AlarmAck);
        eventsQuery.bindValue(":AlarmBriefDesc",instance->AlarmBriefDesc);
        eventsQuery.bindValue(":AlarmDetailedDesc",instance->AlarmDetailedDesc);
        eventsQuery.bindValue(":AlarmChecked",instance->AlarmChecked);
        eventsQuery.bindValue(":AlarmRecovery",instance->AlarmRecovered);
    
        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 ?

    Regards
    Bala B

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 26 Jan 2017, 20:32 last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Beemaneni Bala
        wrote on 26 Jan 2017, 20:40 last edited by
        #3

        it is an sqlite database on Embedded Linux

        P 1 Reply Last reply 26 Jan 2017, 20:49
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 26 Jan 2017, 20:41 last edited by
          #4

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • B Offline
            B Offline
            Beemaneni Bala
            wrote on 26 Jan 2017, 20:46 last edited by
            #5
            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
            1 Reply Last reply
            0
            • B Beemaneni Bala
              26 Jan 2017, 20:40

              it is an sqlite database on Embedded Linux

              P Offline
              P Offline
              Paul Colby
              wrote on 26 Jan 2017, 20:49 last edited by
              #6

              @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?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                SGaist
                Lifetime Qt Champion
                wrote on 26 Jan 2017, 20:51 last edited by
                #7
                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 ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                B 1 Reply Last reply 26 Jan 2017, 20:57
                0
                • B Offline
                  B Offline
                  Beemaneni Bala
                  wrote on 26 Jan 2017, 20:52 last edited by
                  #8

                  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()

                  1 Reply Last reply
                  0
                  • S SGaist
                    26 Jan 2017, 20:51
                    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 ?
                    B Offline
                    B Offline
                    Beemaneni Bala
                    wrote on 26 Jan 2017, 20:57 last edited by
                    #9

                    @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
                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 26 Jan 2017, 21:05 last edited by
                      #10

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

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • B Offline
                        B Offline
                        Beemaneni Bala
                        wrote on 26 Jan 2017, 21:08 last edited by
                        #11

                        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. ?

                        1 Reply Last reply
                        0
                        • B Offline
                          B Offline
                          Beemaneni Bala
                          wrote on 26 Jan 2017, 21:19 last edited by
                          #12

                          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

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on 26 Jan 2017, 21:42 last edited by
                            #13

                            Are you doing anything heavy in the GUI thread ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            0
                            • B Offline
                              B Offline
                              Beemaneni Bala
                              wrote on 26 Jan 2017, 21:46 last edited by
                              #14

                              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.

                              1 Reply Last reply
                              0
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 26 Jan 2017, 22:03 last edited by
                                #15

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

                                How is insertHealthStatusDetails called ?

                                Interested in AI ? www.idiap.ch
                                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                1 Reply Last reply
                                0
                                • B Offline
                                  B Offline
                                  Beemaneni Bala
                                  wrote on 26 Jan 2017, 22:28 last edited by
                                  #16

                                  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 ?

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on 27 Jan 2017, 21:16 last edited by
                                    #17

                                    Looks like there's something else at play.

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

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0

                                    1/17

                                    26 Jan 2017, 20:29

                                    • Login

                                    • Login or register to search.
                                    1 out of 17
                                    • First post
                                      1/17
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • Users
                                    • Groups
                                    • Search
                                    • Get Qt Extensions
                                    • Unsolved