Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved UNIQUE CONSTRAINT FAILED on submitAll()

    General and Desktop
    qsql qsqltablemodel sqlite3 unique qsqlrelationalt
    1
    1
    87
    Loading More Posts
    • 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
      dave997 last edited by dave997

      Hi there, I'm experiencing a rather annoying problem.

      Briefly summarized, I have a SQLite3 table with UNIQUE constraint applied over 2 integer fields.
      As of now, I'm populating such table with 8 rows using all combinations of ([1-2], [1-4]) for fields A and B respectively. So far, so good.

      Problems arise whenever I try to swap rows (that means, reassigning those 2 fields among the 8 rows): even if I check not to make duplicates and the table looks good, submitAll() fails returning UNIQUE CONSTRAINT FAILED.
      I believe this has to do with the way submitAll() works, which probably tries to update each line individually hence obviously creating a duplicate. If I were to write SQL I would obviously use an INSERT OR REPLACE statement.

      I wonder if there's anything I can do to stick with QSql classes and avoid converting a ton of code into SQL statements...

      Thank you.

      1 Reply Last reply Reply Quote 0
      • First post
        Last post