简体   繁体   English

无法使用SQLiteAssetHelper更新android中的数据库

[英]Unable to update database in android using SQLiteAssetHelper

I'm using SQLiteAssetHelper. 我正在使用SQLiteAssetHelper。 I tried to upgrade the database by adding few insertions into the testdb.db file then according to instructions on https://github.com/jgilfelt/android-sqlite-asset-helper I renamed this new file to testdb.db_upgrade_1-2.sql and added to the asset folder in the android app. 我尝试通过在testdb.db文件中添加少量插入内容来升级数据库,然后根据https://github.com/jgilfelt/android-sqlite-asset-helper上的说明进行操作,我将此新文件重命名为testdb.db_upgrade_1-2。 sql并添加到android应用中的asset文件夹中。 I changed the database version to 2 in the Databasehandler, but still there is an error as shown in the stacktrace which is as follows 我在Databasehandler中将数据库版本更改为2,但是仍然出现如下堆栈跟踪所示的错误

I/SQLiteAssetHelper: successfully opened database testdb.db
W/SQLiteAssetHelper: Upgrading database testdb.db from version 1 to 2...
W/SQLiteAssetHelper: processing upgrade: databases/testdb.db_upgrade_1-2.sql
E/SQLiteLog: (1) near "SQLite": syntax error
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main

After this the app crashes. 此后,应用程序崩溃。

My asset folder contains both /databases/testdb.db and /databases/testdb.db_upgrade_1-2.sql 我的资产文件夹同时包含/databases/testdb.db和/databases/testdb.db_upgrade_1-2.sql

I'm using sqlite3 on my computer to generate the database file 我在计算机上使用sqlite3生成数据库文件

I renamed this new file to testdb.db_upgrade_1-2.sql 我将此新文件重命名为testdb.db_upgrade_1-2.sql

That is incorrect. 那是不对的。 testdb.db_upgrade_1-2.sql is supposed to be a text file containing SQL statements to apply to your schema v1 database to convert it into a schema v2 database. testdb.db_upgrade_1-2.sql应该是包含SQL语句的文本文件,该文本将应用于您的架构v1数据库以将其转换为架构v2数据库。

Quoting the documentation , with emphasis added: 引用文档 ,重点是:

Update the initial SQLite database in the project's assets/databases directory with the changes and create a text file containing all required SQL commands to upgrade the database from its previous version to it's current version and place it in the same folder. 使用更改更新项目资产/数据库目录中的初始SQLite数据库,并创建一个包含所有必需SQL命令的文本文件,以将数据库从以前的版本升级到当前版本并将其放置在同一文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM