关于 SQLite

官方文档:SQLite Home Page

自增主键

自增主键必须是 INTEGER PRIMARY KEYINT PRIMARY KEY 都不行。

1
2
3
4
5
6
7
Caused by: org.sqlite.SQLiteException: [SQLITE_ERROR] SQL error or missing database (AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY)
at org.sqlite.core.DB.newSQLException(DB.java:1010)
at org.sqlite.core.DB.newSQLException(DB.java:1022)
at org.sqlite.core.DB.throwex(DB.java:987)
at org.sqlite.core.NativeDB._exec_utf8(NativeDB.java)
at org.sqlite.core.NativeDB._exec(NativeDB.java:94)
at org.sqlite.jdbc3.JDBC3Statement.executeUpdate(JDBC3Statement.java:109)

详细可参考:CREATE TABLE

With one exception noted below, if a rowid table has a primary key that consists of a single column and the declared type of that column is “INTEGER” in any mixture of upper and lower case, then the column becomes an alias for the rowid. Such a column is usually referred to as an “integer primary key”. A PRIMARY KEY column only becomes an integer primary key if the declared type name is exactly “INTEGER”. Other integer type names like “INT” or “BIGINT” or “SHORT INTEGER” or “UNSIGNED INTEGER” causes the primary key column to behave as an ordinary table column with integer affinity and a unique index, not as an alias for the rowid.

拓展

Zepo/GYDataCenter: An alternative to Core Data for people who like using SQLite directly.

参考资料

  1. Sqlite 基本概念及使用概述