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 */


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM