广告
返回顶部
首页 > 资讯 > 数据库 >sqlite3 学习笔记
  • 694
分享到

sqlite3 学习笔记

sqlite3学习笔记数据库入门数据库基础教程 2017-12-28 12:12:20 694人浏览 绘本
摘要

#!/usr/bin/env python3 # -*- coding: utf-8 -*- # @descrip : operate sqlite intrface # @Time : 2020/04/22 21:57 # @Au

sqlite3 学习笔记[数据库教程]

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @descrip : operate sqlite intrface
# @Time    : 2020/04/22 21:57
# @Author  : mingfei.tang
import sqlite3

class SqLite3_Opt():
    def __init__(self):
        print(sqlite3.apilevel)
        self.conn = sqlite3.connect(first.db)
    
    def create_table(self):
        self.cursor = self.conn.cursor()
        #create table -1
        self.cursor.execute(‘‘‘create table user_tb(
                               _id integer primary key autoincrement,
                               name text,
                               passWord text,
                               gender text)‘‘‘)

        #create table -2
        self.cursor.execute(‘‘‘create table order_tb(
                               _id integer primary key autoincrement,
                               item_name text,
                               item_price text,
                               item_number text,
                               user_id inteter,
                               foreign key(user_id) references user_tb(_id))‘‘‘)

        self.cursor.close()
        
    #insert-1  many
    def insert_many_value(self):
        self.cursor = self.conn.cursor()
        self.cursor.executemany(insert into user_tb values(null, ?, ?, ?),
                                ((孙悟空-1, 423456,male),
                                (孙悟空-2, 423456,male),
                                (孙悟空-3, 423456,male),
                                (孙悟空-4, 423456,male)))
        self.conn.commit()
        self.cursor.close()

    #insert-2 single
    def insert_single_value(self):
        self.cursor = self.conn.cursor()
        self.cursor.execute(insert into user_tb values(null, ?, ?, ?),(孙悟空-0, 423456,male))
        self.conn.commit()
        self.cursor.close()

    #delete single
    def delete_single_data(self):
        self.cursor = self.conn.cursor()
        self.cursor.execute("DELETE FROM user_tb WHERE _id=?", (1,))
        self.conn.commit()
        self.cursor.close()
    
    #update single
    def update_data(self):
        self.cursor = self.conn.cursor()
        self.cursor.execute("UPDATE user_tb SET name=? WHERE _id=?", ("猪八戒", 1))
        self.conn.commit()
        self.cursor.close()

    #fatch all data
    def fetch_all(self):
        self.cursor = self.conn.cursor()
        self.cursor.execute("select * from user_tb")
        print(self.cursor.fetchall())
        self.cursor.close()

    #fatch one data
    def fetch_one(self):
        self.cursor = self.conn.cursor()
        self.cursor.execute("select * from user_tb")
        print(self.cursor.fetchone())
        self.cursor.close()

    #fatch many data
    def fetch_many(self):
        self.cursor = self.conn.cursor()
        self.cursor.execute("select * from user_tb")
        print(self.cursor.fetchmany(10))
        self.cursor.close()

    def closedb(self):
        self.conn.close()

class Unit_test():
    def __init__(self):
        pass

    def infor_test(self):
        test = SqLite3_Opt()
        #test.create_table()
        #test.insert_single_value()
        #test.update_data()
        #test.delete_single_data()
        #test.fetch_all()
        #test.fetch_one()
        test.fetch_many()
        test.closedb()


if __name__ == "__main__":
    utest=Unit_test()
    utest.infor_test()

 

sqlite3 学习笔记

原文:https://www.cnblogs.com/mftang2018/p/12764336.html

您可能感兴趣的文档:

--结束END--

本文标题: sqlite3 学习笔记

本文链接: https://www.lsjlt.com/news/5705.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • sqlite3 学习笔记
    #!/usr/bin/env python3 # -*- coding: utf-8 -*- # @descrip : operate SqLite intrface # @Time : 2020/04/22 21:57 # @Au...
    99+
    2017-12-28
    sqlite3 学习笔记 数据库入门 数据库基础教程
  • SQLite3 笔记
    SQLite insert 插入一行: 插入一组: 使用select结果插入 多行插入到新表: 多行插入到新表,一步到位: 非常有用的临时表: sqlite update 更新一条记录: update 注意 约束 sqlite ...
    99+
    2023-01-31
    笔记
  • 学习笔记-TP5框架学习笔记\(路由\)
    TP5框架简单理解 (PS:只做粗略、关键知识的记录,TP程序的开始。详情请阅读官方手册) 1. 架构总览 TP程序的开始 PHP >=5.3.0, PHP7 ThinkPHP5.0应用基于MVC(模型-视图-控制器)的方...
    99+
    2023-10-25
    学习 php 开发语言
  • 学习笔记3
    一文件查找和压缩1文件查找locate 搜索依赖于数据库,非实时搜索,搜索新建文件需手动更新,适于搜索稳定不频繁修改文件 find 实时搜索,精确搜索,默认当前目录递归搜索 find用法 -maxdepth...
    99+
    2023-01-31
    学习笔记
  • python3学习笔记
    好久不用python,努力捡起来ing python3语法 字符串 repr()把其他类型变量转换为字符串 ord()把单个字符转换为相应的ascii码 int()把其他进制的“字符串”转换为十进制 int(str,n...
    99+
    2023-01-31
    学习笔记
  • Android学习笔记
    LinearLayoutCompat 线性布局 android:orientation=“vertical” 指定布局内控件排列方式为 垂直排...
    99+
    2022-06-06
    android学习 Android
  • 20200619 学习笔记
    主键和唯一的区别 主键:唯一、不为空、只能有一个、可以组合但不推荐 唯一:唯一、可为空、可以多个、可以组合但不推荐 外键 要求在从表设置外键关系 从表的外键列的类型和主表的关联列的类型要求一致或兼容 主...
    99+
    2019-12-15
    20200619 学习笔记
  • 20200618_MySQL学习笔记
    加号 + Mysql中加号只能做运算符 select 100+90  ==> 190  select "100"+90 ==> 190  如果有一个是字符串,那么尝试转换成数值型,转换成功 select "ja...
    99+
    2014-11-26
    20200618_MySQL学习笔记
  • 20200617学习笔记
    基数  一个索引上不同的值的个数,我们称之为“基数”(cardinality)。也就是说,这个基数越大,索引的区分度越好 我们可以使用 show index 方法,看到一个索引的基数 MySQL 是怎样得到索引的基数的呢? 采样...
    99+
    2022-02-22
    20200617学习笔记
  • 20200616学习笔记
    count(*) 的实现方式 在不同的 MySQL 引擎中,count(*) 有不同的实现方式 MyISAM 引擎把一个表的总行数存在了磁盘上,因此执行 count(*) 的时候会直接返回这个数,效率很高 而 InnoDB ...
    99+
    2018-10-19
    20200616学习笔记
  • MySQL学习笔记
    作者: Grey 原文地址:MySQL学习笔记 说明 注:本文中的SQL语句如果用到了特定方言,都是基于MySQL数据库。 关于DDL DDL 的英文全称是 Data Definition Language,中文是数据定义语言。它定义了...
    99+
    2015-01-17
    MySQL学习笔记
  • Mycat 学习笔记
    概述 1. Mycat 是什么? Mycat 是数据库中间件,连接 Java 应用程序和数据库,它的作用如下: 读写分离 数据分片:垂直拆分(分库)、水平拆分(分表)、垂直+水平拆分(分库分表) 多数据源整合 2....
    99+
    2019-10-05
    Mycat 学习笔记
  • postgres学习笔记
    将一个标识符变得受限同时也使它变成大小写敏感的,反之非受限名称总是被转换成小写形 式。例如,标识符FOO、foo和"foo"在PostgreSQL中被认为是相同的,而"Foo"和"FOO"则互 不相同且也不同于前面三个标识符(Postgr...
    99+
    2018-01-09
    postgres学习笔记
  • xtrabackup学习笔记
    wget https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.7/binary/tarball/percona-xtrab...
    99+
    2022-10-18
  • AIDE 学习笔记
    参考:http://www.iamle.com/archives/1664.htmlAIDE的用法和tripwire类似。都是通过生成一份文件指纹的数据库,然后对比。所以,我们最好在刚安装完系统后,就安装这...
    99+
    2022-10-18
  • git 学习笔记
      Git是一款免费、开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目,为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件。     ...
    99+
    2022-10-18
  • oracle学习笔记
    oracle安装1.         安装virtualbox:# yum install gcc kernel-devel ...
    99+
    2022-10-18
  • Python学习笔记
    Python介绍 Python是一种解释型、面向对象的语言。 官网:www.python.org Python环境 解释器:www.python.org/downloads 运行方式: 交互模式。在IDLE中运行。 脚本模式。文件的后缀...
    99+
    2023-01-30
    学习笔记 Python
  • tornado学习笔记
    一.UIMOTHODS: 1.在项目目录创建uimothods.py文件(名称可以任意)内容: def test2(self): return ('hello uimothods')2.tornado项目文件中导入并注册: #导入f...
    99+
    2023-01-30
    学习笔记 tornado
  • H3CNE学习笔记
      H3CNE五日“游” ——之第一天 废话少说 直接进入真题!!!!(哈哈 ) H3CNE   H3C认证初级网络工程师 第    一   节 路由器、交换机及其操作系统介绍 路由器 1、 路由器的作用 连接具有不同介质的链路 连接网络或...
    99+
    2023-01-31
    学习笔记 H3CNE
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作