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. Get values from SQLite row using last_insert_rowid()
QtWS25 Last Chance

Get values from SQLite row using last_insert_rowid()

Scheduled Pinned Locked Moved General and Desktop
sqlitesqlquery
2 Posts 2 Posters 3.5k 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.
  • JorgeJ Offline
    JorgeJ Offline
    Jorge
    wrote on last edited by
    #1

    Hi,
    I need to get the values from a query using the row id I tell the query to use, however, I can't seem to know how to call the row id in said query.
    Is this a syntax problem?
    Here's an example of my code:

    QSqlQuery query;
        query.exec("SELECT last_insert_rowid()");
        QString sLastId = query.lastInsertId().toString();
    
        query.exec("SELECT fPrecioUnit, fLitros, fImporte, rowid WHERE rowid=\'" + sLastId + "\'");
    
    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      HI and welcome to devnet,

      usually a SELECT statement is in the form SELECT <field_list> FROM <table_name> WHERE <conditions>; in your queries there's no FROM <tablename>.

      BTW, QSqlQuery::exec() returns a boolean and you can check the errors with QSqlQuery::lastError()

      bool result = query.exec(...);
      if (!result) {
          qDebug() << "Error: " << query.lastError().text();
      }
      

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      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