我有一个带有数据库的应用程序,它是使用标准 SQLiteOpenHelper 创建和打开的。
每当我升级数据库版本时,我也会升级应用程序的版本代码,所以数据库没有办法下降(数据库版本号总是增加,从不减少)。
我通过将 android:allowBackup 属性设置为 false 在我的应用程序中禁用了数据库备份。
但是当我在 Play 商店升级应用程序时,我遇到了很多崩溃
Can't downgrade database from version
nton-1
96% 的崩溃发生在运行 .任何人都知道为什么会出现此问题,更重要的是如何防止此崩溃?
我知道我可以覆盖 onDowngrade 以防止崩溃,但我实际上不明白为什么要调用 onDowngrade,因为崩溃是在始终使用最新版本数据库的应用程序上调用的。
编辑:添加代码示例,FWIW
我的 OpenHelper:
public class MyDBHelper extends SQLiteOpenHelper {
private static final String LOG_TAG = MyDBHelper.class.getName();
public static final String DB_NAME = "my_db";
public static final int DB_V1 = 1;
public static final int DB_V2_UNIQUE_IDS = 2;
public static final int DB_V3_METADATAS = 3;
public static final int DB_V4_CORRUPTED_IDS = 4;
public static final int DB_V5_USAGE_TABLE = 5;
public static final int DB_VERSION = DB_V5_USAGE_TABLE;
public MyDBHelper(final Context context, IExceptionLogger logger) {
super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(final SQLiteDatabase db) {
Debug.log_d(DebugConfig.DEFAULT, LOG_TAG, "onCreate()");
db.execSQL(createMyTable());
}
@Override
public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
Debug.log_d(DebugConfig.DEFAULT, LOG_TAG, "onUpgrade(): oldVersion = " + oldVersion + " : newVersion = " + newVersion);
if (oldVersion < 2) {
Debug.log_d(DebugConfig.DEFAULT, LOG_TAG, "onUpgrade(): upgrading version 1 table to version 2");
db.execSQL(upgradeTable_v1_to_v2());
}
if (oldVersion < 3) {
Debug.log_d(DebugConfig.DEFAULT, LOG_TAG, "onUpgrade(): upgrading version 2 Entry table to version 3");
db.execSQL(upgradeTable_v2_to_v3());
}
}
@Override
@TargetApi(Build.VERSION_CODES.FROYO)
public void onDowngrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) {
Debug.log_d(DebugConfig.DEFAULT, LOG_TAG, "onDowngrade(): oldVersion = " + oldVersion + " : newVersion = " + newVersion);
super.onDowngrade(db, oldVersion, newVersion);
}
}
以及我如何初始化它:
public class DatabaseController {
private MyDBHelper mDBHelper;
public void initialize(final Context context) {
mDBHelper = new MyDBHelper(context);
}
}
最佳答案
这是 SQLiteOpenHelper.onDowngrade(...) 的默认实现:
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
throw new SQLiteException("Can't downgrade database from version " +
oldVersion + " to " + newVersion);
}
如您所见,如果您调用 super.onDowngrade(...),您将获得该异常。你需要自己实现onDowngrade,而不是调用super.onDowngrade。为了完整性,它应该始终被实现,因为不能保证它何时会被调用——用户已经更改为使用旧版本的应用程序听起来很奇怪,但可能会出现这样的情况。您知道异常来自哪个版本的应用程序吗?
关于android - 无法在三星上将数据库从版本 `n` 降级到 `n-1`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43200408/
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我对最新版本的Rails有疑问。我创建了一个新应用程序(railsnewMyProject),但我没有脚本/生成,只有脚本/rails,当我输入ruby./script/railsgeneratepluginmy_plugin"Couldnotfindgeneratorplugin.".你知道如何生成插件模板吗?没有这个命令可以创建插件吗?PS:我正在使用Rails3.2.1和ruby1.8.7[universal-darwin11.0] 最佳答案 随着Rails3.2.0的发布,插件生成器已经被移除。查看变更日志here.现在
我尝试运行2.x应用程序。我使用rvm并为此应用程序设置其他版本的ruby:$rvmuseree-1.8.7-head我尝试运行服务器,然后出现很多错误:$script/serverNOTE:Gem.source_indexisdeprecated,useSpecification.Itwillberemovedonorafter2011-11-01.Gem.source_indexcalledfrom/Users/serg/rails_projects_terminal/work_proj/spohelp/config/../vendor/rails/railties/lib/r
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我正在尝试修改当前依赖于定义为activeresource的gem:s.add_dependency"activeresource","~>3.0"为了让gem与Rails4一起工作,我需要扩展依赖关系以与activeresource的版本3或4一起工作。我不想简单地添加以下内容,因为它可能会在以后引起问题:s.add_dependency"activeresource",">=3.0"有没有办法指定可接受版本的列表?~>3.0还是~>4.0? 最佳答案 根据thedocumentation,如果你想要3到4之间的所有版本,你可以这
我在pry中定义了一个函数:to_s,但我无法调用它。这个方法去哪里了,怎么调用?pry(main)>defto_spry(main)*'hello'pry(main)*endpry(main)>to_s=>"main"我的ruby版本是2.1.2看了一些答案和搜索后,我认为我得到了正确的答案:这个方法用在什么地方?在irb或pry中定义方法时,会转到Object.instance_methods[1]pry(main)>defto_s[1]pry(main)*'hello'[1]pry(main)*end=>:to_s[2]pry(main)>defhello[2]pry(main)
我使用的是Firefox版本36.0.1和Selenium-Webdrivergem版本2.45.0。我能够创建Firefox实例,但无法使用脚本继续进行进一步的操作无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055)错误。有人能帮帮我吗? 最佳答案 我遇到了同样的问题。降级到firefoxv33后一切正常。您可以找到旧版本here 关于ruby-无法在60秒内获得稳定的Firefox连接(127.0.0.1:7055),我们在StackOverflow上找到一个类