SimpleSqlite3


Create SQL database


In [22]:
import sqlite3

connect = sqlite3.connect('simple_sqlite3.db')
cursor = connect.cursor()

def tableCreate():
    cursor.execute("CREATE TABLE SAMSUNG(ID INT, datestamp TEXT, value REAL)")

Create Table (create only once)


In [23]:
tableCreate()


---------------------------------------------------------------------------
OperationalError                          Traceback (most recent call last)
<ipython-input-23-782f085c74e2> in <module>()
----> 1 tableCreate()

<ipython-input-22-a527abaf3ddc> in tableCreate()
      5 
      6 def tableCreate():
----> 7     cursor.execute("CREATE TABLE SAMSUNG(ID INT, datestamp TEXT, value REAL)")

OperationalError: table SAMSUNG already exists

Add a new entry and commit (save)


In [24]:
cursor.execute("INSERT INTO SAMSUNG VALUES(1, '2015-07-01', 50000)")
connect.commit()

간단한 한글 sql


In [29]:
# -*- coding: utf-8 -*-
import sqlite3

connect = sqlite3.connect('test.db')
cursor = connect.cursor()
cursor.execute("CREATE TABLE SAMSUNG(ID INT, datestamp TEXT, value REAL, dada TEXT)")
cursor.execute("INSERT INTO SAMSUNG VALUES(1, '2015-07-01', 50000, '한글1')")
connect.commit()

In [30]:
text_title = u'\xa0\uad6d\ub0b4 \ud658\uc728 \ub9c8\uac10\uc2dc\ud669'
print text_title


 국내 환율 마감시황

In [35]:
connect = sqlite3.connect('test.db')
cursor = connect.cursor()
cursor.execute("INSERT INTO SAMSUNG VALUES (?,?,?,?)", (1, '2015-07-02', 10000, text_title) )
connect.commit()