您的位置:首页 > 数据库

Bottle实例Todo-List—用SQLite3创建数据库

2014-08-27 20:09 471 查看
代码如下:

Python Code
1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

# -*- coding: utf-8 -*-

#!/usr/bin/python

# filename: creat_db.py

# codedtime: 2014-8-26 22:33:58

import sqlite3

#警告: todo.db文件被创建到当前目录下

con = sqlite3.connect('todo.db')

con.execute("CREATE TABLE todo (id INTEGER PRIMARY KEY, task char(100) NOT NULL, status bool NOT NULL)")

con.execute("INSERT INTO todo (task,status) VALUES\

('Read A-byte-of-python to get a good introduction into Python',0)")

con.execute("INSERT INTO todo (task,status) VALUES\

('Visit the Python website',1)")

con.execute("INSERT INTO todo (task,status) VALUES\

('Test various editors for and check the syntax highlighting',1)")

con.execute("INSERT INTO todo (task,status) VALUES\

('Choose your favorite WSGI-Framework',0)")

con.commit()
在IDLE下F5运行会本目录下生成一个叫todo.db的数据库文件,有三个字段:id、task、status;这个数据库将在以后的程序中用到。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: