QSqlite 的变化

发布于 2024-10-25 21:43:24 字数 1201 浏览 3 评论 0原文

我的团队之前使用 Qt 4.3,正在尝试更新到最新版本 (4.7.2)。

之前我们使用的是 qsqlite 插件,但此功能已移至 Qt 的主要 QSql 组件中。

现在我们已经升级了,我们无法读取旧数据库。这似乎是因为当我们创建表时,我们是这样创建的:

CREATE TABLE [Characters] ([Id] INTEGER NOT NULL ON CONFLICT ROLLBACK PRIMARY KEY ON CONFLICT ROLLBACK AUTOINCREMENT UNIQUE ON CONFLICT ROLLBACK, [Project_Id] INTEGER NOT NULL ON CONFLICT ROLLBACK REFERENCES [Projects](Id) ON DELETE RESTRICT ON UPDATE RESTRICT ON INSERT RESTRICT, [CharacterName] VARCHAR(128) NOT NULL ON CONFLICT ROLLBACK UNIQUE ON CONFLICT ROLLBACK);

但是 ON INSERT RESTRICT 不再有效。

我能够删除该代码并创建新表,但如果我在现有数据库之一上执行 myQSqlDatabase.tables() ,它会返回零。

通过深入研究 Qt 代码,我注意到准备方法具有:

#if (SQLITE_VERSION_NUMBER >= 3003011)
    int res = sqlite3_prepare16_v2(d->access, query.constData(), (query.size() + 1) * sizeof(QChar), &d->stmt, 0);
#else
    int res = sqlite3_prepare16(d->access, query.constData(), (query.size() + 1) * sizeof(QChar), &d->stmt, 0);
#endif

并且我们正在输入第一个 if (sqlite3_prepare16_v2)。

我们是否应该在某个地方将 SQLITE_VERSION_NUMBER 定义得更低?我们是否还做错了什么来阻止向后兼容性?

任何帮助将不胜感激。

谢谢, 利隆

My team were previously using Qt 4.3 and are trying to update to the latest release (4.7.2).

Before we were using the qsqlite plugin, but this functionality has been moved into the main QSql component of Qt.

Now that we have upgraded, we're unable to read our old databases. This seems to be because when we created our tables, we created them like this:

CREATE TABLE [Characters] ([Id] INTEGER NOT NULL ON CONFLICT ROLLBACK PRIMARY KEY ON CONFLICT ROLLBACK AUTOINCREMENT UNIQUE ON CONFLICT ROLLBACK, [Project_Id] INTEGER NOT NULL ON CONFLICT ROLLBACK REFERENCES [Projects](Id) ON DELETE RESTRICT ON UPDATE RESTRICT ON INSERT RESTRICT, [CharacterName] VARCHAR(128) NOT NULL ON CONFLICT ROLLBACK UNIQUE ON CONFLICT ROLLBACK);

but ON INSERT RESTRICT is no longer valid.

I was able to remove that code and create new tables, but if I do myQSqlDatabase.tables() on one of the existing DBs, it returns zero.

I noticed by digging into the Qt code, that the prepare method has:

#if (SQLITE_VERSION_NUMBER >= 3003011)
    int res = sqlite3_prepare16_v2(d->access, query.constData(), (query.size() + 1) * sizeof(QChar), &d->stmt, 0);
#else
    int res = sqlite3_prepare16(d->access, query.constData(), (query.size() + 1) * sizeof(QChar), &d->stmt, 0);
#endif

and we are entering the first if (sqlite3_prepare16_v2).

Should we be defining SQLITE_VERSION_NUMBER somewhere to be lower? Is there something else that we're doing wrong to prevent backwards compatibility?

Any help would be appreciated.

Thanks,
Liron

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

欢烬 2024-11-01 21:43:24

从作者网站下载的 sqlite 附带一个命令行程序。
如果您的数据库不兼容,您可以轻松使用它将数据导出到文本文件并将其加载到新数据库中。

sqlite as downloaded from the authors website comes with a command line program.
If your database isn't compatible you can easily use it to export your data to a text file and load it into your new database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文