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. Add Row
Forum Updated to NodeBB v4.3 + New Features

Add Row

Scheduled Pinned Locked Moved Mobile and Embedded
9 Posts 2 Posters 2.4k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    tariq
    wrote on last edited by
    #1

    Greeting,
    I'm new one here and i need some help in my project.
    Actually, I working on Cashed table and trying to change some things on it. But i face problem, When i trying to add new row in the table it not appear to me in the run program. I just get (4 rows ). So Please if anyone can advice me to how i can add more rows in this cashed table??
    @
    QSqlQuery query;

    query.exec("create table test (id int primary key, start text, last varchar(20),Degree varchar(20), ss int(3))");

    query.exec("insert into test values(1, 'Ta', 'Em','Bsc','2')");
    query.exec("insert into test values(2, 'Do', 'Yo','Bsc','3')");
    query.exec("insert into test values(3, 'Ah', 'Sa','Bsc','4')");
    query.exec("insert into test values(4, 'DR', 'Su','Phd','3')");
    query.exec("insert into test values(5, 'Sa', 'hh,'Bsc','3')");
    @
    if you see in the run only 4 rows appear ( 1 - 4) but the last one not appear.
    I will be Grateful for any help and advice

    Kind Regards,

    Fixed formatting for you. Please use @ tags around code sections; André

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      There is an error in the last statement. I have fixed the alignment of the code for you to make it obvious.

      Also, I think the create statement looks iffy. What are the semicolons doing in there?

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tariq
        wrote on last edited by
        #3

        Oh Thanks,

        Actually, I'm not sure if i understood you, But you mean i have problem in the Create Statement or What ??

        Kind Regarrds.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          Looks like it, but your main issue is that your last insert query is faulty. You should get in the habbit of actually checking the return value of query.exec(), and using query.lastError() to get information on what wend wrong.

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tariq
            wrote on last edited by
            #5

            @QSqlQuery query;
            query.exec("create table test (id int primary key,"
            "startname text, lastname varchar(20),Degree varchar(20), ss int(3))");
            query.exec("insert into test values(1, 'Ta', 'Em','Bsc','2')");
            query.exec("insert into test values(2, 'Do', 'Yo','Bsc','3')");
            query.exec("insert into test values(3, 'Ah', 'Sa','Bsc','4')");
            query.exec("insert into test values(4, 'DR', 'Su','Phd','3')");
            query.exec("insert into test values(5, 'Sa', 'hh,'Bsc','3')");
            query.exec();
            query.lastError();@

            mmm the same, Please how i will can get information on what wend wrong

            Regards,

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Again: closely compare your last two insert statements. Their (mis-) alignment gives you a very good hint what is going wrong.

              What is the result of your last query.exec() call? What does query.lastError() return?

              1 Reply Last reply
              0
              • T Offline
                T Offline
                tariq
                wrote on last edited by
                #7

                OMG, I got it. I found the problem. It Was in the quotation.

                Thanks, Very much.

                but i have Question, If i used query.lastError() how it will return and where i can found this ??
                then what query.exec() will use ??

                Thanks

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  lastError will report on the most recently executed query.

                  query.exec() already returns a boolean, so you could write:
                  @
                  if (!query.exec("insert into test values(5, 'Sa', 'hh,'Bsc','3')")) {
                  qDebug() << query.lastError();
                  }
                  @

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tariq
                    wrote on last edited by
                    #9

                    Well, Thanks So much

                    1 Reply Last reply
                    0

                    • Login

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