I would like to collect all entries in a database and write them into a .csv-file.
To do so, i tried to come up with a while-loop like this:
def create_csv():
     query = QSqlQuery(db=db)
     query.prepare("SELECT * FROM database_name")
     query.exec()
     rec = query.record()
            
     print(query.isSelect())
     nameCol = rec.indexOf("name")
          while query.next():
          print(query.value(nameCol)) 
This gives me all entries in the column "name" as expected. But since the database has got a lot more columns, i was wondering if there is an easier way to get all the columns (and the headers) at once?
All at once would make the creation of the csv a lot easier.
 
    