SQLとは?
SQLはStructured Query LanguageでUserが簡単にデータベースをアクセスすることできるようなものです。
SQLはなにができる?
SQLがデータをSortingすることができます。
SQLがデータベースからデータRecordsをアップデートできます。
SQLがデータベースからデータRecordsを削除できます。
SQLがデータベースからデータRecordsを追加できます。
SQLがデータベースからデータテープルを削除できます。
SQLがデータベースからデータテープルをを削除できます。
SQLがデータベースからViewsを作成できます。
SQLがそれらの権限を設定することができます。
などなど…
参考サイド
https://docs.python.jp/3/library/sqlite3.html
https://www.w3schools.com/sql/
実装
プログラムの流れとしては:
Library Importー>DBを作成ー>DBの文字Format設定ー>DBを操作ー>DBデーブル作成ー>DBデーブルをからRowsを選択ー>Printー>Close
って感じですね。
import sqlite3
#create a new db
dbname='database.db'
conn=sqlite3.connect(dbname)
conn.text_factory=str
#start to operate the db
c=conn.cursor()
#create new table
c.execute('create table if not exists Tags (Tagname text,DataType,Node,Comment,unique(Tagname))')
#create new row
try:
c.execute("insert into Tags values('tag1','real','Data1.sometags','nocomment')")
c.execute("insert into Tags values('tag2','real','Data1.sometags','nocomment')")
c.execute("insert into Tags values('tag3','real','Data1.sometags','nocomment')")
c.execute("insert into Tags values('tag4','real','Data1.sometags','nocomment')")
except sqlite3.IntegrityError:
print('the id is exist')
#show
dbrows=c.execute("select * from Tags")
#type of dbrows
print('Type: ',type(dbrows))
#show the keys
for k in dbrows:
print(k)
conn.commit()
conn.close()