April 27, 2018

Handling SQLite database using Python

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. [cc] >>> import sqlite3 >>> conn = sqlite3.connect('mpos_S.sqlite') >>> cur = conn.cursor() [/cc] Check information of columns. [cc] >>> cur.execute("PRAGMA TABLE_INFO(mpos_S)") ### Gets information about columns of table mpos_S >>> cols = cur.fetchall() ### Information of a column is a tuple containing 6 elements. >>> print(cols) […]

Read more