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