Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't execute all query!
Forum Updated to NodeBB v4.3 + New Features

Can't execute all query!

Scheduled Pinned Locked Moved General and Desktop
12 Posts 4 Posters 4.7k 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.
  • A Offline
    A Offline
    absfrm
    wrote on last edited by
    #3

    No , it works!
    but just can create table and can't insert values!

    If You Want You Can!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #4

      That's strange. Could you please share your source code. What is your OS?

      http://anavi.org/

      1 Reply Last reply
      0
      • A Offline
        A Offline
        absfrm
        wrote on last edited by
        #5

        I'm using Windows 7 64bits.
        and this is code :
        @
        QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),
        "",
        tr("Files (.)"));
        QFile file(fileName);
        if(!file.open(QIODevice::ReadOnly)) {
        QMessageBox::information(0, "error", file.errorString());
        }
        QString line;
        QTextStream in(&file);
        line = in.readAll();

        if (mw->dbconnect())
        {
        QSqlQuery query(line);
        }
        @

        If You Want You Can!

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on last edited by
          #6

          The SQL seems OK but try to execute it via "the SQLite command-line shell for accessing and modifying SQLite databases for Windows":http://www.sqlite.org/download.html

          Please also consider the option to execute each of your SQL statement is a separate QSqlQuery in your source code.

          http://anavi.org/

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Seba84
            wrote on last edited by
            #7

            I think the problem is in SQL code. When you declare table and columns names you should not use the "". Moreover, I never saw the TEXT declaration. Try this code:
            @
            CREATE TABLE dic2 ( name CHAR(10), alias CHAR(10) );

            insert into dic2 (name, alias) values ('12', '12');
            insert into dic2 (name, alias) values ('123', '123');
            insert into dic2 (name, alias) values ('123123', 'sdasdasd');
            insert into dic2 (name, alias) values ('123', 'asdasda');
            insert into dic2 (name, alias) values ('asd', 'sasdasd');
            @

            Before writing SQL statements into Qt applications is always best to test them in a SQL console.
            Hope it helps.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              leon.anavi
              wrote on last edited by
              #8

              [quote author="Seba84" date="1342383542"]I think the problem is in SQL code. When you declare table and columns names you should not use the "". Moreover, I never saw the TEXT declaration. [/quote]

              Good point I didn't spot the quotes at the insert statement. TEXT is SQLite specific data type. Check "SQLite documentation":http://www.sqlite.org/datatype3.html for details.

              http://anavi.org/

              1 Reply Last reply
              0
              • A Offline
                A Offline
                absfrm
                wrote on last edited by
                #9

                Hi Seba84,My sql code is works right in console,but in qt , i don't know why can't execute complete of queries!

                If You Want You Can!

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  absfrm
                  wrote on last edited by
                  #10

                  but,its OK!
                  because qt can execute one query per action!
                  i should convert my sql code to one code such as this :
                  @
                  INSERT INTO cds (titel, interpret, jahr, id) VALUES
                  ('Beauty', 'Ryuichi Sakamoto', 1990, 1),
                  ('Goodbye Country (Hello Nightclub)', 'Groove Armada', 2001, 4),
                  ('Glee', 'Bran Van 3000', 1997, 5);
                  @

                  If You Want You Can!

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

                    Yes, Qt only accepts a single SQL statement at a time, and I doubt your last attempt is valid SQL. You'll just have to execute 6 separate statements, and you'll be fine. You could wrap them in a single transaction to keep them as a unit.

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      absfrm
                      wrote on last edited by
                      #12

                      yes,thanks all and thanks to Andre for complete detail. ;)

                      If You Want You Can!

                      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