首页  >  文章  >  数据库  >  UseSqliteinPython

UseSqliteinPython

WBOY
WBOY原创
2016-06-07 15:22:501067浏览

import sqlite3import os,sysDATABASE = os.path.dirname(__file__) + /sqlite.dbdef 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 =

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()
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn