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

  • 相关阅读:
    React中函数式组件与类组件有何不同?
    【计算机网络笔记】网络应用的体系结构
    JDBC学习笔记(2)事务
    详解Java代理
    制作手机IOS苹果ipa应用的重签名工具
    Windows快捷键
    电阻:论“Note”的重要性
    『现学现忘』Git基础 — 3、Git介绍
    【JVM】运行时数据区、程序计数器
    基于PHP+MySQL集训队员管理系统的设计与实现
  • 原文地址:https://blog.csdn.net/u011269801/article/details/126449073