Maziar Parsijani
Maziar Parsijani

Reputation: 55

Set text from sqlite rows in Pyqt textbrowser

I need a way to set some rows from sqlite.db to pyqt textbrowser,But the problem is that it just put the last row.

cur = conn.cursor()
conn.text_factory = str
cur.execute(" SELECT text FROM Translation WHERE priority = ?", (m,))
for row in cur:
    print('{0}'.format(row[0]))
    self.SearchResults.setPlainText('{0}'.format(m))

I used pandas but,

query = "SELECT text FROM Translation WHERE priority=2;"

df = pd.read_sql_query(query,conn)
 self.SearchResults.setPlainText('{0}'.format(df['text'])) 

This is not what I want.And this:

cur = conn.cursor()
conn.text_factory = str
cur.execute(" SELECT text FROM Translation WHERE priority = ?", (m,))
    all_rows=cur.fetchall()

    self.SearchResults.setPlainText('{0}'.format(all_rows))

Upvotes: 0

Views: 127

Answers (1)

eyllanesc
eyllanesc

Reputation: 244132

In the first code you are replacing the text every time you iterate, the solution is to use append()

cur = conn.cursor()
conn.text_factory = str
cur.execute(" SELECT text FROM Translation WHERE priority = ?", (m,))

self.SearchResults.clear() # clear previous text

for row in cur:
    self.SearchResults.append('{0}'.format(str(row[0])))

Upvotes: 1

Related Questions