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. SQL Record ID changes after submitAll

SQL Record ID changes after submitAll

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.0k 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.
  • N Offline
    N Offline
    NitrousUK
    wrote on last edited by
    #1

    I'm trying to write some Python code to simply create a record in an SQL database (sqlite backend), and then get the newly created record. Code is called from within an QSqlTableModel.
    The odd thing is that when I do the following, I'm told the generated records id is 0. However after doing a submitAll, it changes. I'm guessing 1 is the starting value and correct, but why am I getting 0 when I use NULL to generate an ID?
    So I'm not sure how I can grab the record I've just inserted, as both the id and row of the record changes after submitAll.

    @
    self.insertRows(0, 1)

        new_record = self.record(0) #Grab newly inserted record
        new_record.setNull("id")  #Generate an id
    
        # new_record.value("id") == 0
        
        self.submitAll()
    
        #Get the record back out
        new_record = self.record(0)
        
        # new_record.value("id") != 0@
    
    1 Reply Last reply
    0
    • 8 Offline
      8 Offline
      8majkel8
      wrote on last edited by
      #2

      maybe you have auto_increment on id in your database ??

      1 Reply Last reply
      0
      • N Offline
        N Offline
        NitrousUK
        wrote on last edited by
        #3

        Just got "PRIMARY KEY" set on id

        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