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. Error -1 on execute query...
Forum Updated to NodeBB v4.3 + New Features

Error -1 on execute query...

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 2.6k 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.
  • D Offline
    D Offline
    dcbasso
    wrote on last edited by
    #1

    I trying to execute a query, as showed below, and I got error everytime!
    The code error is -1, and As showed at "Qsqlerror":http://qt-project.org/doc/qt-5.0/qsqlerror.html, this error "type cannot be determined.".

    @ QSqlDatabase database = SingletonSession::getDatabase();
    if (database.open())
    {
    QSqlQuery query("SELECT * FROM velocidadeCAN", database);
    query.exec();
    query.first();
    qDebug() << "Consulta: " << query.executedQuery();
    qDebug() << "Error: " << query.lastError();
    query.finish();
    }
    @

    Debug:
    Consulta: "SELECT * FROM velocidadeCAN"
    Error: QSqlError(-1, "", "")

    How can I make some debug, or check the database to validade all! I could open the database created by Qt on Firefox Plugin called "SQLite Manager" and do the same query and get the data from database without errors!

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      If you pass a non-empty query string to the QSqlQuery constructor the query is immediately executed. There is no need to explicitly call exec().

      Quite contrary to, I'm not sure if a call to exec() is only allowed if there has been a query prepared using prepare(). This might be the cause of your error.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dcbasso
        wrote on last edited by
        #3

        Checking...

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dcbasso
          wrote on last edited by
          #4

          Nope, I remove the line "exec()" and the problem persists!

          1 Reply Last reply
          0
          • G Offline
            G Offline
            guziemic
            wrote on last edited by
            #5

            Hi,

            Before exec() you should call prepare()

            BR,

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              [quote author="dcbasso" date="1343328452"]Nope, I remove the line "exec()" and the problem persists![/quote]Well, you might step through then to actually find out what's going wrong.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                dcbasso
                wrote on last edited by
                #7

                There is no error on Code, It's something very weird!
                The last error is -1 but all data is there to be used....
                Thanks

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  franku
                  wrote on last edited by
                  #8

                  @ QSqlDatabase database = SingletonSession::getDatabase();
                  if (database.open()) //did you already open the database in your singleton?
                  {
                  QSqlQuery query("SELECT * FROM velocidadeCAN", database);
                  ...
                  @

                  Instead try (you probably want to omit "yourConnectionName" if you used the default):
                  @
                  QSqlDatabase database = QSqlDatabase::database( "yourConnectionName" );
                  if( database.isOpen() )
                  {
                  QSqlQuery query( database );
                  if( !query.exec( "your SQL statement" ) )
                  {
                  qDebug() << "Consulta: " << query.executedQuery();
                  qDebug() << "Error: " << query.lastError().text();
                  }
                  ...
                  @

                  ... just an idea on how to proceed.

                  This, Jen, is the internet.

                  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