博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【sqlite】错误代码整理
阅读量:7254 次
发布时间:2019-06-29

本文共 3333 字,大约阅读时间需要 11 分钟。

这两天为了一个问题折腾了好久,记载一下。

SQLite语句一定要严格按例子来写,例如:

"CREATE TABLE PunchData (Id Text primary key, Height Float, Angle Float, Radius Float, Strength Float)";

 "INSERT INTO PunchData(Id,Height, Angle, Radius, Strength) VALUES('{0}',{1},{2},{3},{4})";

创建的时候Id是Text类型,插入的时候,{0}要加单引号。。  否则,Id为0123是,通过数据库操作 读取出来后变为123了。

最下面是执行SQLite语句的时候,若出错,出错对应的ErrorCode和Message。

            try

            {
                using (DbCommand cmd = cnn.CreateCommand())
                {
                    cmd.CommandText = string.Format(punchInsertStr, punchData.id, punchData.height.ToString(),
                        punchData.angle.ToString(), punchData.radius.ToString(),
                        punchData.strength.ToString());
                    count = cmd.ExecuteNonQuery();
                }
            }
            catch (SQLiteException ex)
            {
             int  errorCode = (int)ex.ErrorCode;    

            }

//定义错误代码与相应的错误信息

 public readonly Dictionary<int, string> errorMessage = new Dictionary<int, string> {

        { 1, "SQL错误或丢失数据库" }, { 2, "SQLite 内部逻辑错误" },  { 3, "拒绝访问" },
        { 4, "回调函数请求取消操作" }, { 5, "数据库文件被锁定" } ,{ 19, "由于约束违例, 例如编号唯一" } 
        };

//界面上调用 ,返回错误信息

     string ErrorMassage =  errorMessage[errorCode]

附:

#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 */
/* 错误码结束 */

转载于:https://www.cnblogs.com/peterYong/p/6556683.html

你可能感兴趣的文章
高性能图文混排框架,构架顺滑的iOS应用-b
查看>>
windows 下安装使用ipython
查看>>
苹果电脑macbook怎样强制关闭软件
查看>>
Linux下编译LibCURL
查看>>
错误提示:通过 Web 服务器的身份验证的用户无权打开文件系统上的文件
查看>>
python 取两数的百分比
查看>>
1-MSP430点亮一个灯
查看>>
Local System、Local Service與Network Service
查看>>
利用SQL语句查询数据库中所有表
查看>>
虚拟机中的锁优化简介(适应性自旋/锁粗化/锁削除/轻量级锁/偏向锁)
查看>>
Golang的交互模式进阶-读取用户的输入
查看>>
mycat中间件--linux安装mycat1.6版本
查看>>
MySQL的用户管理
查看>>
linux配置java环境变量(详细)
查看>>
HTML CSS + DIV实现整体布局
查看>>
【开源项目】电视盒子好用又强大的APP: TVRemoteIME
查看>>
Java开发报表——Grid++Report 报表设计器
查看>>
三、加载公共语言运行时
查看>>
ABP框架系列之三十五:(MVC-Controllers-MVC控制器)
查看>>
SpringBoot(二)Web整合开发
查看>>