PySide / SQLite3 - need duplicate code to parse query.first() then while query.next() ???



  • I assume this is a very basic database question but I'm still fairly new to database queries...

    When executing a QSqlQuery, is it necessary to process the first row separately from subsequent rows? This is the way that I've been doing it:

    @
    query = QSqlQuery("SELECT Blahblah, Blippity, Bloop FROM Floozle ORDER BY Bloop")

    query.first()
    codeToParseRecord() #If I leave this out it skips the first record

    while query.next():
    codeToParseRecord()
    @

    Is this the best way to do it or am I missing something? It just seems wrong to have to duplicate code every time I execute a query.

    Thanks



  • Hi,
    you do not need the lines
    @
    query.first()
    codeToParseRecord()
    @

    simply start with query.exec():

    @
    query = QSqlQuery("SELECT Blahblah, Blippity, Bloop FROM Floozle ORDER BY Bloop")

    if (query.exec()) {
    while query.next():
    codeToParseRecord()
    }
    @


Log in to reply
 

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