Computer/Python

SQLite3

HEESEOP 2021. 3. 20. 00:04
import sqlite3
dbpath = "test.db"
conn = sqlite3.connect(dbpath)

#File creation part
try:
    cur = conn.cursor()
    cur.execute("CREATE TABLE info (name1 TEXT, name2 INTEGER)")
    conn.commit()
except:
    print('File is Existing')

#Input part
cur = conn.cursor()
cur.execute("INSERT INTO info (name1, name2) VALUES ('Hello', 57)")
conn.commit()

cur = conn.cursor()
cur.execute("SELECT * FROM info")
result = cur.fetchall()

print(result)

#Get the latest 12 data from info by descending name1 

cur = conn.cursor()
cur.execute("SELECT * FROM info ORDER BY name1 DESC LIMIT 12;")
result = cur.fetchall()

 

 

 

Storage Class 
NULL 정보가 없거나 알지 못할경우
INTEGER 소수를 포함한 모든 수(음수퐇함)
REAL 정수만을 포함
TEXT 문자 무제한
BLOB 바이너리 오브젝트를 저장가능, 무제한

 

 

 

 

ref

www.sqlitetutorial.net/