Sqlite and Qt issue, need guidance



  • Hello, I'm looking for some advice on sqlite- I have very little experience with databases.

    I'll start by explaining what I am trying to accomplish. Each entry I have in my database has a total of 12 fields. When I originally submit the entry everything goes great.

    My problem arises from a new function which I use to update specific fields while retaining all the prior information in the other fields that are not being updated.

    This is a small example-- my primary key is the partID followed by partType, partLocation, partAge, etc... I'll keep it 4 fields long for simplicity in this example.

    let's say I already have information in this entry such as

    partID = 123, partType = blade, partLocation = shelf2, partAge = 2 months

    Now for this entry I want to change partLocation from its original location of shelf2 to shelf3- while retaining the data in the other fields that are not changing.

    Here is what I have so far...

    qry.prepare("INSERT OR REPLACE INTO partInformation WHERE partID='"+partNumber+"' (partID,partType,partLocation,partAge) VALUES (:partID,:partType,:partLocation,:partAge)");

    qry.bindValue(":partID", pID); // I don't wish to update this field
    qry.bindValue(":partType", pType); // I don't wish to update this field

    qry.bindValue(":partLocation", pLoc); //This I want to update only

    qry.bindValue(":partAge", pAge);// I dont wish to update this field

    I have been looking for a way to tell it to ignore the unwanted ones, I don't even know if that is possible.

    If I don't include the unwanted bind values I get a parameter count mismatch error.

    Can someone please guide me in the right direction? I appreciate it


  • Qt Champions 2016

    Hi
    Why not use the UPDATE statement then ?
    https://www.w3schools.com/sql/sql_update.asp



  • That solved my issue, thank you for the help


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.