Python Forum
Utilizing SQLite dot commands
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Utilizing SQLite dot commands
#1
Trying to return column headers on a search and I truly do not know where to execute the dot command to make this work. The documentation just shows after the sqlite prompt, ie:: sqlite>.mode column. See below the two # lines of failed attempt.
What is the correct place and format for this command?

def connect(self):
        self.con=sqlite3.connect(self.db_path)
        self.c=self.con.cursor()


def abbr_res(self,cols,tblName,typee,order_by):
        #self.c.mode column
        #sqlite>.mode column
        self.c.execute(f"Select {cols} From  {tblName}  Order By {order_by}")
        cows=self.c.fetchall()
        return cows
Reply
#2
That's not SQL; it's a command for the SQLite shell. Why do you need to return the column names? Don't you already know them?
Reply
#3
The returned information is to be displayed in a multi-row text input box. Even though the sort fields will change based on user selection; i do know what those column names are if i need to create the headers.
for cow in animals:
            self.cow_abbr_txt.text=self.cow_abbr_txt.text +'\n'+ str(cow)
I thought if it were returned already formatted with column names and widths it would be in a layout i could use and not have create my own.
Also if there is a better approach to displaying my data I am interested.
thanks
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020