-1

i need to load only the data from database by todays date. date column in database is in TEXT... ''code to load all the data from database''

def load_database(self):
            today_date = current_date[0:11]
            while self.workingpatient_table.rowCount() > 0:
                    self.workingpatient_table.removeRow(0)
            conn = sqlite3.connect(r'mylab.db')
            content = ("SELECT * FROM daily_patients where date=?",(today_date))
            result = conn.execute(content)
            for row_index,row_data in enumerate(result):
                    self.workingpatient_table.insertRow(row_index)
                    for column_index,column_data in enumerate(row_data):
                            self.workingpatient_table.setItem(row_index,column_index,QTableWidgetItem(str(column_data)))
    
            conn.close()

''when i run the program i get following error ''

result = conn.execute(content)

TypeError: argument 1 must be str, not tuple

any possible solution?

jarvis
  • 1
  • 4
  • That `while` loop is pointless. Change to `if self.workingpatient_table.rowCount():` `self.workingpatient_table.setRowCount(0)`. – musicamante May 06 '22 at 09:53

1 Answers1

0

Change your line from

 content = ("SELECT * FROM daily_patients where date=?",(today_date))
 result = conn.execute(content)

to

 content = ("SELECT * FROM daily_patients where date=?",(today_date, ))
 result = conn.execute(*content)
ewokx
  • 2,204
  • 3
  • 14
  • 27
  • content = ("SELECT * FROM daily_patients where date=?" % (today_date, )) TypeError: not all arguments converted during string formatting '''this is the error i got''' – jarvis May 06 '22 at 07:54
  • not a problem bro.. atleast tried. @ewong – jarvis May 06 '22 at 07:57
  • Does the updated code work now? – ewokx May 06 '22 at 08:11
  • nope. same error bro. {argument must be str not tuple} – jarvis May 06 '22 at 08:14
  • Even with the changes I did earlier? – ewokx May 06 '22 at 08:15
  • yes. after the change the error is like {NOTE: cant format all to strings} – jarvis May 06 '22 at 08:25
  • I'm sorry about my mistakes. I thought it was straight forward.. but I think I'm just incompetent. – ewokx May 06 '22 at 08:35
  • @jarvis the updated code should work, and it cannot give *that* error. Please do *exactly* as suggested, with the asterisk before `content`. – musicamante May 06 '22 at 09:50
  • @musicamante same error bro. File "c:\Users\virus\Desktop\pathalogy-1\workers1.py", line 781, in load_database result = conn.execute(content) TypeError: argument 1 must be str, not tuple – jarvis May 06 '22 at 11:14
  • @jarvis You're still not doing as was suggested, as can be clearly seen from the traceback. – ekhumoro May 06 '22 at 12:14
  • @ekhumoro bro that line 781 is result = conn.execute(content). and the content(or)Query is same as mentioned in post.. – jarvis May 06 '22 at 14:08
  • @jarvis No, you're ***still NOT doing it***, as that error clearly shows that you've ***NOT*** added the asterisk before `content`, as repeatedly told to you. You should really pay more attention to what's being written. And, please, stop with "bro", not everybody likes it. – musicamante May 06 '22 at 15:41
  • @musicamante bro after deleting and recreating the database the code works... but here today entered data is not showing in QTABLEWIDGET... – jarvis May 07 '22 at 03:41
  • @jarvis you say that "the code works" and then that "data is not showing". So: 1. we don't know what you changed, so eventually update your question; 2. the code didn't "magically" work just because of that, as the problem was clearly in your syntax, as repeatedly said above; 3. this is *not* a forum, please take your time to find more about your issues and *then* post a comment with a detailed description or, better, improve your question as said above; 4. really, please stop calling people "bro", it's just annoying: this is not a forum, nor a party, and not even a help desk. – musicamante May 07 '22 at 03:53