zoukankan      html  css  js  c++  java
  • 11、sqlite

    #-*- codeing = utf-8 -*-
    #@Time : 2020/6/14 15:10
    #@Author : zhangfudong
    #@FILE :testSqlite.py
    #@Software : PyCharm
    
    import sqlite3
    ## python 支持的轻便的数据库
    
    ## 连接数据库
    conn = sqlite3.connect("test.db")   ## 数打开或创建数据库文件
    print("sqlist3 opened successfully")
    ## 建表
    c = conn.cursor()
    sql = '''
        create table company(
            id int primary key not null,
            name text not null,
            age int not null,
            address char(50),
            salary real);
    '''
    c.execute(sql)
    conn.commit()
    conn.close()
    print("create table successfully")
    
    #-*- codeing = utf-8 -*-
    #@Time : 2020/6/14 15:10
    #@Author : zhangfudong
    #@FILE :testSqlite.py
    #@Software : PyCharm
    
    import sqlite3
    ## python 支持的轻便的数据库
    
    ## 1、连接数据库
    conn = sqlite3.connect("test.db")   ## 打开或创建数据库文件
    print("database opened successfully")
    ## 2、建表
    c = conn.cursor()         ## 获取游标
    # sql = '''
    #     create table company(
    #         id int primary key not null,
    #         name text not null,
    #         age int not null,
    #         address char(50),
    #         salary real);
    # '''
    ## 3、插入数据库
    # sql = '''
    #     insert into company(id,name,age,address,salary)
    #     values(3,"wangwu",23,"北京",8000)
    # '''
    # c.execute(sql)        ## 执行sql
    # conn.commit()         ## 提交
    # conn.close()          ## 关闭
    # print("create table successfully")
    
    ##4、查询
    sql = '''
        select id,name,age,address,salary from company;
    '''
    
    cusor = c.execute(sql)      ##  接收游标返回值
    for row in cusor:
        print("id = ",row[0])
        print("name = ", row[1])
        print("age = ", row[2])
        print("address = ", row[3])
        print("salary = ", row[4],"
    ")
    
    conn.close()
    
    
    
    def saveData2DB(datalist,savepath2DB):
        ## 创建表
        initDB(savepath2DB)
        ## 插入表
        insertDB()
        ## 查询表
        selectDB()
    
    import sqlite3
    def initDB(dbpath):
        sql = '''
            create table movie250(
                id integer primary key aotoincrement ,
                info_link text,
                pic_link text,
                cname varchar ,
                ename varchar ,
                score numeric ,
                rated numeric ,
                instruoduction text,
                info text
            )
        '''
        conn = sqlite3.connect(dbpath)
        cursor = conn.cursor()
        cursor.execute(sql)
        conn.commit()
        conn.close()
    
  • 相关阅读:
    FAST for SharePoint如何重置Index
    SharePoint 2007有性能问题? 先试试这篇.
    "Cannot generate SSPI context"
    记录一个用过的SQL脚本(select * into)
    IISRESET为什么有时候要带个noforce参数?
    SharePoint跟权限有关的Object Model Class
    DotNET也谈组合强命名破解FlyGrid 1.5.0.31963 for VS2003
    应同学之邀,破解一个软件,学习逆向工程,文章如下
    win2003下建立*.*到asp.net的映射(安装CNBlogsDotText用)
    MS.Net CLR 扩展PE结构分析
  • 原文地址:https://www.cnblogs.com/moox/p/13199468.html
Copyright © 2011-2022 走看看