Sqlite - constraint failed[0x1555]: UNIQUE constraint failed

  执行插入操作时,出现异常constraint failed[0x1555]: UNIQUE constraint failed

  意思是:sqlite 唯一约束失败

  定位于某个表字段上,该字段是表的主键。

  原因:插入的数据中该主键字段值在表中已有存在的记录。

  解决方案:重新调整插入语句中该主键字段的值,保证约束唯一性。

 

  在SQLite中,执行SQL语句的sqlite3_exec()和sqlite3_prepare()两个核心方法的返回值都是一个整型数据,因此,当程序执行出现错误时,我们可以根据执行返回的整型数据来判断错误发生的原因。以下就是SQLite的错误码:

 

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 
#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 ite3_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 ite3_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 */

转载于:https://www.cnblogs.com/MakeView660/p/8488759.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值