我用unidac5连接 sqlite3分别尝试用 integer 和 text类型储存原boolean类型的字段isimg。
在DELPHI XE3中这样读取uniquery1.FieldByName('isimg').AsBoolean;但报错'Cannot access field 'istrimrule' as type Boolean'查看data.db单元中的asboolean的源码为property AsBoolean: Boolean read GetAsBoolean write SetAsBoolean;
function TField.GetAsBoolean: Boolean;
begin
  raise AccessError('Boolean'); { Do not localize }
end;而tfield的子类如tstringfiled等才有GetAsBoolean的实现函数,因此用text存储时尝试这样写
 tstringfiled(uniquery1.FieldByName('isimg')).asboolean; 但仍然报同样错误。请教该如何操作,asboolean在使用sqlite3时确实无法使用吗?

解决方案 »

  1.   

    弄明白了,sqlite 的TEXT存储类型无论是否设长度,在unidac下都会被转为ftwidememo,即tblobfiled,它没有asbloolean方法。用integer存储类型时,可以用在open之前datatypemap指定字段为boolean类型。最后发现,sqlite里,居然可以用integer\text\blob\real之外的其他类型,被navicat for sqlite误导了,它设计表/导入表时默认不提供其他类型选择,但可以自行输入。