Use Sqlite in Python

前端之家收集整理的这篇文章主要介绍了Use Sqlite in Python前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
import sqlite3
import os,sys

DATABASE = os.path.dirname(__file__) + '/sqlite.db'

def test_db():
	db = sqlite3.connect(DATABASE)
	cur = db.cursor()
	sql = '''
	create table post(
	ID INT PRIMARY KEY NOT NULL,TITLE CHAR(50),CONTENT TEXT,AUTHOR CHAR(30)
	)	
	'''
	data = '''
	insert into post(id,title,content,author) values(1,'good news','you win the big prize','admin')
	'''
	print 'run the query'
	query = "select * from post"
	posts = cur.execute(query)
	for post in posts:
		print post[1]
	db.close()
	
if __name__ == '__main__':
	test_db()
原文链接:https://www.f2er.com/sqlite/200851.html

猜你在找的Sqlite相关文章