• c++ SQLite 特别好用的库使用实例-更新(3)


    操作数据库的时候经常会用到更新数据的操作,以下是更新数据库的实例:


    void _UpdateData()
    {
        Kompex::SQLiteDatabase *pDatabase = new Kompex::SQLiteDatabase("test.db", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, 0);
        Kompex::SQLiteStatement *pStmt = new Kompex::SQLiteStatement(pDatabase);

        //获取当前数据表中的数据
        {
            pStmt->Sql("SELECT * FROM user");
            while (pStmt->FetchRow())
            {
                int nData = pStmt->GetColumnInt(0);
                std::string str1 = pStmt->GetColumnString(1);
                std::string str2 = pStmt->GetColumnString(2);
                int nData1 = pStmt->GetColumnInt(3);
                double db1 = pStmt->GetColumnDouble(4);
                int yyyy = 66;
            }
            pStmt->FreeQuery();
        }

        //修改表中的数据
        {
            pStmt->Sql("UPDATE user SET lastName=@lastName, age=@age WHERE userID=@userID");
            pStmt->BindString(1, "Urushihara");
            pStmt->BindInt(2, 56);
            pStmt->BindInt(3, 2);
            pStmt->ExecuteAndFree();
        }
        
        {
            pStmt->Sql("SELECT * FROM user");
            while (pStmt->FetchRow())
            {
                int nData = pStmt->GetColumnInt(0);
                std::string str1 = pStmt->GetColumnString(1);
                std::string str2 = pStmt->GetColumnString(2);
                int nData1 = pStmt->GetColumnInt(3);
                double db1 = pStmt->GetColumnDouble(4);
                int yyyy = 66;
            }
            pStmt->FreeQuery();
        }

        pDatabase->Close();
    }
     

  • 相关阅读:
    G1垃圾回收器学习笔记
    用Python字典简单实现词频统计
    基金客户服务
    实验:基本的路由策略配置
    C++学习笔记(九)
    vue3封装echarts图表数据无法渲染到页面
    腾讯Coding的持续部署模块的使用。
    保存GraphPad Prism文件时,可以选择【PZF】与【PZFX】两种文件格式。
    kafka详解二
    ubuntu gcc版本降级 Reset gcc version from 11.3 to 11.2 on Ubuntu 22.04
  • 原文地址:https://blog.csdn.net/u011269801/article/details/126554675