Suppose that the file name of SQLite’s database is mpos_S.sqlite, its table (like a sheet of Excel) name is mpos_S, and mpos_S contains column data. If the column name of water temperature data is tp, this column tp contains water temperature data. In order to handle it from Python, you need to import sqlite3.
First connect to the database and get the cursor cur.
>>> conn = sqlite3.connect('mpos_S.sqlite')
>>> cur = conn.cursor()
Check information of columns.
>>> cols = cur.fetchall() ### Information of a column is a tuple containing 6 elements.
To get only a name of column, the 2nd element should be taken using list comprehension.
Gets the values for the column tp. Multiple columns are selected by itemizing their names separating by comma.
>>> val = cur.fetchall() ### val is a list of tuple containing values.
Gets data in all the columns.
>>> val = cur.fetchall() ### Extracted as a list of tuple
Always close the database when finished (Required).