0
def showdata(self):
    sender=self.sender()
    self.statusBar().showMessage(sender.text()+' was pressed.')
    with sqlite3.connect('database.db') as db:
        cursor=db.cursor()
        cursor.execute('select* from Item Order BY Name ASC')
        product=cursor.fetchall()
        product=str(product)
        print(len(product))
        self.l.setText(str(product)) #this prints the database headers to a label inside my gui
        self.l124.setText(show) #this prints the database rows to a label inside my gui

This calls to my sqlite database and print all the data out in brackets in one line, such as (2, 'test', 'test', 'test', 'test', 'test', 'test', 'test')], with 2 being the unique id, and the other values input by the user. It also print out the database headers, separately to the rows, I would like to have them together to add simplicity. If any more information is required to aid me with my problem, or any code, please let me know.

1 Answer 1

1

You need to think in terms of processing the results one row at a time instead of en masse.

cursor=db.cursor()
cursor.execute('select* from Item Order BY Name ASC')
self.setupHeaderLabels(cursor.description)
for row in cursor:
    self.showOneRow(row)

Then just implement the setupHeaderLabels and showOneRow methods.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the feedback! I worked from what you said and got the headers working how I wanted.However, I still cannot get the rows to show up in the gui, which may be to do with connecting to the label within the for loop.
@Jurisdiction Baby steps! Look up how to add a row to the table (it won't take you long to search!) given some data in a particular row. Try doing it with a single column of the table; it's the simplest case. Then try doing it with multiple columns, getting the data from the row. You can save the row names from the code to set up the header labels if you want; it's a good use of a field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.