xamarin开发常见错误总结--Sqlite本地数据库使用了保留字段导致语法错误

1.1.1  数据表使用了Sqlite并且字段上使用了Sqlite的保留字段

1.1.1.1 概述

如果使用Sqlite作为本地数据库,创建表的时候,表里的字段使用了Sqlite的保留字段。这个时候直接使用Sql语句进行操作数据库表的时候,就会报错,错误截图如下所示:

1.1.1.1.1        Sqlite保留字段参考链接

https://www.sqlite.org/lang_keywords.html

1.1.1.2 原因分析

使用了保留字段+使用了直接使用Sql语句操作数据库

1.1.1.3 参考链接

https://cloud.tencent.com/developer/ask/49047

1.1.1.4 解决方案

1.1.1.4.1        修改字段名为非保留字段
1.1.1.4.2        使用如下方式描述字段

'keyword'      A keyword in single quotes is a string literal.

"keyword"    A keyword in double-quotes is an identifier.

[keyword]     A keyword enclosed in square brackets is an identifier. This is not standard SQL. This quoting mechanism is used by MS Access and SQL Server and is included in SQLite for compatibility.

`keyword`    A keyword enclosed in grave accents (ASCII code 96) is an identifier. This is not standard SQL. This quoting mechanism is used by MySQL and is included in SQLite for compatibility.

1.1.1.4.3        Dapper操作时推荐使用[keyword]形式

1.1.1.5 总结

之后涉及数据库表的时候,尽量避免使用关键字,这样可以避免好多不必要的麻烦。(例如,给表名或字段名前后添加个性化的前后缀)

posted @ 2021-12-01 10:25  lishidefengchen  阅读(64)  评论(0编辑  收藏  举报