• c++ SQLite 特别好用的库使用实例-查询(2)



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

        {
            double d1 = pStmt->SqlAggregateFuncResult("SELECT COUNT(*) FROM user WHERE lastName = 'Lehmann';");
            double d2 = pStmt->SqlAggregateFuncResult("SELECT COUNT(weight) FROM user;");
            double d3 = pStmt->SqlAggregateFuncResult("SELECT MAX(age) FROM user;");
            double d4 = pStmt->SqlAggregateFuncResult("SELECT MIN(age) FROM user;");
            double d5 = pStmt->SqlAggregateFuncResult("SELECT AVG(age) FROM user;");
            double d6 = pStmt->SqlAggregateFuncResult("SELECT SUM(age) FROM user;");
            double d7 = pStmt->SqlAggregateFuncResult("SELECT TOTAL(age) FROM user;");
        }
        
        {
            pStmt->Sql("SELECT firstName FROM user WHERE lastName = 'Lehmann';");
            const char* strName = pStmt->GetColumnName(0);
            int nCount = pStmt->GetColumnCount();
            const char* strDataBaseName = pStmt->GetColumnDatabaseName(0);
            const char* strTableName = pStmt->GetColumnTableName(0);
            const char* strOriginName = pStmt->GetColumnOriginName(0);
            pStmt->FreeQuery();
        }

        {
            pStmt->Sql("SELECT * FROM user");
            while (pStmt->FetchRow())
            {
                double db1 = pStmt->GetColumnDouble(0);
                std::string str1 = pStmt->GetColumnString(1);
                std::string str2 = pStmt->GetColumnString(2);
                std::string str3 = pStmt->GetColumnString(3);
                std::string str4 = pStmt->GetColumnString(4);
                int Type1 = pStmt->GetColumnType(0);
                int Type2 = pStmt->GetColumnType(1);
                int Type3 = pStmt->GetColumnType(2);
                int Type4 = pStmt->GetColumnType(3);
                int Type5 = pStmt->GetColumnType(4);
            }
            pStmt->FreeQuery();
        }

        {
            //获取数据表的列数 列名
            pStmt->Sql("SELECT * FROM user");
            int nCount = pStmt->GetColumnCount();
            for (int i = 0; i < nCount;i++)
            {
                const char* strName = pStmt->GetColumnName(i);
            }
            pStmt->FreeQuery();
        }

        {
            //获取所有的表
            pStmt->Sql("SELECT name FROM sqlite_master WHERE type = 'table' ORDER BY name");
            while (pStmt->FetchRow())
            {
                std::string str1 = pStmt->GetColumnString(0);
                int yyyy = 66;
            }

            pStmt->FreeQuery();
        }
        pDatabase->Close();
    }

  • 相关阅读:
    多快好省,低门槛AI部署工具FastDeploy测试版来了!
    【电源专题】案例:为什么芯片支持0.8V的工作电压,但EN却又要高达1.25V?
    阿里云GPU计算型gn6v云服务器性能配置|活动优惠价
    拼多多店铺订单API接口(pdd.order.basic.list.get订单基础信息列表查询接口)代码对接教程
    《OpenDRIVE1.6规格文档》2
    idea创建纯净的maven项目简单的maven工程
    LeetCode 2678. 老人的数目【数组】简单
    Conda 环境迁移
    【视觉预训练】《BEIT: BERT Pre-Training of Image Transformers》 ICLR 2022
    PDF转CAD怎么弄?推荐两个转换方法
  • 原文地址:https://blog.csdn.net/u011269801/article/details/126449073