Python Forum

Full Version: Utilizing SQLite dot commands
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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?
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