Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Can't execute all query!

    General and Desktop
    4
    12
    4050
    Loading More Posts
    • 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
      absfrm last edited by

      Hi
      I'm using sqlite , and want to run this query from sql file:
      @
      CREATE TABLE "dic2" (
      "name" TEXT,
      "alias" TEXT
      );
      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');
      @

      table is made but, can't insert values into table! why?

      If You Want You Can!

      1 Reply Last reply Reply Quote 0
      • L
        leon.anavi last edited by

        Did you get any errors?

        http://anavi.org/

        1 Reply Last reply Reply Quote 0
        • A
          absfrm last edited by

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

          If You Want You Can!

          1 Reply Last reply Reply Quote 0
          • L
            leon.anavi last edited by

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

            http://anavi.org/

            1 Reply Last reply Reply Quote 0
            • A
              absfrm last edited by

              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 Reply Quote 0
              • L
                leon.anavi last edited by

                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 Reply Quote 0
                • S
                  Seba84 last edited by

                  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 Reply Quote 0
                  • L
                    leon.anavi last edited by

                    [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 Reply Quote 0
                    • A
                      absfrm last edited by

                      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 Reply Quote 0
                      • A
                        absfrm last edited by

                        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 Reply Quote 0
                        • A
                          andre last edited by

                          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 Reply Quote 0
                          • A
                            absfrm last edited by

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

                            If You Want You Can!

                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post