我想使用 Qt 的 QSqlQuery 获取 sqlite pragma 的当前状态。但是我没有从程序中获得某些值的结果,而是从 sqlite 控制台获得结果。Qt 版本 5.2.1、Sqlite 版本 3.8.4.3、Windows 7、Ubuntu 12.4 LTS
输出:
application_id = "0"
auto_vacuum = "0"
automatic_index = "1"
busy_timeout = "5000"
cache_size = "2000"
cache_spill = [NoResult]
case_sensitive_like = [NoResult]
void MySqliteInfo::PrintState(QString state)
{
printf("%s = ", state.toStdString().c_str());
QSqlQuery query(*m_db);
query.prepare(QString("PRAGMA %1").arg(state));
query.exec();
if(0 == query.size()) {
printf("%s returns nothing\n", state.toStdString().c_str());
}
else {
if(query.next()) {
QVariant value = query.value(0);
if(value.canConvert(QMetaType::QString)) {
printf("\"%s\"\n", value.toString().toStdString().c_str());
}
else {
printf("[UnknownDataType]\n");
}
}
else {
printf("[NoResult]\n");
}
}
query.finish();
}
PrintState("application_id");
PrintState("auto_vacuum");
PrintState("automatic_index");
PrintState("busy_timeout");
PrintState("cache_size");
PrintState("cache_spill");
PrintState("case_sensitive_like");