gpt4 book ai didi

c++ - Qt 5.9.1 SQLite Vacuum 出错?

转载 作者:行者123 更新时间:2023-11-28 01:46:23 30 4
gpt4 key购买 nike

你好,我在 Qt C++ 中有一个小应用程序/SQLite 在 Qt 5.6.2 上运行良好,我确实升级到 Qt 5.9.1,问题是当我尝试 VACUUM 我的数据库时出现运行时错误请注意,除了 vacuum 之外,所有查询都有效 :( 并且它在 Qt 5.6.2 上正常工作

相关代码

QString msql::sqlExec(QString sqlCmd)
{
query->clear();
QString value;

if (!query->exec(sqlCmd))
{
mDebug() << sqlCmd << query->lastError().text();
}
else if (!query->first())
{
//mDebug() << "not valid query: " << sqlCmd << query->isSelect();
mDebug() << query->lastError().text();
return "";
}
else
{
value = query->value(0).toString();
}
query->finish();
return value;
}

bool msql::vacuum()
{
QStringList tables = db.tables(QSql::AllTables);
int x = 1;
int y = tables.count();
foreach (QString table, tables)
{
sqlExec(QString("VACUUM `%1`").arg(table));
emit progress(QString("Optimizing table %1/%2:%3").arg(x).arg(y).arg(table));
if (killLoopFlag_)
return false;
x++;
}
return true;
}

我得到这个错误


Debug:[2017-07-17 02:51 AM] "VACUUM `visits`" "unknown database `visits` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString) 
Debug:[2017-07-17 02:51 AM] "VACUUM `investigations`" "unknown database `investigations` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `credentials`" "unknown database `credentials` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `siblings`" "unknown database `siblings` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `surgicalNotes`" "unknown database `surgicalNotes` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `metadata`" "unknown database `metadata` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `drugs`" "unknown database `drugs` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `deceased`" "unknown database `deceased` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `visitPrices`" "unknown database `visitPrices` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `conditions`" "unknown database `conditions` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `conditions_patients`" "unknown database `conditions_patients` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `perinatal`" "unknown database `perinatal` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `development`" "unknown database `development` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `obgyn`" "unknown database `obgyn` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `patients`" "unknown database `patients` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `agendaView`" "unknown database `agendaView` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `registerView`" "unknown database `registerView` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `sqlite_master`" "unknown database `sqlite_master` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `SERVICES`" "unknown database `SERVICES` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `defaultDoses`" "unknown database `defaultDoses` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `allergies`" "unknown database `allergies` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `complaints`" "unknown database `complaints` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `diagnoses`" "unknown database `diagnoses` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `dictionary`" "unknown database `dictionary` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `doses`" "unknown database `doses` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `surgeries`" "unknown database `surgeries` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `investigations`" "unknown database `investigations` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `jobs`" "unknown database `jobs` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `places`" "unknown database `places` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `placeOfBirth`" "unknown database `placeOfBirth` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `expander`" "unknown database `expander` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `drugs`" "unknown database `drugs` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `diet`" "unknown database `diet` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `sqlite_master`" "unknown database `sqlite_master` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `drugsIndex`" "unknown database `drugsIndex` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `metadata`" "unknown database `metadata` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)
Debug:[2017-07-17 02:51 AM] "VACUUM `sqlite_master`" "unknown database `sqlite_master` Unable to execute statement" (..\qtemr\msql.cpp:16) class QString __thiscall msql::sqlExec(class QString)

最佳答案

VACUUM 不应用于特定表,而是应用于整个数据库。您过去常常附加被 VACUUM 命令忽略的表名。自升级 Qt 以来,您也升级了 SQLite 驱动程序。来自SQLite site :

Compatibility Warning: The ability to vacuum attached databases was added in version 3.15.0 (2016-10-14). Prior to that, a schema-name added to the VACUUM statement would be silently ignored and the "main" schema would be vacuumed.

这里的“Schema-name”是数据库的名称。所以你可以只保留一个字符串

sqlExec("VACUUM");

关于c++ - Qt 5.9.1 SQLite Vacuum 出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44895506/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com