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 總結

之後涉及數據庫表的時候,儘量避免使用關鍵字,這樣可以避免好多不必要的麻煩。(例如,給表名或字段名前後添加個性化的前後綴)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章