Results 1 to 3 of 3

Thread: Copying within QSqlRelationalDataModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Copying within QSqlRelationalDataModel

    Aren't you violating the uniqueness constraint on the primary key? Does insertRow() return true? What about submitAll()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. #2
    Join Date
    Jan 2011
    Location
    Richmond, VA
    Posts
    94
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    14

    Default Re: Copying within QSqlRelationalDataModel

    Well, I tried the submitALL() and nothing happened but let me come back to that. Yep, insertRow() returns true -- just for fun, I changed line 66 to set the data to "old_fp_id" and I was able to effectively double the data saved with the dataset I'm copying. Row 1 was copied to a row 3, and row 2 copied to row 4 and off I went on my merry way.

    As for the primary key, what's happening is I select on a row in my master view (call it SNOW), say COPY, and that prompts me for the name of a new master row (call it RAIN -- this is the primary key), so that's covered. I then want to copy the detail rows linked to SNOW and link those new ones to RAIN which is what you see on line #66 of the first block of code.

    You gave me an idea about the primary key, though. My creation of *new* master and detail records (vs. copy) works great EXCEPT for something I just discovered. I have to submitALL() after the creation of the master record - if I don't and I try to create detail records, a submitALL() at this point results in no detail records being saved. Even though I'm not getting a DB error on my submitALL(), since I don't know the order that the records are being written out, there could be an issue where the child records can't get created in the DB correctly because the parent/primary key record doesn't exist yet.

    When I leave my normal job I'm going to try a submitALL after line 14 of the first block of code (which is where the new master record is being created) and see if that helps...That should write out my new master/parent record...

    Thanks for the questions -- they pulled me up out of the weeds! (BTW -- my day job is as an Oracle DB programmer so you'd think this would be a cakewalk)


    scott

Similar Threads

  1. Copying QList
    By frenk_castle in forum Newbie
    Replies: 3
    Last Post: 27th November 2009, 01:48
  2. Copying a file
    By Nefastious in forum Newbie
    Replies: 3
    Last Post: 27th October 2009, 15:15
  3. Only copying files using qmake
    By sagacity in forum Installation and Deployment
    Replies: 2
    Last Post: 26th June 2009, 15:03
  4. copying QGraphicsItemGroup
    By robertson1 in forum Qt Programming
    Replies: 1
    Last Post: 23rd June 2008, 08:48
  5. Copying row from one table to another
    By ser_bur in forum Qt Programming
    Replies: 2
    Last Post: 29th May 2007, 16:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.