• 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();
    }

  • 相关阅读:
    数据挖掘note(赵老师语录)
    时间管理的本质,是少做事情
    Rust 最常用函数
    一种非线性权重的自适应鲸鱼优化算法IMWOA附matlab代码
    机器学习实战读书笔记——端到端的机器学习项目
    linux系统编程 (四) gdb调试与makefile
    YOLOV8 进行docker环境配置
    Python中的并发编程(5)PyQt 多线程
    【Vue3响应式原理#02】Proxy and Reflect
    生产制造企业仓库管理不到位?ERP系统帮你解决
  • 原文地址:https://blog.csdn.net/u011269801/article/details/126449073