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. Querying database with list of dynamic values
QtWS25 Last Chance

Querying database with list of dynamic values

Scheduled Pinned Locked Moved General and Desktop
sqlitequerybindingselectiondatabase
2 Posts 2 Posters 1.2k 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.
  • F Offline
    F Offline
    fralik
    wrote on last edited by
    #1

    Hi!

    I have three tables (just an example to illustrate my problem):

    1. signatures with columns ID, name.
    2. meta with columns ID, metadata.
    3. signatures2meta with columns ID, meta_id, signature_id.

    The reason behind there tables is that there could be different signatures with exactly the same meta information.

    I have a QListView, which is bound to column 'name' of table 'signatures'. It shows all the names. This works fine. User can select items in QListView.

    I would like to get the selected items, obtain their IDs and find corresponding metadata information.

    I started with slot for QListView click event and there I have:

    QVariantList signatureIds;
    QModelIndexList indexes = ui->lstSignatures->selectionModel()->selectedIndexes();
    foreach (QModelIndex idx, indexes) {
        QSqlRecord record = signaturesModel_->record(idx.row());
        signatureIds << record.value("id").toInt();
    }
    

    At this point I have the list of IDs, but I do not understand how to proceed with the further query. In SQL this is achievable with such a query:

    select * from meta inner join signatures2meta on signatures2meta.meta_id = meta.id where signatures2meta.signature_id in (a, b)
    

    where (a, b) are IDs of interest. Could also be another select.

    For now I ended up by creating a string with list of all ids (like "1, 2") and inserting this string into the query directly (without bind). This works, but doesn't feel elegant at all.

    Any advise on this?

    Thanks!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Do you mean get additional data using QSqlQuery ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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