import sqlite3

# 如果文件不存在,会自动在当前目录创建:
conn = sqlite3.connect('test.db')

# 创建一个Cursor:
cursor = conn.cursor()

# 执行一条SQL语句,创建user表:
# cursor.execute('create table user (id varchar(20) primary key, name varchar(20))')

# 继续执行一条SQL语句,插入一条记录:
# cursor.execute('insert into user (id, name) values (\'1\', \'Michael\')')

# 通过rowcount获得插入的行数:
# print(cursor.rowcount)


# list = cursor.fetchone()
# print(list)

# result = cursor.execute("select * from user")
# print(list(result))

# li=[]
# for item in list:
# print(item)
# li.append(item)

# print(li)

obj = ("3", "adley")

cursor.execute('insert into user (id,name) values(?,?)', obj)

# 关闭Cursor:
cursor.close()

# 提交事务:
conn.commit()

# 关闭Connection:
conn.close()