• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python操作数据库之sqlite3打开数据库、删除、修改示例

python操作数据库之sqlite3打开数据库、删除、修改示例

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python sqlite3,python3 sqlite3,python连接sqlite3,sqlite3数据库,sqlite3创建数据库等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com


def showalldata():
        print "-------------------处理后后的数据-------------------"
        hel = opendata()
        cur = hel[1].cursor()
        cur.execute("select * from tianjia")
        res = cur.fetchall()
        for line in res:
                for h in line:
                        print h,
                print
        cur.close()
#输入信息


def into():
        username1 = str(raw_input("请输入您的用户名:"))
        passworld1 = str(raw_input("请输入您的密码:"))
        address1 = str(raw_input("请输入您的地址:"))
        telnum1 = str(raw_input("请输入您的联系电话:"))
        return username1, passworld1, address1, telnum1
#  (添加)  往数据库中添加内容


def adddata():
        welcome = """-------------------欢迎使用添加数据功能---------------------"""
        print welcome
        person = into()
        hel = opendata()
        hel[1].execute("insert into tianjia(username, passworld, address, telnum)values (?,?,?,?)",
                                        (person[0], person[1], person[2], person[3]))
        hel[1].commit()
        print "-----------------恭喜你数据,添加成功----------------"
        showalldata()
        hel[1].close()
#  (删除)删除数据库中的内容


def deldata():
        welcome = "------------------欢迎您使用删除数据库功能------------------"
        print welcome
        delchoice = raw_input("请输入您想要删除用户的编号:")
        hel = opendata()              # 返回游标conn
        hel[1].execute("delete from tianjia where id ="+delchoice)
        hel[1].commit()
        print "-----------------恭喜你数据,删除成功----------------"
        showalldata()
        hel[1].close()
# (修改)修改数据的内容


def alter():
        welcome = "--------------------欢迎你使用修改数据库功能-----------------"
        print welcome
        changechoice = raw_input("请输入你想要修改的用户的编号:")
        hel =opendata()
        person = into()
        hel[1].execute("update tianjia set username=?, passworld= ?,address=?,telnum=? where id="+changechoice,
                                (person[0], person[1], person[2], person[3]))
        hel[1].commit()
        showalldata()
        hel[1].close()
# 查询数据


def searchdata():
        welcome = "--------------------欢迎你使用查询数据库功能-----------------"
        print welcome
        choice = str(raw_input("请输入你要查询的用户的编号:"))
        hel = opendata()
        cur = hel[1].cursor()
        cur.execute("select * from tianjia where id="+choice)
        hel[1].commit()
        row = cur.fetchone()
        id1 = str(row[0])
        username = str(row[1])
        passworld = str(row[2])
        address = str(row[3])
        telnum = str(row[4])
        print "-------------------恭喜你,你要查找的数据如下---------------------"
        print ("您查询的数据编号是%s" % id1)
        print ("您查询的数据名称是%s" % username)
        print ("您查询的数据密码是%s" % passworld)
        print ("您查询的数据地址是%s" % address)
        print ("您查询的数据电话是%s" % telnum)
        cur.close()
        hel[1].close()
# 是否继续


def contnue1(a):
        choice = raw_input("是否继续?(y or n):")
        if choice == 'y':
                a = 1
        else:
                a = 0
        return a


if __name__ == "__main__":
        flag = 1
        while flag:
                welcome = "---------欢迎使用仙宝数据库通讯录---------"
                print welcome
                choiceshow = """
请选择您的进一步选择:
(添加)往数据库里面添加内容
(删除)删除数据库中内容
(修改)修改书库的内容
(查询)查询数据的内容

您可能想查找下面的文章:

  • 使用Python对SQLite数据库操作
  • Python简单操作sqlite3的方法示例
  • SQLite3中文编码 Python的实现
  • SQLite3中文编码 Python的实现
  • 详解Python 数据库 (sqlite3)应用
  • Python解析excel文件存入sqlite数据库的方法
  • python从sqlite读取并显示数据的方法
  • python实现在sqlite动态创建表的方法
  • python查询sqlite数据表的方法
  • 在Python中使用SQLite的简单教程

相关文章

  • tensorboard实现同时显示训练曲线和测试曲线
  • python使用装饰器和线程限制函数执行时间的方法
  • Python自动化测试工具Splinter简介和使用实例
  • Python下载指定页面上图片的方法
  • Python def函数的定义、使用及参数传递实现代码
  • Python使用Scrapy爬取妹子图
  • python根据距离和时长计算配速示例
  • 举例讲解Python编程中对线程锁的使用
  • 使用wxpython实现的一个简单图片浏览器实例
  • python实现的二叉树算法和kmp算法实例

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • python爬取本站电子书信息并入库的实现代码
    • python发送邮件功能实现代码
    • 学习python之编写简单乘法口诀表实现代码
    • Python中实现对Timestamp和Datetime及UTC时间之间的转换
    • Python datetime时间格式化去掉前导0
    • 利用python获得时间的实例说明
    • python 获取文件列表(或是目录例表)
    • Python中使用ElementTree解析XML示例
    • 举例讲解Python设计模式编程中的访问者与观察者模式
    • python编程实现希尔排序

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有