Quantcast
Channel: QtWebEngine
Viewing all articles
Browse latest Browse all 13965

SQL Record ID changes after submitAll

$
0
0
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

Viewing all articles
Browse latest Browse all 13965

Trending Articles