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

  • 相关阅读:
    Java反射机制(一)
    Vue知识点(4)
    Java回顾-集合概述-Collection的使用
    SQL常见函数整理 —— lead()向下偏移
    docker本机启动多台容器导致出现后续容器启动失败
    autohotkey小脚本集合
    SQL->基础->进阶
    Go——一、Go语言安装及介绍
    CentOS7安装Kafka_2.12-3.3.1集群及使用
    Windows 应用商店无法打开解决办法
  • 原文地址:https://blog.csdn.net/u011269801/article/details/126449073