Retrieving SQLite Pragma user_version with Golang

huangapple go评论63阅读模式
英文:

Retrieving SQLite Pragma user_version with Golang

问题

这是我第一次使用SQLite的项目,为了实现半自动模式迁移,我想使用许多其他stackoverflow答案中提到的user_version pragma。

我正在尝试在Golang中实现这个功能,但不确定是应该使用Exec、Query还是类似的方法来获取结果,然后如何将其转换为可用的形式。

在sqlite3中,我可以运行'PRAGMA user_version;',它将返回我设置的值,比如3。

英文:

This is the first project where I've used SQLite and in an attempt to do semi-automatic schema migration I would like to use the user_version pragma that has been suggested by many other answers on stackoverflow.

I am attempting to do this in Golang but am unsure if I should be using Exec, Query, or something similar to get this result and then how to render it into something usable.

within sqlite3 I can run 'PRAGMA user_version;' and it will return 3 or whatever value I have it set to.

答案1

得分: 1

当你使用PRAGMA user_version来读取值时,这个语句的行为与查询完全相同,即SELECT user_version FROM somewhere
所以只需使用Query()

英文:

When you are using PRAGMA user_version to read the value, this statement behaves exactly like a query, i.e., SELECT user_version FROM somewhere.
So just use Query().

huangapple
  • 本文由 发表于 2017年1月14日 11:53:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/41646639.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定