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. MySql where variable IN (:values) and bindValue()
Qt 6.11 is out! See what's new in the release blog

MySql where variable IN (:values) and bindValue()

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 493 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.
  • Seb TurS Offline
    Seb TurS Offline
    Seb Tur
    wrote on last edited by Seb Tur
    #1

    Would it be possible to pass :values i na bindVaule?

    something like below does not work.
    when i tried to bind myIds directly it fails too

    QString myIds = "1, 12, 13, 14, 15, 16, 2, 3, 4, 7, 8, 9";
    
        // Split the string into a QStringList
        QStringList idsList = myIds.split(", ");
    
        // Convert QStringList to QVariantList
        QVariantList idsVariantList;
        for (const QString &id : idsList) {
            idsVariantList.append(id.toInt());
        }
    
        // Bind the QVariantList to the query
        query.prepare("SELECT * FROM table WHERE id IN (:myIds)");
        query.bindValue(":myIds", idsVariantList);
    
    
    JonBJ 1 Reply Last reply
    0
    • Seb TurS Seb Tur

      Would it be possible to pass :values i na bindVaule?

      something like below does not work.
      when i tried to bind myIds directly it fails too

      QString myIds = "1, 12, 13, 14, 15, 16, 2, 3, 4, 7, 8, 9";
      
          // Split the string into a QStringList
          QStringList idsList = myIds.split(", ");
      
          // Convert QStringList to QVariantList
          QVariantList idsVariantList;
          for (const QString &id : idsList) {
              idsVariantList.append(id.toInt());
          }
      
          // Bind the QVariantList to the query
          query.prepare("SELECT * FROM table WHERE id IN (:myIds)");
          query.bindValue(":myIds", idsVariantList);
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Seb-Tur
      You will find that you cannot bind to the list of values for an IN clause. Not supported by the driver.

      I think you would have to produce the actual IN ( ..., ... ) as a string for the query. Doubtless with caveats about injection.

      There may be MySQL possibilities to work around this, I don't know.

      1 Reply Last reply
      0
      • Seb TurS Seb Tur has marked this topic as solved on

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved