为SQLite编写验证层的最佳方法是什么

Ram*_*der 3 .net c# sqlite

我正在使用SQLite的ADO.net提供程序.我想引导SQLite的一些"功能",比如允许整数字段中的字符串,并允许在varchar(n)类型的字段中使用长于n的字符串.实现这种验证的最佳方法是什么?存储过程?触发?我正在寻找适用于任何数据库而不仅仅是我的数据库模式的通用解决方案.

tui*_*oel 5

您可以添加列约束.

create table example
( 
  age integer not null check (typeof(age)='integer'),
  name text not null check (length(name) between 1 and 100),
  salary integer check (salary is null or typeof(salary)='integer')
)
Run Code Online (Sandbox Code Playgroud)