今天收到一个线上问题,用户发送消息一直失败,然后拉取日志查询之后发现是sqlite保存出错了,错误信息如下所示:
[E][2018-12-24 +8.0 14:56:28.729][21394, 1737][:][OrmLiteDao.java, insert, 125][
net.sqlcipher.database.SQLiteDiskIOException: error code 10: disk I/O error
at net.sqlcipher.database.SQLiteStatement.native_execute(Native Method)
at net.sqlcipher.database.SQLiteStatement.executeInsert(SQLiteStatement.java:83)
at com.j256.ormlite.sqlcipher.android.AndroidDatabaseConnection.insert(AndroidDatabaseConnection.java:158)
at com.j256.ormlite.stmt.mapped.MappedCreate.insert(MappedCreate.java:91)
at com.j256.ormlite.stmt.StatementExecutor.create(StatementExecutor.java:450)
at com.j256.ormlite.dao.BaseDaoImpl.create(BaseDaoImpl.java:310)
最终在sqlite官网 https://www.sqlite.org/rescode.html#ioerr 网站看到了关于此问题的描述
(10) SQLITE_IOERR
The SQLITE_IOERR result code says that the operation could not finish because the operating system reported an I/O error.
A full disk drive will normally give an SQLITE_FULL error rather than an SQLITE_IOERR error.
There are many different extended result codes for I/O errors that identify the specific I/O operation that failed.
这个大类的扩展错误码有如下几种:
SQLITE_IOERR_ACCESS (3338)
SQLITE_IOERR_BLOCKED (2826)
SQLITE_IOERR_CHECKRESERVEDLOCK (3594)
SQLITE_IOERR_CLOSE (4106)
SQLITE_IOERR_CONVPATH (6666)
SQLITE_IOERR_DELETE (2570)
SQLITE_IOERR_DELETE_NOENT (5898)
SQLITE_IOERR_DIR_CLOSE (4362)
SQLITE_IOERR_DIR_FSYNC (1290)
SQLITE_IOERR_FSTAT (1802)
SQLITE_IOERR_FSYNC (1034)
SQLITE_IOERR_GETTEMPPATH (6410)
SQLITE_IOERR_LOCK (3850)
SQLITE_IOERR_MMAP (6154)
SQLITE_IOERR_NOMEM (3082)
SQLITE_IOERR_RDLOCK (2314)
SQLITE_IOERR_READ (266)
SQLITE_IOERR_SEEK (5642)
SQLITE_IOERR_SHMLOCK (5130)
SQLITE_IOERR_SHMMAP (5386)
SQLITE_IOERR_SHMOPEN (4618)
SQLITE_IOERR_SHMSIZE (4874)
SQLITE_IOERR_SHORT_READ (522)
SQLITE_IOERR_TRUNCATE (1546)
SQLITE_IOERR_UNLOCK (2058)
SQLITE_IOERR_WRITE (778)
将这些可能的方向试了几个,都没解决,用户不耐烦了,最后祭出了绝招:卸载重装。然后用户恢复正常了,很尴尬,日志信息不全,又不能让用户一个猜测一个猜测的去实验。
PS:这里将尝试解决该问题中,查找到的关于sqlite错误码整理一下,如下所示。
错误码分为 主要错误码和扩展错误码。
现有结果代码的名称和数值是固定且不变的。但是,新的结果代码,尤其是新的扩展结果代码,可能会出现在SQLite的未来版本中。
SQLITE_ABORT (4)
SQLITE_AUTH (23)
SQLITE_BUSY (5)
SQLITE_CANTOPEN (14)
SQLITE_CONSTRAINT (19)
SQLITE_CORRUPT (11)
SQLITE_DONE (101)
SQLITE_EMPTY (16)
SQLITE_ERROR (1)
SQLITE_FORMAT (24)
SQLITE_FULL (13)
SQLITE_INTERNAL (2)
SQLITE_INTERRUPT (9)
SQLITE_IOERR (10)
SQLITE_LOCKED (6)
SQLITE_MISMATCH (20)
SQLITE_MISUSE (21)
SQLITE_NOLFS (22)
SQLITE_NOMEM (7)
SQLITE_NOTADB (26)
SQLITE_NOTFOUND (12)
SQLITE_NOTICE (27)
SQLITE_OK (0)
SQLITE_PERM (3)
SQLITE_PROTOCOL (15)
SQLITE_RANGE (25)
SQLITE_READONLY (8)
SQLITE_ROW (100)
SQLITE_SCHEMA (17)
SQLITE_TOOBIG (18)
链接: https://www.sqlite.org/c3ref/c_abort.html 中定义的
sqlite3.h文件中定义的 一些主要的错误码
#define SQLITE_OK 0 /* Successful result */
/* beginning-of-error-codes */
#define SQLITE_ERROR 1 /* Generic error */
#define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */
#define SQLITE_PERM 3 /* Access permission denied */
#define SQLITE_ABORT 4 /* Callback routine requested an abort */
#define SQLITE_BUSY 5 /* The database file is locked */
#define SQLITE_LOCKED 6 /* A table in the database is locked */
#define SQLITE_NOMEM 7 /* A malloc() failed */
#define SQLITE_READONLY 8 /* Attempt to write a readonly database */
#define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/
#define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */
#define SQLITE_CORRUPT 11 /* The database disk image is malformed */
#define SQLITE_NOTFOUND 12 /* Unknown opcode in sqlite3_file_control() */
#define SQLITE_FULL 13 /* Insertion failed because database is full */
#define SQLITE_CANTOPEN 14 /* Unable to open the database file */
#define SQLITE_PROTOCOL 15 /* Database lock protocol error */
#define SQLITE_EMPTY 16 /* Internal use only */
#define SQLITE_SCHEMA 17 /* The database schema changed */
#define SQLITE_TOOBIG 18 /* String or BLOB exceeds size limit */
#define SQLITE_CONSTRAINT 19 /* Abort due to constraint violation */
#define SQLITE_MISMATCH 20 /* Data type mismatch */
#define SQLITE_MISUSE 21 /* Library used incorrectly */
#define SQLITE_NOLFS 22 /* Uses OS features not supported on host */
#define SQLITE_AUTH 23 /* Authorization denied */
#define SQLITE_FORMAT 24 /* Not used */
#define SQLITE_RANGE 25 /* 2nd parameter to sqlite3_bind out of range */
#define SQLITE_NOTADB 26 /* File opened that is not a database file */
#define SQLITE_NOTICE 27 /* Notifications from sqlite3_log() */
#define SQLITE_WARNING 28 /* Warnings from sqlite3_log() */
#define SQLITE_ROW 100 /* sqlite3_step() has another row ready */
#define SQLITE_DONE 101 /* sqlite3_step() has finished executing */
/* end-of-error-codes */
错误码定义 | 错误码数值 | 错误码中文含义 | 错误码英文含义 |
---|---|---|---|
#define SQLITE_OK | 0 | 成功 | Successful result |
#define SQLITE_ERROR | 1 | SQL错误 或 丢失数据库 | SQL error or missing database |
#define SQLITE_INTERNAL | 2 | SQLite 内部逻辑错误 | Internal logic error in SQLite |
#define SQLITE_PERM | 3 | 拒绝访问 | Access permission denied |
#define SQLITE_ABORT | 4 | 回调函数请求取消操作 | Callback routine requested an abort |
#define SQLITE_BUSY | 5 | 数据库文件被锁定 | The database file is locked |
#define SQLITE_LOCKED | 6 | 数据库中的一个表被锁定 | A table in the database is locked |
#define SQLITE_NOMEM | 7 | 某次 malloc() 函数调用失败 | A malloc() failed |
#define SQLITE_READONLY | 8 | 尝试写入一个只读数据库 | Attempt to write a readonly database |
#define SQLITE_INTERRUPT | 9 | 操作被 sqlite3_interupt() 函数中断 | Operation terminated by sqlite3_interrupt() |
#define SQLITE_IOERR | 10 | 发生某些磁盘 I/O 错误 | Some kind of disk I/O error occurred |
#define SQLITE_CORRUPT | 11 | 数据库磁盘映像不正确 | The database disk image is malformed |
#define SQLITE_NOTFOUND | 12 | sqlite3_file_control() 中出现未知操作数 | Unknown opcode in sqlite3_file_control() |
#define SQLITE_FULL | 13 | 因为数据库满导致插入失败 | Insertion failed because database is full |
#define SQLITE_CANTOPEN | 14 | 无法打开数据库文件 | Unable to open the database file |
#define SQLITE_PROTOCOL | 15 | 数据库锁定协议错误 | Database lock protocol error |
#define SQLITE_EMPTY | 16 | 数据库为空 | Database is empty |
#define SQLITE_SCHEMA | 17 | 数据结构发生改变 | The database schema changed |
#define SQLITE_TOOBIG | 18 | 字符串或二进制数据超过大小限制 | String or BLOB exceeds size limit |
#define SQLITE_CONSTRAINT | 19 | 由于约束违例而取消 (例如:主键约束) | Abort due to constraint violation |
#define SQLITE_MISMATCH | 20 | 数据类型不匹配 | Data type mismatch |
#define SQLITE_MISUSE | 21 | 不正确的库使用 | Library used incorrectly |
#define SQLITE_NOLFS | 22 | 使用了操作系统不支持的功能 | Uses OS features not supported on host |
#define SQLITE_AUTH | 23 | 授权失败 | Authorization denied |
#define SQLITE_FORMAT | 24 | 附加数据库格式错误 | Auxiliary database format error |
#define SQLITE_RANGE | 25 | 传递给sqlite3_bind()的第二个参数超出范围 | 2nd parameter to sqlite3_bind out of range |
#define SQLITE_NOTADB | 26 | 被打开的文件不是一个数据库文件 | File opened that is not a database file |
#define SQLITE_ROW | 100 | sqlite3_step() 已经产生一个行结果 | sqlite3_step() has another row ready |
#define SQLITE_DONE | 101 | sqlite3_step() 完成执行操作 | sqlite3_step() has finished executing |
扩展错误码列表
SQLITE_ABORT_ROLLBACK (516)
SQLITE_BUSY_RECOVERY (261)
SQLITE_BUSY_SNAPSHOT (517)
SQLITE_CANTOPEN_CONVPATH (1038)
SQLITE_CANTOPEN_DIRTYWAL (1294)
SQLITE_CANTOPEN_FULLPATH (782)
SQLITE_CANTOPEN_ISDIR (526)
SQLITE_CANTOPEN_NOTEMPDIR (270)
SQLITE_CONSTRAINT_CHECK (275)
SQLITE_CONSTRAINT_COMMITHOOK (531)
SQLITE_CONSTRAINT_FOREIGNKEY (787)
SQLITE_CONSTRAINT_FUNCTION (1043)
SQLITE_CONSTRAINT_NOTNULL (1299)
SQLITE_CONSTRAINT_PRIMARYKEY (1555)
SQLITE_CONSTRAINT_ROWID (2579)
SQLITE_CONSTRAINT_TRIGGER (1811)
SQLITE_CONSTRAINT_UNIQUE (2067)
SQLITE_CONSTRAINT_VTAB (2323)
SQLITE_CORRUPT_SEQUENCE (523)
SQLITE_CORRUPT_VTAB (267)
SQLITE_ERROR_MISSING_COLLSEQ (257)
SQLITE_ERROR_RETRY (513)
SQLITE_ERROR_SNAPSHOT (769)
SQLITE_IOERR_ACCESS (3338)
SQLITE_IOERR_BLOCKED (2826)
SQLITE_IOERR_CHECKRESERVEDLOCK (3594)
SQLITE_IOERR_CLOSE (4106)
SQLITE_IOERR_CONVPATH (6666)
SQLITE_IOERR_DELETE (2570)
SQLITE_IOERR_DELETE_NOENT (5898)
SQLITE_IOERR_DIR_CLOSE (4362)
SQLITE_IOERR_DIR_FSYNC (1290)
SQLITE_IOERR_FSTAT (1802)
SQLITE_IOERR_FSYNC (1034)
SQLITE_IOERR_GETTEMPPATH (6410)
SQLITE_IOERR_LOCK (3850)
SQLITE_IOERR_MMAP (6154)
SQLITE_IOERR_NOMEM (3082)
SQLITE_IOERR_RDLOCK (2314)
SQLITE_IOERR_READ (266)
SQLITE_IOERR_SEEK (5642)
SQLITE_IOERR_SHMLOCK (5130)
SQLITE_IOERR_SHMMAP (5386)
SQLITE_IOERR_SHMOPEN (4618)
SQLITE_IOERR_SHMSIZE (4874)
SQLITE_IOERR_SHORT_READ (522)
SQLITE_IOERR_TRUNCATE (1546)
SQLITE_IOERR_UNLOCK (2058)
https://www.sqlite.org/c3ref/c_abort_rollback.html 定义了扩展错误码
sqlite3.h文件中定义的 一些扩展错误码
#define SQLITE_ERROR_MISSING_COLLSEQ (SQLITE_ERROR | (1<<8))
#define SQLITE_ERROR_RETRY (SQLITE_ERROR | (2<<8))
#define SQLITE_ERROR_SNAPSHOT (SQLITE_ERROR | (3<<8))
#define SQLITE_IOERR_READ (SQLITE_IOERR | (1<<8))
#define SQLITE_IOERR_SHORT_READ (SQLITE_IOERR | (2<<8))
#define SQLITE_IOERR_WRITE (SQLITE_IOERR | (3<<8))
#define SQLITE_IOERR_FSYNC (SQLITE_IOERR | (4<<8))
#define SQLITE_IOERR_DIR_FSYNC (SQLITE_IOERR | (5<<8))
#define SQLITE_IOERR_TRUNCATE (SQLITE_IOERR | (6<<8))
#define SQLITE_IOERR_FSTAT (SQLITE_IOERR | (7<<8))
#define SQLITE_IOERR_UNLOCK (SQLITE_IOERR | (8<<8))
#define SQLITE_IOERR_RDLOCK (SQLITE_IOERR | (9<<8))
#define SQLITE_IOERR_DELETE (SQLITE_IOERR | (10<<8))
#define SQLITE_IOERR_BLOCKED (SQLITE_IOERR | (11<<8))
#define SQLITE_IOERR_NOMEM (SQLITE_IOERR | (12<<8))
#define SQLITE_IOERR_ACCESS (SQLITE_IOERR | (13<<8))
#define SQLITE_IOERR_CHECKRESERVEDLOCK (SQLITE_IOERR | (14<<8))
#define SQLITE_IOERR_LOCK (SQLITE_IOERR | (15<<8))
#define SQLITE_IOERR_CLOSE (SQLITE_IOERR | (16<<8))
#define SQLITE_IOERR_DIR_CLOSE (SQLITE_IOERR | (17<<8))
#define SQLITE_IOERR_SHMOPEN (SQLITE_IOERR | (18<<8))
#define SQLITE_IOERR_SHMSIZE (SQLITE_IOERR | (19<<8))
#define SQLITE_IOERR_SHMLOCK (SQLITE_IOERR | (20<<8))
#define SQLITE_IOERR_SHMMAP (SQLITE_IOERR | (21<<8))
#define SQLITE_IOERR_SEEK (SQLITE_IOERR | (22<<8))
#define SQLITE_IOERR_DELETE_NOENT (SQLITE_IOERR | (23<<8))
#define SQLITE_IOERR_MMAP (SQLITE_IOERR | (24<<8))
#define SQLITE_IOERR_GETTEMPPATH (SQLITE_IOERR | (25<<8))
#define SQLITE_IOERR_CONVPATH (SQLITE_IOERR | (26<<8))
#define SQLITE_IOERR_VNODE (SQLITE_IOERR | (27<<8))
#define SQLITE_IOERR_AUTH (SQLITE_IOERR | (28<<8))
#define SQLITE_IOERR_BEGIN_ATOMIC (SQLITE_IOERR | (29<<8))
#define SQLITE_IOERR_COMMIT_ATOMIC (SQLITE_IOERR | (30<<8))
#define SQLITE_IOERR_ROLLBACK_ATOMIC (SQLITE_IOERR | (31<<8))
#define SQLITE_LOCKED_SHAREDCACHE (SQLITE_LOCKED | (1<<8))
#define SQLITE_LOCKED_VTAB (SQLITE_LOCKED | (2<<8))
#define SQLITE_BUSY_RECOVERY (SQLITE_BUSY | (1<<8))
#define SQLITE_BUSY_SNAPSHOT (SQLITE_BUSY | (2<<8))
#define SQLITE_CANTOPEN_NOTEMPDIR (SQLITE_CANTOPEN | (1<<8))
#define SQLITE_CANTOPEN_ISDIR (SQLITE_CANTOPEN | (2<<8))
#define SQLITE_CANTOPEN_FULLPATH (SQLITE_CANTOPEN | (3<<8))
#define SQLITE_CANTOPEN_CONVPATH (SQLITE_CANTOPEN | (4<<8))
#define SQLITE_CANTOPEN_DIRTYWAL (SQLITE_CANTOPEN | (5<<8)) /* Not Used */
#define SQLITE_CORRUPT_VTAB (SQLITE_CORRUPT | (1<<8))
#define SQLITE_CORRUPT_SEQUENCE (SQLITE_CORRUPT | (2<<8))
#define SQLITE_READONLY_RECOVERY (SQLITE_READONLY | (1<<8))
#define SQLITE_READONLY_CANTLOCK (SQLITE_READONLY | (2<<8))
#define SQLITE_READONLY_ROLLBACK (SQLITE_READONLY | (3<<8))
#define SQLITE_READONLY_DBMOVED (SQLITE_READONLY | (4<<8))
#define SQLITE_READONLY_CANTINIT (SQLITE_READONLY | (5<<8))
#define SQLITE_READONLY_DIRECTORY (SQLITE_READONLY | (6<<8))
#define SQLITE_ABORT_ROLLBACK (SQLITE_ABORT | (2<<8))
#define SQLITE_CONSTRAINT_CHECK (SQLITE_CONSTRAINT | (1<<8))
#define SQLITE_CONSTRAINT_COMMITHOOK (SQLITE_CONSTRAINT | (2<<8))
#define SQLITE_CONSTRAINT_FOREIGNKEY (SQLITE_CONSTRAINT | (3<<8))
#define SQLITE_CONSTRAINT_FUNCTION (SQLITE_CONSTRAINT | (4<<8))
#define SQLITE_CONSTRAINT_NOTNULL (SQLITE_CONSTRAINT | (5<<8))
#define SQLITE_CONSTRAINT_PRIMARYKEY (SQLITE_CONSTRAINT | (6<<8))
#define SQLITE_CONSTRAINT_TRIGGER (SQLITE_CONSTRAINT | (7<<8))
#define SQLITE_CONSTRAINT_UNIQUE (SQLITE_CONSTRAINT | (8<<8))
#define SQLITE_CONSTRAINT_VTAB (SQLITE_CONSTRAINT | (9<<8))
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
扩展错误码太多,也不常遇到,这里就不翻译了,具体查看链接:https://www.sqlite.org/rescode.html
作者:欧阳鹏 欢迎转载,与人分享是进步的源泉!
转载请保留原文地址:https://blog.csdn.net/qq446282412/article/details/85235154
☞ 本人QQ: 3024665621
☞ QQ交流群: 123133153
☞ github.com/ouyangpeng
☞ [email protected]
如果本文对您有所帮助,欢迎您扫码下图所示的支付宝和微信支付二维码对本文进行打赏。