How to index alias database column
Unsolved
Qt for Python
-
I want to index the Age column which is an alias column of the table below. The first two line works perfectly but trying to index the alias column using
Age = self.ui.label_572.setText(query[2])
does not return any value, please any help on what I'm doing wrong.Table
Code
name = self.ui.label_570.setText(query[0]) DOB = self.ui.label_571.setText(query[1]) Age = self.ui.label_572.setText(query[2])
-
Hi,
Which database backend are you using ?
What kind of query do you use ? -
Can you answer all the questions ?
-
@SGaist sorry, I'm using sqlite and below is the query I executed.
con = sqlite3.connect("ClientsDatabase.db") cur.execute( ''' SELECT name,dob, strftime('%Y',date('now'))-strftime('%Y',date(dob)) , CASE WHEN strftime('%m', date('now')) > strftime('%m', date(dob)) THEN strftime('%Y', date('now')) - strftime('%Y', date(dob)) WHEN strftime('%m', date('now')) = strftime('%m', date(dob)) THEN CASE WHEN strftime('%d', date('now')) >= strftime('%d', date(dob)) THEN strftime('%Y', date('now')) - strftime('%Y', date(dob)) ELSE strftime('%Y', date('now')) - strftime('%Y', date(dob)) - 1 END WHEN strftime('%m', date('now')) < strftime('%m', date(dob)) THEN strftime('%Y', date('now')) - strftime('%Y', date(dob)) - 1 END AS 'Age' FROM client_details) query = cur.fetchone()