简体   繁体   English

SQLiteAssetHelper升级异常

[英]SQLiteAssetHelper upgrade exception

I have an app using SQLiteAssetHelper. 我有一个使用SQLiteAssetHelper的应用程序。 I'm trying to update its database to include an additional table. 我正在尝试更新其数据库以包括其他表。

All is well except I cannot make the primary key to autoincrement. 一切都很好,只不过我无法将主键设置为自动增量。 Whatever I try gives me an exception. 无论我尝试什么,都会给我一个例外。

I reckon it could be a syntax issue since using INTEGER instead of INT also crashes the app. 我认为这可能是语法问题,因为使用INTEGER而不是INT也会使应用程序崩溃。

Where can I find a reference for the syntax that SQLiteAssetHelper uses? 在哪里可以找到SQLiteAssetHelper使用的语法参考?

Thank you all. 谢谢你们。

The offending script looks as follows: 令人讨厌的脚本如下所示:

CREATE TABLE heat (
_id int PRIMARY KEY AUTOINCREMENT,
amount int,
comment text
);

Even when I get the script to work (is it AUTOINCREMENT or auto_increment ?), insert statements fail to add a value in the _id column. 即使我使脚本可以工作(是AUTOINCREMENT还是auto_increment吗?),insert语句也无法在_id列中添加值。 It is left blank. 它留为空白。

final ContentValues cv = new ContentValues();

cv.put( KEY_AMOUNT, lAmount );
cv.put( KEY_COMMENT, sComment );

final long lId = m_db.insert( TABLE_NAME, null, cv );

Change the database version to upgrade the table 更改数据库版本以升级表

 private static final int DATABASE_VERSION = 1;

 public DatabaseHandler(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

AUTOINCREMENT requires an INTEGER PRIMARY KEY , an INT PRIMARY KEY won't do. AUTOINCREMENT需要INTEGER PRIMARY KEY ,而INT PRIMARY KEY则无效。 Changing that fixed the problem with the SQL you posted. 对此进行更改可以解决您发布的SQL的问题。 If you have other problems, please post the exception message and code that causes it. 如果您还有其他问题,请发布导致异常的异常消息和代码。

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

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