QSqlite 的变化
我的团队之前使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从作者网站下载的 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.